Skip to content

Commit

Permalink
Tuple in ABI support
Browse files Browse the repository at this point in the history
  • Loading branch information
tvorogme committed Oct 26, 2024
1 parent d9a8cbc commit 0fa7039
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 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.3c1",
version="0.0.0.1.2c0" if not IS_DEV else "0.0.0.5.4a1",
author="Disintar LLP",
author_email="andrey@head-labs.com",
description="Types / API for TON blockchain",
Expand Down
22 changes: 20 additions & 2 deletions src/tonpy/abi/getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'String',
'FixedString(64)',
'Address',
'Boolean',
'Datetime'
]

Expand Down Expand Up @@ -51,13 +52,13 @@ def __init__(self, instance):
elif self.dton_type == 'Null':
self.dton_type = 'UInt8'
elif self.type == 'Bool':
self.dton_type = 'UInt8'
self.dton_type = 'Boolean'

if self.dton_type != 'Tuple':
assert self.dton_type in supported_types, f'Unsupported ABI type {self.dton_type}'
else:
self.dton_type = None
self.items = self.instance['items']
self.items = [ABIGetterResultInstance(i) for i in self.instance['items']]

if 'dton_parse_prefix' not in self.labels:
self.dton_parse_prefix = f''
Expand Down Expand Up @@ -108,6 +109,16 @@ def get_columns(self):
tmp[f'{self.dton_parse_prefix}{self.name}_{name}'] = dtype

return tmp
elif self.type == 'Tuple':
if not self.items or not len(self.items):
return {}

data = {}

for tmp in self.items:
data.update(tmp.get_columns())

return data

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

Expand Down Expand Up @@ -220,6 +231,13 @@ def parse_stack_item(self, stack_entry: StackEntry, tlb_sources, force_all: bool
return {
f"{self.dton_parse_prefix}{self.name}": stack_entry.as_uint(64)
}
elif self.type == 'Tuple' and stack_entry.get_type() is StackEntry.Type.t_tuple:
data = {}

for tmp, result_item in zip(self.items, stack_entry.get()):
data.update(tmp.parse_stack_item(result_item, tlb_sources, force_all, tvm))

return data
else:
raise ValueError(f'Unsupported ABI type {self.dton_type}')

Expand Down

0 comments on commit 0fa7039

Please sign in to comment.