Skip to content
Merged
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
3 changes: 2 additions & 1 deletion ton-http-api/.docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 22 additions & 0 deletions ton-http-api/pyTON/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'])
Expand All @@ -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'])
Expand All @@ -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'])
Expand Down
Loading