From 62c9b1155f966cfb91d01d5598f974610962fa82 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 13 Dec 2012 18:59:10 +0400 Subject: [PATCH 1/2] listreceivedbyaddress now provides tx ids (issue #1149) --- src/rpcwallet.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 90a68f56..e17be780 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -813,6 +813,7 @@ struct tallyitem { int64 nAmount; int nConf; + vector txids; tallyitem() { nAmount = 0; @@ -854,6 +855,7 @@ Value ListReceived(const Array& params, bool fByAccounts) tallyitem& item = mapTally[address]; item.nAmount += txout.nValue; item.nConf = min(item.nConf, nDepth); + item.txids.push_back(wtx.GetHash()); } } @@ -889,6 +891,12 @@ Value ListReceived(const Array& params, bool fByAccounts) obj.push_back(Pair("account", strAccount)); obj.push_back(Pair("amount", ValueFromAmount(nAmount))); obj.push_back(Pair("confirmations", (nConf == std::numeric_limits::max() ? 0 : nConf))); + Array transactions; + BOOST_FOREACH(const uint256& item, (*it).second.txids) + { + transactions.push_back(item.GetHex()); + } + obj.push_back(Pair("txids", transactions)); ret.push_back(obj); } } From 1a20469428ef623f4edc2cdac72aef001836536c Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 16 Dec 2012 23:10:32 +0400 Subject: [PATCH 2/2] Updated help and tests for getreceivedby(account|address) --- src/rpcwallet.cpp | 10 +++++++--- src/test/rpc_tests.cpp | 35 ++++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index e17be780..d9d364c8 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -892,9 +892,12 @@ Value ListReceived(const Array& params, bool fByAccounts) obj.push_back(Pair("amount", ValueFromAmount(nAmount))); obj.push_back(Pair("confirmations", (nConf == std::numeric_limits::max() ? 0 : nConf))); Array transactions; - BOOST_FOREACH(const uint256& item, (*it).second.txids) + if (it != mapTally.end()) { - transactions.push_back(item.GetHex()); + BOOST_FOREACH(const uint256& item, (*it).second.txids) + { + transactions.push_back(item.GetHex()); + } } obj.push_back(Pair("txids", transactions)); ret.push_back(obj); @@ -929,7 +932,8 @@ Value listreceivedbyaddress(const Array& params, bool fHelp) " \"address\" : receiving address\n" " \"account\" : the account of the receiving address\n" " \"amount\" : total amount received by the address\n" - " \"confirmations\" : number of confirmations of the most recent transaction included"); + " \"confirmations\" : number of confirmations of the most recent transaction included\n" + " \"txids\" : list of transactions with outputs to the address\n"); return ListReceived(params, false); } diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp index f8fe443b..35eabed0 100644 --- a/src/test/rpc_tests.cpp +++ b/src/test/rpc_tests.cpp @@ -79,23 +79,44 @@ static Value CallRPC(string args) } } -BOOST_AUTO_TEST_CASE(rpc_rawparams) +BOOST_AUTO_TEST_CASE(rpc_wallet) { - // Test raw transaction API argument handling + // Test RPC calls for various wallet statistics Value r; - BOOST_CHECK_THROW(CallRPC("getrawtransaction"), runtime_error); - BOOST_CHECK_THROW(CallRPC("getrawtransaction not_hex"), runtime_error); - BOOST_CHECK_THROW(CallRPC("getrawtransaction a3b807410df0b60fcb9736768df5823938b2f838694939ba45f3c0a1bff150ed not_int"), runtime_error); - BOOST_CHECK_NO_THROW(CallRPC("listunspent")); BOOST_CHECK_THROW(CallRPC("listunspent string"), runtime_error); BOOST_CHECK_THROW(CallRPC("listunspent 0 string"), runtime_error); BOOST_CHECK_THROW(CallRPC("listunspent 0 1 not_array"), runtime_error); + BOOST_CHECK_THROW(CallRPC("listunspent 0 1 [] extra"), runtime_error); BOOST_CHECK_NO_THROW(r=CallRPC("listunspent 0 1 []")); - BOOST_CHECK_THROW(r=CallRPC("listunspent 0 1 [] extra"), runtime_error); BOOST_CHECK(r.get_array().empty()); + BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaddress")); + BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaddress 0")); + BOOST_CHECK_THROW(CallRPC("listreceivedbyaddress not_int"), runtime_error); + BOOST_CHECK_THROW(CallRPC("listreceivedbyaddress 0 not_bool"), runtime_error); + BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaddress 0 true")); + BOOST_CHECK_THROW(CallRPC("listreceivedbyaddress 0 true extra"), runtime_error); + + BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount")); + BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount 0")); + BOOST_CHECK_THROW(CallRPC("listreceivedbyaccount not_int"), runtime_error); + BOOST_CHECK_THROW(CallRPC("listreceivedbyaccount 0 not_bool"), runtime_error); + BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount 0 true")); + BOOST_CHECK_THROW(CallRPC("listreceivedbyaccount 0 true extra"), runtime_error); +} + + +BOOST_AUTO_TEST_CASE(rpc_rawparams) +{ + // Test raw transaction API argument handling + Value r; + + BOOST_CHECK_THROW(CallRPC("getrawtransaction"), runtime_error); + BOOST_CHECK_THROW(CallRPC("getrawtransaction not_hex"), runtime_error); + BOOST_CHECK_THROW(CallRPC("getrawtransaction a3b807410df0b60fcb9736768df5823938b2f838694939ba45f3c0a1bff150ed not_int"), runtime_error); + BOOST_CHECK_THROW(CallRPC("createrawtransaction"), runtime_error); BOOST_CHECK_THROW(CallRPC("createrawtransaction null null"), runtime_error); BOOST_CHECK_THROW(CallRPC("createrawtransaction not_array"), runtime_error);