From 9a55c8b23898da7ea32b64d8999bd53ba3e61c82 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 28 Jan 2020 20:34:40 -0300 Subject: [PATCH] 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));