Auto merge of #4282 - oxarbitrage:issue2375, r=daira

Add a flag to get amount results as integer

Closes https://github.com/zcash/zcash/issues/2375
This commit is contained in:
Homu 2020-06-03 11:26:00 +00:00
commit e9a6d7926b
8 changed files with 126 additions and 55 deletions

View File

@ -38,28 +38,29 @@ class ListTransactionsTest(BitcoinTestFramework):
self.sync_all()
check_array_result(self.nodes[0].listtransactions(),
{"txid":txid},
{"category":"send","account":"","amount":Decimal("-0.1"),"confirmations":0})
{"category":"send","account":"","amount":Decimal("-0.1"),"amountZat":-10000000,"confirmations":0})
check_array_result(self.nodes[1].listtransactions(),
{"txid":txid},
{"category":"receive","account":"","amount":Decimal("0.1"),"confirmations":0})
{"category":"receive","account":"","amount":Decimal("0.1"),"amountZat":10000000,"confirmations":0})
# mine a block, confirmations should change:
self.nodes[0].generate(1)
self.sync_all()
check_array_result(self.nodes[0].listtransactions(),
{"txid":txid},
{"category":"send","account":"","amount":Decimal("-0.1"),"confirmations":1})
{"category":"send","account":"","amount":Decimal("-0.1"),"amountZat":-10000000,"confirmations":1})
check_array_result(self.nodes[1].listtransactions(),
{"txid":txid},
{"category":"receive","account":"","amount":Decimal("0.1"),"confirmations":1})
{"category":"receive","account":"","amount":Decimal("0.1"),"amountZat":10000000,"confirmations":1})
# send-to-self:
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 0.2)
check_array_result(self.nodes[0].listtransactions(),
{"txid":txid, "category":"send"},
{"amount":Decimal("-0.2")})
{"amount":Decimal("-0.2"),"amountZat":-20000000})
check_array_result(self.nodes[0].listtransactions(),
{"txid":txid, "category":"receive"},
{"amount":Decimal("0.2")})
{"amount":Decimal("0.2"),"amountZat":20000000})
# sendmany from node1: twice to self, twice to node2:
send_to = { self.nodes[0].getnewaddress() : 0.11,
@ -69,28 +70,28 @@ class ListTransactionsTest(BitcoinTestFramework):
txid = self.nodes[1].sendmany("", send_to)
self.sync_all()
check_array_result(self.nodes[1].listtransactions(),
{"category":"send","amount":Decimal("-0.11")},
{"category":"send","amount":Decimal("-0.11"),"amountZat":-11000000},
{"txid":txid} )
check_array_result(self.nodes[0].listtransactions(),
{"category":"receive","amount":Decimal("0.11")},
{"category":"receive","amount":Decimal("0.11"),"amountZat":11000000},
{"txid":txid} )
check_array_result(self.nodes[1].listtransactions(),
{"category":"send","amount":Decimal("-0.22")},
{"category":"send","amount":Decimal("-0.22"),"amountZat":-22000000},
{"txid":txid} )
check_array_result(self.nodes[1].listtransactions(),
{"category":"receive","amount":Decimal("0.22")},
{"category":"receive","amount":Decimal("0.22"),"amountZat":22000000},
{"txid":txid} )
check_array_result(self.nodes[1].listtransactions(),
{"category":"send","amount":Decimal("-0.33")},
{"category":"send","amount":Decimal("-0.33"),"amountZat":-33000000},
{"txid":txid} )
check_array_result(self.nodes[0].listtransactions(),
{"category":"receive","amount":Decimal("0.33")},
{"category":"receive","amount":Decimal("0.33"),"amountZat":33000000},
{"txid":txid, "account" : ""} )
check_array_result(self.nodes[1].listtransactions(),
{"category":"send","amount":Decimal("-0.44")},
{"category":"send","amount":Decimal("-0.44"),"amountZat":-44000000},
{"txid":txid, "account" : ""} )
check_array_result(self.nodes[1].listtransactions(),
{"category":"receive","amount":Decimal("0.44")},
{"category":"receive","amount":Decimal("0.44"),"amountZat":44000000},
{"txid":txid, "account" : ""} )
multisig = self.nodes[1].createmultisig(1, [self.nodes[1].getnewaddress()])
@ -100,9 +101,8 @@ class ListTransactionsTest(BitcoinTestFramework):
self.sync_all()
assert(len(self.nodes[0].listtransactions("watchonly", 100, 0, False)) == 0)
check_array_result(self.nodes[0].listtransactions("watchonly", 100, 0, True),
{"category":"receive","amount":Decimal("0.1")},
{"category":"receive","amount":Decimal("0.1"),"amountZat":10000000},
{"txid":txid, "account" : "watchonly"} )
if __name__ == '__main__':
ListTransactionsTest().main()

View File

@ -6,6 +6,7 @@
# Exercise the listreceivedbyaddress API
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
from decimal import Decimal
@ -71,11 +72,11 @@ class ReceivedByTest(BitcoinTestFramework):
self.sync_all()
check_array_result(self.nodes[1].listreceivedbyaddress(),
{"address":addr},
{"address":addr, "account":"", "amount":Decimal("0.1"), "confirmations":10, "txids":[txid,]})
{"address":addr, "account":"", "amount":Decimal("0.1"), "amountZat":10000000, "confirmations":10, "txids":[txid,]})
# With min confidence < 10
check_array_result(self.nodes[1].listreceivedbyaddress(5),
{"address":addr},
{"address":addr, "account":"", "amount":Decimal("0.1"), "confirmations":10, "txids":[txid,]})
{"address":addr, "account":"", "amount":Decimal("0.1"), "amountZat":10000000, "confirmations":10, "txids":[txid,]})
# With min confidence > 10, should not find Tx
check_array_result(self.nodes[1].listreceivedbyaddress(11),{"address":addr},{ },True)
@ -83,7 +84,7 @@ class ReceivedByTest(BitcoinTestFramework):
addr = self.nodes[1].getnewaddress()
check_array_result(self.nodes[1].listreceivedbyaddress(0,True),
{"address":addr},
{"address":addr, "account":"", "amount":0, "confirmations":0, "txids":[]})
{"address":addr, "account":"", "amount":0, "confirmations":0, "amountZat":0, "txids":[]})
'''
getreceivedbyaddress Test
@ -95,20 +96,22 @@ class ReceivedByTest(BitcoinTestFramework):
# Check balance is 0 because of 0 confirmations
balance = self.nodes[1].getreceivedbyaddress(addr)
if balance != Decimal("0.0"):
raise AssertionError("Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance))
assert_equal(balance, Decimal("0.0"), "Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance))
# Check balance is 0.1
balance = self.nodes[1].getreceivedbyaddress(addr,0)
if balance != Decimal("0.1"):
raise AssertionError("Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance))
assert_equal(balance, Decimal("0.1"), "Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance))
# Bury Tx under 10 block so it will be returned by the default getreceivedbyaddress
self.nodes[1].generate(10)
self.sync_all()
balance = self.nodes[1].getreceivedbyaddress(addr)
if balance != Decimal("0.1"):
raise AssertionError("Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance))
assert_equal(balance, Decimal("0.1"), "Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance))
# Get balance as integer
balance = self.nodes[1].getreceivedbyaddress(addr, 1, True)
assert_equal(balance, 10000000, "Wrong balance returned by getreceivedbyaddress, %i"%(balance))
'''
listreceivedbyaccount + getreceivedbyaccount Test
@ -117,6 +120,7 @@ class ReceivedByTest(BitcoinTestFramework):
addrArr = self.nodes[1].getnewaddress()
account = self.nodes[1].getaccount(addrArr)
received_by_account_json = get_sub_array_from_array(self.nodes[1].listreceivedbyaccount(),{"account":account})
if len(received_by_account_json) == 0:
raise AssertionError("No accounts found in node")
balance_by_account = self.nodes[1].getreceivedbyaccount(account)
@ -129,22 +133,24 @@ class ReceivedByTest(BitcoinTestFramework):
{"account":account},
received_by_account_json)
# getreceivedbyaddress should return same balance because of 0 confirmations
# getreceivedbyaccount should return same balance because of 0 confirmations
balance = self.nodes[1].getreceivedbyaccount(account)
if balance != balance_by_account:
raise AssertionError("Wrong balance returned by getreceivedbyaccount, %0.2f"%(balance))
assert_equal(balance, balance_by_account, "Wrong balance returned by getreceivedbyaccount, %0.2f"%(balance))
self.nodes[1].generate(10)
self.sync_all()
# listreceivedbyaccount should return updated account balance
check_array_result(self.nodes[1].listreceivedbyaccount(),
{"account":account},
{"account":received_by_account_json["account"], "amount":(received_by_account_json["amount"] + Decimal("0.1"))})
{"account":received_by_account_json["account"], "amount":(received_by_account_json["amount"] + Decimal("0.1")), "amountZat":30000000})
# getreceivedbyaddress should return updates balance
# getreceivedbyaccount should return updates balance
balance = self.nodes[1].getreceivedbyaccount(account)
if balance != balance_by_account + Decimal("0.1"):
raise AssertionError("Wrong balance returned by getreceivedbyaccount, %0.2f"%(balance))
assert_equal(balance, balance_by_account + Decimal("0.1"), "Wrong balance returned by getreceivedbyaccount, %0.2f"%(balance))
# Get balance as integer
balance = self.nodes[1].getreceivedbyaccount(account, 1, True)
assert_equal(balance, 30000000, "Wrong balance returned by getreceivedbyaccount, %i"%(balance))
# Create a new account named "mynewaccount" that has a 0 balance
self.nodes[1].getaccountaddress("mynewaccount")
@ -152,14 +158,12 @@ class ReceivedByTest(BitcoinTestFramework):
if len(received_by_account_json) == 0:
raise AssertionError("No accounts found in node")
# Test includeempty of listreceivedbyaccount
if received_by_account_json["amount"] != Decimal("0.0"):
raise AssertionError("Wrong balance returned by listreceivedbyaccount, %0.2f"%(received_by_account_json["amount"]))
# Test listreceivedbyaccount for 0 amount accounts
assert_equal(received_by_account_json["amount"], Decimal("0.0"), "Wrong balance returned by listreceivedbyaccount, %0.2f"%(received_by_account_json["amount"]))
# Test getreceivedbyaccount for 0 amount accounts
balance = self.nodes[1].getreceivedbyaccount("mynewaccount")
if balance != Decimal("0.0"):
raise AssertionError("Wrong balance returned by getreceivedbyaccount, %0.2f"%(balance))
assert_equal(balance, Decimal("0.0"), "Wrong balance returned by getreceivedbyaccount, %0.2f"%(balance))
if __name__ == '__main__':
ReceivedByTest().main()

View File

@ -226,6 +226,7 @@ class WalletTest (BitcoinTestFramework):
if uTx['txid'] == zeroValueTxid:
found = True
assert_equal(uTx['amount'], Decimal('0.00000000'))
assert_equal(uTx['amountZat'], 0)
assert(found)
#do some -walletbroadcast tests
@ -269,9 +270,12 @@ class WalletTest (BitcoinTestFramework):
self.nodes[0].generate(1)
sync_blocks(self.nodes)
#tx should be added to balance because after restarting the nodes tx should be broadcastet
assert_equal(self.nodes[2].getbalance(), Decimal('13.99800000')) #should not be
assert_equal(self.nodes[2].getbalance("*"), Decimal('13.99800000')) #should not be
# tx should be added to balance because after restarting the nodes tx should be broadcast
assert_equal(self.nodes[2].getbalance(), Decimal('13.99800000'))
assert_equal(self.nodes[2].getbalance("*"), Decimal('13.99800000'))
# check integer balances from getbalance
assert_equal(self.nodes[2].getbalance("*", 1, False, True), 1399800000)
# send from node 0 to node 2 taddr
mytaddr = self.nodes[2].getnewaddress()
@ -283,6 +287,9 @@ class WalletTest (BitcoinTestFramework):
mybalance = self.nodes[2].z_getbalance(mytaddr)
assert_equal(mybalance, Decimal('10.0'))
# check integer balances from z_getbalance
assert_equal(self.nodes[2].z_getbalance(mytaddr, 1, True), 1000000000)
mytxdetails = self.nodes[2].gettransaction(mytxid)
myvjoinsplits = mytxdetails["vjoinsplit"]
assert_equal(0, len(myvjoinsplits))
@ -385,15 +392,18 @@ class WalletTest (BitcoinTestFramework):
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "2")
txObj = self.nodes[0].gettransaction(txId)
assert_equal(txObj['amount'], Decimal('-2.00000000'))
assert_equal(txObj['amountZat'], -200000000)
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "0.0001")
txObj = self.nodes[0].gettransaction(txId)
assert_equal(txObj['amount'], Decimal('-0.00010000'))
assert_equal(txObj['amountZat'], -10000)
#check if JSON parser can handle scientific notation in strings
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "1e-4")
txObj = self.nodes[0].gettransaction(txId)
assert_equal(txObj['amount'], Decimal('-0.00010000'))
assert_equal(txObj['amountZat'], -10000)
#this should fail
errorString = ""

View File

@ -15,6 +15,7 @@ my_memo = my_memo + '0'*(1024-len(my_memo))
no_memo = 'f6' + ('0'*1022) # see section 5.5 of the protocol spec
fee = Decimal('0.0001')
feeZat = 10000
class ListReceivedTest (BitcoinTestFramework):
@ -106,6 +107,7 @@ class ListReceivedTest (BitcoinTestFramework):
assert_equal(1, len(r), "Should have received one (unconfirmed) note")
assert_equal(txid, r[0]['txid'])
assert_equal(1, r[0]['amount'])
assert_equal(100000000, r[0]['amountZat'])
assert_false(r[0]['change'], "Note should not be change")
assert_equal(my_memo, r[0]['memo'])
assert_equal(0, r[0]['confirmations'])
@ -203,11 +205,13 @@ class ListReceivedTest (BitcoinTestFramework):
assert_equal(txid, r[0]['txid'])
assert_equal(Decimal('0.4')-fee, r[0]['amount'])
assert_equal(40000000-feeZat, r[0]['amountZat'])
assert_true(r[0]['change'], "Note valued at (0.4-fee) should be change")
assert_equal(no_memo, r[0]['memo'])
# The old note still exists (it's immutable), even though it is spent
assert_equal(Decimal('1.0'), r[1]['amount'])
assert_equal(100000000, r[1]['amountZat'])
assert_false(r[1]['change'], "Note valued at 1.0 should not be change")
assert_equal(my_memo, r[1]['memo'])
@ -217,6 +221,7 @@ class ListReceivedTest (BitcoinTestFramework):
assert_equal(1, len(r), "zaddr2 Should have received 1 notes")
assert_equal(txid, r[0]['txid'])
assert_equal(Decimal('0.6'), r[0]['amount'])
assert_equal(60000000, r[0]['amountZat'])
assert_false(r[0]['change'], "Note valued at 0.6 should not be change")
assert_equal(no_memo, r[0]['memo'])

View File

@ -8,6 +8,7 @@
#include "tinyformat.h"
const std::string CURRENCY_UNIT = "ZEC";
const std::string MINOR_CURRENCY_UNIT = "zatoshis";
CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize)
{

View File

@ -17,6 +17,7 @@ static const CAmount COIN = 100000000;
static const CAmount CENT = 1000000;
extern const std::string CURRENCY_UNIT;
extern const std::string MINOR_CURRENCY_UNIT;
/** No amount larger than this (in satoshi) is valid.
*

View File

@ -37,7 +37,9 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "sendtoaddress", 4 },
{ "settxfee", 0 },
{ "getreceivedbyaddress", 1 },
{ "getreceivedbyaddress", 2 },
{ "getreceivedbyaccount", 1 },
{ "getreceivedbyaccount", 2 },
{ "listreceivedbyaddress", 0 },
{ "listreceivedbyaddress", 1 },
{ "listreceivedbyaddress", 2 },
@ -46,6 +48,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "listreceivedbyaccount", 2 },
{ "getbalance", 1 },
{ "getbalance", 2 },
{ "getbalance", 3 },
{ "getblockhash", 0 },
{ "move", 2 },
{ "move", 3 },
@ -125,6 +128,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "z_listunspent", 2 },
{ "z_listunspent", 3 },
{ "z_getbalance", 1},
{ "z_getbalance", 2},
{ "z_gettotalbalance", 0},
{ "z_gettotalbalance", 1},
{ "z_gettotalbalance", 2},

View File

@ -597,15 +597,16 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp)
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() < 1 || params.size() > 2)
if (fHelp || params.size() < 1 || params.size() > 3)
throw runtime_error(
"getreceivedbyaddress \"zcashaddress\" ( minconf )\n"
"getreceivedbyaddress \"zcashaddress\" ( minconf ) ( inZat )\n"
"\nReturns the total amount received by the given Zcash address in transactions with at least minconf confirmations.\n"
"\nArguments:\n"
"1. \"zcashaddress\" (string, required) The Zcash address for transactions.\n"
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
"3. inZat (bool, optional, default=false) Get the result amount in " + MINOR_CURRENCY_UNIT + " (as an integer).\n"
"\nResult:\n"
"amount (numeric) The total amount in " + CURRENCY_UNIT + " received at this address.\n"
"amount (numeric) The total amount in " + CURRENCY_UNIT + "(or " + MINOR_CURRENCY_UNIT + " if inZat is true) received at this address.\n"
"\nExamples:\n"
"\nThe amount from transactions with at least 1 confirmation\n"
+ HelpExampleCli("getreceivedbyaddress", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\"") +
@ -648,7 +649,12 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp)
nAmount += txout.nValue;
}
return ValueFromAmount(nAmount);
// inZat
if (params.size() > 2 && params[2].get_bool()) {
return nAmount;
}
return ValueFromAmount(nAmount);
}
@ -657,15 +663,16 @@ UniValue getreceivedbyaccount(const UniValue& params, bool fHelp)
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() < 1 || params.size() > 2)
if (fHelp || params.size() < 1 || params.size() > 3)
throw runtime_error(
"getreceivedbyaccount \"account\" ( minconf )\n"
"getreceivedbyaccount \"account\" ( minconf ) ( inZat )\n"
"\nDEPRECATED. Returns the total amount received by addresses with <account> in transactions with at least [minconf] confirmations.\n"
"\nArguments:\n"
"1. \"account\" (string, required) MUST be set to the empty string \"\" to represent the default account. Passing any other string will result in an error.\n"
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
"3. inZat (bool, optional, default=false) Get the result amount in " + MINOR_CURRENCY_UNIT + " (as an integer).\n"
"\nResult:\n"
"amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n"
"amount (numeric) The total amount in " + CURRENCY_UNIT + "(or " + MINOR_CURRENCY_UNIT + " if inZat is true) received for this account.\n"
"\nExamples:\n"
"\nAmount received by the default account with at least 1 confirmation\n"
+ HelpExampleCli("getreceivedbyaccount", "\"\"") +
@ -705,6 +712,11 @@ UniValue getreceivedbyaccount(const UniValue& params, bool fHelp)
}
}
// inZat
if (params.size() > 2 && params[2].get_bool()) {
return nAmount;
}
return ValueFromAmount(nAmount);
}
@ -746,16 +758,17 @@ UniValue getbalance(const UniValue& params, bool fHelp)
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() > 3)
if (fHelp || params.size() > 4)
throw runtime_error(
"getbalance ( \"account\" minconf includeWatchonly )\n"
"getbalance ( \"account\" minconf includeWatchonly inZat )\n"
"\nReturns the server's total available balance.\n"
"\nArguments:\n"
"1. \"account\" (string, optional) DEPRECATED. If provided, it MUST be set to the empty string \"\" or to the string \"*\", either of which will give the total available balance. Passing any other string will result in an error.\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"
"4. inZat (bool, optional, default=false) Get the result amount in " + MINOR_CURRENCY_UNIT + " (as an integer).\n"
"\nResult:\n"
"amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n"
"amount (numeric) The total amount in " + CURRENCY_UNIT + "(or " + MINOR_CURRENCY_UNIT + " if inZat is true) received.\n"
"\nExamples:\n"
"\nThe total amount in the wallet\n"
+ HelpExampleCli("getbalance", "") +
@ -803,6 +816,12 @@ UniValue getbalance(const UniValue& params, bool fHelp)
nBalance -= s.amount;
nBalance -= allFee;
}
// inZat
if (params.size() > 3 && params[3].get_bool()) {
return nBalance;
}
return ValueFromAmount(nBalance);
}
@ -810,6 +829,10 @@ UniValue getbalance(const UniValue& params, bool fHelp)
CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, filter);
if (params.size() > 3 && params[3].get_bool()) {
return nBalance;
}
return ValueFromAmount(nBalance);
}
@ -1229,6 +1252,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
obj.pushKV("address", EncodeDestination(dest));
obj.pushKV("account", strAccount);
obj.pushKV("amount", ValueFromAmount(nAmount));
obj.pushKV("amountZat", nAmount);
obj.pushKV("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf));
UniValue transactions(UniValue::VARR);
if (it != mapTally.end())
@ -1254,6 +1278,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
obj.pushKV("involvesWatchonly", true);
obj.pushKV("account", (*it).first);
obj.pushKV("amount", ValueFromAmount(nAmount));
obj.pushKV("amountZat", nAmount);
obj.pushKV("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf));
ret.push_back(obj);
}
@ -1283,6 +1308,7 @@ UniValue listreceivedbyaddress(const UniValue& params, bool fHelp)
" \"address\" : \"receivingaddress\", (string) The receiving address\n"
" \"account\" : \"accountname\", (string) DEPRECATED. The account of the receiving address. The default account is \"\".\n"
" \"amount\" : x.xxx, (numeric) The total amount in " + CURRENCY_UNIT + " received by the address\n"
" \"amountZat\" : xxxx (numeric) The amount in " + MINOR_CURRENCY_UNIT + "\n"
" \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n"
" }\n"
" ,...\n"
@ -1319,6 +1345,7 @@ UniValue listreceivedbyaccount(const UniValue& params, bool fHelp)
" \"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"
" \"amountZat\" : xxxx (numeric) The amount in " + MINOR_CURRENCY_UNIT + "\n"
" \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n"
" }\n"
" ,...\n"
@ -1366,6 +1393,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
MaybePushAddress(entry, s.destination);
entry.pushKV("category", "send");
entry.pushKV("amount", ValueFromAmount(-s.amount));
entry.pushKV("amountZat", -s.amount);
entry.pushKV("vout", s.vout);
entry.pushKV("fee", ValueFromAmount(-nFee));
if (fLong)
@ -1404,6 +1432,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
entry.pushKV("category", "receive");
}
entry.pushKV("amount", ValueFromAmount(r.amount));
entry.pushKV("amountZat", r.amount);
entry.pushKV("vout", r.vout);
if (fLong)
WalletTxToJSON(wtx, entry);
@ -1425,6 +1454,7 @@ void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Un
entry.pushKV("category", "move");
entry.pushKV("time", acentry.nTime);
entry.pushKV("amount", ValueFromAmount(acentry.nCreditDebit));
entry.pushKV("amountZat", acentry.nCreditDebit);
entry.pushKV("otheraccount", acentry.strOtherAccount);
entry.pushKV("comment", acentry.strComment);
ret.push_back(entry);
@ -1461,6 +1491,7 @@ UniValue listtransactions(const UniValue& params, bool fHelp)
" \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the\n"
" 'move' category for moves outbound. It is positive for the 'receive' category,\n"
" and for the 'move' category for inbound funds.\n"
" \"amountZat\": x.xxx, (numeric) The amount in " + MINOR_CURRENCY_UNIT + ". Negative and positive are the same as 'amount' field.\n"
" \"vout\" : n, (numeric) the vout value\n"
" \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n"
" 'send' category of transactions.\n"
@ -1658,6 +1689,7 @@ UniValue listsinceblock(const UniValue& params, bool fHelp)
" or 'expired'. Available for 'send' and 'receive' category of transactions.\n"
" \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the 'move' category for moves \n"
" outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds.\n"
" \"amountZat\": x.xxx, (numeric) The amount in " + MINOR_CURRENCY_UNIT + ". Negative and positive are the same as for the 'amount' field.\n"
" \"vout\" : n, (numeric) the vout value\n"
" \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the 'send' category of transactions.\n"
" \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n"
@ -1744,6 +1776,7 @@ UniValue gettransaction(const UniValue& params, bool fHelp)
"{\n"
" \"status\" : \"mined|waiting|expiringsoon|expired\", (string) The transaction status, can be 'mined', 'waiting', 'expiringsoon' or 'expired'\n"
" \"amount\" : x.xxx, (numeric) The transaction amount in " + CURRENCY_UNIT + "\n"
" \"amountZat\" : x (numeric) The amount in " + MINOR_CURRENCY_UNIT + "\n"
" \"confirmations\" : n, (numeric) The number of confirmations\n"
" \"blockhash\" : \"hash\", (string) The block hash\n"
" \"blockindex\" : xx, (numeric) The block index\n"
@ -1757,6 +1790,7 @@ UniValue gettransaction(const UniValue& params, bool fHelp)
" \"address\" : \"zcashaddress\", (string) The Zcash address involved in the transaction\n"
" \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n"
" \"amount\" : x.xxx (numeric) The amount in " + CURRENCY_UNIT + "\n"
" \"amountZat\" : x (numeric) The amount in " + MINOR_CURRENCY_UNIT + "\n"
" \"vout\" : n, (numeric) the vout value\n"
" }\n"
" ,...\n"
@ -1802,6 +1836,7 @@ UniValue gettransaction(const UniValue& params, bool fHelp)
CAmount nFee = (wtx.IsFromMe(filter) ? wtx.GetValueOut() - nDebit : 0);
entry.pushKV("amount", ValueFromAmount(nNet - nFee));
entry.pushKV("amountZat", nNet - nFee);
if (wtx.IsFromMe(filter))
entry.pushKV("fee", ValueFromAmount(nFee));
@ -2380,6 +2415,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
" \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n"
" \"scriptPubKey\" : \"key\", (string) the script key\n"
" \"amount\" : x.xxx, (numeric) the transaction amount in " + CURRENCY_UNIT + "\n"
" \"amountZat\" : xxxx (numeric) the transaction amount in " + MINOR_CURRENCY_UNIT + "\n"
" \"confirmations\" : n, (numeric) The number of confirmations\n"
" \"redeemScript\" : n (string) The redeemScript if scriptPubKey is P2SH\n"
" \"spendable\" : xxx (bool) Whether we have the private keys to spend this output\n"
@ -2455,6 +2491,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
entry.pushKV("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end()));
entry.pushKV("amount", ValueFromAmount(out.tx->vout[out.i].nValue));
entry.pushKV("amountZat", out.tx->vout[out.i].nValue);
entry.pushKV("confirmations", out.nDepth);
entry.pushKV("spendable", out.fSpendable);
results.push_back(entry);
@ -3353,6 +3390,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
"{\n"
" \"txid\": \"txid\", (string) the transaction id\n"
" \"amount\": xxxxx, (numeric) the amount of value in the note\n"
" \"amountZat\" : xxxx (numeric) The amount in " + MINOR_CURRENCY_UNIT + "\n"
" \"memo\": xxxxx, (string) hexadecimal string representation of memo field\n"
" \"confirmations\" : n, (numeric) the number of confirmations\n"
" \"blockheight\": n, (numeric) The block height containing the transaction\n"
@ -3407,6 +3445,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
UniValue obj(UniValue::VOBJ);
obj.pushKV("txid", entry.jsop.hash.ToString());
obj.pushKV("amount", ValueFromAmount(CAmount(entry.note.value())));
obj.pushKV("amountZat", CAmount(entry.note.value()));
std::string data(entry.memo.begin(), entry.memo.end());
obj.pushKV("memo", HexStr(data));
obj.pushKV("jsindex", entry.jsop.js);
@ -3428,6 +3467,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
UniValue obj(UniValue::VOBJ);
obj.pushKV("txid", entry.op.hash.ToString());
obj.pushKV("amount", ValueFromAmount(CAmount(entry.note.value())));
obj.pushKV("amountZat", CAmount(entry.note.value()));
obj.pushKV("memo", HexStr(entry.memo));
obj.pushKV("outindex", (int)entry.op.n);
obj.pushKV("confirmations", entry.confirmations);
@ -3451,17 +3491,18 @@ UniValue z_getbalance(const UniValue& params, bool fHelp)
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size()==0 || params.size() >2)
if (fHelp || params.size() == 0 || params.size() > 3)
throw runtime_error(
"z_getbalance \"address\" ( minconf )\n"
"z_getbalance \"address\" ( minconf inZat )\n"
"\nReturns the balance of a taddr or zaddr belonging to the node's wallet.\n"
"\nCAUTION: If the wallet has only an incoming viewing key for this address, then spends cannot be"
"\ndetected, and so the returned balance may be larger than the actual balance.\n"
"\nArguments:\n"
"1. \"address\" (string) The selected address. It may be a transparent or private address.\n"
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
"3. inZat (bool, optional, default=false) Get the result amount in " + MINOR_CURRENCY_UNIT + " (as an integer).\n"
"\nResult:\n"
"amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this address.\n"
"amount (numeric) The total amount in " + CURRENCY_UNIT + "(or " + MINOR_CURRENCY_UNIT + " if inZat is true) received at this address.\n"
"\nExamples:\n"
"\nThe total amount received by address \"myaddress\"\n"
+ HelpExampleCli("z_getbalance", "\"myaddress\"") +
@ -3503,6 +3544,11 @@ UniValue z_getbalance(const UniValue& params, bool fHelp)
nBalance = getBalanceZaddr(fromaddress, nMinDepth, false);
}
// inZat
if (params.size() > 2 && params[2].get_bool()) {
return nBalance;
}
return ValueFromAmount(nBalance);
}