diff --git a/qa/rpc-tests/addressindex.py b/qa/rpc-tests/addressindex.py index 7ec00cc4f..a07d4de1e 100755 --- a/qa/rpc-tests/addressindex.py +++ b/qa/rpc-tests/addressindex.py @@ -178,6 +178,10 @@ class AddressIndexTest(BitcoinTestFramework): assert_equal(balance3, change_amount) assert_equal(deltas[0]["address"], address2) + # Check that entire range will be queried + deltasAll = self.nodes[1].getaddressdeltas({"addresses": [address2]}) + assert_equal(len(deltasAll), len(deltas)) + # Check that deltas can be returned from range of block heights deltas = self.nodes[1].getaddressdeltas({"addresses": [address2], "start": 113, "end": 113}) assert_equal(len(deltas), 1) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 067dfd727..1a2329cae 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -696,12 +696,16 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp) UniValue startValue = find_value(params[0].get_obj(), "start"); UniValue endValue = find_value(params[0].get_obj(), "end"); - if (!startValue.isNum() || !endValue.isNum()) { - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Start and end values are expected to be block heights"); - } + int start = 0; + int end = 0; - int start = startValue.get_int(); - int end = startValue.get_int(); + if (startValue.isNum() && endValue.isNum()) { + start = startValue.get_int(); + end = endValue.get_int(); + if (end < start) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "End value is expected to be greater than start"); + } + } std::vector > addresses; @@ -712,8 +716,14 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp) std::vector > addressIndex; for (std::vector >::iterator it = addresses.begin(); it != addresses.end(); it++) { - if (!GetAddressIndex((*it).first, (*it).second, addressIndex, start, end)) { - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address"); + if (start > 0 && end > 0) { + if (!GetAddressIndex((*it).first, (*it).second, addressIndex, start, end)) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address"); + } + } else { + if (!GetAddressIndex((*it).first, (*it).second, addressIndex)) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address"); + } } }