Skip to content

Commit 80dda36

Browse files
removed default argument values for ismine filter
1 parent d5087d1 commit 80dda36

File tree

5 files changed

+32
-31
lines changed

5 files changed

+32
-31
lines changed

src/qt/transactiondesc.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
5454
strHTML += "<html><font face='verdana, arial, helvetica, sans-serif'>";
5555

5656
int64_t nTime = wtx.GetTxTime();
57-
int64_t nCredit = wtx.GetCredit();
58-
int64_t nDebit = wtx.GetDebit();
57+
int64_t nCredit = wtx.GetCredit(MINE_SPENDABLE|MINE_WATCH_ONLY);
58+
int64_t nDebit = wtx.GetDebit(MINE_SPENDABLE|MINE_WATCH_ONLY);
5959
int64_t nNet = nCredit - nDebit;
6060

6161
strHTML += "<b>" + tr("Status") + ":</b> " + FormatTxStatus(wtx);
@@ -139,7 +139,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
139139
//
140140
int64_t nUnmatured = 0;
141141
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
142-
nUnmatured += wallet->GetCredit(txout);
142+
nUnmatured += wallet->GetCredit(txout, MINE_SPENDABLE|MINE_WATCH_ONLY);
143143
strHTML += "<b>" + tr("Credit") + ":</b> ";
144144
if (wtx.IsInMainChain())
145145
strHTML += BitcoinUnits::formatWithUnit(unit, nUnmatured)+ " (" + tr("matures in %n more block(s)", "", wtx.GetBlocksToMaturity()) + ")";
@@ -228,10 +228,10 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
228228
//
229229
BOOST_FOREACH(const CTxIn& txin, wtx.vin)
230230
if (wallet->IsMine(txin))
231-
strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, -wallet->GetDebit(txin)) + "<br>";
231+
strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, -wallet->GetDebit(txin, MINE_SPENDABLE|MINE_WATCH_ONLY)) + "<br>";
232232
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
233233
if (wallet->IsMine(txout))
234-
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, wallet->GetCredit(txout)) + "<br>";
234+
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, wallet->GetCredit(txout, MINE_SPENDABLE|MINE_WATCH_ONLY)) + "<br>";
235235
}
236236
}
237237

@@ -281,10 +281,10 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
281281
strHTML += "<hr><br>" + tr("Debug information") + "<br><br>";
282282
BOOST_FOREACH(const CTxIn& txin, wtx.vin)
283283
if(wallet->IsMine(txin))
284-
strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, -wallet->GetDebit(txin)) + "<br>";
284+
strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, -wallet->GetDebit(txin, MINE_SPENDABLE|MINE_WATCH_ONLY)) + "<br>";
285285
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
286286
if(wallet->IsMine(txout))
287-
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, wallet->GetCredit(txout)) + "<br>";
287+
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, wallet->GetCredit(txout, MINE_SPENDABLE|MINE_WATCH_ONLY)) + "<br>";
288288

289289
strHTML += "<br><b>" + tr("Transaction") + ":</b><br>";
290290
strHTML += GUIUtil::HtmlEscape(wtx.ToString(), true);

src/qt/transactionrecord.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
3333
QList<TransactionRecord> parts;
3434
int64_t nTime = wtx.GetTxTime();
3535
int64_t nCredit = wtx.GetCredit(true);
36-
int64_t nDebit = wtx.GetDebit();
36+
int64_t nDebit = wtx.GetDebit(MINE_SPENDABLE|MINE_WATCH_ONLY);
3737
int64_t nNet = nCredit - nDebit;
3838
uint256 hash = wtx.GetHash();
3939
std::map<std::string, std::string> mapValue = wtx.mapValue;

src/rpcwallet.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
557557
}
558558

559559

560-
int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth, const isminefilter& filter = MINE_SPENDABLE)
560+
int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth, const isminefilter& filter)
561561
{
562562
int64_t nBalance = 0;
563563

@@ -582,7 +582,7 @@ int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi
582582
return nBalance;
583583
}
584584

585-
int64_t GetAccountBalance(const string& strAccount, int nMinDepth, const isminefilter& filter = MINE_SPENDABLE)
585+
int64_t GetAccountBalance(const string& strAccount, int nMinDepth, const isminefilter& filter)
586586
{
587587
CWalletDB walletdb(pwalletMain->strWalletFile);
588588
return GetAccountBalance(walletdb, strAccount, nMinDepth, filter);
@@ -786,7 +786,7 @@ Value sendfrom(const Array& params, bool fHelp)
786786
EnsureWalletIsUnlocked();
787787

788788
// Check funds
789-
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth);
789+
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, MINE_SPENDABLE);
790790
if (nAmount > nBalance)
791791
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
792792

@@ -863,7 +863,7 @@ Value sendmany(const Array& params, bool fHelp)
863863
EnsureWalletIsUnlocked();
864864

865865
// Check funds
866-
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth);
866+
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, MINE_SPENDABLE);
867867
if (totalAmount > nBalance)
868868
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
869869

@@ -1129,7 +1129,7 @@ static void MaybePushAddress(Object & entry, const CTxDestination &dest)
11291129
entry.push_back(Pair("address", addr.ToString()));
11301130
}
11311131

1132-
void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret, const isminefilter& filter=MINE_SPENDABLE)
1132+
void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret, const isminefilter& filter)
11331133
{
11341134
int64_t nFee;
11351135
string strSentAccount;
@@ -1552,13 +1552,13 @@ Value gettransaction(const Array& params, bool fHelp)
15521552
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
15531553
const CWalletTx& wtx = pwalletMain->mapWallet[hash];
15541554

1555-
int64_t nCredit = wtx.GetCredit();
1556-
int64_t nDebit = wtx.GetDebit();
1555+
int64_t nCredit = wtx.GetCredit(filter);
1556+
int64_t nDebit = wtx.GetDebit(filter);
15571557
int64_t nNet = nCredit - nDebit;
1558-
int64_t nFee = (wtx.IsFromMe() ? wtx.GetValueOut() - nDebit : 0);
1558+
int64_t nFee = (wtx.IsFromMe(filter) ? wtx.GetValueOut() - nDebit : 0);
15591559

15601560
entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));
1561-
if (wtx.IsFromMe())
1561+
if (wtx.IsFromMe(filter))
15621562
entry.push_back(Pair("fee", ValueFromAmount(nFee)));
15631563

15641564
WalletTxToJSON(wtx, entry);

src/wallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfT
12161216

12171217
const CWalletTx *pcoin = output.tx;
12181218

1219-
if (output.nDepth < (pcoin->IsFromMe() ? nConfMine : nConfTheirs))
1219+
if (output.nDepth < (pcoin->IsFromMe(MINE_SPENDABLE|MINE_WATCH_ONLY) ? nConfMine : nConfTheirs))
12201220
continue;
12211221

12221222
int i = output.i;
@@ -1845,7 +1845,7 @@ std::map<CTxDestination, int64_t> CWallet::GetAddressBalances()
18451845
continue;
18461846

18471847
int nDepth = pcoin->GetDepthInMainChain();
1848-
if (nDepth < (pcoin->IsFromMe() ? 0 : 1))
1848+
if (nDepth < (pcoin->IsFromMe(MINE_SPENDABLE|MINE_WATCH_ONLY) ? 0 : 1))
18491849
continue;
18501850

18511851
for (unsigned int i = 0; i < pcoin->vout.size(); i++)

src/wallet.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,12 @@ class CWallet : public CCryptoKeyStore, public CWalletInterface
288288
std::set<CTxDestination> GetAccountAddresses(std::string strAccount) const;
289289

290290
isminetype IsMine(const CTxIn& txin) const;
291-
int64_t GetDebit(const CTxIn& txin, const isminefilter& filter=(MINE_SPENDABLE|MINE_WATCH_ONLY)) const;
291+
int64_t GetDebit(const CTxIn& txin, const isminefilter& filter) const;
292292
isminetype IsMine(const CTxOut& txout) const
293293
{
294294
return ::IsMine(*this, txout.scriptPubKey);
295295
}
296-
int64_t GetCredit(const CTxOut& txout, const isminefilter& filter=(MINE_WATCH_ONLY|MINE_SPENDABLE)) const
296+
int64_t GetCredit(const CTxOut& txout, const isminefilter& filter) const
297297
{
298298
if (!MoneyRange(txout.nValue))
299299
throw std::runtime_error("CWallet::GetCredit() : value out of range");
@@ -313,9 +313,9 @@ class CWallet : public CCryptoKeyStore, public CWalletInterface
313313
return true;
314314
return false;
315315
}
316-
bool IsFromMe(const CTransaction& tx) const
316+
bool IsFromMe(const CTransaction& tx) const // should probably be renamed to IsRelevantToMe
317317
{
318-
return (GetDebit(tx) > 0);
318+
return (GetDebit(tx, MINE_SPENDABLE|MINE_WATCH_ONLY) > 0);
319319
}
320320
bool IsConflicting(const CTransaction& tx) const
321321
{
@@ -324,7 +324,7 @@ class CWallet : public CCryptoKeyStore, public CWalletInterface
324324
return true;
325325
return false;
326326
}
327-
int64_t GetDebit(const CTransaction& tx, const isminefilter& filter=(MINE_SPENDABLE|MINE_WATCH_ONLY)) const
327+
int64_t GetDebit(const CTransaction& tx, const isminefilter& filter) const
328328
{
329329
int64_t nDebit = 0;
330330
BOOST_FOREACH(const CTxIn& txin, tx.vin)
@@ -335,7 +335,7 @@ class CWallet : public CCryptoKeyStore, public CWalletInterface
335335
}
336336
return nDebit;
337337
}
338-
int64_t GetCredit(const CTransaction& tx, const isminefilter& filter=(MINE_SPENDABLE|MINE_WATCH_ONLY)) const
338+
int64_t GetCredit(const CTransaction& tx, const isminefilter& filter) const
339339
{
340340
int64_t nCredit = 0;
341341
BOOST_FOREACH(const CTxOut& txout, tx.vout)
@@ -614,7 +614,8 @@ class CWalletTx : public CMerkleTx
614614
MarkDirty();
615615
}
616616

617-
int64_t GetDebit(const isminefilter& filter=(MINE_SPENDABLE|MINE_WATCH_ONLY)) const
617+
// filter decides which addresses will count towards the debit
618+
int64_t GetDebit(const isminefilter& filter) const
618619
{
619620
if (vin.empty())
620621
return 0;
@@ -654,7 +655,7 @@ class CWalletTx : public CMerkleTx
654655
// GetBalance can assume transactions in mapWallet won't change
655656
if (fUseCache && fCreditCached)
656657
return nCreditCached;
657-
nCreditCached = pwallet->GetCredit(*this);
658+
nCreditCached = pwallet->GetCredit(*this, MINE_SPENDABLE|MINE_WATCH_ONLY);
658659
fCreditCached = true;
659660
return nCreditCached;
660661
}
@@ -756,12 +757,12 @@ class CWalletTx : public CMerkleTx
756757
}
757758

758759
void GetAmounts(std::list<std::pair<CTxDestination, int64_t> >& listReceived,
759-
std::list<std::pair<CTxDestination, int64_t> >& listSent, int64_t& nFee, std::string& strSentAccount, const isminefilter& filter=(MINE_SPENDABLE|MINE_WATCH_ONLY)) const;
760+
std::list<std::pair<CTxDestination, int64_t> >& listSent, int64_t& nFee, std::string& strSentAccount, const isminefilter& filter) const;
760761

761762
void GetAccountAmounts(const std::string& strAccount, int64_t& nReceived,
762-
int64_t& nSent, int64_t& nFee, const isminefilter& filter=(MINE_SPENDABLE|MINE_WATCH_ONLY)) const;
763+
int64_t& nSent, int64_t& nFee, const isminefilter& filter) const;
763764

764-
bool IsFromMe(const isminefilter& filter=(MINE_SPENDABLE|MINE_WATCH_ONLY)) const
765+
bool IsFromMe(const isminefilter& filter) const
765766
{
766767
return (GetDebit(filter) > 0);
767768
}
@@ -776,7 +777,7 @@ class CWalletTx : public CMerkleTx
776777
return true;
777778
if (nDepth < 0)
778779
return false;
779-
if (!bSpendZeroConfChange || !IsFromMe()) // using wtx's cached debit
780+
if (!bSpendZeroConfChange || !IsFromMe(MINE_SPENDABLE|MINE_WATCH_ONLY)) // using wtx's cached debit
780781
return false;
781782

782783
// Trusted if all inputs are from us and are in the mempool:

0 commit comments

Comments
 (0)