wallet: add IsTxAssumed() to WalletTxStatus

Determine if a given transaction belongs to a block that is assumed to be valid pending background validation.

Add this information to WalletTxStatus.

Github-Pull: #28616
Rebased-From: a6c53bb24436ecc1ae717b032c0cccdd704044eb
This commit is contained in:
Sjors Provoost 2023-10-09 11:21:45 +02:00 committed by Luke Dashjr
parent 2904c57bc4
commit d8a448249a
4 changed files with 16 additions and 0 deletions

View File

@ -426,6 +426,8 @@ struct WalletTxStatus
bool is_abandoned;
bool is_coinbase;
bool is_in_main_chain;
// The block containing this transaction is assumed valid
bool is_assumed;
};
//! Wallet transaction output.

View File

@ -104,6 +104,7 @@ WalletTxStatus MakeWalletTxStatus(const CWallet& wallet, const CWalletTx& wtx)
result.is_abandoned = wtx.isAbandoned();
result.is_coinbase = wtx.IsCoinBase();
result.is_in_main_chain = wtx.isConfirmed();
result.is_assumed = wallet.IsTxAssumed(wtx);
return result;
}

View File

@ -3473,6 +3473,18 @@ bool CWallet::IsTxImmatureCoinBase(const CWalletTx& wtx) const
return GetTxBlocksToMaturity(wtx) > 0;
}
bool CWallet::IsTxAssumed(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
{
AssertLockHeld(cs_wallet);
if (GetBackgroundValidationHeight() == -1) return false;
if (auto* conf = wtx.state<TxStateConfirmed>()) {
int height{conf->confirmed_block_height};
return height > GetBackgroundValidationHeight();
}
return false;
}
bool CWallet::IsCrypted() const
{
return HasEncryptionKeys();

View File

@ -525,6 +525,7 @@ public:
* referenced in transaction, and might cause assert failures.
*/
int GetTxDepthInMainChain(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool IsTxAssumed(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
/**
* @return number of blocks to maturity for this transaction: