@@ -2162,9 +2162,9 @@ CAmount CWallet::GetBalance(const isminefilter& filter, const int min_depth) con
2162
2162
LOCK (cs_wallet);
2163
2163
for (const auto & entry : mapWallet)
2164
2164
{
2165
- const CWalletTx* pcoin = & entry.second ;
2166
- if (pcoin-> IsTrusted (*locked_chain) && pcoin-> GetDepthInMainChain (*locked_chain) >= min_depth) {
2167
- nTotal += pcoin-> GetAvailableCredit (*locked_chain, true , filter);
2165
+ const CWalletTx& wtx = entry.second ;
2166
+ if (wtx. IsTrusted (*locked_chain) && wtx. GetDepthInMainChain (*locked_chain) >= min_depth) {
2167
+ nTotal += wtx. GetAvailableCredit (*locked_chain, true , filter);
2168
2168
}
2169
2169
}
2170
2170
}
@@ -2180,9 +2180,9 @@ CAmount CWallet::GetUnconfirmedBalance() const
2180
2180
LOCK (cs_wallet);
2181
2181
for (const auto & entry : mapWallet)
2182
2182
{
2183
- const CWalletTx* pcoin = & entry.second ;
2184
- if (!pcoin-> IsTrusted (*locked_chain) && pcoin-> GetDepthInMainChain (*locked_chain) == 0 && pcoin-> InMempool ())
2185
- nTotal += pcoin-> GetAvailableCredit (*locked_chain);
2183
+ const CWalletTx& wtx = entry.second ;
2184
+ if (!wtx. IsTrusted (*locked_chain) && wtx. GetDepthInMainChain (*locked_chain) == 0 && wtx. InMempool ())
2185
+ nTotal += wtx. GetAvailableCredit (*locked_chain);
2186
2186
}
2187
2187
}
2188
2188
return nTotal;
@@ -2196,8 +2196,8 @@ CAmount CWallet::GetImmatureBalance() const
2196
2196
LOCK (cs_wallet);
2197
2197
for (const auto & entry : mapWallet)
2198
2198
{
2199
- const CWalletTx* pcoin = & entry.second ;
2200
- nTotal += pcoin-> GetImmatureCredit (*locked_chain);
2199
+ const CWalletTx& wtx = entry.second ;
2200
+ nTotal += wtx. GetImmatureCredit (*locked_chain);
2201
2201
}
2202
2202
}
2203
2203
return nTotal;
@@ -2211,9 +2211,9 @@ CAmount CWallet::GetUnconfirmedWatchOnlyBalance() const
2211
2211
LOCK (cs_wallet);
2212
2212
for (const auto & entry : mapWallet)
2213
2213
{
2214
- const CWalletTx* pcoin = & entry.second ;
2215
- if (!pcoin-> IsTrusted (*locked_chain) && pcoin-> GetDepthInMainChain (*locked_chain) == 0 && pcoin-> InMempool ())
2216
- nTotal += pcoin-> GetAvailableCredit (*locked_chain, true , ISMINE_WATCH_ONLY);
2214
+ const CWalletTx& wtx = entry.second ;
2215
+ if (!wtx. IsTrusted (*locked_chain) && wtx. GetDepthInMainChain (*locked_chain) == 0 && wtx. InMempool ())
2216
+ nTotal += wtx. GetAvailableCredit (*locked_chain, true , ISMINE_WATCH_ONLY);
2217
2217
}
2218
2218
}
2219
2219
return nTotal;
@@ -2227,53 +2227,13 @@ CAmount CWallet::GetImmatureWatchOnlyBalance() const
2227
2227
LOCK (cs_wallet);
2228
2228
for (const auto & entry : mapWallet)
2229
2229
{
2230
- const CWalletTx* pcoin = & entry.second ;
2231
- nTotal += pcoin-> GetImmatureWatchOnlyCredit (*locked_chain);
2230
+ const CWalletTx& wtx = entry.second ;
2231
+ nTotal += wtx. GetImmatureWatchOnlyCredit (*locked_chain);
2232
2232
}
2233
2233
}
2234
2234
return nTotal;
2235
2235
}
2236
2236
2237
- // Calculate total balance in a different way from GetBalance. The biggest
2238
- // difference is that GetBalance sums up all unspent TxOuts paying to the
2239
- // wallet, while this sums up both spent and unspent TxOuts paying to the
2240
- // wallet, and then subtracts the values of TxIns spending from the wallet. This
2241
- // also has fewer restrictions on which unconfirmed transactions are considered
2242
- // trusted.
2243
- CAmount CWallet::GetLegacyBalance (const isminefilter& filter, int minDepth) const
2244
- {
2245
- auto locked_chain = chain ().lock ();
2246
- LOCK (cs_wallet);
2247
-
2248
- CAmount balance = 0 ;
2249
- for (const auto & entry : mapWallet) {
2250
- const CWalletTx& wtx = entry.second ;
2251
- const int depth = wtx.GetDepthInMainChain (*locked_chain);
2252
- if (depth < 0 || !locked_chain->checkFinalTx (*wtx.tx ) || wtx.IsImmatureCoinBase (*locked_chain)) {
2253
- continue ;
2254
- }
2255
-
2256
- // Loop through tx outputs and add incoming payments. For outgoing txs,
2257
- // treat change outputs specially, as part of the amount debited.
2258
- CAmount debit = wtx.GetDebit (filter);
2259
- const bool outgoing = debit > 0 ;
2260
- for (const CTxOut& out : wtx.tx ->vout ) {
2261
- if (outgoing && IsChange (out)) {
2262
- debit -= out.nValue ;
2263
- } else if (IsMine (out) & filter && depth >= minDepth) {
2264
- balance += out.nValue ;
2265
- }
2266
- }
2267
-
2268
- // For outgoing txs, subtract amount debited.
2269
- if (outgoing) {
2270
- balance -= debit;
2271
- }
2272
- }
2273
-
2274
- return balance;
2275
- }
2276
-
2277
2237
CAmount CWallet::GetAvailableBalance (const CCoinControl* coinControl) const
2278
2238
{
2279
2239
auto locked_chain = chain ().lock ();
@@ -2300,25 +2260,25 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<
2300
2260
for (const auto & entry : mapWallet)
2301
2261
{
2302
2262
const uint256& wtxid = entry.first ;
2303
- const CWalletTx* pcoin = & entry.second ;
2263
+ const CWalletTx& wtx = entry.second ;
2304
2264
2305
- if (!locked_chain.checkFinalTx (*pcoin-> tx )) {
2265
+ if (!locked_chain.checkFinalTx (*wtx. tx )) {
2306
2266
continue ;
2307
2267
}
2308
2268
2309
- if (pcoin-> IsImmatureCoinBase (locked_chain))
2269
+ if (wtx. IsImmatureCoinBase (locked_chain))
2310
2270
continue ;
2311
2271
2312
- int nDepth = pcoin-> GetDepthInMainChain (locked_chain);
2272
+ int nDepth = wtx. GetDepthInMainChain (locked_chain);
2313
2273
if (nDepth < 0 )
2314
2274
continue ;
2315
2275
2316
2276
// We should not consider coins which aren't at least in our mempool
2317
2277
// It's possible for these to be conflicted via ancestors which we may never be able to detect
2318
- if (nDepth == 0 && !pcoin-> InMempool ())
2278
+ if (nDepth == 0 && !wtx. InMempool ())
2319
2279
continue ;
2320
2280
2321
- bool safeTx = pcoin-> IsTrusted (locked_chain);
2281
+ bool safeTx = wtx. IsTrusted (locked_chain);
2322
2282
2323
2283
// We should not consider coins from transactions that are replacing
2324
2284
// other transactions.
@@ -2335,7 +2295,7 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<
2335
2295
// be a 1-block reorg away from the chain where transactions A and C
2336
2296
// were accepted to another chain where B, B', and C were all
2337
2297
// accepted.
2338
- if (nDepth == 0 && pcoin-> mapValue .count (" replaces_txid" )) {
2298
+ if (nDepth == 0 && wtx. mapValue .count (" replaces_txid" )) {
2339
2299
safeTx = false ;
2340
2300
}
2341
2301
@@ -2347,7 +2307,7 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<
2347
2307
// intending to replace A', but potentially resulting in a scenario
2348
2308
// where A, A', and D could all be accepted (instead of just B and
2349
2309
// D, or just A and A' like the user would want).
2350
- if (nDepth == 0 && pcoin-> mapValue .count (" replaced_by_txid" )) {
2310
+ if (nDepth == 0 && wtx. mapValue .count (" replaced_by_txid" )) {
2351
2311
safeTx = false ;
2352
2312
}
2353
2313
@@ -2358,8 +2318,8 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<
2358
2318
if (nDepth < nMinDepth || nDepth > nMaxDepth)
2359
2319
continue ;
2360
2320
2361
- for (unsigned int i = 0 ; i < pcoin-> tx ->vout .size (); i++) {
2362
- if (pcoin-> tx ->vout [i].nValue < nMinimumAmount || pcoin-> tx ->vout [i].nValue > nMaximumAmount)
2321
+ for (unsigned int i = 0 ; i < wtx. tx ->vout .size (); i++) {
2322
+ if (wtx. tx ->vout [i].nValue < nMinimumAmount || wtx. tx ->vout [i].nValue > nMaximumAmount)
2363
2323
continue ;
2364
2324
2365
2325
if (coinControl && coinControl->HasSelected () && !coinControl->fAllowOtherInputs && !coinControl->IsSelected (COutPoint (entry.first , i)))
@@ -2371,20 +2331,20 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<
2371
2331
if (IsSpent (locked_chain, wtxid, i))
2372
2332
continue ;
2373
2333
2374
- isminetype mine = IsMine (pcoin-> tx ->vout [i]);
2334
+ isminetype mine = IsMine (wtx. tx ->vout [i]);
2375
2335
2376
2336
if (mine == ISMINE_NO) {
2377
2337
continue ;
2378
2338
}
2379
2339
2380
- bool solvable = IsSolvable (*this , pcoin-> tx ->vout [i].scriptPubKey );
2340
+ bool solvable = IsSolvable (*this , wtx. tx ->vout [i].scriptPubKey );
2381
2341
bool spendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable));
2382
2342
2383
- vCoins.push_back (COutput (pcoin , i, nDepth, spendable, solvable, safeTx, (coinControl && coinControl->fAllowWatchOnly )));
2343
+ vCoins.push_back (COutput (&wtx , i, nDepth, spendable, solvable, safeTx, (coinControl && coinControl->fAllowWatchOnly )));
2384
2344
2385
2345
// Checks the sum amount of all UTXO's.
2386
2346
if (nMinimumSumAmount != MAX_MONEY) {
2387
- nTotal += pcoin-> tx ->vout [i].nValue ;
2347
+ nTotal += wtx. tx ->vout [i].nValue ;
2388
2348
2389
2349
if (nTotal >= nMinimumSumAmount) {
2390
2350
return ;
@@ -2542,13 +2502,13 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
2542
2502
std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find (outpoint.hash );
2543
2503
if (it != mapWallet.end ())
2544
2504
{
2545
- const CWalletTx* pcoin = & it->second ;
2505
+ const CWalletTx& wtx = it->second ;
2546
2506
// Clearly invalid input, fail
2547
- if (pcoin-> tx ->vout .size () <= outpoint.n )
2507
+ if (wtx. tx ->vout .size () <= outpoint.n )
2548
2508
return false ;
2549
2509
// Just to calculate the marginal byte size
2550
- nValueFromPresetInputs += pcoin-> tx ->vout [outpoint.n ].nValue ;
2551
- setPresetCoins.insert (CInputCoin (pcoin-> tx , outpoint.n ));
2510
+ nValueFromPresetInputs += wtx. tx ->vout [outpoint.n ].nValue ;
2511
+ setPresetCoins.insert (CInputCoin (wtx. tx , outpoint.n ));
2552
2512
} else
2553
2513
return false ; // TODO: Allow non-wallet inputs
2554
2514
}
@@ -3586,27 +3546,27 @@ std::map<CTxDestination, CAmount> CWallet::GetAddressBalances(interfaces::Chain:
3586
3546
LOCK (cs_wallet);
3587
3547
for (const auto & walletEntry : mapWallet)
3588
3548
{
3589
- const CWalletTx *pcoin = & walletEntry.second ;
3549
+ const CWalletTx& wtx = walletEntry.second ;
3590
3550
3591
- if (!pcoin-> IsTrusted (locked_chain))
3551
+ if (!wtx. IsTrusted (locked_chain))
3592
3552
continue ;
3593
3553
3594
- if (pcoin-> IsImmatureCoinBase (locked_chain))
3554
+ if (wtx. IsImmatureCoinBase (locked_chain))
3595
3555
continue ;
3596
3556
3597
- int nDepth = pcoin-> GetDepthInMainChain (locked_chain);
3598
- if (nDepth < (pcoin-> IsFromMe (ISMINE_ALL) ? 0 : 1 ))
3557
+ int nDepth = wtx. GetDepthInMainChain (locked_chain);
3558
+ if (nDepth < (wtx. IsFromMe (ISMINE_ALL) ? 0 : 1 ))
3599
3559
continue ;
3600
3560
3601
- for (unsigned int i = 0 ; i < pcoin-> tx ->vout .size (); i++)
3561
+ for (unsigned int i = 0 ; i < wtx. tx ->vout .size (); i++)
3602
3562
{
3603
3563
CTxDestination addr;
3604
- if (!IsMine (pcoin-> tx ->vout [i]))
3564
+ if (!IsMine (wtx. tx ->vout [i]))
3605
3565
continue ;
3606
- if (!ExtractDestination (pcoin-> tx ->vout [i].scriptPubKey , addr))
3566
+ if (!ExtractDestination (wtx. tx ->vout [i].scriptPubKey , addr))
3607
3567
continue ;
3608
3568
3609
- CAmount n = IsSpent (locked_chain, walletEntry.first , i) ? 0 : pcoin-> tx ->vout [i].nValue ;
3569
+ CAmount n = IsSpent (locked_chain, walletEntry.first , i) ? 0 : wtx. tx ->vout [i].nValue ;
3610
3570
3611
3571
if (!balances.count (addr))
3612
3572
balances[addr] = 0 ;
@@ -3626,13 +3586,13 @@ std::set< std::set<CTxDestination> > CWallet::GetAddressGroupings()
3626
3586
3627
3587
for (const auto & walletEntry : mapWallet)
3628
3588
{
3629
- const CWalletTx *pcoin = & walletEntry.second ;
3589
+ const CWalletTx& wtx = walletEntry.second ;
3630
3590
3631
- if (pcoin-> tx ->vin .size () > 0 )
3591
+ if (wtx. tx ->vin .size () > 0 )
3632
3592
{
3633
3593
bool any_mine = false ;
3634
3594
// group all input addresses with each other
3635
- for (const CTxIn& txin : pcoin-> tx ->vin )
3595
+ for (const CTxIn& txin : wtx. tx ->vin )
3636
3596
{
3637
3597
CTxDestination address;
3638
3598
if (!IsMine (txin)) /* If this input isn't mine, ignore it */
@@ -3646,7 +3606,7 @@ std::set< std::set<CTxDestination> > CWallet::GetAddressGroupings()
3646
3606
// group change with input addresses
3647
3607
if (any_mine)
3648
3608
{
3649
- for (const CTxOut& txout : pcoin-> tx ->vout )
3609
+ for (const CTxOut& txout : wtx. tx ->vout )
3650
3610
if (IsChange (txout))
3651
3611
{
3652
3612
CTxDestination txoutAddr;
@@ -3663,7 +3623,7 @@ std::set< std::set<CTxDestination> > CWallet::GetAddressGroupings()
3663
3623
}
3664
3624
3665
3625
// group lone addrs by themselves
3666
- for (const auto & txout : pcoin-> tx ->vout )
3626
+ for (const auto & txout : wtx. tx ->vout )
3667
3627
if (IsMine (txout))
3668
3628
{
3669
3629
CTxDestination address;
0 commit comments