@@ -69,7 +69,7 @@ class PendingWalletTxImpl : public PendingWalletTx
6969};
7070
7171// ! Construct wallet tx struct.
72- static WalletTx MakeWalletTx (CWallet& wallet, const CWalletTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_main )
72+ WalletTx MakeWalletTx (interfaces::Chain::Lock& locked_chain, CWallet& wallet, const CWalletTx& wtx)
7373{
7474 WalletTx result;
7575 result.tx = wtx.tx ;
@@ -87,7 +87,7 @@ static WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx) EXCLUSIVE_LO
8787 IsMine (wallet, result.txout_address .back ()) :
8888 ISMINE_NO );
8989 }
90- result.credit = wtx.GetCredit (ISMINE_ALL );
90+ result.credit = wtx.GetCredit (locked_chain, ISMINE_ALL );
9191 result.debit = wtx.GetDebit (ISMINE_ALL );
9292 result.change = wtx.GetChange ();
9393 result.time = wtx.GetTxTime ();
@@ -97,32 +97,38 @@ static WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx) EXCLUSIVE_LO
9797}
9898
9999// ! Construct wallet tx status struct.
100- static WalletTxStatus MakeWalletTxStatus (const CWalletTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_main )
100+ WalletTxStatus MakeWalletTxStatus (interfaces::Chain::Lock& locked_chain, const CWalletTx& wtx)
101101{
102+ LockAnnotation lock (::cs_main); // Temporary, for CheckFinalTx below. Removed in upcoming commit.
103+
102104 WalletTxStatus result;
103105 auto mi = ::mapBlockIndex.find (wtx.hashBlock );
104106 CBlockIndex* block = mi != ::mapBlockIndex.end () ? mi->second : nullptr ;
105107 result.block_height = (block ? block->nHeight : std::numeric_limits<int >::max ());
106- result.blocks_to_maturity = wtx.GetBlocksToMaturity ();
107- result.depth_in_main_chain = wtx.GetDepthInMainChain ();
108+ result.blocks_to_maturity = wtx.GetBlocksToMaturity (locked_chain );
109+ result.depth_in_main_chain = wtx.GetDepthInMainChain (locked_chain );
108110 result.time_received = wtx.nTimeReceived ;
109111 result.lock_time = wtx.tx ->nLockTime ;
110112 result.is_final = CheckFinalTx (*wtx.tx );
111- result.is_trusted = wtx.IsTrusted ();
113+ result.is_trusted = wtx.IsTrusted (locked_chain );
112114 result.is_abandoned = wtx.isAbandoned ();
113115 result.is_coinbase = wtx.IsCoinBase ();
114- result.is_in_main_chain = wtx.IsInMainChain ();
116+ result.is_in_main_chain = wtx.IsInMainChain (locked_chain );
115117 return result;
116118}
117119
118120// ! Construct wallet TxOut struct.
119- static WalletTxOut MakeWalletTxOut (CWallet& wallet, const CWalletTx& wtx, int n, int depth) EXCLUSIVE_LOCKS_REQUIRED(cs_main, wallet.cs_wallet)
121+ WalletTxOut MakeWalletTxOut (interfaces::Chain::Lock& locked_chain,
122+ CWallet& wallet,
123+ const CWalletTx& wtx,
124+ int n,
125+ int depth) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
120126{
121127 WalletTxOut result;
122128 result.txout = wtx.tx ->vout [n];
123129 result.time = wtx.GetTxTime ();
124130 result.depth_in_main_chain = depth;
125- result.is_spent = wallet.IsSpent (wtx.GetHash (), n);
131+ result.is_spent = wallet.IsSpent (locked_chain, wtx.GetHash (), n);
126132 return result;
127133}
128134
@@ -242,7 +248,7 @@ class WalletImpl : public Wallet
242248 auto locked_chain = m_wallet.chain ().lock ();
243249 LOCK (m_wallet.cs_wallet );
244250 auto pending = MakeUnique<PendingWalletTxImpl>(m_wallet);
245- if (!m_wallet.CreateTransaction (recipients, pending->m_tx , pending->m_key , fee, change_pos,
251+ if (!m_wallet.CreateTransaction (*locked_chain, recipients, pending->m_tx , pending->m_key , fee, change_pos,
246252 fail_reason, coin_control, sign)) {
247253 return {};
248254 }
@@ -253,7 +259,7 @@ class WalletImpl : public Wallet
253259 {
254260 auto locked_chain = m_wallet.chain ().lock ();
255261 LOCK (m_wallet.cs_wallet );
256- return m_wallet.AbandonTransaction (txid);
262+ return m_wallet.AbandonTransaction (*locked_chain, txid);
257263 }
258264 bool transactionCanBeBumped (const uint256& txid) override
259265 {
@@ -295,7 +301,7 @@ class WalletImpl : public Wallet
295301 LOCK (m_wallet.cs_wallet );
296302 auto mi = m_wallet.mapWallet .find (txid);
297303 if (mi != m_wallet.mapWallet .end ()) {
298- return MakeWalletTx (m_wallet, mi->second );
304+ return MakeWalletTx (*locked_chain, m_wallet, mi->second );
299305 }
300306 return {};
301307 }
@@ -306,7 +312,7 @@ class WalletImpl : public Wallet
306312 std::vector<WalletTx> result;
307313 result.reserve (m_wallet.mapWallet .size ());
308314 for (const auto & entry : m_wallet.mapWallet ) {
309- result.emplace_back (MakeWalletTx (m_wallet, entry.second ));
315+ result.emplace_back (MakeWalletTx (*locked_chain, m_wallet, entry.second ));
310316 }
311317 return result;
312318 }
@@ -327,7 +333,7 @@ class WalletImpl : public Wallet
327333 return false ;
328334 }
329335 num_blocks = ::chainActive.Height ();
330- tx_status = MakeWalletTxStatus (mi->second );
336+ tx_status = MakeWalletTxStatus (*locked_chain, mi->second );
331337 return true ;
332338 }
333339 WalletTx getWalletTxDetails (const uint256& txid,
@@ -343,8 +349,8 @@ class WalletImpl : public Wallet
343349 num_blocks = ::chainActive.Height ();
344350 in_mempool = mi->second .InMempool ();
345351 order_form = mi->second .vOrderForm ;
346- tx_status = MakeWalletTxStatus (mi->second );
347- return MakeWalletTx (m_wallet, mi->second );
352+ tx_status = MakeWalletTxStatus (*locked_chain, mi->second );
353+ return MakeWalletTx (*locked_chain, m_wallet, mi->second );
348354 }
349355 return {};
350356 }
@@ -408,11 +414,11 @@ class WalletImpl : public Wallet
408414 auto locked_chain = m_wallet.chain ().lock ();
409415 LOCK (m_wallet.cs_wallet );
410416 CoinsList result;
411- for (const auto & entry : m_wallet.ListCoins ()) {
417+ for (const auto & entry : m_wallet.ListCoins (*locked_chain )) {
412418 auto & group = result[entry.first ];
413419 for (const auto & coin : entry.second ) {
414- group.emplace_back (
415- COutPoint (coin. tx -> GetHash (), coin. i ), MakeWalletTxOut ( m_wallet, *coin.tx , coin.i , coin.nDepth ));
420+ group.emplace_back (COutPoint (coin. tx -> GetHash (), coin. i ),
421+ MakeWalletTxOut (*locked_chain, m_wallet, *coin.tx , coin.i , coin.nDepth ));
416422 }
417423 }
418424 return result;
@@ -427,9 +433,9 @@ class WalletImpl : public Wallet
427433 result.emplace_back ();
428434 auto it = m_wallet.mapWallet .find (output.hash );
429435 if (it != m_wallet.mapWallet .end ()) {
430- int depth = it->second .GetDepthInMainChain ();
436+ int depth = it->second .GetDepthInMainChain (*locked_chain );
431437 if (depth >= 0 ) {
432- result.back () = MakeWalletTxOut (m_wallet, it->second , output.n , depth);
438+ result.back () = MakeWalletTxOut (*locked_chain, m_wallet, it->second , output.n , depth);
433439 }
434440 }
435441 }
0 commit comments