mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
Merge pull request #4045
a3e192areplaced MINE_ with ISMINE_ (JaSK)53a2148fixed bug where validateaddress doesn't display information (JaSK)f28707afixed bug in ListReceived() (JaSK)519dd1cAdded MINE_ALL = (spendable|watchonly) (JaSK)23b0506Fixed some stuff in TransactionDesc (JaSK)80dda36removed default argument values for ismine filter (JaSK)d5087d1Use script matching rather than destination matching for watch-only. (Pieter Wuille)0fa2f88added includedWatchonly argument to listreceivedbyaddress/...account (JaSK)f87ba3dadded includeWatchonly argument to 'gettransaction' because it affects balance calculation (JaSK)a5c6c5dfixed tiny glitch and improved readability like laanwj suggested (JaSK)d7d5d23Added argument to listtransactions and listsinceblock to include watchonly addresses (JaSK)952877eShowing 'involvesWatchonly' property for transactions returned by 'listtransactions' and 'listsinceblock'. It is only appended when the transaction involves a watchonly address. (JaSK)83f3543Added argument to listaccounts to include watchonly addresses (JaSK)d4640d7Added argument to getbalance to include watchonly addresses and fixed errors in balance calculation. (JaSK)d2692f6Watchonly transactions are marked in transaction history (JaSK)ffd40daWatchonly balances are shown separately in gui. (JaSK)2935b21qt: Hide unspendable outputs in coin control (Wladimir J. van der Laan)c898846Add support for watch-only addresses (Pieter Wuille)
This commit is contained in:
@@ -557,7 +557,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
|
||||
}
|
||||
|
||||
|
||||
int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth)
|
||||
int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth, const isminefilter& filter)
|
||||
{
|
||||
int64_t nBalance = 0;
|
||||
|
||||
@@ -569,7 +569,7 @@ int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi
|
||||
continue;
|
||||
|
||||
int64_t nReceived, nSent, nFee;
|
||||
wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee);
|
||||
wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter);
|
||||
|
||||
if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
|
||||
nBalance += nReceived;
|
||||
@@ -582,18 +582,18 @@ int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi
|
||||
return nBalance;
|
||||
}
|
||||
|
||||
int64_t GetAccountBalance(const string& strAccount, int nMinDepth)
|
||||
int64_t GetAccountBalance(const string& strAccount, int nMinDepth, const isminefilter& filter)
|
||||
{
|
||||
CWalletDB walletdb(pwalletMain->strWalletFile);
|
||||
return GetAccountBalance(walletdb, strAccount, nMinDepth);
|
||||
return GetAccountBalance(walletdb, strAccount, nMinDepth, filter);
|
||||
}
|
||||
|
||||
|
||||
Value getbalance(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 2)
|
||||
if (fHelp || params.size() > 3)
|
||||
throw runtime_error(
|
||||
"getbalance ( \"account\" minconf )\n"
|
||||
"getbalance ( \"account\" minconf includeWatchonly )\n"
|
||||
"\nIf account is not specified, returns the server's total available balance.\n"
|
||||
"If account is specified, returns the balance in the account.\n"
|
||||
"Note that the account \"\" is not the same as leaving the parameter out.\n"
|
||||
@@ -601,6 +601,7 @@ Value getbalance(const Array& params, bool fHelp)
|
||||
"\nArguments:\n"
|
||||
"1. \"account\" (string, optional) The selected account, or \"*\" for entire wallet. It may be the default account using \"\".\n"
|
||||
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
|
||||
"3. includeWatchonly (bool, optional, default=false) Also include balance in watchonly addresses (see 'importaddress')\n"
|
||||
"\nResult:\n"
|
||||
"amount (numeric) The total amount in btc received for this account.\n"
|
||||
"\nExamples:\n"
|
||||
@@ -622,6 +623,10 @@ Value getbalance(const Array& params, bool fHelp)
|
||||
int nMinDepth = 1;
|
||||
if (params.size() > 1)
|
||||
nMinDepth = params[1].get_int();
|
||||
isminefilter filter = ISMINE_SPENDABLE;
|
||||
if(params.size() > 2)
|
||||
if(params[2].get_bool())
|
||||
filter = filter | ISMINE_WATCH_ONLY;
|
||||
|
||||
if (params[0].get_str() == "*") {
|
||||
// Calculate total balance a different way from GetBalance()
|
||||
@@ -638,7 +643,7 @@ Value getbalance(const Array& params, bool fHelp)
|
||||
string strSentAccount;
|
||||
list<pair<CTxDestination, int64_t> > listReceived;
|
||||
list<pair<CTxDestination, int64_t> > listSent;
|
||||
wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount);
|
||||
wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
|
||||
if (wtx.GetDepthInMainChain() >= nMinDepth)
|
||||
{
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listReceived)
|
||||
@@ -653,7 +658,7 @@ Value getbalance(const Array& params, bool fHelp)
|
||||
|
||||
string strAccount = AccountFromValue(params[0]);
|
||||
|
||||
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth);
|
||||
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, filter);
|
||||
|
||||
return ValueFromAmount(nBalance);
|
||||
}
|
||||
@@ -781,7 +786,7 @@ Value sendfrom(const Array& params, bool fHelp)
|
||||
EnsureWalletIsUnlocked();
|
||||
|
||||
// Check funds
|
||||
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth);
|
||||
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
|
||||
if (nAmount > nBalance)
|
||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
|
||||
|
||||
@@ -858,7 +863,7 @@ Value sendmany(const Array& params, bool fHelp)
|
||||
EnsureWalletIsUnlocked();
|
||||
|
||||
// Check funds
|
||||
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth);
|
||||
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
|
||||
if (totalAmount > nBalance)
|
||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
|
||||
|
||||
@@ -927,10 +932,12 @@ struct tallyitem
|
||||
int64_t nAmount;
|
||||
int nConf;
|
||||
vector<uint256> txids;
|
||||
bool fIsWatchonly;
|
||||
tallyitem()
|
||||
{
|
||||
nAmount = 0;
|
||||
nConf = std::numeric_limits<int>::max();
|
||||
fIsWatchonly = false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -946,6 +953,11 @@ Value ListReceived(const Array& params, bool fByAccounts)
|
||||
if (params.size() > 1)
|
||||
fIncludeEmpty = params[1].get_bool();
|
||||
|
||||
isminefilter filter = ISMINE_SPENDABLE;
|
||||
if(params.size() > 2)
|
||||
if(params[2].get_bool())
|
||||
filter = filter | ISMINE_WATCH_ONLY;
|
||||
|
||||
// Tally
|
||||
map<CBitcoinAddress, tallyitem> mapTally;
|
||||
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
||||
@@ -962,13 +974,19 @@ Value ListReceived(const Array& params, bool fByAccounts)
|
||||
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
|
||||
{
|
||||
CTxDestination address;
|
||||
if (!ExtractDestination(txout.scriptPubKey, address) || !IsMine(*pwalletMain, address))
|
||||
if (!ExtractDestination(txout.scriptPubKey, address))
|
||||
continue;
|
||||
|
||||
isminefilter mine = IsMine(*pwalletMain, address);
|
||||
if(!(mine & filter))
|
||||
continue;
|
||||
|
||||
tallyitem& item = mapTally[address];
|
||||
item.nAmount += txout.nValue;
|
||||
item.nConf = min(item.nConf, nDepth);
|
||||
item.txids.push_back(wtx.GetHash());
|
||||
if (mine & ISMINE_WATCH_ONLY)
|
||||
item.fIsWatchonly = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -985,10 +1003,12 @@ Value ListReceived(const Array& params, bool fByAccounts)
|
||||
|
||||
int64_t nAmount = 0;
|
||||
int nConf = std::numeric_limits<int>::max();
|
||||
bool fIsWatchonly = false;
|
||||
if (it != mapTally.end())
|
||||
{
|
||||
nAmount = (*it).second.nAmount;
|
||||
nConf = (*it).second.nConf;
|
||||
fIsWatchonly = (*it).second.fIsWatchonly;
|
||||
}
|
||||
|
||||
if (fByAccounts)
|
||||
@@ -996,10 +1016,13 @@ Value ListReceived(const Array& params, bool fByAccounts)
|
||||
tallyitem& item = mapAccountTally[strAccount];
|
||||
item.nAmount += nAmount;
|
||||
item.nConf = min(item.nConf, nConf);
|
||||
item.fIsWatchonly = fIsWatchonly;
|
||||
}
|
||||
else
|
||||
{
|
||||
Object obj;
|
||||
if(fIsWatchonly)
|
||||
obj.push_back(Pair("involvesWatchonly", true));
|
||||
obj.push_back(Pair("address", address.ToString()));
|
||||
obj.push_back(Pair("account", strAccount));
|
||||
obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
|
||||
@@ -1024,6 +1047,8 @@ Value ListReceived(const Array& params, bool fByAccounts)
|
||||
int64_t nAmount = (*it).second.nAmount;
|
||||
int nConf = (*it).second.nConf;
|
||||
Object obj;
|
||||
if((*it).second.fIsWatchonly)
|
||||
obj.push_back(Pair("involvesWatchonly", true));
|
||||
obj.push_back(Pair("account", (*it).first));
|
||||
obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
|
||||
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
|
||||
@@ -1036,17 +1061,19 @@ Value ListReceived(const Array& params, bool fByAccounts)
|
||||
|
||||
Value listreceivedbyaddress(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 2)
|
||||
if (fHelp || params.size() > 3)
|
||||
throw runtime_error(
|
||||
"listreceivedbyaddress ( minconf includeempty )\n"
|
||||
"listreceivedbyaddress ( minconf includeempty includeWatchonly)\n"
|
||||
"\nList balances by receiving address.\n"
|
||||
"\nArguments:\n"
|
||||
"1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
|
||||
"2. includeempty (numeric, optional, dafault=false) Whether to include addresses that haven't received any payments.\n"
|
||||
"3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n"
|
||||
|
||||
"\nResult:\n"
|
||||
"[\n"
|
||||
" {\n"
|
||||
" \"involvesWatchonly\" : \"true\", (bool) Only returned if imported addresses were involved in transaction\n"
|
||||
" \"address\" : \"receivingaddress\", (string) The receiving address\n"
|
||||
" \"account\" : \"accountname\", (string) The account of the receiving address. The default account is \"\".\n"
|
||||
" \"amount\" : x.xxx, (numeric) The total amount in btc received by the address\n"
|
||||
@@ -1058,7 +1085,7 @@ Value listreceivedbyaddress(const Array& params, bool fHelp)
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("listreceivedbyaddress", "")
|
||||
+ HelpExampleCli("listreceivedbyaddress", "6 true")
|
||||
+ HelpExampleRpc("listreceivedbyaddress", "6, true")
|
||||
+ HelpExampleRpc("listreceivedbyaddress", "6, true, true")
|
||||
);
|
||||
|
||||
return ListReceived(params, false);
|
||||
@@ -1066,17 +1093,19 @@ Value listreceivedbyaddress(const Array& params, bool fHelp)
|
||||
|
||||
Value listreceivedbyaccount(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 2)
|
||||
if (fHelp || params.size() > 3)
|
||||
throw runtime_error(
|
||||
"listreceivedbyaccount ( minconf includeempty )\n"
|
||||
"listreceivedbyaccount ( minconf includeempty includeWatchonly)\n"
|
||||
"\nList balances by account.\n"
|
||||
"\nArguments:\n"
|
||||
"1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
|
||||
"2. includeempty (boolean, optional, default=false) Whether to include accounts that haven't received any payments.\n"
|
||||
"3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n"
|
||||
|
||||
"\nResult:\n"
|
||||
"[\n"
|
||||
" {\n"
|
||||
" \"involvesWatchonly\" : \"true\", (bool) Only returned if imported addresses were involved in transaction\n"
|
||||
" \"account\" : \"accountname\", (string) The account name of the receiving account\n"
|
||||
" \"amount\" : x.xxx, (numeric) The total amount received by addresses with this account\n"
|
||||
" \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n"
|
||||
@@ -1087,7 +1116,7 @@ Value listreceivedbyaccount(const Array& params, bool fHelp)
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("listreceivedbyaccount", "")
|
||||
+ HelpExampleCli("listreceivedbyaccount", "6 true")
|
||||
+ HelpExampleRpc("listreceivedbyaccount", "6, true")
|
||||
+ HelpExampleRpc("listreceivedbyaccount", "6, true, true")
|
||||
);
|
||||
|
||||
return ListReceived(params, true);
|
||||
@@ -1100,16 +1129,17 @@ static void MaybePushAddress(Object & entry, const CTxDestination &dest)
|
||||
entry.push_back(Pair("address", addr.ToString()));
|
||||
}
|
||||
|
||||
void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret)
|
||||
void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret, const isminefilter& filter)
|
||||
{
|
||||
int64_t nFee;
|
||||
string strSentAccount;
|
||||
list<pair<CTxDestination, int64_t> > listReceived;
|
||||
list<pair<CTxDestination, int64_t> > listSent;
|
||||
|
||||
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount);
|
||||
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter);
|
||||
|
||||
bool fAllAccounts = (strAccount == string("*"));
|
||||
bool involvesWatchonly = wtx.IsFromMe(ISMINE_WATCH_ONLY);
|
||||
|
||||
// Sent
|
||||
if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount))
|
||||
@@ -1117,6 +1147,8 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& s, listSent)
|
||||
{
|
||||
Object entry;
|
||||
if(involvesWatchonly || (::IsMine(*pwalletMain, s.first) & ISMINE_WATCH_ONLY))
|
||||
entry.push_back(Pair("involvesWatchonly", true));
|
||||
entry.push_back(Pair("account", strSentAccount));
|
||||
MaybePushAddress(entry, s.first);
|
||||
entry.push_back(Pair("category", "send"));
|
||||
@@ -1139,6 +1171,8 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
|
||||
if (fAllAccounts || (account == strAccount))
|
||||
{
|
||||
Object entry;
|
||||
if(involvesWatchonly || (::IsMine(*pwalletMain, r.first) & ISMINE_WATCH_ONLY))
|
||||
entry.push_back(Pair("involvesWatchonly", true));
|
||||
entry.push_back(Pair("account", account));
|
||||
MaybePushAddress(entry, r.first);
|
||||
if (wtx.IsCoinBase())
|
||||
@@ -1182,16 +1216,16 @@ void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Ar
|
||||
|
||||
Value listtransactions(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 3)
|
||||
if (fHelp || params.size() > 4)
|
||||
throw runtime_error(
|
||||
"listtransactions ( \"account\" count from )\n"
|
||||
"listtransactions ( \"account\" count from includeWatchonly)\n"
|
||||
"\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"account\" (string, optional) The account name. If not included, it will list all transactions for all accounts.\n"
|
||||
" If \"\" is set, it will list transactions for the default account.\n"
|
||||
"2. count (numeric, optional, default=10) The number of transactions to return\n"
|
||||
"3. from (numeric, optional, default=0) The number of transactions to skip\n"
|
||||
|
||||
"4. includeWatchonly (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')\n"
|
||||
"\nResult:\n"
|
||||
"[\n"
|
||||
" {\n"
|
||||
@@ -1251,6 +1285,10 @@ Value listtransactions(const Array& params, bool fHelp)
|
||||
int nFrom = 0;
|
||||
if (params.size() > 2)
|
||||
nFrom = params[2].get_int();
|
||||
isminefilter filter = ISMINE_SPENDABLE;
|
||||
if(params.size() > 3)
|
||||
if(params[3].get_bool())
|
||||
filter = filter | ISMINE_WATCH_ONLY;
|
||||
|
||||
if (nCount < 0)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count");
|
||||
@@ -1267,7 +1305,7 @@ Value listtransactions(const Array& params, bool fHelp)
|
||||
{
|
||||
CWalletTx *const pwtx = (*it).second.first;
|
||||
if (pwtx != 0)
|
||||
ListTransactions(*pwtx, strAccount, 0, true, ret);
|
||||
ListTransactions(*pwtx, strAccount, 0, true, ret, filter);
|
||||
CAccountingEntry *const pacentry = (*it).second.second;
|
||||
if (pacentry != 0)
|
||||
AcentryToJSON(*pacentry, strAccount, ret);
|
||||
@@ -1295,12 +1333,13 @@ Value listtransactions(const Array& params, bool fHelp)
|
||||
|
||||
Value listaccounts(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 1)
|
||||
if (fHelp || params.size() > 2)
|
||||
throw runtime_error(
|
||||
"listaccounts ( minconf )\n"
|
||||
"listaccounts ( minconf includeWatchonly)\n"
|
||||
"\nReturns Object that has account names as keys, account balances as values.\n"
|
||||
"\nArguments:\n"
|
||||
"1. minconf (numeric, optional, default=1) Only onclude transactions with at least this many confirmations\n"
|
||||
"1. minconf (numeric, optional, default=1) Only onclude transactions with at least this many confirmations\n"
|
||||
"2. includeWatchonly (bool, optional, default=false) Include balances in watchonly addresses (see 'importaddress')\n"
|
||||
"\nResult:\n"
|
||||
"{ (json object where keys are account names, and values are numeric balances\n"
|
||||
" \"account\": x.xxx, (numeric) The property name is the account name, and the value is the total balance for the account.\n"
|
||||
@@ -1320,10 +1359,14 @@ Value listaccounts(const Array& params, bool fHelp)
|
||||
int nMinDepth = 1;
|
||||
if (params.size() > 0)
|
||||
nMinDepth = params[0].get_int();
|
||||
isminefilter includeWatchonly = ISMINE_SPENDABLE;
|
||||
if(params.size() > 1)
|
||||
if(params[1].get_bool())
|
||||
includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY;
|
||||
|
||||
map<string, int64_t> mapAccountBalances;
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& entry, pwalletMain->mapAddressBook) {
|
||||
if (IsMine(*pwalletMain, entry.first)) // This address belongs to me
|
||||
if (IsMine(*pwalletMain, entry.first) & includeWatchonly) // This address belongs to me
|
||||
mapAccountBalances[entry.second.name] = 0;
|
||||
}
|
||||
|
||||
@@ -1337,7 +1380,7 @@ Value listaccounts(const Array& params, bool fHelp)
|
||||
int nDepth = wtx.GetDepthInMainChain();
|
||||
if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0)
|
||||
continue;
|
||||
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount);
|
||||
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly);
|
||||
mapAccountBalances[strSentAccount] -= nFee;
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& s, listSent)
|
||||
mapAccountBalances[strSentAccount] -= s.second;
|
||||
@@ -1367,11 +1410,12 @@ Value listsinceblock(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp)
|
||||
throw runtime_error(
|
||||
"listsinceblock ( \"blockhash\" target-confirmations )\n"
|
||||
"listsinceblock ( \"blockhash\" target-confirmations includeWatchonly)\n"
|
||||
"\nGet all transactions in blocks since block [blockhash], or all transactions if omitted\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"blockhash\" (string, optional) The block hash to list transactions since\n"
|
||||
"2. target-confirmations: (numeric, optional) The confirmations required, must be 1 or more\n"
|
||||
"3. includeWatchonly: (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')"
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"transactions\": [\n"
|
||||
@@ -1407,6 +1451,7 @@ Value listsinceblock(const Array& params, bool fHelp)
|
||||
|
||||
CBlockIndex *pindex = NULL;
|
||||
int target_confirms = 1;
|
||||
isminefilter filter = ISMINE_SPENDABLE;
|
||||
|
||||
if (params.size() > 0)
|
||||
{
|
||||
@@ -1426,6 +1471,10 @@ Value listsinceblock(const Array& params, bool fHelp)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
|
||||
}
|
||||
|
||||
if(params.size() > 2)
|
||||
if(params[2].get_bool())
|
||||
filter = filter | ISMINE_WATCH_ONLY;
|
||||
|
||||
int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1;
|
||||
|
||||
Array transactions;
|
||||
@@ -1435,7 +1484,7 @@ Value listsinceblock(const Array& params, bool fHelp)
|
||||
CWalletTx tx = (*it).second;
|
||||
|
||||
if (depth == -1 || tx.GetDepthInMainChain() < depth)
|
||||
ListTransactions(tx, "*", 0, true, transactions);
|
||||
ListTransactions(tx, "*", 0, true, transactions, filter);
|
||||
}
|
||||
|
||||
CBlockIndex *pblockLast = chainActive[chainActive.Height() + 1 - target_confirms];
|
||||
@@ -1450,12 +1499,13 @@ Value listsinceblock(const Array& params, bool fHelp)
|
||||
|
||||
Value gettransaction(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1)
|
||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||
throw runtime_error(
|
||||
"gettransaction \"txid\"\n"
|
||||
"\nGet detailed information about in-wallet transaction <txid>\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"txid\" (string, required) The transaction id\n"
|
||||
"2. \"includeWatchonly\" (bool, optional, default=false) Whether to include watchonly addresses in balance calculation and details[]\n"
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"amount\" : x.xxx, (numeric) The transaction amount in btc\n"
|
||||
@@ -1492,24 +1542,29 @@ Value gettransaction(const Array& params, bool fHelp)
|
||||
uint256 hash;
|
||||
hash.SetHex(params[0].get_str());
|
||||
|
||||
isminefilter filter = ISMINE_SPENDABLE;
|
||||
if(params.size() > 1)
|
||||
if(params[1].get_bool())
|
||||
filter = filter | ISMINE_WATCH_ONLY;
|
||||
|
||||
Object entry;
|
||||
if (!pwalletMain->mapWallet.count(hash))
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
|
||||
const CWalletTx& wtx = pwalletMain->mapWallet[hash];
|
||||
|
||||
int64_t nCredit = wtx.GetCredit();
|
||||
int64_t nDebit = wtx.GetDebit();
|
||||
int64_t nCredit = wtx.GetCredit(filter);
|
||||
int64_t nDebit = wtx.GetDebit(filter);
|
||||
int64_t nNet = nCredit - nDebit;
|
||||
int64_t nFee = (wtx.IsFromMe() ? wtx.GetValueOut() - nDebit : 0);
|
||||
int64_t nFee = (wtx.IsFromMe(filter) ? wtx.GetValueOut() - nDebit : 0);
|
||||
|
||||
entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));
|
||||
if (wtx.IsFromMe())
|
||||
if (wtx.IsFromMe(filter))
|
||||
entry.push_back(Pair("fee", ValueFromAmount(nFee)));
|
||||
|
||||
WalletTxToJSON(wtx, entry);
|
||||
|
||||
Array details;
|
||||
ListTransactions(wtx, "*", 0, false, details);
|
||||
ListTransactions(wtx, "*", 0, false, details, filter);
|
||||
entry.push_back(Pair("details", details));
|
||||
|
||||
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
|
||||
|
||||
Reference in New Issue
Block a user