Skip to content

Commit afc8937

Browse files
Added hash preparation
1 parent b30c7b0 commit afc8937

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

ton-http-api/pyTON/api/api_v2/endpoints/common.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ def prepare_address(address):
5151
raise HTTPException(status_code=416, detail="Incorrect address")
5252

5353

54+
def prepare_hash(value):
55+
if value is None:
56+
return None
57+
if len(value) == 44:
58+
value = value.replace('_', '/').replace('-', '+')
59+
data = codecs.decode(codecs.encode(value, 'utf-8'), 'base64')
60+
b64 = codecs.encode(data, 'base64').decode('utf-8')
61+
return b64.strip()
62+
if len(value) == 64:
63+
data = codecs.decode(codecs.encode(value, 'utf-8'), 'hex')
64+
b64 = codecs.encode(data, 'base64').decode('utf-8')
65+
return b64.strip()
66+
raise ValueError('Invalid hash')
67+
68+
5469
def address_state(account_info):
5570
if isinstance(account_info.get("code", ""), int) or len(account_info.get("code", "")) == 0:
5671
if len(account_info.get("frozen_hash", "")) == 0:
@@ -327,6 +342,9 @@ async def get_block_transactions(
327342
"""
328343
Get transactions of the given block.
329344
"""
345+
root_hash = prepare_hash(root_hash)
346+
file_hash = prepare_hash(file_hash)
347+
after_hash = prepare_hash(after_hash)
330348
return await tonlib.getBlockTransactions(workchain, shard, seqno, count, root_hash, file_hash, after_lt, after_hash)
331349

332350
@router.get('/getBlockTransactionsExt', response_model=TonResponse, response_model_exclude_none=True, tags=['blocks','transactions'])
@@ -346,6 +364,9 @@ async def get_block_transactions_ext(
346364
"""
347365
Get transactions of the given block.
348366
"""
367+
root_hash = prepare_hash(root_hash)
368+
file_hash = prepare_hash(file_hash)
369+
after_hash = prepare_hash(after_hash)
349370
return await tonlib.getBlockTransactionsExt(workchain, shard, seqno, count, root_hash, file_hash, after_lt, after_hash)
350371

351372
@router.get('/getBlockHeader', response_model=TonResponse, response_model_exclude_none=True, tags=['blocks'])
@@ -362,6 +383,8 @@ async def get_block_header(
362383
"""
363384
Get metadata of a given block.
364385
"""
386+
root_hash = prepare_hash(root_hash)
387+
file_hash = prepare_hash(file_hash)
365388
return await tonlib.getBlockHeader(workchain, shard, seqno, root_hash, file_hash)
366389

367390
@router.get('/getConfigParam', response_model=TonResponse, response_model_exclude_none=True, tags=['get config'])

ton-http-api/pyTON/core/tonlib/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ async def raw_run_method(self, address, method, stack_data, seqno=None):
341341
return await self.dispatch_request('raw_run_method', address, method, stack_data, seqno)
342342

343343
async def _send_message(self, serialized_boc, method):
344-
ls_index_list = self.select_worker(count=4)
344+
ls_index_list = self.select_worker(count=2)
345345
result = None
346346
try:
347347
task_ids = []

0 commit comments

Comments
 (0)