diff --git a/ton-http-api/.docker/Dockerfile b/ton-http-api/.docker/Dockerfile index 1eb5176..507c38a 100644 --- a/ton-http-api/.docker/Dockerfile +++ b/ton-http-api/.docker/Dockerfile @@ -1,7 +1,8 @@ FROM ubuntu:22.04 RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get update && apt-get -y install tzdata -RUN apt-get update && apt-get install -y wget python3 python3-pip +RUN apt-get update -y && apt-get install -y wget python3 python3-pip zlib1g-dev libsecp256k1-dev \ + libmicrohttpd-dev libsodium-dev liblz4-dev libjemalloc-dev && rm -rf /var/lib/{apt,dpkg,cache,log}/ # python requirements ADD ./requirements.txt /tmp/requirements.txt diff --git a/ton-http-api/pyTON/main.py b/ton-http-api/pyTON/main.py index 9cc3c34..f4eed7c 100644 --- a/ton-http-api/pyTON/main.py +++ b/ton-http-api/pyTON/main.py @@ -182,6 +182,20 @@ def prepare_address(address): except: raise HTTPException(status_code=416, detail="Incorrect address") +def prepare_hash(value): + if value is None: + return None + if len(value) == 44: + value = value.replace('_', '/').replace('-', '+') + data = codecs.decode(codecs.encode(value, 'utf-8'), 'base64') + b64 = codecs.encode(data, 'base64').decode('utf-8') + return b64.strip() + if len(value) == 64: + data = codecs.decode(codecs.encode(value, 'utf-8'), 'hex') + b64 = codecs.encode(data, 'base64').decode('utf-8') + return b64.strip() + raise ValueError('Invalid hash') + def address_state(account_info): if isinstance(account_info.get("code", ""), int) or len(account_info.get("code", "")) == 0: if len(account_info.get("frozen_hash", "")) == 0: @@ -453,6 +467,9 @@ async def get_block_transactions( """ Get transactions of the given block. """ + root_hash = prepare_hash(root_hash) + file_hash = prepare_hash(file_hash) + after_hash = prepare_hash(after_hash) return await tonlib.getBlockTransactions(workchain, shard, seqno, count, root_hash, file_hash, after_lt, after_hash) @app.get('/getBlockTransactionsExt', response_model=TonResponse, response_model_exclude_none=True, tags=['blocks','transactions']) @@ -471,6 +488,9 @@ async def get_block_transactions_ext( """ Get transactions of the given block. """ + root_hash = prepare_hash(root_hash) + file_hash = prepare_hash(file_hash) + after_hash = prepare_hash(after_hash) return await tonlib.getBlockTransactionsExt(workchain, shard, seqno, count, root_hash, file_hash, after_lt, after_hash) @app.get('/getBlockHeader', response_model=TonResponse, response_model_exclude_none=True, tags=['blocks']) @@ -486,6 +506,8 @@ async def get_block_header( """ Get metadata of a given block. """ + root_hash = prepare_hash(root_hash) + file_hash = prepare_hash(file_hash) return await tonlib.getBlockHeader(workchain, shard, seqno, root_hash, file_hash) @app.get('/getConfigParam', response_model=TonResponse, response_model_exclude_none=True, tags=['get config'])