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

Added method getBlockTransactionsExt #128

Merged
merged 2 commits into from
Aug 23, 2024
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,8 @@ To point the HTTP API to your own lite server you should set `TON_API_TONLIB_LIT
Binary file `libtonlibjson` now moved to [pytonlib](https://github.com/toncenter/pytonlib).
- Docker Compose: `docker-compose build --no-cache`.
- Local run: `pip install -U ton-http-api`.

### No working liteservers error.

Usually, liteservers from the config has already deleted the block, which specified in `init_block` section.
To update init block, please **backup your config file** and run script `./scripts/update_init_block.sh private/mainnet.json`. For testnet add flag `--testnet`.
66 changes: 66 additions & 0 deletions scripts/update_init_block.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

ENDPOINT=https://toncenter.com/api/v2


function usage() {
echo 'required 1 positional argument: name of config file'
echo 'Supported argumets:'
echo ' -h --help Show this message'
echo ' --testnet Use testnet endpoint'
exit
}


while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
usage
exit 1
;;
--testnet)
ENDPOINT=https://testnet.toncenter.com/api/v2
shift
;;
-*|--*)
echo "Error: unknown option $1"
usage
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done

set -- "${POSITIONAL_ARGS[@]}"

# main logic
LAST_SEQNO=$(curl -s ${ENDPOINT}/getMasterchainInfo | jq ".result.last.seqno")
echo "Last seqno is $LAST_SEQNO"

sleep 1
LAST_KEYBLOCK_SEQNO=$(curl -s "${ENDPOINT}/getBlockHeader?workchain=-1&shard=-9223372036854775808&seqno=${LAST_SEQNO}" | jq .result.prev_key_block_seqno)
echo "Last keyblock seqno is $LAST_KEYBLOCK_SEQNO"

sleep 1
RES=$(curl -s "${ENDPOINT}/lookupBlock?workchain=-1&shard=-9223372036854775808&seqno=${LAST_KEYBLOCK_SEQNO}" | jq .result )

SEQNO=$(echo "$RES" | jq '.seqno')
FILEHASH=$(echo "$RES" | jq '.file_hash')
ROOTHASH=$(echo "$RES" | jq '.root_hash')

FILENAME=$1
python3 <<EOF
import json
with open("$FILENAME", 'r') as f:
data = json.load(f)
data['validator']['init_block']['seqno'] = $SEQNO
data['validator']['init_block']['file_hash'] = $FILEHASH
data['validator']['init_block']['root_hash'] = $ROOTHASH

with open("$FILENAME", 'w') as f:
json.dump(data, f, indent=4)
EOF
echo "Init block updated"
2 changes: 1 addition & 1 deletion ton-http-api/.docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM ubuntu:20.04

RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata
RUN apt-get install -y git cmake wget python3 python3-pip libsecp256k1-dev libsodium-dev
RUN apt-get install -y git cmake wget python3 python3-pip libsecp256k1-dev libsodium-dev libc6

# python requirements
ADD ./requirements.txt /tmp/requirements.txt
Expand Down
18 changes: 18 additions & 0 deletions ton-http-api/pyTON/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,24 @@ async def get_block_transactions(
"""
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'])
@json_rpc('getBlockTransactionsExt')
@wrap_result
async def get_block_transactions_ext(
workchain: int,
shard: int,
seqno: int,
root_hash: Optional[str] = None,
file_hash: Optional[str] = None,
after_lt: Optional[int] = None,
after_hash: Optional[str] = None,
count: int = 40
):
"""
Get transactions of the given block.
"""
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'])
@json_rpc('getBlockHeader')
@wrap_result
Expand Down
3 changes: 3 additions & 0 deletions ton-http-api/pyTON/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@ async def raw_getBlockTransactions(self, fullblock, count, after_tx):
async def getBlockTransactions(self, workchain, shard, seqno, count, root_hash=None, file_hash=None, after_lt=None, after_hash=None):
return await self.dispatch_archival_request('get_block_transactions', workchain, shard, seqno, count, root_hash, file_hash, after_lt, after_hash)

async def getBlockTransactionsExt(self, workchain, shard, seqno, count, root_hash=None, file_hash=None, after_lt=None, after_hash=None):
return await self.dispatch_archival_request('get_block_transactions_ext', workchain, shard, seqno, count, root_hash, file_hash, after_lt, after_hash)

async def getBlockHeader(self, workchain, shard, seqno, root_hash=None, file_hash=None):
method = 'get_block_header'
if workchain == -1 and seqno and self.consensus_block.seqno - seqno < 2000:
Expand Down
Loading