rpc: query txids for addresses within block height range
This commit is contained in:
parent
abe40712ce
commit
96d8307b55
@ -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)
|
||||
|
@ -668,11 +668,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<std::pair<CAddressIndexKey, CAmount> > addressIndex;
|
||||
|
||||
for (std::vector<std::pair<uint160, int> >::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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user