From ba773c09aa10324d85e1af86d019a90f2a6a988f Mon Sep 17 00:00:00 2001 From: Andrey Kravchenko Date: Fri, 12 Jan 2024 11:35:46 +0300 Subject: [PATCH] Add to lt param to get_transactions (#15) * Add to_lt param to get_transactions * Add to_lt param to balancer * Fix array concatenate boundary * update version --------- Co-authored-by: Maksim Kurbatov <94808996+yungwine@users.noreply.github.com> --- pytoniq/liteclient/balancer.py | 3 ++- pytoniq/liteclient/client.py | 15 +++++++++++++-- setup.py | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pytoniq/liteclient/balancer.py b/pytoniq/liteclient/balancer.py index ce3a383..3a99224 100644 --- a/pytoniq/liteclient/balancer.py +++ b/pytoniq/liteclient/balancer.py @@ -349,7 +349,8 @@ async def raw_get_transactions(self, address: typing.Union[Address, str], count: return await self.execute_method('raw_get_transactions', **self._get_args(locals())) async def get_transactions(self, address: typing.Union[Address, str], count: int, - from_lt: int = None, from_hash: typing.Optional[bytes] = None + from_lt: int = None, from_hash: typing.Optional[bytes] = None, + to_lt: int = 0 , **kwargs) -> typing.List[Transaction]: return await self.execute_method('get_transactions', **self._get_args(locals())) diff --git a/pytoniq/liteclient/client.py b/pytoniq/liteclient/client.py index 00867b9..0c2a7a8 100644 --- a/pytoniq/liteclient/client.py +++ b/pytoniq/liteclient/client.py @@ -646,7 +646,8 @@ async def raw_get_transactions(self, address: typing.Union[Address, str], count: return tr_result, block_ids async def get_transactions(self, address: typing.Union[Address, str], count: int, - from_lt: int = None, from_hash: typing.Optional[bytes] = None + from_lt: int = None, from_hash: typing.Optional[bytes] = None, + to_lt: int = 0 ) -> typing.List[Transaction]: """ Returns account transactions @@ -654,13 +655,23 @@ async def get_transactions(self, address: typing.Union[Address, str], count: int :param count: :param from_lt: :param from_hash: + :param to_lt: :return: """ result: typing.List[Transaction] = [] + reach_lt = False for i in range(0, count, 16): amount = min(16, count - i) - tr_result, block_ids = await self.raw_get_transactions(address, amount, from_lt, from_hash) + tr_result, _ = await self.raw_get_transactions(address, amount, from_lt, from_hash) + if to_lt > 0 and tr_result[-1].lt <= to_lt: + for j, t in enumerate(tr_result): + if t.lt <= to_lt: + result += tr_result[:j] + reach_lt = True + break + if reach_lt: + break result += tr_result from_lt, from_hash = result[-1].prev_trans_lt, result[-1].prev_trans_hash if from_lt == 0: diff --git a/setup.py b/setup.py index 3290da4..167314f 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pytoniq", - version="0.1.27", + version="0.1.28", author="Maksim Kurbatov", author_email="cyrbatoff@gmail.com", description="TON Blockchain SDK",