changeset 29657:190090231c39

rpc: query txids for addresses within block height range
author Braydon Fuller <courier@braydon.com>
date Tue, 12 Apr 2016 16:04:10 -0400
parents 604556232498
children 0757de524b85
files qa/rpc-tests/addressindex.py src/rpcmisc.cpp
diffstat 2 files changed, 29 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/qa/rpc-tests/addressindex.py	Tue Apr 12 15:31:19 2016 -0400
+++ b/qa/rpc-tests/addressindex.py	Tue Apr 12 16:04:10 2016 -0400
@@ -84,6 +84,16 @@
         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)
--- a/src/rpcmisc.cpp	Tue Apr 12 15:31:19 2016 -0400
+++ b/src/rpcmisc.cpp	Tue Apr 12 16:04:10 2016 -0400
@@ -668,11 +668,28 @@
         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");
+            }
         }
     }