diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -440,8 +440,9 @@ "Something wrong with merkleblock"); } - wtx.SetConf(CWalletTx::Status::CONFIRMED, merkleBlock.header.GetHash(), - txnIndex); + CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, + merkleBlock.header.GetHash(), txnIndex); + wtx.m_confirm = confirm; auto locked_chain = pwallet->chain().lock(); LOCK(pwallet->cs_wallet); diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -307,8 +307,9 @@ wallet.SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash()); - wtx.SetConf(CWalletTx::Status::CONFIRMED, - ::ChainActive().Tip()->GetBlockHash(), 0); + CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, + ::ChainActive().Tip()->GetBlockHash(), 0); + wtx.m_confirm = confirm; // Call GetImmatureCredit() once before adding the key to the wallet to // cache the current immature credit amount, which is 0. @@ -350,7 +351,9 @@ wallet.AddToWallet(wtx); } if (block) { - wtx.SetConf(CWalletTx::Status::CONFIRMED, block->GetBlockHash(), 0); + CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, + block->GetBlockHash(), 0); + wtx.m_confirm = confirm; } wallet.AddToWallet(wtx); return wallet.mapWallet.at(wtx.GetId()).nTimeSmart; @@ -538,8 +541,10 @@ ::ChainActive().Tip()->GetBlockHash()); auto it = wallet->mapWallet.find(tx->GetId()); BOOST_CHECK(it != wallet->mapWallet.end()); - it->second.SetConf(CWalletTx::Status::CONFIRMED, - ::ChainActive().Tip()->GetBlockHash(), 1); + CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, + ::ChainActive().Tip()->GetBlockHash(), + 1); + it->second.m_confirm = confirm; return it->second; } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -360,9 +360,12 @@ * conflicting tx. */ struct Confirmation { - Status status = UNCONFIRMED; - BlockHash hashBlock = BlockHash(); - int nIndex = 0; + Status status; + BlockHash hashBlock; + int nIndex; + Confirmation(Status s = UNCONFIRMED, BlockHash h = BlockHash(), + int i = 0) + : status(s), hashBlock(h), nIndex(i) {} }; Confirmation m_confirm; @@ -506,8 +509,6 @@ // in place. std::set GetConflicts() const NO_THREAD_SAFETY_ANALYSIS; - void SetConf(Status status, const BlockHash &block_hash, int posInBlock); - /** * Return depth of transaction in blockchain: * <0 : conflicts with a transaction this deep in the blockchain @@ -691,9 +692,7 @@ * when necessary. */ bool AddToWalletIfInvolvingMe(const CTransactionRef &tx, - CWalletTx::Status status, - const BlockHash &block_hash, int posInBlock, - bool fUpdate) + CWalletTx::Confirmation confirm, bool fUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); /** @@ -718,9 +717,8 @@ * Should be called with non-zero block_hash and posInBlock if this is for a * transaction that is included in a block. */ - void SyncTransaction(const CTransactionRef &tx, CWalletTx::Status status, - const BlockHash &block_hash, int posInBlock = 0, - bool update_tx = true) + void SyncTransaction(const CTransactionRef &tx, + CWalletTx::Confirmation confirm, bool update_tx = true) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); std::atomic m_wallet_flags{0}; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -906,13 +906,12 @@ } bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef &ptx, - CWalletTx::Status status, - const BlockHash &block_hash, - int posInBlock, bool fUpdate) { + CWalletTx::Confirmation confirm, + bool fUpdate) { const CTransaction &tx = *ptx; AssertLockHeld(cs_wallet); - if (!block_hash.IsNull()) { + if (!confirm.hashBlock.IsNull()) { for (const CTxIn &txin : tx.vin) { std::pair range = mapTxSpends.equal_range(txin.prevout); @@ -921,11 +920,11 @@ WalletLogPrintf( "Transaction %s (in block %s) conflicts with wallet " "transaction %s (both spend %s:%i)\n", - tx.GetId().ToString(), block_hash.ToString(), + tx.GetId().ToString(), confirm.hashBlock.ToString(), range.first->second.ToString(), range.first->first.GetTxId().ToString(), range.first->first.GetN()); - MarkConflicted(block_hash, range.first->second); + MarkConflicted(confirm.hashBlock, range.first->second); } range.first++; } @@ -956,7 +955,7 @@ // Block disconnection override an abandoned tx as unconfirmed // which means user may have to call abandontransaction again - wtx.SetConf(status, block_hash, posInBlock); + wtx.m_confirm = confirm; return AddToWallet(wtx, false); } @@ -1100,11 +1099,8 @@ } void CWallet::SyncTransaction(const CTransactionRef &ptx, - CWalletTx::Status status, - const BlockHash &block_hash, int posInBlock, - bool update_tx) { - if (!AddToWalletIfInvolvingMe(ptx, status, block_hash, posInBlock, - update_tx)) { + CWalletTx::Confirmation confirm, bool update_tx) { + if (!AddToWalletIfInvolvingMe(ptx, confirm, update_tx)) { // Not one of ours return; } @@ -1118,8 +1114,9 @@ void CWallet::TransactionAddedToMempool(const CTransactionRef &ptx) { auto locked_chain = chain().lock(); LOCK(cs_wallet); - SyncTransaction(ptx, CWalletTx::Status::UNCONFIRMED, - BlockHash() /* block hash */, 0 /* position in block */); + CWalletTx::Confirmation confirm(CWalletTx::Status::UNCONFIRMED, BlockHash(), + 0); + SyncTransaction(ptx, confirm); auto it = mapWallet.find(ptx->GetId()); if (it != mapWallet.end()) { @@ -1145,8 +1142,9 @@ m_last_block_processed_height = height; m_last_block_processed = block_hash; for (size_t i = 0; i < block.vtx.size(); i++) { - SyncTransaction(block.vtx[i], CWalletTx::Status::CONFIRMED, block_hash, - i); + CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, + m_last_block_processed, i); + SyncTransaction(block.vtx[i], confirm); TransactionRemovedFromMempool(block.vtx[i]); } for (const CTransactionRef &ptx : vtxConflicted) { @@ -1166,9 +1164,9 @@ m_last_block_processed_height = height - 1; m_last_block_processed = block.hashPrevBlock; for (const CTransactionRef &ptx : block.vtx) { - SyncTransaction(ptx, CWalletTx::Status::UNCONFIRMED, - BlockHash() /* block hash */, - 0 /* position in block */); + CWalletTx::Confirmation confirm(CWalletTx::Status::UNCONFIRMED, + BlockHash(), 0); + SyncTransaction(ptx, confirm); } } @@ -1765,9 +1763,9 @@ } for (size_t posInBlock = 0; posInBlock < block.vtx.size(); ++posInBlock) { - SyncTransaction(block.vtx[posInBlock], - CWalletTx::Status::CONFIRMED, block_hash, - posInBlock, fUpdate); + CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, + block_hash, posInBlock); + SyncTransaction(block.vtx[posInBlock], confirm, fUpdate); } // scan succeeded, record block as most recent successfully // scanned @@ -4368,18 +4366,6 @@ m_pre_split = false; } -void CWalletTx::SetConf(Status status, const BlockHash &block_hash, - int posInBlock) { - // Update tx status - m_confirm.status = status; - - // Update the tx's hashBlock - m_confirm.hashBlock = block_hash; - - // Set the position of the transaction in the block. - m_confirm.nIndex = posInBlock; -} - int CWalletTx::GetDepthInMainChain( interfaces::Chain::Lock &locked_chain) const { if (isUnconfirmed() || isAbandoned()) {