changeset 29663:689c04c73d0f

rpc: optional "start" and "end" params for getaddressdeltas
author Braydon Fuller <courier@braydon.com>
date Thu, 21 Apr 2016 16:07:42 -0400
parents e28c6eb681af
children 62be9d50f6fa
files qa/rpc-tests/addressindex.py src/rpcmisc.cpp
diffstat 2 files changed, 21 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/qa/rpc-tests/addressindex.py	Thu Apr 21 15:59:51 2016 -0400
+++ b/qa/rpc-tests/addressindex.py	Thu Apr 21 16:07:42 2016 -0400
@@ -178,6 +178,10 @@
         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)
--- a/src/rpcmisc.cpp	Thu Apr 21 15:59:51 2016 -0400
+++ b/src/rpcmisc.cpp	Thu Apr 21 16:07:42 2016 -0400
@@ -582,13 +582,17 @@
     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;
+
+    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");
+        }
     }
 
-    int start = startValue.get_int();
-    int end = startValue.get_int();
-
     std::vector<std::pair<uint160, int> > addresses;
 
     if (!getAddressesFromParams(params, addresses)) {
@@ -598,8 +602,14 @@
     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");
+            }
         }
     }