wallet: Add asserts to detect unset transaction height values

Also document GetTxDepthInMainChain preconditions better
This commit is contained in:
Ryan Ofsky
2023-09-27 13:16:52 -04:00
parent 262a78b133
commit f06016d77d
2 changed files with 9 additions and 0 deletions

View File

@@ -3303,8 +3303,10 @@ int CWallet::GetTxDepthInMainChain(const CWalletTx& wtx) const
{
AssertLockHeld(cs_wallet);
if (auto* conf = wtx.state<TxStateConfirmed>()) {
assert(conf->confirmed_block_height >= 0);
return GetLastBlockHeight() - conf->confirmed_block_height + 1;
} else if (auto* conf = wtx.state<TxStateConflicted>()) {
assert(conf->conflicting_block_height >= 0);
return -1 * (GetLastBlockHeight() - conf->conflicting_block_height + 1);
} else {
return 0;