Add LookupBlockIndex function
This commit is contained in:
@@ -359,9 +359,10 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
|
||||
if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) == merkleBlock.header.hashMerkleRoot) {
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
if (!mapBlockIndex.count(merkleBlock.header.GetHash()) || !chainActive.Contains(mapBlockIndex[merkleBlock.header.GetHash()]))
|
||||
const CBlockIndex* pindex = LookupBlockIndex(merkleBlock.header.GetHash());
|
||||
if (!pindex || !chainActive.Contains(pindex)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found in chain");
|
||||
}
|
||||
|
||||
std::vector<uint256>::const_iterator it;
|
||||
if ((it = std::find(vMatch.begin(), vMatch.end(), hashTx))==vMatch.end()) {
|
||||
|
||||
@@ -95,7 +95,7 @@ void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry)
|
||||
{
|
||||
entry.pushKV("blockhash", wtx.hashBlock.GetHex());
|
||||
entry.pushKV("blockindex", wtx.nIndex);
|
||||
entry.pushKV("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime());
|
||||
entry.pushKV("blocktime", LookupBlockIndex(wtx.hashBlock)->GetBlockTime());
|
||||
} else {
|
||||
entry.pushKV("trusted", wtx.IsTrusted());
|
||||
}
|
||||
@@ -2014,11 +2014,10 @@ UniValue listsinceblock(const JSONRPCRequest& request)
|
||||
uint256 blockId;
|
||||
|
||||
blockId.SetHex(request.params[0].get_str());
|
||||
BlockMap::iterator it = mapBlockIndex.find(blockId);
|
||||
if (it == mapBlockIndex.end()) {
|
||||
paltindex = pindex = LookupBlockIndex(blockId);
|
||||
if (!pindex) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||
}
|
||||
paltindex = pindex = it->second;
|
||||
if (chainActive[pindex->nHeight] != pindex) {
|
||||
// the block being asked for is a part of a deactivated chain;
|
||||
// we don't want to depend on its perceived height in the block
|
||||
|
||||
+15
-15
@@ -1148,11 +1148,9 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
|
||||
int conflictconfirms = 0;
|
||||
if (mapBlockIndex.count(hashBlock)) {
|
||||
CBlockIndex* pindex = mapBlockIndex[hashBlock];
|
||||
if (chainActive.Contains(pindex)) {
|
||||
conflictconfirms = -(chainActive.Height() - pindex->nHeight + 1);
|
||||
}
|
||||
CBlockIndex* pindex = LookupBlockIndex(hashBlock);
|
||||
if (pindex && chainActive.Contains(pindex)) {
|
||||
conflictconfirms = -(chainActive.Height() - pindex->nHeight + 1);
|
||||
}
|
||||
// If number of conflict confirms cannot be determined, this means
|
||||
// that the block is still unknown or not yet part of the main chain,
|
||||
@@ -3768,10 +3766,10 @@ void CWallet::GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) c
|
||||
for (const auto& entry : mapWallet) {
|
||||
// iterate over all wallet transactions...
|
||||
const CWalletTx &wtx = entry.second;
|
||||
BlockMap::const_iterator blit = mapBlockIndex.find(wtx.hashBlock);
|
||||
if (blit != mapBlockIndex.end() && chainActive.Contains(blit->second)) {
|
||||
CBlockIndex* pindex = LookupBlockIndex(wtx.hashBlock);
|
||||
if (pindex && chainActive.Contains(pindex)) {
|
||||
// ... which are already in a block
|
||||
int nHeight = blit->second->nHeight;
|
||||
int nHeight = pindex->nHeight;
|
||||
for (const CTxOut &txout : wtx.tx->vout) {
|
||||
// iterate over all their outputs
|
||||
CAffectedKeysVisitor(*this, vAffected).Process(txout.scriptPubKey);
|
||||
@@ -3779,7 +3777,7 @@ void CWallet::GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) c
|
||||
// ... and all their affected keys
|
||||
std::map<CKeyID, CBlockIndex*>::iterator rit = mapKeyFirstBlock.find(keyid);
|
||||
if (rit != mapKeyFirstBlock.end() && nHeight < rit->second->nHeight)
|
||||
rit->second = blit->second;
|
||||
rit->second = pindex;
|
||||
}
|
||||
vAffected.clear();
|
||||
}
|
||||
@@ -3816,7 +3814,12 @@ unsigned int CWallet::ComputeTimeSmart(const CWalletTx& wtx) const
|
||||
{
|
||||
unsigned int nTimeSmart = wtx.nTimeReceived;
|
||||
if (!wtx.hashUnset()) {
|
||||
if (mapBlockIndex.count(wtx.hashBlock)) {
|
||||
const CBlockIndex* pindex = nullptr;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
pindex = LookupBlockIndex(wtx.hashBlock);
|
||||
}
|
||||
if (pindex) {
|
||||
int64_t latestNow = wtx.nTimeReceived;
|
||||
int64_t latestEntry = 0;
|
||||
|
||||
@@ -3847,7 +3850,7 @@ unsigned int CWallet::ComputeTimeSmart(const CWalletTx& wtx) const
|
||||
}
|
||||
}
|
||||
|
||||
int64_t blocktime = mapBlockIndex[wtx.hashBlock]->GetBlockTime();
|
||||
int64_t blocktime = pindex->GetBlockTime();
|
||||
nTimeSmart = std::max(latestEntry, std::min(blocktime, latestNow));
|
||||
} else {
|
||||
LogPrintf("%s: found %s in block %s not in index\n", __func__, wtx.GetHash().ToString(), wtx.hashBlock.ToString());
|
||||
@@ -4162,10 +4165,7 @@ int CMerkleTx::GetDepthInMainChain(const CBlockIndex* &pindexRet) const
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
// Find the block it claims to be in
|
||||
BlockMap::iterator mi = mapBlockIndex.find(hashBlock);
|
||||
if (mi == mapBlockIndex.end())
|
||||
return 0;
|
||||
CBlockIndex* pindex = (*mi).second;
|
||||
CBlockIndex* pindex = LookupBlockIndex(hashBlock);
|
||||
if (!pindex || !chainActive.Contains(pindex))
|
||||
return 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user