Skip to content

Commit 766e8a4

Browse files
committed
[wallet] Add IsAllFromMe: true if all inputs are from wallet
1 parent 5754e03 commit 766e8a4

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/wallet/wallet.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,8 @@ isminetype CWallet::IsMine(const CTxIn &txin) const
11541154
return ISMINE_NO;
11551155
}
11561156

1157+
// Note that this function doesn't distinguish between a 0-valued input,
1158+
// and a not-"is mine" (according to the filter) input.
11571159
CAmount CWallet::GetDebit(const CTxIn &txin, const isminefilter& filter) const
11581160
{
11591161
{
@@ -1236,6 +1238,27 @@ CAmount CWallet::GetDebit(const CTransaction& tx, const isminefilter& filter) co
12361238
return nDebit;
12371239
}
12381240

1241+
bool CWallet::IsAllFromMe(const CTransaction& tx, const isminefilter& filter) const
1242+
{
1243+
LOCK(cs_wallet);
1244+
1245+
BOOST_FOREACH(const CTxIn& txin, tx.vin)
1246+
{
1247+
auto mi = mapWallet.find(txin.prevout.hash);
1248+
if (mi == mapWallet.end())
1249+
return false; // any unknown inputs can't be from us
1250+
1251+
const CWalletTx& prev = (*mi).second;
1252+
1253+
if (txin.prevout.n >= prev.tx->vout.size())
1254+
return false; // invalid input!
1255+
1256+
if (!(IsMine(prev.tx->vout[txin.prevout.n]) & filter))
1257+
return false;
1258+
}
1259+
return true;
1260+
}
1261+
12391262
CAmount CWallet::GetCredit(const CTransaction& tx, const isminefilter& filter) const
12401263
{
12411264
CAmount nCredit = 0;

src/wallet/wallet.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,10 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
825825
std::set<CTxDestination> GetAccountAddresses(const std::string& strAccount) const;
826826

827827
isminetype IsMine(const CTxIn& txin) const;
828+
/**
829+
* Returns amount of debit if the input matches the
830+
* filter, otherwise returns 0
831+
*/
828832
CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
829833
isminetype IsMine(const CTxOut& txout) const;
830834
CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const;
@@ -834,6 +838,8 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
834838
/** should probably be renamed to IsRelevantToMe */
835839
bool IsFromMe(const CTransaction& tx) const;
836840
CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
841+
/** Returns whether all of the inputs match the filter */
842+
bool IsAllFromMe(const CTransaction& tx, const isminefilter& filter) const;
837843
CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const;
838844
CAmount GetChange(const CTransaction& tx) const;
839845
void SetBestChain(const CBlockLocator& loc);

0 commit comments

Comments
 (0)