Skip to content

Commit

Permalink
Add to lt param to get_transactions (#15)
Browse files Browse the repository at this point in the history
* Add to_lt param to get_transactions

* Add to_lt param to balancer

* Fix array concatenate boundary

* update version

---------

Co-authored-by: Maksim Kurbatov <[email protected]>
  • Loading branch information
XaBbl4 and yungwine authored Jan 12, 2024
1 parent 3951dcc commit ba773c0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pytoniq/liteclient/balancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))

Expand Down
15 changes: 13 additions & 2 deletions pytoniq/liteclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,21 +646,32 @@ 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
:param address:
: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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pytoniq",
version="0.1.27",
version="0.1.28",
author="Maksim Kurbatov",
author_email="[email protected]",
description="TON Blockchain SDK",
Expand Down

0 comments on commit ba773c0

Please sign in to comment.