Skip to content

Commit 0cb1772

Browse files
committed
wallet: unify CachedTxGetImmatureCredit and CachedTxGetImmatureWatchOnlyCredit
1 parent 04c6423 commit 0cb1772

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

src/wallet/receive.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,12 @@ CAmount CachedTxGetChange(const CWallet& wallet, const CWalletTx& wtx)
164164
return wtx.nChangeCached;
165165
}
166166

167-
CAmount CachedTxGetImmatureCredit(const CWallet& wallet, const CWalletTx& wtx)
167+
CAmount CachedTxGetImmatureCredit(const CWallet& wallet, const CWalletTx& wtx, const isminefilter& filter)
168168
{
169169
AssertLockHeld(wallet.cs_wallet);
170170

171171
if (wallet.IsTxImmatureCoinBase(wtx) && wallet.IsTxInMainChain(wtx)) {
172-
return GetCachableAmount(wallet, wtx, CWalletTx::IMMATURE_CREDIT, ISMINE_SPENDABLE);
173-
}
174-
175-
return 0;
176-
}
177-
178-
CAmount CachedTxGetImmatureWatchOnlyCredit(const CWallet& wallet, const CWalletTx& wtx)
179-
{
180-
AssertLockHeld(wallet.cs_wallet);
181-
182-
if (wallet.IsTxImmatureCoinBase(wtx) && wallet.IsTxInMainChain(wtx)) {
183-
return GetCachableAmount(wallet, wtx, CWalletTx::IMMATURE_CREDIT, ISMINE_WATCH_ONLY);
172+
return GetCachableAmount(wallet, wtx, CWalletTx::IMMATURE_CREDIT, filter);
184173
}
185174

186175
return 0;
@@ -342,8 +331,8 @@ Balance GetBalance(const CWallet& wallet, const int min_depth, bool avoid_reuse)
342331
ret.m_mine_untrusted_pending += tx_credit_mine;
343332
ret.m_watchonly_untrusted_pending += tx_credit_watchonly;
344333
}
345-
ret.m_mine_immature += CachedTxGetImmatureCredit(wallet, wtx);
346-
ret.m_watchonly_immature += CachedTxGetImmatureWatchOnlyCredit(wallet, wtx);
334+
ret.m_mine_immature += CachedTxGetImmatureCredit(wallet, wtx, ISMINE_SPENDABLE);
335+
ret.m_watchonly_immature += CachedTxGetImmatureCredit(wallet, wtx, ISMINE_WATCH_ONLY);
347336
}
348337
}
349338
return ret;

src/wallet/receive.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ CAmount CachedTxGetCredit(const CWallet& wallet, const CWalletTx& wtx, const ism
2929
//! filter decides which addresses will count towards the debit
3030
CAmount CachedTxGetDebit(const CWallet& wallet, const CWalletTx& wtx, const isminefilter& filter);
3131
CAmount CachedTxGetChange(const CWallet& wallet, const CWalletTx& wtx);
32-
CAmount CachedTxGetImmatureCredit(const CWallet& wallet, const CWalletTx& wtx)
33-
EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
34-
CAmount CachedTxGetImmatureWatchOnlyCredit(const CWallet& wallet, const CWalletTx& wtx)
32+
CAmount CachedTxGetImmatureCredit(const CWallet& wallet, const CWalletTx& wtx, const isminefilter& filter)
3533
EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
3634
CAmount CachedTxGetAvailableCredit(const CWallet& wallet, const CWalletTx& wtx, const isminefilter& filter = ISMINE_SPENDABLE)
3735
EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);

src/wallet/test/wallet_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,13 @@ BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
350350

351351
// Call GetImmatureCredit() once before adding the key to the wallet to
352352
// cache the current immature credit amount, which is 0.
353-
BOOST_CHECK_EQUAL(CachedTxGetImmatureCredit(wallet, wtx), 0);
353+
BOOST_CHECK_EQUAL(CachedTxGetImmatureCredit(wallet, wtx, ISMINE_SPENDABLE), 0);
354354

355355
// Invalidate the cached value, add the key, and make sure a new immature
356356
// credit amount is calculated.
357357
wtx.MarkDirty();
358358
AddKey(wallet, coinbaseKey);
359-
BOOST_CHECK_EQUAL(CachedTxGetImmatureCredit(wallet, wtx), 50*COIN);
359+
BOOST_CHECK_EQUAL(CachedTxGetImmatureCredit(wallet, wtx, ISMINE_SPENDABLE), 50*COIN);
360360
}
361361

362362
static int64_t AddTx(ChainstateManager& chainman, CWallet& wallet, uint32_t lockTime, int64_t mockTime, int64_t blockTime)

0 commit comments

Comments
 (0)