Skip to content

Commit

Permalink
Use block for getting transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
tvorogme committed Feb 24, 2024
1 parent 83fadef commit a4a2f9e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def finalize_options(self):

setup(
name="tonpy" if not IS_DEV else "tonpy-dev",
version="0.0.0.1.2b0" if not IS_DEV else "0.0.0.3.1b1",
version="0.0.0.1.2b0" if not IS_DEV else "0.0.0.3.1c1",
author="Disintar LLP",
author_email="andrey@head-labs.com",
description="Types / API for TON blockchain",
Expand Down
39 changes: 24 additions & 15 deletions src/tonpy/blockscanner/blockscanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import requests

from tonpy import LiteClient, Cell, get_block_info, BlockId, BlockIdExt, \
Address, Emulator, begin_cell, StackEntry, VmDict, CellSlice
Address, Emulator, begin_cell, StackEntry, VmDict, CellSlice, SkipCryptoCurrency
from tonpy.tvm.not_native.emulator_extern import EmulatorExtern

from tonpy.utils.shard_account import shard_is_ancestor, shard_child, shard_parent
Expand Down Expand Up @@ -42,22 +42,31 @@ def get_mega_libs():
def process_block(block, lc):
block_txs = {}

ready = False
account_blocks = VmDict(256, False, cell_root=block['account_blocks'].begin_parse().load_ref(),
aug=SkipCryptoCurrency())

account_address = None
lt = None
for i in account_blocks:
account, data = i
data = data.data
# acc_trans#5
assert data.load_uint(4) == 5
me = data.load_uint(256)

while not ready:
answer = lc.list_block_transactions_ext(block['block_id'], 256,
account_address=account_address,
lt=lt)
ready = not answer.incomplete
# account_addr:bits256
assert me == account

for tx in answer.transactions:
# state_update:^(HASH_UPDATE Account)
data.skip_refs(1, True)

transactions = VmDict(64, False, cell_root=data, aug=SkipCryptoCurrency())
for t in transactions:
lt, txdata = t
tx = txdata.data.load_ref()
tx_tlb = Transaction()
tx_tlb = tx_tlb.cell_unpack(tx, True)

account_address = int(tx_tlb.account_addr, 2)
assert account_address == me

if account_address not in block_txs:
block_txs[account_address] = []
Expand All @@ -69,8 +78,6 @@ def process_block(block, lc):
'is_tock': tx_tlb.description.is_tock if hasattr(tx_tlb.description, 'is_tock') else False
})

lt = tx_tlb.lt

total_block_txs = []

for account in block_txs:
Expand Down Expand Up @@ -147,7 +154,7 @@ def process_shard(x, prev_data=None, lc=None):
block = Block().cell_unpack(current_full_block)
block_info = BlockInfo().cell_unpack(block.info, True)
block_extra = BlockExtra().cell_unpack(block.extra, False)
block_info.prev_ref

rand_seed = int(block_extra.rand_seed, 2)
prev_key_block_seqno = block_info.prev_key_block_seqno
right_shard = None
Expand Down Expand Up @@ -190,7 +197,8 @@ def process_shard(x, prev_data=None, lc=None):
'prev_key_block_seqno': prev_key_block_seqno,
'prev_block_left': left_shard,
'prev_block_right': right_shard,
'master': block_info.master_ref.master.seq_no
'master': block_info.master_ref.master.seq_no,
'account_blocks': block_extra.account_blocks
}, *prev_data]

if loglevel > 1:
Expand Down Expand Up @@ -233,7 +241,8 @@ def process_mc_blocks(seqnos, lcparams, loglevel):
'shards': lc.get_all_shards_info(block_id),
'rand_seed': rand_seed,
'prev_key_block_seqno': prev_key_block_seqno,
'gen_utime': block_info.gen_utime
'gen_utime': block_info.gen_utime,
'account_blocks': block_extra.account_blocks
})

break
Expand Down
1 change: 1 addition & 0 deletions src/tonpy/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from tonpy.types.lite_utils import *
from tonpy.types.liteclient import *
from tonpy.types.address import *
from tonpy.types.vmdict_extra import *


def begin_cell():
Expand Down
16 changes: 16 additions & 0 deletions src/tonpy/types/vmdict_extra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from tonpy.types.vmdict import AugmentedData
from tonpy.types.cellslice import CellSlice
from typing import Optional


class SkipCryptoCurrency(AugmentedData):
def skip_extra(self, cs: CellSlice) -> (bool, Optional[CellSlice]):
cs.load_var_uint(16)

has_ref = cs.preload_bool()
if has_ref:
cs.advance(0x10001)
else:
cs.advance(1)

return True, cs

0 comments on commit a4a2f9e

Please sign in to comment.