Skip to content

Commit aa0599f

Browse files
committed
Merge #714: [0.17] Backport assetlabel fixes and tests
a965d44 [RPC]Add assetlabel support to some commands (Akio Nakamura) Pull request description: Tree-SHA512: 3ce6b244c80f3c6e4062bd5c428f392d881baddb1890bbb5b060dcfd8edb9f1915b12c65313ae26400450ee65f537df9bbb374aebe7e1e9249ef51541db3e4b2
2 parents 7a3c997 + a965d44 commit aa0599f

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

src/wallet/rpcwallet.cpp

+17-11
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ static UniValue getreceivedbyaddress(const JSONRPCRequest& request)
609609
return NullUniValue;
610610
}
611611

612-
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
612+
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
613613
throw std::runtime_error(
614614
"getreceivedbyaddress \"address\" ( minconf )\n"
615615
"\nReturns the total amount received by the given address in transactions with at least minconf confirmations.\n"
@@ -692,7 +692,7 @@ static UniValue getreceivedbylabel(const JSONRPCRequest& request)
692692
return NullUniValue;
693693
}
694694

695-
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
695+
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
696696
throw std::runtime_error(
697697
"getreceivedbylabel \"label\" ( minconf )\n"
698698
"\nReturns the total amount received by addresses with <label> in transactions with at least [minconf] confirmations.\n"
@@ -1285,7 +1285,7 @@ static UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bo
12851285

12861286
bool has_filtered_address = false;
12871287
CTxDestination filtered_address = CNoDestination();
1288-
if (!by_label && params.size() > 3 && params[3].get_str() != "") {
1288+
if (!by_label && params[3].isStr() && params[3].get_str() != "") {
12891289
if (!IsValidDestinationString(params[3].get_str())) {
12901290
throw JSONRPCError(RPC_WALLET_ERROR, "address_filter parameter was invalid");
12911291
}
@@ -1395,7 +1395,7 @@ static UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bo
13951395
if(fIsWatchonly)
13961396
obj.pushKV("involvesWatchonly", true);
13971397
obj.pushKV("address", EncodeDestination(address));
1398-
obj.pushKV("amount", AmountMapToUniv(mapAmount, ""));
1398+
obj.pushKV("amount", AmountMapToUniv(mapAmount, strasset));
13991399
obj.pushKV("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf));
14001400
obj.pushKV("label", label);
14011401
UniValue transactions(UniValue::VARR);
@@ -1894,13 +1894,14 @@ static UniValue gettransaction(const JSONRPCRequest& request)
18941894
return NullUniValue;
18951895
}
18961896

1897-
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
1897+
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
18981898
throw std::runtime_error(
18991899
"gettransaction \"txid\" ( include_watchonly )\n"
19001900
"\nGet detailed information about in-wallet transaction <txid>\n"
19011901
"\nArguments:\n"
19021902
"1. \"txid\" (string, required) The transaction id\n"
19031903
"2. \"include_watchonly\" (bool, optional, default=false) Whether to include watch-only addresses in balance calculation and details[]\n"
1904+
"3. \"assetlabel\" (string, optional) Hex asset id or asset label for balance.\n"
19041905
"\nResult:\n"
19051906
"{\n"
19061907
" \"amount\" : x.xxx, (numeric) The transaction amount in " + CURRENCY_UNIT + "\n"
@@ -1952,6 +1953,11 @@ static UniValue gettransaction(const JSONRPCRequest& request)
19521953
if(request.params[1].get_bool())
19531954
filter = filter | ISMINE_WATCH_ONLY;
19541955

1956+
std::string asset = "";
1957+
if (request.params[2].isStr() && !request.params[2].get_str().empty()) {
1958+
asset = request.params[2].get_str();
1959+
}
1960+
19551961
UniValue entry(UniValue::VOBJ);
19561962
auto it = pwallet->mapWallet.find(hash);
19571963
if (it == pwallet->mapWallet.end()) {
@@ -1973,7 +1979,7 @@ static UniValue gettransaction(const JSONRPCRequest& request)
19731979
nFee[::policyAsset] = wtx.IsFromMe(filter) ? total_out - nDebit[::policyAsset] : 0;
19741980
}
19751981

1976-
entry.pushKV("amount", AmountMapToUniv(nNet - nFee, ""));
1982+
entry.pushKV("amount", AmountMapToUniv(nNet - nFee, asset));
19771983
if (wtx.IsFromMe(filter))
19781984
entry.pushKV("fee", AmountMapToUniv(nFee, ""));
19791985

@@ -6251,12 +6257,12 @@ static const CRPCCommand commands[] =
62516257
{ "wallet", "encryptwallet", &encryptwallet, {"passphrase"} },
62526258
{ "wallet", "getaddressesbylabel", &getaddressesbylabel, {"label"} },
62536259
{ "wallet", "getaddressinfo", &getaddressinfo, {"address"} },
6254-
{ "wallet", "getbalance", &getbalance, {"dummy","minconf","include_watchonly"} },
6260+
{ "wallet", "getbalance", &getbalance, {"dummy","minconf","include_watchonly","assetlabel"} },
62556261
{ "wallet", "getnewaddress", &getnewaddress, {"label","address_type"} },
62566262
{ "wallet", "getrawchangeaddress", &getrawchangeaddress, {"address_type"} },
6257-
{ "wallet", "getreceivedbyaddress", &getreceivedbyaddress, {"address","minconf"} },
6258-
{ "wallet", "getreceivedbylabel", &getreceivedbylabel, {"label","minconf"} },
6259-
{ "wallet", "gettransaction", &gettransaction, {"txid","include_watchonly"} },
6263+
{ "wallet", "getreceivedbyaddress", &getreceivedbyaddress, {"address","minconf","assetlabel"} },
6264+
{ "wallet", "getreceivedbylabel", &getreceivedbylabel, {"label","minconf","assetlabel"} },
6265+
{ "wallet", "gettransaction", &gettransaction, {"txid","include_watchonly","assetlabel"} },
62606266
{ "wallet", "getunconfirmedbalance", &getunconfirmedbalance, {} },
62616267
{ "wallet", "getwalletinfo", &getwalletinfo, {} },
62626268
{ "wallet", "importaddress", &importaddress, {"address","label","rescan","p2sh"} },
@@ -6269,7 +6275,7 @@ static const CRPCCommand commands[] =
62696275
{ "wallet", "listaddressgroupings", &listaddressgroupings, {} },
62706276
{ "wallet", "listlabels", &listlabels, {"purpose"} },
62716277
{ "wallet", "listlockunspent", &listlockunspent, {} },
6272-
{ "wallet", "listreceivedbyaddress", &listreceivedbyaddress, {"minconf","include_empty","include_watchonly","address_filter"} },
6278+
{ "wallet", "listreceivedbyaddress", &listreceivedbyaddress, {"minconf","include_empty","include_watchonly","address_filter","assetlabel"} },
62736279
{ "wallet", "listreceivedbylabel", &listreceivedbylabel, {"minconf","include_empty","include_watchonly"} },
62746280
{ "wallet", "listsinceblock", &listsinceblock, {"blockhash","target_confirmations","include_watchonly","include_removed"} },
62756281
{ "wallet", "listtransactions", &listtransactions, {"dummy","count","skip","include_watchonly"} },

test/functional/feature_confidential_transactions.py

+6
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ def run_test(self):
181181

182182
# Check 2's listreceivedbyaddress
183183
received_by_address = self.nodes[2].listreceivedbyaddress(0, False, False, "", "bitcoin")
184+
validate_by_address = [(address2, value1 + value3), (address, value0 + value2)]
185+
assert_equal(sorted([(ele['address'], ele['amount']) for ele in received_by_address], key=lambda t: t[0]),
186+
sorted(validate_by_address, key = lambda t: t[0]))
187+
received_by_address = self.nodes[2].listreceivedbyaddress(0, False, False, "")
184188
validate_by_address = [(address2, {"bitcoin": value1 + value3}), (address, {"bitcoin": value0 + value2})]
185189
assert_equal(sorted([(ele['address'], ele['amount']) for ele in received_by_address], key=lambda t: t[0]),
186190
sorted(validate_by_address, key = lambda t: t[0]))
@@ -210,6 +214,7 @@ def run_test(self):
210214
assert(found_unblinded)
211215

212216
assert_equal(self.nodes[1].gettransaction(raw_tx_id, True)['amount']["bitcoin"], value3)
217+
assert_equal(self.nodes[1].gettransaction(raw_tx_id, True, "bitcoin")['amount'], value3)
213218
list_unspent = self.nodes[1].listunspent(1, 9999999, [], True, {"asset": "bitcoin"})
214219
assert_equal(list_unspent[0]['amount']+list_unspent[1]['amount'], value1+value3)
215220
received_by_address = self.nodes[1].listreceivedbyaddress(1, False, True)
@@ -352,6 +357,7 @@ def run_test(self):
352357
# Assets balance checking, note that accounts are completely ignored because
353358
# balance queries with accounts are horrifically broken upstream
354359
assert_equal(self.nodes[0].getbalance("*", 0, False, "bitcoin"), self.nodes[0].getbalance("*", 0, False, "bitcoin"))
360+
assert_equal(self.nodes[0].getbalance("*", 0, False)['bitcoin'], self.nodes[0].getbalance("*", 0, False, "bitcoin"))
355361
assert_equal(self.nodes[0].getwalletinfo()['balance']['bitcoin'], self.nodes[0].getbalance("*", 0, False, "bitcoin"))
356362

357363
# Send some bitcoin and other assets over as well to fund wallet

test/functional/wallet_labels.py

+3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ def run_test(self):
8989
for label in labels:
9090
assert_equal(
9191
node.getreceivedbyaddress(label.addresses[0])['bitcoin'], amount_to_send)
92+
assert_equal(
93+
node.getreceivedbyaddress(label.addresses[0], 1, "bitcoin"), amount_to_send)
9294
assert_equal(node.getreceivedbylabel(label.name)['bitcoin'], amount_to_send)
95+
assert_equal(node.getreceivedbylabel(label.name, 1, "bitcoin"), amount_to_send)
9396

9497
for i, label in enumerate(labels):
9598
to_label = labels[(i + 1) % len(labels)]

0 commit comments

Comments
 (0)