rpc: optional "start" and "end" params for getaddressdeltas

This commit is contained in:
Braydon Fuller 2016-04-21 16:07:42 -04:00 committed by Simon
parent bc628e6e56
commit 29495b5e25
2 changed files with 21 additions and 7 deletions

View File

@ -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)

View File

@ -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<std::pair<uint160, int> > addresses;
@ -712,8 +716,14 @@ 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 (!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");
}
}
}