Skip to content

Commit

Permalink
Support Int address
Browse files Browse the repository at this point in the history
  • Loading branch information
tvorogme committed Oct 24, 2024
1 parent b847f9c commit f1ae3cb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 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.2c0" if not IS_DEV else "0.0.0.5.2c1",
version="0.0.0.1.2c0" if not IS_DEV else "0.0.0.5.3a1",
author="Disintar LLP",
author_email="andrey@head-labs.com",
description="Types / API for TON blockchain",
Expand Down
22 changes: 19 additions & 3 deletions src/tonpy/abi/getter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from traceback import format_exc

from tonpy import StackEntry, add_tlb, Address
from tonpy import StackEntry, add_tlb, Address, CellSlice
from tonpy.tvm import TVM
from loguru import logger

Expand Down Expand Up @@ -76,6 +76,11 @@ def get_columns(self):
f'{self.dton_parse_prefix}{self.name}_address': 'FixedString(64)',
f'{self.dton_parse_prefix}{self.name}_type': 'String',
}
elif self.type == 'Int' and self.labels.get('address', False):
return {
f'{self.dton_parse_prefix}{self.name}_workchain': 'Int16',
f'{self.dton_parse_prefix}{self.name}_address': 'FixedString(64)'
}
elif self.type in ['Slice', 'Cell', 'Continuation', 'Builder'] and self.instance.get('tlb', None):
tlb = self.instance.get('tlb')

Expand Down Expand Up @@ -106,7 +111,7 @@ def get_columns(self):

return {f'{self.dton_parse_prefix}{self.name}': self.dton_type}

def parse_stack_item(self, stack_entry: StackEntry, tlb_sources, force_all: bool = False) -> dict:
def parse_stack_item(self, stack_entry: StackEntry, tlb_sources, force_all: bool = False, tvm: TVM = None) -> dict:
if self.skip_parse and not force_all:
return {}

Expand All @@ -125,6 +130,17 @@ def parse_stack_item(self, stack_entry: StackEntry, tlb_sources, force_all: bool
f'{self.dton_parse_prefix}{self.name}_address': address.address,
f'{self.dton_parse_prefix}{self.name}_type': address.type,
}
elif self.type == 'Int' and self.labels.get('address', False):
wc = None
if tvm is not None and tvm.c7 is not None:
cs: CellSlice = tvm.c7.address.copy()
address = cs.load_address()
wc = address.wc

return {
f'{self.dton_parse_prefix}{self.name}_workchain': wc,
f'{self.dton_parse_prefix}{self.name}_address': hex(stack_entry.get()).upper()[2:].zfill(64),
}
elif self.parse_special == 'String':
if stack_entry.get_type() is StackEntry.Type.t_cell:
tmp = stack_entry.as_cell().begin_parse().load_string()
Expand Down Expand Up @@ -269,7 +285,7 @@ def parse_getters(self, tvm: TVM, tlb_sources, force_all: bool = False) -> dict:
continue

try:
tmp.update(getter.parse_stack_item(stack_entry, tlb_sources, force_all))
tmp.update(getter.parse_stack_item(stack_entry, tlb_sources, force_all, tvm=tvm))
except Exception as e:
logger.error(f"Can't parse {getter}: {e}, {format_exc()}")

Expand Down
2 changes: 2 additions & 0 deletions src/tonpy/tvm/tvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, log_level: int = 0,
self.code_hash = code.get_hash()
self.vm_steps_detailed: Optional[List[StepInfo]] = None
self.enable_stack_dump = enable_stack_dump
self.c7 = None

def set_stack(self, value: Union[Stack, List]) -> None:
if isinstance(value, list):
Expand All @@ -48,6 +49,7 @@ def set_c7(self, value: Union[Union[StackEntry, List], C7]) -> None:
if isinstance(value, list):
self.tvm.set_c7(StackEntry(value=value).entry)
elif isinstance(value, C7):
self.c7 = value
self.tvm.set_c7(StackEntry(value=value.to_data()).entry)
else:
assert value.get_type() is StackEntry.Type.t_tuple, "C7 must be tuple"
Expand Down

0 comments on commit f1ae3cb

Please sign in to comment.