mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-31 19:06:10 +02:00
Add LookupBlockIndex function
This commit is contained in:
@@ -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