@@ -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+
5469def 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' ])
0 commit comments