diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2022-04-27 10:52:30 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2022-06-08 11:22:39 -0300 |
commit | a06fa94ff81e2bccef0316ea5ec4eca0f4de5071 (patch) | |
tree | 2539c545d00292374270690795d78a91b92fee6c | |
parent | 91902b77202fc636edb3db587cb6e87d9fb9b60a (diff) |
wallet: IsSpent, 'COutPoint' arg instead of (hash, index)
-rw-r--r-- | src/wallet/interfaces.cpp | 4 | ||||
-rw-r--r-- | src/wallet/receive.cpp | 15 | ||||
-rw-r--r-- | src/wallet/rpc/coins.cpp | 2 | ||||
-rw-r--r-- | src/wallet/rpc/spend.cpp | 2 | ||||
-rw-r--r-- | src/wallet/spend.cpp | 2 | ||||
-rw-r--r-- | src/wallet/wallet.cpp | 6 | ||||
-rw-r--r-- | src/wallet/wallet.h | 2 |
7 files changed, 15 insertions, 18 deletions
diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp index 897c198664..f54b2c83d2 100644 --- a/src/wallet/interfaces.cpp +++ b/src/wallet/interfaces.cpp @@ -110,7 +110,7 @@ WalletTxOut MakeWalletTxOut(const CWallet& wallet, result.txout = wtx.tx->vout[n]; result.time = wtx.GetTxTime(); result.depth_in_main_chain = depth; - result.is_spent = wallet.IsSpent(wtx.GetHash(), n); + result.is_spent = wallet.IsSpent(COutPoint(wtx.GetHash(), n)); return result; } @@ -121,7 +121,7 @@ WalletTxOut MakeWalletTxOut(const CWallet& wallet, result.txout = output.txout; result.time = output.time; result.depth_in_main_chain = output.depth; - result.is_spent = wallet.IsSpent(output.outpoint.hash, output.outpoint.n); + result.is_spent = wallet.IsSpent(output.outpoint); return result; } diff --git a/src/wallet/receive.cpp b/src/wallet/receive.cpp index 8cce07b921..39d4574def 100644 --- a/src/wallet/receive.cpp +++ b/src/wallet/receive.cpp @@ -204,9 +204,8 @@ CAmount CachedTxGetAvailableCredit(const CWallet& wallet, const CWalletTx& wtx, bool allow_used_addresses = (filter & ISMINE_USED) || !wallet.IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE); CAmount nCredit = 0; uint256 hashTx = wtx.GetHash(); - for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) - { - if (!wallet.IsSpent(hashTx, i) && (allow_used_addresses || !wallet.IsSpentKey(hashTx, i))) { + for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) { + if (!wallet.IsSpent(COutPoint(hashTx, i)) && (allow_used_addresses || !wallet.IsSpentKey(hashTx, i))) { const CTxOut &txout = wtx.tx->vout[i]; nCredit += OutputGetCredit(wallet, txout, filter); if (!MoneyRange(nCredit)) @@ -371,15 +370,15 @@ std::map<CTxDestination, CAmount> GetAddressBalances(const CWallet& wallet) if (nDepth < (CachedTxIsFromMe(wallet, wtx, ISMINE_ALL) ? 0 : 1)) continue; - for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) - { + for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) { + const auto& output = wtx.tx->vout[i]; CTxDestination addr; - if (!wallet.IsMine(wtx.tx->vout[i])) + if (!wallet.IsMine(output)) continue; - if(!ExtractDestination(wtx.tx->vout[i].scriptPubKey, addr)) + if(!ExtractDestination(output.scriptPubKey, addr)) continue; - CAmount n = wallet.IsSpent(walletEntry.first, i) ? 0 : wtx.tx->vout[i].nValue; + CAmount n = wallet.IsSpent(COutPoint(walletEntry.first, i)) ? 0 : output.nValue; balances[addr] += n; } } diff --git a/src/wallet/rpc/coins.cpp b/src/wallet/rpc/coins.cpp index d9ecbc661e..3eea03ff78 100644 --- a/src/wallet/rpc/coins.cpp +++ b/src/wallet/rpc/coins.cpp @@ -341,7 +341,7 @@ RPCHelpMan lockunspent() throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout index out of bounds"); } - if (pwallet->IsSpent(outpt.hash, outpt.n)) { + if (pwallet->IsSpent(outpt)) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected unspent output"); } diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp index 98e180e4a1..9627111a06 100644 --- a/src/wallet/rpc/spend.cpp +++ b/src/wallet/rpc/spend.cpp @@ -1387,7 +1387,7 @@ RPCHelpMan sendall() throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot combine send_max with specific inputs."); } else if (options.exists("inputs")) { for (const CTxIn& input : rawTx.vin) { - if (pwallet->IsSpent(input.prevout.hash, input.prevout.n)) { + if (pwallet->IsSpent(input.prevout)) { throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Input not available. UTXO (%s:%d) was already spent.", input.prevout.hash.ToString(), input.prevout.n)); } const CWalletTx* tx{pwallet->GetWalletTx(input.prevout.hash)}; diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 14edfecdca..d178358048 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -182,7 +182,7 @@ CoinsResult AvailableCoins(const CWallet& wallet, if (wallet.IsLockedCoin(outpoint)) continue; - if (wallet.IsSpent(wtxid, i)) + if (wallet.IsSpent(outpoint)) continue; isminetype mine = wallet.IsMine(output); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 19650ed166..de5f191520 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -629,14 +629,12 @@ void CWallet::SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator> ran * Outpoint is spent if any non-conflicted transaction * spends it: */ -bool CWallet::IsSpent(const uint256& hash, unsigned int n) const +bool CWallet::IsSpent(const COutPoint& outpoint) const { - const COutPoint outpoint(hash, n); std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range; range = mapTxSpends.equal_range(outpoint); - for (TxSpends::const_iterator it = range.first; it != range.second; ++it) - { + for (TxSpends::const_iterator it = range.first; it != range.second; ++it) { const uint256& wtxid = it->second; std::map<uint256, CWalletTx>::const_iterator mit = mapWallet.find(wtxid); if (mit != mapWallet.end()) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index bd4a4b2846..7969b59f4a 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -441,7 +441,7 @@ public: //! check whether we support the named feature bool CanSupportFeature(enum WalletFeature wf) const override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); return IsFeatureSupported(nWalletVersion, wf); } - bool IsSpent(const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); + bool IsSpent(const COutPoint& outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); // Whether this or any known UTXO with the same single key has been spent. bool IsSpentKey(const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); |