From f2d00bfe1a32a11c0d88e8c1d3bae6a6b01db15e Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Fri, 22 Jul 2022 14:49:10 -0400 Subject: [PATCH] wallet: Add CWallet::IsMine(COutPoint) It is useful to have an IsMine function that can take an outpoint. --- src/wallet/wallet.cpp | 13 +++++++++++++ src/wallet/wallet.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 45f49954a3..02fe6fba5b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1421,6 +1421,19 @@ bool CWallet::IsMine(const CTransaction& tx) const return false; } +isminetype CWallet::IsMine(const COutPoint& outpoint) const +{ + AssertLockHeld(cs_wallet); + auto wtx = GetWalletTx(outpoint.hash); + if (!wtx) { + return ISMINE_NO; + } + if (outpoint.n >= wtx->tx->vout.size()) { + return ISMINE_NO; + } + return IsMine(wtx->tx->vout[outpoint.n]); +} + bool CWallet::IsFromMe(const CTransaction& tx) const { return (GetDebit(tx, ISMINE_ALL) > 0); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 247c172da3..d8c54bdb01 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -684,6 +684,7 @@ public: CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const; isminetype IsMine(const CTxOut& txout) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); bool IsMine(const CTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); + isminetype IsMine(const COutPoint& outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); /** should probably be renamed to IsRelevantToMe */ bool IsFromMe(const CTransaction& tx) const; CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;