Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase/versionbump #1

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 107 additions & 14 deletions pytonlib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async def raw_get_transactions(self, account_address: str, from_transaction_lt:
}
return await self.tonlib_wrapper.execute(request, timeout=self.tonlib_timeout)

async def raw_get_account_state(self, address: str, *args, **kwargs):
async def raw_get_account_state(self, address: str, seqno = None, *args, **kwargs):
"""
TL Spec:
raw.getAccountState account_address:accountAddress = raw.AccountState;
Expand All @@ -186,10 +186,36 @@ async def raw_get_account_state(self, address: str, *args, **kwargs):
'account_address': address
}
}
if seqno is not None:
wc, shard = -1, -9223372036854775808
block_id = await self.lookup_block(wc, shard, seqno)
request = {
'@type': 'withBlock',
'id': block_id,
'function' : request
}

return await self.tonlib_wrapper.execute(request, timeout=self.tonlib_timeout)

async def get_shard_account_cell(self, address: str, seqno = None, *args, **kwargs):
request = {
'@type': 'getShardAccountCell',
'account_address': {
'account_address': address
}
}
if seqno is not None:
wc, shard = -1, -9223372036854775808
block_id = await self.lookup_block(wc, shard, seqno)
request = {
'@type': 'withBlock',
'id': block_id,
'function' : request
}

return await self.tonlib_wrapper.execute(request, timeout=self.tonlib_timeout)

async def generic_get_account_state(self, address: str, *args, **kwargs):
async def generic_get_account_state(self, address: str, seqno = None, *args, **kwargs):
# TODO: understand why this is not used
account_address = prepare_address(address)
request = {
Expand All @@ -198,21 +224,38 @@ async def generic_get_account_state(self, address: str, *args, **kwargs):
'account_address': address
}
}
if seqno is not None:
wc, shard = -1, -9223372036854775808
block_id = await self.lookup_block(wc, shard, seqno)
request = {
'@type': 'withBlock',
'id': block_id,
'function' : request
}

return await self.tonlib_wrapper.execute(request, timeout=self.tonlib_timeout)

async def _load_contract(self, address, *args, **kwargs):
async def _load_contract(self, address, seqno = None, *args, **kwargs):
# TODO: understand why this is not used
account_address = prepare_address(address)
# account_address = prepare_address(address)
request = {
'@type': 'smc.load',
'account_address': {
'account_address': address
}
}
if seqno is not None:
wc, shard = -1, -9223372036854775808
block_id = await self.lookup_block(wc, shard, seqno)
request = {
'@type': 'withBlock',
'id': block_id,
'function' : request
}
result = await self.tonlib_wrapper.execute(request, timeout=self.tonlib_timeout)
return result["id"]

async def raw_run_method(self, address, method, stack_data, output_layout=None, *args, **kwargs):
async def raw_run_method(self, address, method, stack_data, seqno = None, *args, **kwargs):
"""
For numeric data only
TL Spec:
Expand Down Expand Up @@ -241,7 +284,7 @@ async def raw_run_method(self, address, method, stack_data, output_layout=None,
method = {'@type': 'smc.methodIdNumber', 'number': method}
else:
method = {'@type': 'smc.methodIdName', 'name': str(method)}
contract_id = await self._load_contract(address)
contract_id = await self._load_contract(address, seqno)
request = {
'@type': 'smc.runGetMethod',
'id': contract_id,
Expand All @@ -251,6 +294,13 @@ async def raw_run_method(self, address, method, stack_data, output_layout=None,
r = await self.tonlib_wrapper.execute(request, timeout=self.tonlib_timeout)
if 'stack' in r:
r['stack'] = serialize_tvm_stack(r['stack'])
request = {
'@type': 'smc.getRawFullAccountState',
'id': contract_id
}
raw_full_account_state = await self.tonlib_wrapper.execute(request, timeout=self.tonlib_timeout)
r['block_id'] = raw_full_account_state['block_id']
r['last_transaction_id'] = raw_full_account_state['last_transaction_id']
return r

async def raw_send_message(self, serialized_boc, *args, **kwargs):
Expand Down Expand Up @@ -311,7 +361,7 @@ async def _raw_send_query(self, query_info, *args, **kwargs):

async def raw_create_and_send_query(self, destination, body, init_code=b'', init_data=b'', *args, **kwargs):
query_info = await self._raw_create_query(destination, body, init_code, init_data)
return self._raw_send_query(query_info)
return await self._raw_send_query(query_info)

async def raw_create_and_send_message(self, destination, body, initial_account_state=b'', *args, **kwargs):
# Very close to raw_create_and_send_query, but StateInit should be generated outside
Expand Down Expand Up @@ -474,7 +524,7 @@ async def get_masterchain_block_signatures(self, seqno: int, *args, **kwargs):
}
return await self.tonlib_wrapper.execute(request)

async def get_shard_block_proof(self, workchain: int, shard: int, seqno: int, from_seqno=None, *args, **kwargs):
async def get_shard_block_proof(self, workchain: int, shard: int, seqno: int, from_seqno = None, *args, **kwargs):
block_id = await self.lookup_block(workchain, shard, seqno)
mode = 0
if from_seqno is not None:
Expand All @@ -491,8 +541,16 @@ async def get_shard_block_proof(self, workchain: int, shard: int, seqno: int, fr
request['from'] = from_block_id

return await self.tonlib_wrapper.execute(request, timeout=self.tonlib_timeout)

async def get_out_msg_queue_sizes(self, *args, **kwargs):
request = {
'@type': 'blocks.getOutMsgQueueSizes',
'mode': 0
}

return await self.tonlib_wrapper.execute(request, timeout=self.tonlib_timeout)

async def lookup_block(self, workchain, shard, seqno=None, lt=None, unixtime=None, *args, **kwargs):
async def lookup_block(self, workchain, shard, seqno = None, lt=None, unixtime=None, *args, **kwargs):
assert (seqno is not None) or (lt is not None) or (unixtime is not None), "Seqno, LT or unixtime should be defined"
mode = 0
if seqno is not None:
Expand All @@ -515,7 +573,7 @@ async def lookup_block(self, workchain, shard, seqno=None, lt=None, unixtime=Non
}
return await self.tonlib_wrapper.execute(request, timeout=self.tonlib_timeout)

async def get_shards(self, master_seqno=None, lt=None, unixtime=None, *args, **kwargs):
async def get_shards(self, master_seqno = None, lt=None, unixtime=None, *args, **kwargs):
assert (master_seqno is not None) or (lt is not None) or (unixtime is not None), "Seqno, LT or unixtime should be defined"
wc, shard = -1, -9223372036854775808
fullblock = await self.lookup_block(wc, shard, master_seqno, lt, unixtime)
Expand Down Expand Up @@ -651,16 +709,39 @@ async def get_block_header(self, workchain, shard, seqno, root_hash=None, file_h
}
return await self.tonlib_wrapper.execute(request, timeout=self.tonlib_timeout)

async def get_config_param(self, config_id: int, seqno: int, *args, **kwargs):
wc, shard = -1, -9223372036854775808
fullblock = await self.lookup_block(wc, shard, seqno)
async def get_config_param(self, config_id: int, seqno = None, *args, **kwargs):
request = {
'@type': 'getConfigParam',
'id': fullblock,
'param': config_id,
'mode': 0
}

if seqno is not None:
wc, shard = -1, -9223372036854775808
block_id = await self.lookup_block(wc, shard, seqno)
request = {
'@type': 'withBlock',
'id': block_id,
'function' : request
}

return await self.tonlib_wrapper.execute(request, timeout=self.tonlib_timeout)

async def get_config_all(self, seqno = None, *args, **kwargs):
request = {
'@type': 'getConfigAll',
'mode': 0
}

if seqno is not None:
wc, shard = -1, -9223372036854775808
block_id = await self.lookup_block(wc, shard, seqno)
request = {
'@type': 'withBlock',
'id': block_id,
'function' : request
}

return await self.tonlib_wrapper.execute(request, timeout=self.tonlib_timeout)

async def try_locate_tx_by_incoming_message(self, source, destination, creation_lt, *args, **kwargs):
Expand Down Expand Up @@ -732,6 +813,7 @@ async def try_locate_tx_by_outcoming_message(self, source, destination, creation
for tx in txses:
try:
for msg in tx["out_msgs"]:
if not msg["destination"]: continue
if detect_address(msg["destination"])["raw_form"] == dest["raw_form"]:
if int(msg["created_lt"]) == int(creation_lt):
return tx
Expand Down Expand Up @@ -790,3 +872,14 @@ async def get_token_data(self, address: str):
result['content'] = content
result['contract_type'] = contract_type
return result

async def get_libraries(self, library_list: list):
"""
:param library_list: list of base64-encoded libraries hashes
"""

request = {
'@type': 'smc.getLibraries',
'library_list': library_list
}
return await self.tonlib_wrapper.execute(request, timeout=self.tonlib_timeout)
Binary file modified pytonlib/distlib/darwin/libtonlibjson.arm64.dylib
100644 → 100755
Binary file not shown.
Binary file modified pytonlib/distlib/darwin/libtonlibjson.x86_64.dylib
Binary file not shown.
Binary file modified pytonlib/distlib/linux/libtonlibjson.aarch64.so
100755 → 100644
Binary file not shown.
Binary file modified pytonlib/distlib/linux/libtonlibjson.x86_64.so
100644 → 100755
Binary file not shown.
Binary file modified pytonlib/distlib/windows/tonlibjson.amd64.dll
Binary file not shown.
2 changes: 2 additions & 0 deletions pytonlib/tonlibjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ async def read_results(self):
result = None
try:
result = await asyncio.wait_for(self.loop.run_in_executor(None, receive_func), timeout=timeout + delta)
except asyncio.CancelledError:
raise
except asyncio.TimeoutError:
logger.critical(f"Tonlib #{self.ls_index:03d} stuck (timeout error)")
self._state = "stuck"
Expand Down
6 changes: 3 additions & 3 deletions pytonlib/utils/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def account_forms(raw_form, test_only=False):
workchain_tag = b'\xff' if workchain == -1 else workchain.to_bytes(1, "big")
btag = bounceable_tag
nbtag = non_bounceable_tag
# if test_only:
# btag = (btag[0] | 0x80).to_bytes(1,'big')
# nbtag = (nbtag[0] | 0x80).to_bytes(1,'big')
if test_only:
btag = (btag[0] | 0x80).to_bytes(1,'big')
nbtag = (nbtag[0] | 0x80).to_bytes(1,'big')
preaddr_b = btag + workchain_tag + address
preaddr_u = nbtag + workchain_tag + address
b64_b = base64.b64encode(preaddr_b+calcCRC(preaddr_b)).decode('utf8')
Expand Down
7 changes: 4 additions & 3 deletions pytonlib/utils/tlb.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,16 @@ def __init__(self, cell_slice):
self.type = 'addr_none'
elif prefix == bitarray('01'):
self.type = 'addr_extern'
cell_slice.read_next(cell_slice.bits_left()) #TODO: parse len and external_address
self.len = cell_slice.read_uint(9)
self.external_address = cell_slice.read_next(self.len)

class MsgAddressInt:
"""
anycast_info$_ depth:(#<= 30) { depth >= 1 }
rewrite_pfx:(bits depth) = Anycast;
addr_std$10 anycast:(Maybe Anycast)
addr_std$10 anycast:(Maybe Anycast)
workchain_id:int8 address:bits256 = MsgAddressInt;
addr_var$11 anycast:(Maybe Anycast) addr_len:(## 9)
addr_var$11 anycast:(Maybe Anycast) addr_len:(## 9)
workchain_id:int32 address:(bits addr_len) = MsgAddressInt;
"""
def __init__(self, cell_slice):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
crc16>=0.1.1
tvm_valuetypes==0.0.10
tvm_valuetypes==0.0.12
requests>=2.27.1
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
long_description = f.read()


version = os.environ.get('PYTONLIB_VERSION', 'dev')
version = os.environ.get('PYTONLIB_VERSION', '0.52+gromgull')


setup(
Expand All @@ -18,7 +18,7 @@
packages=find_packages('.', exclude=['tests']),
install_requires=[
'crc16>=0.1.1',
'tvm_valuetypes==0.0.10',
'tvm_valuetypes==0.0.12',
'requests>=2.27.1'
],
package_data={
Expand Down