@@ -3554,12 +3554,13 @@ void CWallet::GetKeyBirthTimes(interfaces::Chain::Lock& locked_chain, std::map<C
3554
3554
}
3555
3555
3556
3556
// map in which we'll infer heights of other keys
3557
- const Optional<int > tip_height = locked_chain.getHeight ();
3558
- const int max_height = tip_height && *tip_height > 144 ? *tip_height - 144 : 0 ; // the tip can be reorganized; use a 144-block safety margin
3559
- std::map<CKeyID, int > mapKeyFirstBlock;
3557
+ std::map<CKeyID, const CWalletTx::Confirmation*> mapKeyFirstBlock;
3558
+ CWalletTx::Confirmation max_confirm;
3559
+ max_confirm.block_height = GetLastBlockHeight () > 144 ? GetLastBlockHeight () - 144 : 0 ; // the tip can be reorganized; use a 144-block safety margin
3560
+ CHECK_NONFATAL (chain ().findAncestorByHeight (GetLastBlockHash (), max_confirm.block_height , FoundBlock ().hash (max_confirm.hashBlock )));
3560
3561
for (const CKeyID &keyid : spk_man->GetKeys ()) {
3561
3562
if (mapKeyBirth.count (keyid) == 0 )
3562
- mapKeyFirstBlock[keyid] = max_height ;
3563
+ mapKeyFirstBlock[keyid] = &max_confirm ;
3563
3564
}
3564
3565
3565
3566
// if there are no such keys, we're done
@@ -3570,23 +3571,27 @@ void CWallet::GetKeyBirthTimes(interfaces::Chain::Lock& locked_chain, std::map<C
3570
3571
for (const auto & entry : mapWallet) {
3571
3572
// iterate over all wallet transactions...
3572
3573
const CWalletTx &wtx = entry.second ;
3573
- if (Optional< int > height = locked_chain. getBlockHeight ( wtx.m_confirm .hashBlock ) ) {
3574
+ if (wtx.m_confirm .status == CWalletTx::CONFIRMED ) {
3574
3575
// ... which are already in a block
3575
3576
for (const CTxOut &txout : wtx.tx ->vout ) {
3576
3577
// iterate over all their outputs
3577
3578
for (const auto &keyid : GetAffectedKeys (txout.scriptPubKey , *spk_man)) {
3578
3579
// ... and all their affected keys
3579
- std::map<CKeyID, int >::iterator rit = mapKeyFirstBlock.find (keyid);
3580
- if (rit != mapKeyFirstBlock.end () && *height < rit->second )
3581
- rit->second = *height;
3580
+ auto rit = mapKeyFirstBlock.find (keyid);
3581
+ if (rit != mapKeyFirstBlock.end () && wtx.m_confirm .block_height < rit->second ->block_height ) {
3582
+ rit->second = &wtx.m_confirm ;
3583
+ }
3582
3584
}
3583
3585
}
3584
3586
}
3585
3587
}
3586
3588
3587
3589
// Extract block timestamps for those keys
3588
- for (const auto & entry : mapKeyFirstBlock)
3589
- mapKeyBirth[entry.first ] = locked_chain.getBlockTime (entry.second ) - TIMESTAMP_WINDOW; // block times can be 2h off
3590
+ for (const auto & entry : mapKeyFirstBlock) {
3591
+ int64_t block_time;
3592
+ CHECK_NONFATAL (chain ().findBlock (entry.second ->hashBlock , FoundBlock ().time (block_time)));
3593
+ mapKeyBirth[entry.first ] = block_time - TIMESTAMP_WINDOW; // block times can be 2h off
3594
+ }
3590
3595
}
3591
3596
3592
3597
/* *
0 commit comments