From 4b61aede289cd27b7aed34a544e1963aebc3e75d Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Thu, 2 Jan 2020 11:04:47 -0300 Subject: [PATCH 01/21] add bool argument to get balance in satoshis to rpc getreceivedbyaddress --- qa/rpc-tests/receivedby.py | 5 +++++ src/wallet/rpcwallet.cpp | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/receivedby.py b/qa/rpc-tests/receivedby.py index b19c55e68..dc17bf088 100755 --- a/qa/rpc-tests/receivedby.py +++ b/qa/rpc-tests/receivedby.py @@ -110,6 +110,11 @@ class ReceivedByTest(BitcoinTestFramework): if balance != Decimal("0.1"): raise AssertionError("Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance)) + # Get balance as integer + balance = self.nodes[1].getreceivedbyaddress(addr, 0, True) + if balance != int("10000000"): + raise AssertionError("Wrong balance returned by getreceivedbyaddress, %i"%(balance)) + ''' listreceivedbyaccount + getreceivedbyaccount Test ''' diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c08da799c..6dae48435 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -597,7 +597,7 @@ 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" "\nReturns the total amount received by the given Zcash address in transactions with at least minconf confirmations.\n" @@ -647,8 +647,11 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) if (wtx.GetDepthInMainChain() >= nMinDepth) nAmount += txout.nValue; } + if(params.size() > 2) + if(params[2].get_bool()) + return nAmount; - return ValueFromAmount(nAmount); + return ValueFromAmount(nAmount); } From aba1d946733749c232750349d5ed96a5f0b02b5c Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Thu, 2 Jan 2020 11:38:38 -0300 Subject: [PATCH 02/21] add documentation to flag --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6dae48435..3cc6709b5 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -603,7 +603,8 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) "\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. inzatoshi (bool, optional, default=false) Get the result amount as an integer.\n" "\nResult:\n" "amount (numeric) The total amount in " + CURRENCY_UNIT + " received at this address.\n" "\nExamples:\n" From 4155db0325525dc5f376a1be13ac6ec66561f2b5 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 28 Jan 2020 11:11:43 -0300 Subject: [PATCH 03/21] change argument name --- src/wallet/rpcwallet.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3cc6709b5..dd57a8e22 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -604,7 +604,7 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) "\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" - "3. inzatoshi (bool, optional, default=false) Get the result amount as an integer.\n" + "3. inZat (bool, optional, default=false) Get the result amount as an integer.\n" "\nResult:\n" "amount (numeric) The total amount in " + CURRENCY_UNIT + " received at this address.\n" "\nExamples:\n" @@ -648,8 +648,10 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) if (wtx.GetDepthInMainChain() >= nMinDepth) nAmount += txout.nValue; } - if(params.size() > 2) - if(params[2].get_bool()) + + // inZat + if (params.size() > 2) + if (params[2].get_bool()) return nAmount; return ValueFromAmount(nAmount); From d2c26b33e01ab7c7fd1b8c830244031e274c6cd0 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 28 Jan 2020 12:48:40 -0300 Subject: [PATCH 04/21] add boolean inZat to getreceivedbyaccount --- qa/rpc-tests/receivedby.py | 11 ++++++++--- src/wallet/rpcwallet.cpp | 14 ++++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/qa/rpc-tests/receivedby.py b/qa/rpc-tests/receivedby.py index dc17bf088..3184adf68 100755 --- a/qa/rpc-tests/receivedby.py +++ b/qa/rpc-tests/receivedby.py @@ -111,7 +111,7 @@ class ReceivedByTest(BitcoinTestFramework): raise AssertionError("Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance)) # Get balance as integer - balance = self.nodes[1].getreceivedbyaddress(addr, 0, True) + balance = self.nodes[1].getreceivedbyaddress(addr, 1, True) if balance != int("10000000"): raise AssertionError("Wrong balance returned by getreceivedbyaddress, %i"%(balance)) @@ -134,7 +134,7 @@ 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)) @@ -146,11 +146,16 @@ class ReceivedByTest(BitcoinTestFramework): {"account":account}, {"account":received_by_account_json["account"], "amount":(received_by_account_json["amount"] + Decimal("0.1"))}) - # 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)) + # Get balance as integer + balance = self.nodes[1].getreceivedbyaccount(account, 1, True) + if balance != int("30000000"): + raise AssertionError("Wrong balance returned by getreceivedbyaccount, %i"%(balance)) + # Create a new account named "mynewaccount" that has a 0 balance self.nodes[1].getaccountaddress("mynewaccount") received_by_account_json = get_sub_array_from_array(self.nodes[1].listreceivedbyaccount(0,True),{"account":"mynewaccount"}) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index dd57a8e22..c822432f8 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -599,7 +599,7 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) 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" @@ -663,13 +663,14 @@ 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 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 as an integer.\n" "\nResult:\n" "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n" "\nExamples:\n" @@ -711,6 +712,11 @@ UniValue getreceivedbyaccount(const UniValue& params, bool fHelp) } } + // inZat + if (params.size() > 2) + if (params[2].get_bool()) + return nAmount; + return ValueFromAmount(nAmount); } From 50372cab6250757dfc70f8e3a35ca2a5f3fbc260 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 28 Jan 2020 17:36:26 -0300 Subject: [PATCH 05/21] add boolean inZat to getbalance --- qa/rpc-tests/wallet.py | 5 ++++- src/wallet/rpcwallet.cpp | 11 +++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index ba4c7afdf..57fdf1e51 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -263,10 +263,13 @@ 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 + # 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 + # check integer balances from getbalance + assert_equal(self.nodes[2].getbalance("*", 1, False, True), int('1399800000')) #should not be + # send from node 0 to node 2 taddr mytaddr = self.nodes[2].getnewaddress() mytxid = self.nodes[0].sendtoaddress(mytaddr, 10.0) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c822432f8..b55e8ae83 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -758,14 +758,15 @@ 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 as an integer.\n" "\nResult:\n" "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n" "\nExamples:\n" @@ -815,6 +816,12 @@ UniValue getbalance(const UniValue& params, bool fHelp) nBalance -= s.amount; nBalance -= allFee; } + + // inZat + if (params.size() > 3) + if (params[3].get_bool()) + return nBalance; + return ValueFromAmount(nBalance); } From 306270911ecc1ab7e2f88ce1d7632ab0f4698d97 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 28 Jan 2020 17:55:37 -0300 Subject: [PATCH 06/21] add boolean inZat to z_getbalance --- qa/rpc-tests/wallet.py | 3 +++ src/wallet/rpcwallet.cpp | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index 57fdf1e51..226ca4994 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -280,6 +280,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), int('10')) + mytxdetails = self.nodes[2].gettransaction(mytxid) myvjoinsplits = mytxdetails["vjoinsplit"] assert_equal(0, len(myvjoinsplits)) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b55e8ae83..de05acd4b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3470,15 +3470,16 @@ 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 as an integer.\n" "\nResult:\n" "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this address.\n" "\nExamples:\n" @@ -3522,6 +3523,11 @@ UniValue z_getbalance(const UniValue& params, bool fHelp) nBalance = getBalanceZaddr(fromaddress, nMinDepth, false); } + // inZat + if (params.size() > 3) + if (params[3].get_bool()) + return nBalance; + return ValueFromAmount(nBalance); } From 2ec9ac3c81888e57a01c036c1da0b4797a69bdc9 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 28 Jan 2020 18:30:14 -0300 Subject: [PATCH 07/21] add amountZat field to listreceivedbyaddress and listreceivedbyaccount --- qa/rpc-tests/receivedby.py | 8 ++++---- src/wallet/rpcwallet.cpp | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/qa/rpc-tests/receivedby.py b/qa/rpc-tests/receivedby.py index 3184adf68..2c23cb892 100755 --- a/qa/rpc-tests/receivedby.py +++ b/qa/rpc-tests/receivedby.py @@ -71,11 +71,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":int("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":int("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 +83,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":int("0"), "txids":[]}) ''' getreceivedbyaddress Test @@ -144,7 +144,7 @@ class ReceivedByTest(BitcoinTestFramework): # 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":int("30000000")}) # getreceivedbyaccount should return updates balance balance = self.nodes[1].getreceivedbyaccount(account) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index de05acd4b..535906362 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1248,6 +1248,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::max() ? 0 : nConf)); UniValue transactions(UniValue::VARR); if (it != mapTally.end()) @@ -1273,6 +1274,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::max() ? 0 : nConf)); ret.push_back(obj); } @@ -1302,6 +1304,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 zatoshis\n" " \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n" " }\n" " ,...\n" @@ -1338,6 +1341,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 zatoshis\n" " \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n" " }\n" " ,...\n" From 9a55c8b23898da7ea32b64d8999bd53ba3e61c82 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 28 Jan 2020 20:34:40 -0300 Subject: [PATCH 08/21] add amountZat field to listtransactions, gettransaction and listsinceblock --- qa/rpc-tests/listtransactions.py | 32 +++++++++++++++++--------------- qa/rpc-tests/wallet.py | 3 +++ src/wallet/rpcwallet.cpp | 8 ++++++++ 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/qa/rpc-tests/listtransactions.py b/qa/rpc-tests/listtransactions.py index 00e17a989..5cdc48d04 100755 --- a/qa/rpc-tests/listtransactions.py +++ b/qa/rpc-tests/listtransactions.py @@ -6,6 +6,7 @@ # Exercise the listtransactions API from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import assert_equal from decimal import Decimal @@ -38,28 +39,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":int("-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":int("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":int("-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":int("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":int("-20000000")}) check_array_result(self.nodes[0].listtransactions(), {"txid":txid, "category":"receive"}, - {"amount":Decimal("0.2")}) + {"amount":Decimal("0.2"),"amountZat":int("20000000")}) # sendmany from node1: twice to self, twice to node2: send_to = { self.nodes[0].getnewaddress() : 0.11, @@ -69,28 +71,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":int("-11000000")}, {"txid":txid} ) check_array_result(self.nodes[0].listtransactions(), - {"category":"receive","amount":Decimal("0.11")}, + {"category":"receive","amount":Decimal("0.11"),"amountZat":int("11000000")}, {"txid":txid} ) check_array_result(self.nodes[1].listtransactions(), - {"category":"send","amount":Decimal("-0.22")}, + {"category":"send","amount":Decimal("-0.22"),"amountZat":int("-22000000")}, {"txid":txid} ) check_array_result(self.nodes[1].listtransactions(), - {"category":"receive","amount":Decimal("0.22")}, + {"category":"receive","amount":Decimal("0.22"),"amountZat":int("22000000")}, {"txid":txid} ) check_array_result(self.nodes[1].listtransactions(), - {"category":"send","amount":Decimal("-0.33")}, + {"category":"send","amount":Decimal("-0.33"),"amountZat":int("-33000000")}, {"txid":txid} ) check_array_result(self.nodes[0].listtransactions(), - {"category":"receive","amount":Decimal("0.33")}, + {"category":"receive","amount":Decimal("0.33"),"amountZat":int("33000000")}, {"txid":txid, "account" : ""} ) check_array_result(self.nodes[1].listtransactions(), - {"category":"send","amount":Decimal("-0.44")}, + {"category":"send","amount":Decimal("-0.44"),"amountZat":int("-44000000")}, {"txid":txid, "account" : ""} ) check_array_result(self.nodes[1].listtransactions(), - {"category":"receive","amount":Decimal("0.44")}, + {"category":"receive","amount":Decimal("0.44"),"amountZat":int("44000000")}, {"txid":txid, "account" : ""} ) multisig = self.nodes[1].createmultisig(1, [self.nodes[1].getnewaddress()]) @@ -100,7 +102,7 @@ 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":int("10000000")}, {"txid":txid, "account" : "watchonly"} ) if __name__ == '__main__': diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index 226ca4994..91ecc9cf4 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -385,15 +385,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'], int('-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'], int('-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'], int('-10000')) #this should fail errorString = "" diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 535906362..70e423e62 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1389,6 +1389,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) @@ -1427,6 +1428,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); @@ -1448,6 +1450,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); @@ -1484,6 +1487,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 zatoshis. 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" @@ -1681,6 +1685,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 zatoshis. 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 'send' category of transactions.\n" " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n" @@ -1767,6 +1772,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 zatoshis\n" " \"confirmations\" : n, (numeric) The number of confirmations\n" " \"blockhash\" : \"hash\", (string) The block hash\n" " \"blockindex\" : xx, (numeric) The block index\n" @@ -1780,6 +1786,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 zatoshis\n" " \"vout\" : n, (numeric) the vout value\n" " }\n" " ,...\n" @@ -1825,6 +1832,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)); From 76e7f21d4a8031100b8b151ddbc6795f7102ba0c Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 28 Jan 2020 20:44:36 -0300 Subject: [PATCH 09/21] add amountZat field to listunspent --- qa/rpc-tests/wallet.py | 1 + src/wallet/rpcwallet.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index 91ecc9cf4..5803c117d 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -220,6 +220,7 @@ class WalletTest (BitcoinTestFramework): if uTx['txid'] == zeroValueTxid: found = True assert_equal(uTx['amount'], Decimal('0.00000000')) + assert_equal(uTx['amountZat'], int('0')) assert(found) #do some -walletbroadcast tests diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 70e423e62..cf43d0e21 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2411,6 +2411,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 zatoshis\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" @@ -2486,6 +2487,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); From 25f48c21ddee7845b0e933c4e7606843f4797d33 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 28 Jan 2020 21:27:31 -0300 Subject: [PATCH 10/21] add amountZat field to z_listreceivedbyaddress --- qa/rpc-tests/wallet_listreceived.py | 5 +++++ src/wallet/rpcwallet.cpp | 3 +++ 2 files changed, 8 insertions(+) diff --git a/qa/rpc-tests/wallet_listreceived.py b/qa/rpc-tests/wallet_listreceived.py index 52dff938a..ad30e9537 100755 --- a/qa/rpc-tests/wallet_listreceived.py +++ b/qa/rpc-tests/wallet_listreceived.py @@ -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 = Decimal('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(Decimal('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']) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index cf43d0e21..d2a9aa28d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3386,6 +3386,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 zatoshis\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" @@ -3440,6 +3441,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); @@ -3461,6 +3463,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); From 25bccb4814a01d88dfd7ff17cc1898aa376f437a Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 22 Apr 2020 09:13:15 -0300 Subject: [PATCH 11/21] replace with AssertionError assert_equal in receivedby.py Co-Authored-By: Daira Hopwood --- qa/rpc-tests/receivedby.py | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/qa/rpc-tests/receivedby.py b/qa/rpc-tests/receivedby.py index 2c23cb892..6e831dbe7 100755 --- a/qa/rpc-tests/receivedby.py +++ b/qa/rpc-tests/receivedby.py @@ -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 @@ -95,25 +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) - if balance != int("10000000"): - raise AssertionError("Wrong balance returned by getreceivedbyaddress, %i"%(balance)) + assert_equal(balance, 10000000, "Wrong balance returned by getreceivedbyaddress, %i"%(balance)) ''' listreceivedbyaccount + getreceivedbyaccount Test @@ -122,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) @@ -136,25 +135,22 @@ class ReceivedByTest(BitcoinTestFramework): # 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")), "amountZat":int("30000000")}) + {"account":received_by_account_json["account"], "amount":(received_by_account_json["amount"] + Decimal("0.1")), "amountZat":30000000}) # 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) - if balance != int("30000000"): - raise AssertionError("Wrong balance returned by getreceivedbyaccount, %i"%(balance)) + 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") @@ -162,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() From 24d3516e35dc3f06db4eaa5c081192fac1892725 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 22 Apr 2020 09:23:22 -0300 Subject: [PATCH 12/21] Fix casting in wallet.py Co-Authored-By: Daira Hopwood --- qa/rpc-tests/wallet.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index 5803c117d..a1f08ffba 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -264,12 +264,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 + # tx should be added to balance because after restarting the nodes tx should be broadcast assert_equal(self.nodes[2].getbalance(), Decimal('13.99800000')) #should not be assert_equal(self.nodes[2].getbalance("*"), Decimal('13.99800000')) #should not be # check integer balances from getbalance - assert_equal(self.nodes[2].getbalance("*", 1, False, True), int('1399800000')) #should not be + assert_equal(self.nodes[2].getbalance("*", 1, False, True), 1399800000) #should not be # send from node 0 to node 2 taddr mytaddr = self.nodes[2].getnewaddress() @@ -282,7 +282,7 @@ class WalletTest (BitcoinTestFramework): assert_equal(mybalance, Decimal('10.0')) # check integer balances from z_getbalance - assert_equal(self.nodes[2].z_getbalance(mytaddr, 1, True), int('10')) + assert_equal(self.nodes[2].z_getbalance(mytaddr, 1, True), 10) mytxdetails = self.nodes[2].gettransaction(mytxid) myvjoinsplits = mytxdetails["vjoinsplit"] @@ -386,18 +386,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'], int('-200000000')) + 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'], int('-10000')) + 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'], int('-10000')) + assert_equal(txObj['amountZat'], -10000) #this should fail errorString = "" From 507e1623f9efeea90031f31cdb1bf250852e0435 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 22 Apr 2020 11:00:32 -0300 Subject: [PATCH 13/21] simplify inzat balances logic Co-Authored-By: Daira Hopwood --- src/wallet/rpcwallet.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d2a9aa28d..851541a12 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -650,9 +650,9 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) } // inZat - if (params.size() > 2) - if (params[2].get_bool()) - return nAmount; + if (params.size() > 2 && params[2].get_bool()) { + return nAmount; + } return ValueFromAmount(nAmount); } @@ -713,9 +713,9 @@ UniValue getreceivedbyaccount(const UniValue& params, bool fHelp) } // inZat - if (params.size() > 2) - if (params[2].get_bool()) - return nAmount; + if (params.size() > 2 && params[2].get_bool()) { + return nAmount; + } return ValueFromAmount(nAmount); } @@ -818,9 +818,9 @@ UniValue getbalance(const UniValue& params, bool fHelp) } // inZat - if (params.size() > 3) - if (params[3].get_bool()) - return nBalance; + if (params.size() > 3 && params[3].get_bool()) { + return nBalance; + } return ValueFromAmount(nBalance); } @@ -1685,7 +1685,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 zatoshis. Negative and positive are the same as 'amount' field.\n" + " \"amountZat\": x.xxx, (numeric) The amount in zatoshis. 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" @@ -3541,9 +3541,9 @@ UniValue z_getbalance(const UniValue& params, bool fHelp) } // inZat - if (params.size() > 3) - if (params[3].get_bool()) - return nBalance; + if (params.size() > 3 && params[3].get_bool()) { + return nBalance; + } return ValueFromAmount(nBalance); } From 26e4889f874e6728ff2afe66529ef0b8da82ebf3 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 22 Apr 2020 11:04:16 -0300 Subject: [PATCH 14/21] Fix casting in listtransactions.py --- qa/rpc-tests/listtransactions.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/qa/rpc-tests/listtransactions.py b/qa/rpc-tests/listtransactions.py index 5cdc48d04..990f9a605 100755 --- a/qa/rpc-tests/listtransactions.py +++ b/qa/rpc-tests/listtransactions.py @@ -39,29 +39,29 @@ class ListTransactionsTest(BitcoinTestFramework): self.sync_all() check_array_result(self.nodes[0].listtransactions(), {"txid":txid}, - {"category":"send","account":"","amount":Decimal("-0.1"),"amountZat":int("-10000000"),"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"),"amountZat":int("10000000"),"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"),"amountZat":int("-10000000"),"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"),"amountZat":int("10000000"),"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"),"amountZat":int("-20000000")}) + {"amount":Decimal("-0.2"),"amountZat":-20000000}) check_array_result(self.nodes[0].listtransactions(), {"txid":txid, "category":"receive"}, - {"amount":Decimal("0.2"),"amountZat":int("20000000")}) + {"amount":Decimal("0.2"),"amountZat":20000000}) # sendmany from node1: twice to self, twice to node2: send_to = { self.nodes[0].getnewaddress() : 0.11, @@ -71,28 +71,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"),"amountZat":int("-11000000")}, + {"category":"send","amount":Decimal("-0.11"),"amountZat":-11000000}, {"txid":txid} ) check_array_result(self.nodes[0].listtransactions(), - {"category":"receive","amount":Decimal("0.11"),"amountZat":int("11000000")}, + {"category":"receive","amount":Decimal("0.11"),"amountZat":11000000}, {"txid":txid} ) check_array_result(self.nodes[1].listtransactions(), - {"category":"send","amount":Decimal("-0.22"),"amountZat":int("-22000000")}, + {"category":"send","amount":Decimal("-0.22"),"amountZat":-22000000}, {"txid":txid} ) check_array_result(self.nodes[1].listtransactions(), - {"category":"receive","amount":Decimal("0.22"),"amountZat":int("22000000")}, + {"category":"receive","amount":Decimal("0.22"),"amountZat":22000000}, {"txid":txid} ) check_array_result(self.nodes[1].listtransactions(), - {"category":"send","amount":Decimal("-0.33"),"amountZat":int("-33000000")}, + {"category":"send","amount":Decimal("-0.33"),"amountZat":-33000000}, {"txid":txid} ) check_array_result(self.nodes[0].listtransactions(), - {"category":"receive","amount":Decimal("0.33"),"amountZat":int("33000000")}, + {"category":"receive","amount":Decimal("0.33"),"amountZat":33000000}, {"txid":txid, "account" : ""} ) check_array_result(self.nodes[1].listtransactions(), - {"category":"send","amount":Decimal("-0.44"),"amountZat":int("-44000000")}, + {"category":"send","amount":Decimal("-0.44"),"amountZat":-44000000}, {"txid":txid, "account" : ""} ) check_array_result(self.nodes[1].listtransactions(), - {"category":"receive","amount":Decimal("0.44"),"amountZat":int("44000000")}, + {"category":"receive","amount":Decimal("0.44"),"amountZat":44000000}, {"txid":txid, "account" : ""} ) multisig = self.nodes[1].createmultisig(1, [self.nodes[1].getnewaddress()]) @@ -102,7 +102,7 @@ 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"),"amountZat":int("10000000")}, + {"category":"receive","amount":Decimal("0.1"),"amountZat":10000000}, {"txid":txid, "account" : "watchonly"} ) if __name__ == '__main__': From 1805466d5c555778017bdb165688fd699bcbcdbb Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 22 Apr 2020 11:21:12 -0300 Subject: [PATCH 15/21] add MINOR_CURRENCY_UNIT --- src/amount.cpp | 1 + src/amount.h | 1 + src/wallet/rpcwallet.cpp | 16 ++++++++-------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/amount.cpp b/src/amount.cpp index 3572e59c8..78e90bc78 100644 --- a/src/amount.cpp +++ b/src/amount.cpp @@ -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) { diff --git a/src/amount.h b/src/amount.h index 9913e565e..73f7741c0 100644 --- a/src/amount.h +++ b/src/amount.h @@ -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. * diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 851541a12..92a36bdb4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1304,7 +1304,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 zatoshis\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" @@ -1341,7 +1341,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 zatoshis\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" @@ -1487,7 +1487,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 zatoshis. Negative and positive are the same as 'amount' field.\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" @@ -1685,7 +1685,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 zatoshis. Negative and positive are the same as for the 'amount' field.\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" @@ -1772,7 +1772,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 zatoshis\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" @@ -1786,7 +1786,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 zatoshis\n" + " \"amountZat\" : x (numeric) The amount in " + MINOR_CURRENCY_UNIT + "\n" " \"vout\" : n, (numeric) the vout value\n" " }\n" " ,...\n" @@ -2411,7 +2411,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 zatoshis\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" @@ -3386,7 +3386,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 zatoshis\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" From d42e0a433cafee963a9cf79ecd33a1165a82e89c Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Mon, 18 May 2020 18:02:22 -0300 Subject: [PATCH 16/21] remove additional not needed casts from py tests --- qa/rpc-tests/receivedby.py | 4 ++-- qa/rpc-tests/wallet.py | 2 +- qa/rpc-tests/wallet_listreceived.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/qa/rpc-tests/receivedby.py b/qa/rpc-tests/receivedby.py index 6e831dbe7..f60bdfa97 100755 --- a/qa/rpc-tests/receivedby.py +++ b/qa/rpc-tests/receivedby.py @@ -72,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"), "amountZat":int("10000000"), "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"), "amountZat":int("10000000"), "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) diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index a1f08ffba..626818a3b 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -220,7 +220,7 @@ class WalletTest (BitcoinTestFramework): if uTx['txid'] == zeroValueTxid: found = True assert_equal(uTx['amount'], Decimal('0.00000000')) - assert_equal(uTx['amountZat'], int('0')) + assert_equal(uTx['amountZat'], 0) assert(found) #do some -walletbroadcast tests diff --git a/qa/rpc-tests/wallet_listreceived.py b/qa/rpc-tests/wallet_listreceived.py index ad30e9537..7addb4aae 100755 --- a/qa/rpc-tests/wallet_listreceived.py +++ b/qa/rpc-tests/wallet_listreceived.py @@ -15,7 +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 = Decimal('10000') +feeZat = 10000 class ListReceivedTest (BitcoinTestFramework): @@ -205,7 +205,7 @@ class ListReceivedTest (BitcoinTestFramework): assert_equal(txid, r[0]['txid']) assert_equal(Decimal('0.4')-fee, r[0]['amount']) - assert_equal(Decimal('40000000')-feeZat, r[0]['amountZat']) + 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']) From 76cb4e8d0437be9f2843d7affac0f7573605dd12 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Fri, 29 May 2020 11:24:39 -0300 Subject: [PATCH 17/21] remove not needed comments from wallet.py --- qa/rpc-tests/wallet.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index 626818a3b..4e2d157e1 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -265,11 +265,11 @@ class WalletTest (BitcoinTestFramework): sync_blocks(self.nodes) # tx should be added to balance because after restarting the nodes tx should be broadcast - assert_equal(self.nodes[2].getbalance(), Decimal('13.99800000')) #should not be - assert_equal(self.nodes[2].getbalance("*"), Decimal('13.99800000')) #should not be + 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) #should not be + assert_equal(self.nodes[2].getbalance("*", 1, False, True), 1399800000) # send from node 0 to node 2 taddr mytaddr = self.nodes[2].getnewaddress() From e7c829aa0e3cfe4336268e8576a0539d88cc4fc5 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Sat, 30 May 2020 10:34:03 -0300 Subject: [PATCH 18/21] update docs --- qa/rpc-tests/receivedby.py | 2 +- src/wallet/rpcwallet.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/qa/rpc-tests/receivedby.py b/qa/rpc-tests/receivedby.py index f60bdfa97..e40b4dd6f 100755 --- a/qa/rpc-tests/receivedby.py +++ b/qa/rpc-tests/receivedby.py @@ -84,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, "amountZat":int("0"), "txids":[]}) + {"address":addr, "account":"", "amount":0, "confirmations":0, "amountZat":0, "txids":[]}) ''' getreceivedbyaddress Test diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 92a36bdb4..786202b36 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -604,9 +604,9 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) "\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" - "3. inZat (bool, optional, default=false) Get the result amount as an integer.\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\"") + @@ -670,9 +670,9 @@ UniValue getreceivedbyaccount(const UniValue& params, bool fHelp) "\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" - "3. inZat (bool, optional, default=false) Get the result amount as an integer.\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 at this address.\n" "\nExamples:\n" "\nAmount received by the default account with at least 1 confirmation\n" + HelpExampleCli("getreceivedbyaccount", "\"\"") + @@ -766,9 +766,9 @@ UniValue getbalance(const UniValue& params, bool fHelp) "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 as an integer.\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 at this address.\n" "\nExamples:\n" "\nThe total amount in the wallet\n" + HelpExampleCli("getbalance", "") + @@ -3496,9 +3496,9 @@ UniValue z_getbalance(const UniValue& params, bool fHelp) "\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 as an integer.\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\"") + From 93afebeef43597610ef8bad66c1ae1c9e69926b7 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Sat, 30 May 2020 12:18:43 -0300 Subject: [PATCH 19/21] add new parameters to rpc client and fix some bugs --- qa/rpc-tests/wallet.py | 2 +- src/rpc/client.cpp | 4 ++++ src/wallet/rpcwallet.cpp | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index 4e2d157e1..fb3238460 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -282,7 +282,7 @@ class WalletTest (BitcoinTestFramework): assert_equal(mybalance, Decimal('10.0')) # check integer balances from z_getbalance - assert_equal(self.nodes[2].z_getbalance(mytaddr, 1, True), 10) + assert_equal(self.nodes[2].z_getbalance(mytaddr, 1, True), 1000000000) mytxdetails = self.nodes[2].gettransaction(mytxid) myvjoinsplits = mytxdetails["vjoinsplit"] diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index fe084b8f2..4887d0555 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -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}, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 786202b36..b954598b9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -829,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); } @@ -3541,7 +3545,7 @@ UniValue z_getbalance(const UniValue& params, bool fHelp) } // inZat - if (params.size() > 3 && params[3].get_bool()) { + if (params.size() > 2 && params[2].get_bool()) { return nBalance; } From 916351be049a613adf2574a899edd402862f4494 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 2 Jun 2020 09:14:50 -0300 Subject: [PATCH 20/21] fix/improve docs Co-authored-by: str4d --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b954598b9..75c273095 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -672,7 +672,7 @@ UniValue getreceivedbyaccount(const UniValue& params, bool fHelp) "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 + "(or " + MINOR_CURRENCY_UNIT + " if inZat is true) received at this address.\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", "\"\"") + @@ -768,7 +768,7 @@ UniValue getbalance(const UniValue& params, bool fHelp) "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 + "(or " + MINOR_CURRENCY_UNIT + " if inZat is true) received at this address.\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", "") + From 270a724c877f40aca61224e298931fbc7011d7fe Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Wed, 3 Jun 2020 12:25:31 +0100 Subject: [PATCH 21/21] Remove unused import in qa/rpc-tests/listtransactions.py Co-authored-by: Dimitris Apostolou --- qa/rpc-tests/listtransactions.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/qa/rpc-tests/listtransactions.py b/qa/rpc-tests/listtransactions.py index 990f9a605..6d14a3344 100755 --- a/qa/rpc-tests/listtransactions.py +++ b/qa/rpc-tests/listtransactions.py @@ -6,7 +6,6 @@ # Exercise the listtransactions API from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal from decimal import Decimal @@ -107,4 +106,3 @@ class ListTransactionsTest(BitcoinTestFramework): if __name__ == '__main__': ListTransactionsTest().main() -