From 891744e805d5794bcbd3b039d980c95a9838a914 Mon Sep 17 00:00:00 2001
From: Caner Candan <candan@info.univ-angers.fr>
Date: Sat, 1 Feb 2014 04:45:21 +0100
Subject: [PATCH] * merke_easy_parser get optional begin and end argument in to
 slice requests * used in tx.Sender and tx.Recipient request

---
 __init__.py                  |  4 ++--
 hdc/transactions/__init__.py | 16 ++++++++++++----
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/__init__.py b/__init__.py
index 62ea64ab..38a92099 100644
--- a/__init__.py
+++ b/__init__.py
@@ -177,9 +177,9 @@ class API:
 
         return response
 
-    def merkle_easy_parser(self, path):
+    def merkle_easy_parser(self, path, begin=None, end=None):
         root = self.requests_get(path, leaves='true').json()
-        for leaf in root['leaves']:
+        for leaf in root['leaves'][begin:end]:
             yield self.requests_get(path, leaf=leaf).json()['leaf']
 
 from . import pks, ucg, hdc, wrappers
diff --git a/hdc/transactions/__init__.py b/hdc/transactions/__init__.py
index cc230c0a..61b6bb61 100644
--- a/hdc/transactions/__init__.py
+++ b/hdc/transactions/__init__.py
@@ -71,34 +71,42 @@ class Last(Base):
 class Sender(Base):
     """GET all the transactions sent by this sender and stored by this node (should contain all transactions of the sender)."""
 
-    def __init__(self, pgp_fingerprint):
+    def __init__(self, pgp_fingerprint, begin=None, end=None):
         """
         Arguments:
         - `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions.
+        - `begin`: integer value used by the merkle parser to know when to begin requesting.
+        - `end`: integer value used by the merkle parser to know when to end requesting.
         """
 
         super().__init__()
 
         self.pgp_fingerprint = pgp_fingerprint
+        self.begin = begin
+        self.end = end
 
     def __get__(self, **kwargs):
-        return self.merkle_easy_parser('/sender/%s' % self.pgp_fingerprint)
+        return self.merkle_easy_parser('/sender/%s' % self.pgp_fingerprint, begin=self.begin, end=self.end)
 
 class Recipient(Base):
     """GET all the transactions received for this recipient stored by this node."""
 
-    def __init__(self, pgp_fingerprint):
+    def __init__(self, pgp_fingerprint, begin=None, end=None):
         """
         Arguments:
         - `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions.
+        - `begin`: integer value used by the merkle parser to know when to begin requesting.
+        - `end`: integer value used by the merkle parser to know when to end requesting.
         """
 
         super().__init__()
 
         self.pgp_fingerprint = pgp_fingerprint
+        self.begin = begin
+        self.end = end
 
     def __get__(self, **kwargs):
-        return self.merkle_easy_parser('/recipient/%s' % self.pgp_fingerprint)
+        return self.merkle_easy_parser('/recipient/%s' % self.pgp_fingerprint, begin=self.begin, end=self.end)
 
 class View(Base):
     """GET the transaction of given TRANSACTION_ID."""
-- 
GitLab