@@ -69,7 +69,7 @@ class PendingWalletTxImpl : public PendingWalletTx
69
69
};
70
70
71
71
// ! 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)
73
73
{
74
74
WalletTx result;
75
75
result.tx = wtx.tx ;
@@ -87,7 +87,7 @@ static WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx) EXCLUSIVE_LO
87
87
IsMine (wallet, result.txout_address .back ()) :
88
88
ISMINE_NO);
89
89
}
90
- result.credit = wtx.GetCredit (ISMINE_ALL);
90
+ result.credit = wtx.GetCredit (locked_chain, ISMINE_ALL);
91
91
result.debit = wtx.GetDebit (ISMINE_ALL);
92
92
result.change = wtx.GetChange ();
93
93
result.time = wtx.GetTxTime ();
@@ -97,32 +97,38 @@ static WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx) EXCLUSIVE_LO
97
97
}
98
98
99
99
// ! 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)
101
101
{
102
+ LockAnnotation lock (::cs_main); // Temporary, for CheckFinalTx below. Removed in upcoming commit.
103
+
102
104
WalletTxStatus result;
103
105
auto mi = ::mapBlockIndex.find (wtx.hashBlock );
104
106
CBlockIndex* block = mi != ::mapBlockIndex.end () ? mi->second : nullptr ;
105
107
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 );
108
110
result.time_received = wtx.nTimeReceived ;
109
111
result.lock_time = wtx.tx ->nLockTime ;
110
112
result.is_final = CheckFinalTx (*wtx.tx );
111
- result.is_trusted = wtx.IsTrusted ();
113
+ result.is_trusted = wtx.IsTrusted (locked_chain );
112
114
result.is_abandoned = wtx.isAbandoned ();
113
115
result.is_coinbase = wtx.IsCoinBase ();
114
- result.is_in_main_chain = wtx.IsInMainChain ();
116
+ result.is_in_main_chain = wtx.IsInMainChain (locked_chain );
115
117
return result;
116
118
}
117
119
118
120
// ! 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)
120
126
{
121
127
WalletTxOut result;
122
128
result.txout = wtx.tx ->vout [n];
123
129
result.time = wtx.GetTxTime ();
124
130
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);
126
132
return result;
127
133
}
128
134
@@ -242,7 +248,7 @@ class WalletImpl : public Wallet
242
248
auto locked_chain = m_wallet.chain ().lock ();
243
249
LOCK (m_wallet.cs_wallet );
244
250
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,
246
252
fail_reason, coin_control, sign)) {
247
253
return {};
248
254
}
@@ -253,7 +259,7 @@ class WalletImpl : public Wallet
253
259
{
254
260
auto locked_chain = m_wallet.chain ().lock ();
255
261
LOCK (m_wallet.cs_wallet );
256
- return m_wallet.AbandonTransaction (txid);
262
+ return m_wallet.AbandonTransaction (*locked_chain, txid);
257
263
}
258
264
bool transactionCanBeBumped (const uint256& txid) override
259
265
{
@@ -295,7 +301,7 @@ class WalletImpl : public Wallet
295
301
LOCK (m_wallet.cs_wallet );
296
302
auto mi = m_wallet.mapWallet .find (txid);
297
303
if (mi != m_wallet.mapWallet .end ()) {
298
- return MakeWalletTx (m_wallet, mi->second );
304
+ return MakeWalletTx (*locked_chain, m_wallet, mi->second );
299
305
}
300
306
return {};
301
307
}
@@ -306,7 +312,7 @@ class WalletImpl : public Wallet
306
312
std::vector<WalletTx> result;
307
313
result.reserve (m_wallet.mapWallet .size ());
308
314
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 ));
310
316
}
311
317
return result;
312
318
}
@@ -327,7 +333,7 @@ class WalletImpl : public Wallet
327
333
return false ;
328
334
}
329
335
num_blocks = ::chainActive.Height ();
330
- tx_status = MakeWalletTxStatus (mi->second );
336
+ tx_status = MakeWalletTxStatus (*locked_chain, mi->second );
331
337
return true ;
332
338
}
333
339
WalletTx getWalletTxDetails (const uint256& txid,
@@ -343,8 +349,8 @@ class WalletImpl : public Wallet
343
349
num_blocks = ::chainActive.Height ();
344
350
in_mempool = mi->second .InMempool ();
345
351
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 );
348
354
}
349
355
return {};
350
356
}
@@ -408,11 +414,11 @@ class WalletImpl : public Wallet
408
414
auto locked_chain = m_wallet.chain ().lock ();
409
415
LOCK (m_wallet.cs_wallet );
410
416
CoinsList result;
411
- for (const auto & entry : m_wallet.ListCoins ()) {
417
+ for (const auto & entry : m_wallet.ListCoins (*locked_chain )) {
412
418
auto & group = result[entry.first ];
413
419
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 ));
416
422
}
417
423
}
418
424
return result;
@@ -427,9 +433,9 @@ class WalletImpl : public Wallet
427
433
result.emplace_back ();
428
434
auto it = m_wallet.mapWallet .find (output.hash );
429
435
if (it != m_wallet.mapWallet .end ()) {
430
- int depth = it->second .GetDepthInMainChain ();
436
+ int depth = it->second .GetDepthInMainChain (*locked_chain );
431
437
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);
433
439
}
434
440
}
435
441
}
0 commit comments