rpc: optional "start" and "end" params for getaddressdeltas
This commit is contained in:
parent
8391ff0b0a
commit
98f8fdddc8
@ -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)
|
||||
|
@ -582,12 +582,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<std::pair<uint160, int> > addresses;
|
||||
|
||||
@ -598,9 +602,15 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp)
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
|
||||
|
||||
for (std::vector<std::pair<uint160, int> >::iterator it = addresses.begin(); it != addresses.end(); it++) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UniValue result(UniValue::VARR);
|
||||
|
Loading…
Reference in New Issue
Block a user