diff --git a/src/wallet/receive.cpp b/src/wallet/receive.cpp index 1d03c33273..8e43f3f537 100644 --- a/src/wallet/receive.cpp +++ b/src/wallet/receive.cpp @@ -113,27 +113,12 @@ bool ScriptIsChange(const CWallet& wallet, const CScript& script) return false; } -CAmountMap OutputGetChange(const CWallet& wallet, const CTxOut& txout) -{ - AssertLockHeld(wallet.cs_wallet); - - CAmountMap change; - change[txout.nAsset.GetAsset()] = txout.nValue.GetAmount(); - if (!MoneyRange(change)) - throw std::runtime_error(std::string(__func__) + ": value out of range"); - return (OutputIsChange(wallet, txout) ? change : CAmountMap()); -} - -CAmountMap TxGetChange(const CWallet& wallet, const CTransaction& tx) +CAmountMap TxGetChange(const CWallet& wallet, const CWalletTx& wtx) { LOCK(wallet.cs_wallet); - CAmountMap nChange; - for (const CTxOut& txout : tx.vout) - { - nChange += OutputGetChange(wallet, txout); - if (!MoneyRange(nChange)) - throw std::runtime_error(std::string(__func__) + ": value out of range"); - } + CAmountMap nChange = GetChange(wallet, wtx); + if (!MoneyRange(nChange)) + throw std::runtime_error(std::string(__func__) + ": value out of range"); return nChange; } @@ -203,7 +188,7 @@ CAmountMap CachedTxGetChange(const CWallet& wallet, const CWalletTx& wtx) { if (wtx.fChangeCached) return wtx.nChangeCached; - wtx.nChangeCached = TxGetChange(wallet, *wtx.tx); + wtx.nChangeCached = TxGetChange(wallet, wtx); wtx.fChangeCached = true; return wtx.nChangeCached; } diff --git a/src/wallet/receive.h b/src/wallet/receive.h index d89024883d..c91f018e9f 100644 --- a/src/wallet/receive.h +++ b/src/wallet/receive.h @@ -22,9 +22,8 @@ CAmountMap TxGetCredit(const CWallet& wallet, const CTransaction& tx, const ismi bool ScriptIsChange(const CWallet& wallet, const CScript& script) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet); bool OutputIsChange(const CWallet& wallet, const CTxOut& txout) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet); -CAmountMap OutputGetChange(const CWallet& wallet, const CTxOut& txout) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet); -CAmountMap TxGetChange(const CWallet& wallet, const CTransaction& tx); // ELEMENTS: +CAmountMap TxGetChange(const CWallet& wallet, const CWalletTx& wtx); CAmountMap GetCredit(const CWallet& wallet, const CWalletTx& wtx, const isminefilter& filter) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet); CAmountMap GetChange(const CWallet& wallet, const CWalletTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);