Skip to content

Commit b8405b8

Browse files
committed
wallet: IsChange requires cs_wallet lock
1 parent d8441f3 commit b8405b8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/wallet/wallet.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ bool CWallet::IsChange(const CScript& script) const
12831283
// a better way of identifying which outputs are 'the send' and which are
12841284
// 'the change' will need to be implemented (maybe extend CWalletTx to remember
12851285
// which output, if any, was change).
1286-
LOCK(cs_wallet);
1286+
AssertLockHeld(cs_wallet);
12871287
if (IsMine(script))
12881288
{
12891289
CTxDestination address;
@@ -1298,6 +1298,7 @@ bool CWallet::IsChange(const CScript& script) const
12981298

12991299
CAmount CWallet::GetChange(const CTxOut& txout) const
13001300
{
1301+
AssertLockHeld(cs_wallet);
13011302
if (!MoneyRange(txout.nValue))
13021303
throw std::runtime_error(std::string(__func__) + ": value out of range");
13031304
return (IsChange(txout) ? txout.nValue : 0);
@@ -1364,6 +1365,7 @@ CAmount CWallet::GetCredit(const CTransaction& tx, const isminefilter& filter) c
13641365

13651366
CAmount CWallet::GetChange(const CTransaction& tx) const
13661367
{
1368+
LOCK(cs_wallet);
13671369
CAmount nChange = 0;
13681370
for (const CTxOut& txout : tx.vout)
13691371
{

src/wallet/wallet.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,9 +1048,9 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
10481048
CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
10491049
isminetype IsMine(const CTxOut& txout) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
10501050
CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const;
1051-
bool IsChange(const CTxOut& txout) const;
1052-
bool IsChange(const CScript& script) const;
1053-
CAmount GetChange(const CTxOut& txout) const;
1051+
bool IsChange(const CTxOut& txout) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
1052+
bool IsChange(const CScript& script) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
1053+
CAmount GetChange(const CTxOut& txout) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
10541054
bool IsMine(const CTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
10551055
/** should probably be renamed to IsRelevantToMe */
10561056
bool IsFromMe(const CTransaction& tx) const;

0 commit comments

Comments
 (0)