diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -27,8 +27,7 @@ namespace { //! Construct wallet tx struct. - static WalletTx MakeWalletTx(interfaces::Chain::Lock &locked_chain, - CWallet &wallet, const CWalletTx &wtx) { + static WalletTx MakeWalletTx(CWallet &wallet, const CWalletTx &wtx) { WalletTx result; result.tx = wtx.tx; result.txin_is_mine.reserve(wtx.tx->vin.size()); @@ -47,7 +46,7 @@ ? wallet.IsMine(result.txout_address.back()) : ISMINE_NO); } - result.credit = wtx.GetCredit(locked_chain, ISMINE_ALL); + result.credit = wtx.GetCredit(ISMINE_ALL); result.debit = wtx.GetDebit(ISMINE_ALL); result.change = wtx.GetChange(); result.time = wtx.GetTxTime(); @@ -64,8 +63,8 @@ result.block_height = locked_chain.getBlockHeight(wtx.m_confirm.hashBlock) .get_value_or(std::numeric_limits::max()); - result.blocks_to_maturity = wtx.GetBlocksToMaturity(locked_chain); - result.depth_in_main_chain = wtx.GetDepthInMainChain(locked_chain); + result.blocks_to_maturity = wtx.GetBlocksToMaturity(); + result.depth_in_main_chain = wtx.GetDepthInMainChain(); result.time_received = wtx.nTimeReceived; result.lock_time = wtx.tx->nLockTime; TxValidationState state; @@ -75,21 +74,19 @@ result.is_trusted = wtx.IsTrusted(locked_chain); result.is_abandoned = wtx.isAbandoned(); result.is_coinbase = wtx.IsCoinBase(); - result.is_in_main_chain = wtx.IsInMainChain(locked_chain); + result.is_in_main_chain = wtx.IsInMainChain(); return result; } //! Construct wallet TxOut struct. - static WalletTxOut MakeWalletTxOut(interfaces::Chain::Lock &locked_chain, - CWallet &wallet, const CWalletTx &wtx, + static WalletTxOut MakeWalletTxOut(CWallet &wallet, const CWalletTx &wtx, int n, int depth) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet) { WalletTxOut result; result.txout = wtx.tx->vout[n]; result.time = wtx.GetTxTime(); result.depth_in_main_chain = depth; - result.is_spent = - wallet.IsSpent(locked_chain, COutPoint(wtx.GetId(), n)); + result.is_spent = wallet.IsSpent(COutPoint(wtx.GetId(), n)); return result; } @@ -249,7 +246,7 @@ bool abandonTransaction(const TxId &txid) override { auto locked_chain = m_wallet->chain().lock(); LOCK(m_wallet->cs_wallet); - return m_wallet->AbandonTransaction(*locked_chain, txid); + return m_wallet->AbandonTransaction(txid); } CTransactionRef getTx(const TxId &txid) override { auto locked_chain = m_wallet->chain().lock(); @@ -265,7 +262,7 @@ LOCK(m_wallet->cs_wallet); auto mi = m_wallet->mapWallet.find(txid); if (mi != m_wallet->mapWallet.end()) { - return MakeWalletTx(*locked_chain, *m_wallet, mi->second); + return MakeWalletTx(*m_wallet, mi->second); } return {}; } @@ -275,8 +272,7 @@ std::vector result; result.reserve(m_wallet->mapWallet.size()); for (const auto &entry : m_wallet->mapWallet) { - result.emplace_back( - MakeWalletTx(*locked_chain, *m_wallet, entry.second)); + result.emplace_back(MakeWalletTx(*m_wallet, entry.second)); } return result; } @@ -317,7 +313,7 @@ in_mempool = mi->second.InMempool(); order_form = mi->second.vOrderForm; tx_status = MakeWalletTxStatus(*locked_chain, mi->second); - return MakeWalletTx(*locked_chain, *m_wallet, mi->second); + return MakeWalletTx(*m_wallet, mi->second); } return {}; } @@ -384,9 +380,8 @@ auto &group = result[entry.first]; for (const auto &coin : entry.second) { group.emplace_back(COutPoint(coin.tx->GetId(), coin.i), - MakeWalletTxOut(*locked_chain, *m_wallet, - *coin.tx, coin.i, - coin.nDepth)); + MakeWalletTxOut(*m_wallet, *coin.tx, + coin.i, coin.nDepth)); } } return result; @@ -401,11 +396,10 @@ result.emplace_back(); auto it = m_wallet->mapWallet.find(output.GetTxId()); if (it != m_wallet->mapWallet.end()) { - int depth = it->second.GetDepthInMainChain(*locked_chain); + int depth = it->second.GetDepthInMainChain(); if (depth >= 0) { - result.back() = - MakeWalletTxOut(*locked_chain, *m_wallet, - it->second, output.GetN(), depth); + result.back() = MakeWalletTxOut(*m_wallet, it->second, + output.GetN(), depth); } } } diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -367,7 +367,7 @@ { auto locked_chain = pwallet->chain().lock(); LOCK(pwallet->cs_wallet); - pwallet->ReacceptWalletTransactions(*locked_chain); + pwallet->ReacceptWalletTransactions(); } } @@ -605,7 +605,7 @@ { auto locked_chain = pwallet->chain().lock(); LOCK(pwallet->cs_wallet); - pwallet->ReacceptWalletTransactions(*locked_chain); + pwallet->ReacceptWalletTransactions(); } } @@ -1755,7 +1755,7 @@ { auto locked_chain = pwallet->chain().lock(); LOCK(pwallet->cs_wallet); - pwallet->ReacceptWalletTransactions(*locked_chain); + pwallet->ReacceptWalletTransactions(); } if (pwallet->IsAbortingRescan()) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -155,7 +155,7 @@ static void WalletTxToJSON(interfaces::Chain &chain, interfaces::Chain::Lock &locked_chain, const CWalletTx &wtx, UniValue &entry) { - int confirms = wtx.GetDepthInMainChain(locked_chain); + int confirms = wtx.GetDepthInMainChain(); entry.pushKV("confirmations", confirms); if (wtx.IsCoinBase()) { entry.pushKV("generated", true); @@ -719,7 +719,7 @@ for (const CTxOut &txout : wtx.tx->vout) { if (txout.scriptPubKey == scriptPubKey) { - if (wtx.GetDepthInMainChain(*locked_chain) >= nMinDepth) { + if (wtx.GetDepthInMainChain() >= nMinDepth) { nAmount += txout.nValue; } } @@ -795,7 +795,7 @@ CTxDestination address; if (ExtractDestination(txout.scriptPubKey, address) && pwallet->IsMine(address) && setAddress.count(address)) { - if (wtx.GetDepthInMainChain(*locked_chain) >= nMinDepth) { + if (wtx.GetDepthInMainChain() >= nMinDepth) { nAmount += txout.nValue; } } @@ -1218,7 +1218,7 @@ continue; } - int nDepth = wtx.GetDepthInMainChain(locked_chain); + int nDepth = wtx.GetDepthInMainChain(); if (nDepth < nMinDepth) { continue; } @@ -1505,8 +1505,7 @@ } // Received - if (listReceived.size() > 0 && - wtx.GetDepthInMainChain(locked_chain) >= nMinDepth) { + if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) { for (const COutputEntry &r : listReceived) { std::string label; if (pwallet->mapAddressBook.count(r.destination)) { @@ -1522,9 +1521,9 @@ } MaybePushAddress(entry, r.destination); if (wtx.IsCoinBase()) { - if (wtx.GetDepthInMainChain(locked_chain) < 1) { + if (wtx.GetDepthInMainChain() < 1) { entry.pushKV("category", "orphan"); - } else if (wtx.IsImmatureCoinBase(locked_chain)) { + } else if (wtx.IsImmatureCoinBase()) { entry.pushKV("category", "immature"); } else { entry.pushKV("category", "generate"); @@ -1876,7 +1875,7 @@ for (const std::pair &pairWtx : pwallet->mapWallet) { CWalletTx tx = pairWtx.second; - if (depth == -1 || tx.GetDepthInMainChain(*locked_chain) < depth) { + if (depth == -1 || tx.GetDepthInMainChain() < depth) { ListTransactions(*locked_chain, pwallet, tx, 0, true, transactions, filter, nullptr /* filter_label */); } @@ -2044,7 +2043,7 @@ } const CWalletTx &wtx = it->second; - Amount nCredit = wtx.GetCredit(*locked_chain, filter); + Amount nCredit = wtx.GetCredit(filter); Amount nDebit = wtx.GetDebit(filter); Amount nNet = nCredit - nDebit; Amount nFee = (wtx.IsFromMe(filter) ? wtx.tx->GetValueOut() - nDebit @@ -2122,7 +2121,7 @@ "Invalid or non-wallet transaction id"); } - if (!pwallet->AbandonTransaction(*locked_chain, txid)) { + if (!pwallet->AbandonTransaction(txid)) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not eligible for abandonment"); } @@ -2637,7 +2636,7 @@ "Invalid parameter, vout index out of bounds"); } - if (pwallet->IsSpent(*locked_chain, output)) { + if (pwallet->IsSpent(output)) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected unspent output"); } 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 @@ -314,13 +314,13 @@ // Call GetImmatureCredit() once before adding the key to the wallet to // cache the current immature credit amount, which is 0. - BOOST_CHECK_EQUAL(wtx.GetImmatureCredit(*locked_chain), Amount::zero()); + BOOST_CHECK_EQUAL(wtx.GetImmatureCredit(), Amount::zero()); // Invalidate the cached value, add the key, and make sure a new immature // credit amount is calculated. wtx.MarkDirty(); BOOST_CHECK(spk_man->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey())); - BOOST_CHECK_EQUAL(wtx.GetImmatureCredit(*locked_chain), 50 * COIN); + BOOST_CHECK_EQUAL(wtx.GetImmatureCredit(), 50 * COIN); } static int64_t AddTx(CWallet &wallet, uint32_t lockTime, int64_t mockTime, diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -456,21 +456,17 @@ //! filter decides which addresses will count towards the debit Amount GetDebit(const isminefilter &filter) const; - Amount GetCredit(interfaces::Chain::Lock &locked_chain, - const isminefilter &filter) const; - Amount GetImmatureCredit(interfaces::Chain::Lock &locked_chain, - bool fUseCache = true) const; + Amount GetCredit(const isminefilter &filter) const; + Amount GetImmatureCredit(bool fUseCache = true) const; // TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct // annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The // annotation "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid // having to resolve the issue of member access into incomplete type // CWallet. - Amount GetAvailableCredit(interfaces::Chain::Lock &locked_chain, - bool fUseCache = true, + Amount GetAvailableCredit(bool fUseCache = true, const isminefilter &filter = ISMINE_SPENDABLE) const NO_THREAD_SAFETY_ANALYSIS; - Amount GetImmatureWatchOnlyCredit(interfaces::Chain::Lock &locked_chain, - const bool fUseCache = true) const; + Amount GetImmatureWatchOnlyCredit(const bool fUseCache = true) const; Amount GetChange() const; // Get the marginal bytes if spending the specified output from this @@ -498,8 +494,7 @@ // Pass this transaction to node for mempool insertion and relay to peers if // flag set to true - bool SubmitMemoryPoolAndRelay(std::string &err_string, bool relay, - interfaces::Chain::Lock &locked_chain); + bool SubmitMemoryPoolAndRelay(std::string &err_string, bool relay); // TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct // annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The annotation @@ -521,18 +516,15 @@ // resolve the issue of member access into incomplete type CWallet. Note // that we still have the runtime check "AssertLockHeld(pwallet->cs_wallet)" // in place. - int GetDepthInMainChain(interfaces::Chain::Lock &locked_chain) const - NO_THREAD_SAFETY_ANALYSIS; - bool IsInMainChain(interfaces::Chain::Lock &locked_chain) const { - return GetDepthInMainChain(locked_chain) > 0; - } + int GetDepthInMainChain() const NO_THREAD_SAFETY_ANALYSIS; + bool IsInMainChain() const { return GetDepthInMainChain() > 0; } /** * @return number of blocks to maturity for this transaction: * 0 : is not a coinbase transaction, or is a mature coinbase transaction * >0 : is a coinbase transaction which matures in this many blocks */ - int GetBlocksToMaturity(interfaces::Chain::Lock &locked_chain) const; + int GetBlocksToMaturity() const; bool isAbandoned() const { return m_confirm.status == CWalletTx::ABANDONED; } @@ -556,7 +548,7 @@ void setConfirmed() { m_confirm.status = CWalletTx::CONFIRMED; } TxId GetId() const { return tx->GetId(); } bool IsCoinBase() const { return tx->IsCoinBase(); } - bool IsImmatureCoinBase(interfaces::Chain::Lock &locked_chain) const; + bool IsImmatureCoinBase() const; }; class COutput { @@ -908,8 +900,7 @@ const CoinSelectionParams &coin_selection_params, bool &bnb_used) const; - bool IsSpent(interfaces::Chain::Lock &locked_chain, - const COutPoint &outpoint) const + bool IsSpent(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); // Whether this or any UTXO with the same CTxDestination has been spent. @@ -1029,8 +1020,7 @@ const WalletRescanReserver &reserver, bool fUpdate); void TransactionRemovedFromMempool(const CTransactionRef &ptx) override; - void ReacceptWalletTransactions(interfaces::Chain::Lock &locked_chain) - EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); + void ReacceptWalletTransactions() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void ResendWalletTransactions(); struct Balance { //! Trusted, at depth=GetBalance.min_depth or more @@ -1267,8 +1257,7 @@ * Mark a transaction (and it in-wallet descendants) as abandoned so its * inputs may be respent. */ - bool AbandonTransaction(interfaces::Chain::Lock &locked_chain, - const TxId &txid); + bool AbandonTransaction(const TxId &txid); //! Verify wallet naming and perform salvage on the wallet if required static bool Verify(const CChainParams &chainParams, diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -525,8 +525,7 @@ /** * Outpoint is spent if any non-conflicted transaction, spends it: */ -bool CWallet::IsSpent(interfaces::Chain::Lock &locked_chain, - const COutPoint &outpoint) const { +bool CWallet::IsSpent(const COutPoint &outpoint) const { std::pair range = mapTxSpends.equal_range(outpoint); @@ -534,7 +533,7 @@ const TxId &wtxid = it->second; std::map::const_iterator mit = mapWallet.find(wtxid); if (mit != mapWallet.end()) { - int depth = mit->second.GetDepthInMainChain(locked_chain); + int depth = mit->second.GetDepthInMainChain(); if (depth > 0 || (depth == 0 && !mit->second.isAbandoned())) { // Spent return true; @@ -981,8 +980,8 @@ auto locked_chain = chain().lock(); LOCK(cs_wallet); const CWalletTx *wtx = GetWalletTx(txid); - return wtx && !wtx->isAbandoned() && - wtx->GetDepthInMainChain(*locked_chain) == 0 && !wtx->InMempool(); + return wtx && !wtx->isAbandoned() && wtx->GetDepthInMainChain() == 0 && + !wtx->InMempool(); } void CWallet::MarkInputsDirty(const CTransactionRef &tx) { @@ -994,10 +993,9 @@ } } -bool CWallet::AbandonTransaction(interfaces::Chain::Lock &locked_chain, - const TxId &txid) { +bool CWallet::AbandonTransaction(const TxId &txid) { // Temporary. Removed in upcoming lock cleanup - auto locked_chain_recursive = chain().lock(); + auto locked_chain = chain().lock(); LOCK(cs_wallet); WalletBatch batch(*database, "r+"); @@ -1009,7 +1007,7 @@ auto it = mapWallet.find(txid); assert(it != mapWallet.end()); CWalletTx &origtx = it->second; - if (origtx.GetDepthInMainChain(locked_chain) != 0 || origtx.InMempool()) { + if (origtx.GetDepthInMainChain() != 0 || origtx.InMempool()) { return false; } @@ -1022,7 +1020,7 @@ it = mapWallet.find(now); assert(it != mapWallet.end()); CWalletTx &wtx = it->second; - int currentconfirm = wtx.GetDepthInMainChain(locked_chain); + int currentconfirm = wtx.GetDepthInMainChain(); // If the orig tx was not in block, none of its spends can be. assert(currentconfirm <= 0); // If (currentconfirm < 0) {Tx and spends are already conflicted, no @@ -1085,7 +1083,7 @@ auto it = mapWallet.find(now); assert(it != mapWallet.end()); CWalletTx &wtx = it->second; - int currentconfirm = wtx.GetDepthInMainChain(*locked_chain); + int currentconfirm = wtx.GetDepthInMainChain(); if (conflictconfirms < currentconfirm) { // Block is 'more conflicted' than current confirm; update. // Mark transaction as conflicted with this block. @@ -1842,8 +1840,7 @@ return result; } -void CWallet::ReacceptWalletTransactions( - interfaces::Chain::Lock &locked_chain) { +void CWallet::ReacceptWalletTransactions() { // If transactions aren't being broadcasted, don't let them into local // mempool either. if (!fBroadcastTransactions) { @@ -1859,7 +1856,7 @@ CWalletTx &wtx = item.second; assert(wtx.GetId() == wtxid); - int nDepth = wtx.GetDepthInMainChain(locked_chain); + int nDepth = wtx.GetDepthInMainChain(); if (!wtx.IsCoinBase() && (nDepth == 0 && !wtx.isAbandoned())) { mapSorted.insert(std::make_pair(wtx.nOrderPos, &wtx)); @@ -1870,13 +1867,11 @@ for (const std::pair &item : mapSorted) { CWalletTx &wtx = *(item.second); std::string unused_err_string; - wtx.SubmitMemoryPoolAndRelay(unused_err_string, false, locked_chain); + wtx.SubmitMemoryPoolAndRelay(unused_err_string, false); } } -bool CWalletTx::SubmitMemoryPoolAndRelay( - std::string &err_string, bool relay, - interfaces::Chain::Lock &locked_chain) { +bool CWalletTx::SubmitMemoryPoolAndRelay(std::string &err_string, bool relay) { // Can't relay if wallet is not broadcasting if (!pwallet->GetBroadcastTransactions()) { return false; @@ -1891,7 +1886,7 @@ return false; } // Don't try to submit conflicted or confirmed transactions. - if (GetDepthInMainChain(locked_chain) != 0) { + if (GetDepthInMainChain() != 0) { return false; } @@ -1950,11 +1945,10 @@ return debit; } -Amount CWalletTx::GetCredit(interfaces::Chain::Lock &locked_chain, - const isminefilter &filter) const { +Amount CWalletTx::GetCredit(const isminefilter &filter) const { // Must wait until coinbase is safely deep enough in the chain before // valuing it. - if (IsImmatureCoinBase(locked_chain)) { + if (IsImmatureCoinBase()) { return Amount::zero(); } @@ -1971,17 +1965,15 @@ return credit; } -Amount CWalletTx::GetImmatureCredit(interfaces::Chain::Lock &locked_chain, - bool fUseCache) const { - if (IsImmatureCoinBase(locked_chain) && IsInMainChain(locked_chain)) { +Amount CWalletTx::GetImmatureCredit(bool fUseCache) const { + if (IsImmatureCoinBase() && IsInMainChain()) { return GetCachableAmount(IMMATURE_CREDIT, ISMINE_SPENDABLE, !fUseCache); } return Amount::zero(); } -Amount CWalletTx::GetAvailableCredit(interfaces::Chain::Lock &locked_chain, - bool fUseCache, +Amount CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter &filter) const { if (pwallet == nullptr) { return Amount::zero(); @@ -1994,7 +1986,7 @@ // Must wait until coinbase is safely deep enough in the chain before // valuing it. - if (IsImmatureCoinBase(locked_chain)) { + if (IsImmatureCoinBase()) { return Amount::zero(); } @@ -2009,7 +2001,7 @@ Amount nCredit = Amount::zero(); const TxId &txid = GetId(); for (uint32_t i = 0; i < tx->vout.size(); i++) { - if (!pwallet->IsSpent(locked_chain, COutPoint(txid, i)) && + if (!pwallet->IsSpent(COutPoint(txid, i)) && (allow_used_addresses || !pwallet->IsUsedDestination(txid, i))) { const CTxOut &txout = tx->vout[i]; nCredit += pwallet->GetCredit(txout, filter); @@ -2027,10 +2019,8 @@ return nCredit; } -Amount -CWalletTx::GetImmatureWatchOnlyCredit(interfaces::Chain::Lock &locked_chain, - const bool fUseCache) const { - if (IsImmatureCoinBase(locked_chain) && IsInMainChain(locked_chain)) { +Amount CWalletTx::GetImmatureWatchOnlyCredit(const bool fUseCache) const { + if (IsImmatureCoinBase() && IsInMainChain()) { return GetCachableAmount(IMMATURE_CREDIT, ISMINE_WATCH_ONLY, !fUseCache); } @@ -2060,7 +2050,7 @@ return false; } - int nDepth = GetDepthInMainChain(locked_chain); + int nDepth = GetDepthInMainChain(); if (nDepth >= 1) { return true; } @@ -2162,8 +2152,7 @@ continue; } std::string unused_err_string; - if (wtx.SubmitMemoryPoolAndRelay(unused_err_string, true, - *locked_chain)) { + if (wtx.SubmitMemoryPoolAndRelay(unused_err_string, true)) { ++submitted_tx_count; } } @@ -2197,13 +2186,11 @@ for (const auto &entry : mapWallet) { const CWalletTx &wtx = entry.second; const bool is_trusted{wtx.IsTrusted(*locked_chain)}; - const int tx_depth{wtx.GetDepthInMainChain(*locked_chain)}; - const Amount tx_credit_mine{ - wtx.GetAvailableCredit(*locked_chain, /* fUseCache */ true, - ISMINE_SPENDABLE | reuse_filter)}; - const Amount tx_credit_watchonly{ - wtx.GetAvailableCredit(*locked_chain, /* fUseCache */ true, - ISMINE_WATCH_ONLY | reuse_filter)}; + const int tx_depth{wtx.GetDepthInMainChain()}; + const Amount tx_credit_mine{wtx.GetAvailableCredit( + /* fUseCache */ true, ISMINE_SPENDABLE | reuse_filter)}; + const Amount tx_credit_watchonly{wtx.GetAvailableCredit( + /* fUseCache */ true, ISMINE_WATCH_ONLY | reuse_filter)}; if (is_trusted && tx_depth >= min_depth) { ret.m_mine_trusted += tx_credit_mine; ret.m_watchonly_trusted += tx_credit_watchonly; @@ -2212,9 +2199,8 @@ ret.m_mine_untrusted_pending += tx_credit_mine; ret.m_watchonly_untrusted_pending += tx_credit_watchonly; } - ret.m_mine_immature += wtx.GetImmatureCredit(*locked_chain); - ret.m_watchonly_immature += - wtx.GetImmatureWatchOnlyCredit(*locked_chain); + ret.m_mine_immature += wtx.GetImmatureCredit(); + ret.m_watchonly_immature += wtx.GetImmatureWatchOnlyCredit(); } return ret; } @@ -2269,11 +2255,11 @@ continue; } - if (wtx.IsImmatureCoinBase(locked_chain)) { + if (wtx.IsImmatureCoinBase()) { continue; } - int nDepth = wtx.GetDepthInMainChain(locked_chain); + int nDepth = wtx.GetDepthInMainChain(); if (nDepth < 0) { continue; } @@ -2333,7 +2319,7 @@ continue; } - if (IsSpent(locked_chain, outpoint)) { + if (IsSpent(outpoint)) { continue; } @@ -2402,7 +2388,7 @@ for (const auto &output : lockedCoins) { auto it = mapWallet.find(output.GetTxId()); if (it != mapWallet.end()) { - int depth = it->second.GetDepthInMainChain(locked_chain); + int depth = it->second.GetDepthInMainChain(); if (depth >= 0 && output.GetN() < it->second.tx->vout.size() && IsMine(it->second.tx->vout[output.GetN()]) == ISMINE_SPENDABLE) { @@ -3252,7 +3238,7 @@ } std::string err_string; - if (!wtx.SubmitMemoryPoolAndRelay(err_string, true, *locked_chain)) { + if (!wtx.SubmitMemoryPoolAndRelay(err_string, true)) { WalletLogPrintf("CommitTransaction(): Transaction cannot be broadcast " "immediately, %s\n", err_string); @@ -3478,11 +3464,11 @@ continue; } - if (wtx.IsImmatureCoinBase(locked_chain)) { + if (wtx.IsImmatureCoinBase()) { continue; } - int nDepth = wtx.GetDepthInMainChain(locked_chain); + int nDepth = wtx.GetDepthInMainChain(); if (nDepth < (wtx.IsFromMe(ISMINE_ALL) ? 0 : 1)) { continue; } @@ -3497,7 +3483,7 @@ continue; } - Amount n = IsSpent(locked_chain, COutPoint(walletEntry.first, i)) + Amount n = IsSpent(COutPoint(walletEntry.first, i)) ? Amount::zero() : wtx.tx->vout[i].nValue; @@ -4361,7 +4347,7 @@ // Add wallet transactions that aren't already in a block to mempool. // Do this here as mempool requires genesis block to be loaded. - ReacceptWalletTransactions(*locked_chain); + ReacceptWalletTransactions(); // Update wallet transactions with current mempool transactions. chain().requestMempoolTransactions(*this); @@ -4384,8 +4370,7 @@ m_pre_split = false; } -int CWalletTx::GetDepthInMainChain( - interfaces::Chain::Lock &locked_chain) const { +int CWalletTx::GetDepthInMainChain() const { assert(pwallet != nullptr); AssertLockHeld(pwallet->cs_wallet); if (isUnconfirmed() || isAbandoned()) { @@ -4396,22 +4381,20 @@ (isConflicted() ? -1 : 1); } -int CWalletTx::GetBlocksToMaturity( - interfaces::Chain::Lock &locked_chain) const { +int CWalletTx::GetBlocksToMaturity() const { if (!IsCoinBase()) { return 0; } - int chain_depth = GetDepthInMainChain(locked_chain); + int chain_depth = GetDepthInMainChain(); // coinbase tx should not be conflicted assert(chain_depth >= 0); return std::max(0, (COINBASE_MATURITY + 1) - chain_depth); } -bool CWalletTx::IsImmatureCoinBase( - interfaces::Chain::Lock &locked_chain) const { +bool CWalletTx::IsImmatureCoinBase() const { // note GetBlocksToMaturity is 0 for non-coinbase tx - return GetBlocksToMaturity(locked_chain) > 0; + return GetBlocksToMaturity() > 0; } std::vector