diff --git a/qa/rpc-tests/addressindex.py b/qa/rpc-tests/addressindex.py index d28cd393f..3ef5bcf67 100755 --- a/qa/rpc-tests/addressindex.py +++ b/qa/rpc-tests/addressindex.py @@ -84,6 +84,16 @@ class AddressIndexTest(BitcoinTestFramework): assert_equal(txidsb[1], txidb1) assert_equal(txidsb[2], txidb2) + # Check that limiting by height works + chain_height = self.nodes[1].getblockcount() + height_txids = self.nodes[1].getaddresstxids({ + "addresses": ["2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br"], + "start": 111, + "end": 111 + }) + assert_equal(len(height_txids), 1) + assert_equal(height_txids[0], txidb2) + # Check that multiple addresses works multitxids = self.nodes[1].getaddresstxids({"addresses": ["2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br", "mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs"]}) assert_equal(len(multitxids), 6) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index b50bec52b..b76adb26f 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -782,11 +782,28 @@ UniValue getaddresstxids(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); } + int start = 0; + int end = 0; + if (params[0].isObject()) { + UniValue startValue = find_value(params[0].get_obj(), "start"); + UniValue endValue = find_value(params[0].get_obj(), "end"); + if (startValue.isNum() && endValue.isNum()) { + start = startValue.get_int(); + end = startValue.get_int(); + } + } + std::vector > addressIndex; for (std::vector >::iterator it = addresses.begin(); it != addresses.end(); it++) { - if (!GetAddressIndex((*it).first, (*it).second, addressIndex)) { - 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"); + } } }