From 7e946d7ccb224bfdc22ac98ed4484033c077923d Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 3 Dec 2019 11:24:30 -0300 Subject: [PATCH] add blockheight, blockindex and blocktime to z_listreceivedbyaddress --- qa/rpc-tests/wallet_listreceived.py | 9 ++++++++ src/wallet/rpcwallet.cpp | 32 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/qa/rpc-tests/wallet_listreceived.py b/qa/rpc-tests/wallet_listreceived.py index 7ee5f9e33..85ec0be6e 100755 --- a/qa/rpc-tests/wallet_listreceived.py +++ b/qa/rpc-tests/wallet_listreceived.py @@ -49,6 +49,9 @@ class ListReceivedTest (BitcoinTestFramework): assert_equal(1, r[0]['amount']) assert_false(r[0]['change'], "Note should not be change") assert_equal(my_memo, r[0]['memo']) + assert_equal(0, r[0]['confirmations']) + assert_equal(-1, r[0]['blockindex']) + assert_equal(0, r[0]['blockheight']) # Confirm transaction (1 ZEC from taddr to zaddr1) self.generate_and_sync(height+3) @@ -56,6 +59,12 @@ class ListReceivedTest (BitcoinTestFramework): # adjust previous result because now there is one more confirmation r[0]['confirmations'] += 1 + # adjust blockindex as now there are 2 transactions confirmed in the block + r[0]['blockindex'] = 1 + + # adjust height as we generated blocks + r[0]['blockheight'] = height + 3 + # Require one confirmation, note should be present assert_equal(r, self.nodes[1].z_listreceivedbyaddress(zaddr1)) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 81c7abcd6..2ad17b058 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3303,6 +3303,23 @@ CAmount getBalanceZaddr(std::string address, int minDepth = 1, bool ignoreUnspen return balance; } +struct trxblock +{ + int blockheight = 0; + int blockindex = -1; + int64_t blocktime = 0; + + trxblock(uint256 hash) + { + if(pwalletMain->mapWallet.count(hash)) { + const CWalletTx& wtx = pwalletMain->mapWallet[hash]; + if(!wtx.hashBlock.IsNull()) + blockheight = mapBlockIndex[wtx.hashBlock]->nHeight; + blockindex = wtx.nIndex; + blocktime = wtx.GetTxTime(); + } + } +}; UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) { @@ -3322,6 +3339,9 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) " \"amount\": xxxxx, (numeric) the amount of value in the note\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" + " \"blockindex\": n, (numeric) The block index containing the transaction.\n" + " \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n" " \"jsindex\" (sprout) : n, (numeric) the joinsplit index\n" " \"jsoutindex\" (sprout) : n, (numeric) the output index of the joinsplit\n" " \"outindex\" (sapling) : n, (numeric) the output index\n" @@ -3376,6 +3396,12 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) obj.push_back(Pair("jsindex", entry.jsop.js)); obj.push_back(Pair("jsoutindex", entry.jsop.n)); obj.push_back(Pair("confirmations", entry.confirmations)); + + trxblock additional(entry.jsop.hash); + obj.push_back(Pair("blockheight", additional.blockheight)); + obj.push_back(Pair("blockindex", additional.blockindex)); + obj.push_back(Pair("blocktime", additional.blocktime)); + if (hasSpendingKey) { obj.push_back(Pair("change", pwalletMain->IsNoteSproutChange(nullifierSet, entry.address, entry.jsop))); } @@ -3389,6 +3415,12 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) obj.push_back(Pair("memo", HexStr(entry.memo))); obj.push_back(Pair("outindex", (int)entry.op.n)); obj.push_back(Pair("confirmations", entry.confirmations)); + + trxblock additional(entry.op.hash); + obj.push_back(Pair("blockheight", additional.blockheight)); + obj.push_back(Pair("blockindex", additional.blockindex)); + obj.push_back(Pair("blocktime", additional.blocktime)); + if (hasSpendingKey) { obj.push_back(Pair("change", pwalletMain->IsNoteSaplingChange(nullifierSet, entry.address, entry.op))); }