Skip to content

Commit

Permalink
add post methods docs (#66)
Browse files Browse the repository at this point in the history
* Update README

* add post methods docs

---------

Co-authored-by: PixelPlex <dev@pixelplex.io>
  • Loading branch information
a-bahdanau and pixelplex authored Aug 2, 2024
1 parent 66e4e25 commit 691c89a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,24 @@ TON Indexer stack consists of:
## How to run

Requirements:
* Docker and Docker compose (see [instruction](https://docs.docker.com/engine/install/)).
* Running TON full node (archival for full indexing).
* Docker and Docker compose v2 (see [instruction](https://docs.docker.com/engine/install/)).
* Running [TON full node](https://docs.ton.org/participate/run-nodes/full-node) ([archival](https://docs.ton.org/participate/run-nodes/archive-node) for full indexing).
* **NOTE:** Archive Node requires capacity of more than 4 TB, SSD OR Provided 32+k IOPS storage. Please, pay attention that node is constantly growing and resource consumption my increase within time.
* Recommended hardware:
* Database and API: 4 CPU, 32 GB RAM, 200GB disk, SSD recommended (more than 1TB required for archival indexing).
* Worker: 4 CPU, 32 GB RAM, SSD recommended (for archival: 8 CPUs, 64 GB RAM, SSD recommended).

Do the following steps to setup TON Indexer:
* Clone repository: `git clone --recursive --branch cpp-indexer https://github.com/kdimentionaltree/ton-indexer`.
* Clone repository: `git clone --recursive --branch master https://github.com/toncenter/ton-indexer.git && cd ./ton-indexer`.
* Create *.env* file with command `./configure.sh`.
* Run `./configure.sh --worker` to configure TON Index worker.
* Adjust parameters in *.env* file (see [list of available parameters](#available-parameters)).
* Set PostgreSQL password `echo -n "MY_PASSWORD" > private/postgres_password`
* Build docker images: `docker compose build postgres alembic index-api`.
* Run stack: `docker compose up -d postgres alembic index-api`.
* To start worker use command `docker compose up -d index-worker` after creating all services.

**NOTE:** we recommend to setup indexer stack and index worker on separate servers. To install index worker to **Systemd** check this [instruction](https://github.com/kdimentionaltree/ton-index-cpp).
**NOTE:** we recommend to setup indexer stack and index worker on separate servers. To install index worker to **Systemd** check this [instruction](https://github.com/toncenter/ton-index-worker).

### Available parameters

Expand Down Expand Up @@ -66,3 +68,7 @@ Do the following steps to setup TON Indexer:
## How to update code
* Pull new commits: `git pull`.
* Update submodules: `git submodule update --recursive --init`.
* Build new image: `docker compose build postgres alembic index-api`.
* Build new image of worker: `docker compose build index-worker`
* Run new version: `docker compose up -d postgres alembic index-api`
* Run new version of worker: `docker compose up -d index-worker`
26 changes: 20 additions & 6 deletions indexer/indexer/api/api_v1/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,19 +750,33 @@ def from_ton_http_api(cls, obj):

return GetMethodParameter(type=GetMethodParameterType.unsupported_type, value=None)


class RunGetMethodRequestStackValueType(Enum):
cell = "cell"
slice = "slice"
num = "num"

class RunGetMethodRequestStackValue(BaseModel):
type: RunGetMethodRequestStackValueType
value: str

class RunGetMethodRequest(BaseModel):
address: str
method: str
stack: List[GetMethodParameter]
address: str = Field(description="Contract address in any format",
examples=["EQBSzBN6cnxDwDjn_IQXqgU8OJXUMcol9pxyL-yLkpKzYs9U"])

method: str = Field(description="Method name to run", examples=["seqno"])

stack: List[RunGetMethodRequestStackValue] = Field(description="stack arguments",
examples=[[{"type": "num", "value": "0x12a"}]])

def to_ton_http_api(self) -> dict:
ton_http_api_stack = []
for p in self.stack:
if p.type == GetMethodParameterType.num:
if p.type == RunGetMethodRequestStackValueType.num:
ton_http_api_stack.append(['num', p.value])
elif p.type == GetMethodParameterType.cell:
elif p.type == RunGetMethodRequestStackValueType.cell:
ton_http_api_stack.append(['tvm.Cell', p.value])
elif p.type == GetMethodParameterType.slice:
elif p.type == RunGetMethodRequestStackValueType.slice:
ton_http_api_stack.append(['tvm.Slice', p.value])
else:
raise Exception(f"Unsupported stack parameter type: {p.type}")
Expand Down
10 changes: 8 additions & 2 deletions indexer/indexer/api/api_v1/ton_http_api_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def get_result(body):
async def send_message(
message: schemas.ExternalMessage = Body(..., description='Message in boc base64 format.')):
"""
Send external message to TON network.
Send external message in boc base64 format to TON network. Returns message hash in hex format.
External messages are sent from the outside to the smart contracts to make them perform certain actions.
For instance, a wallet smart contract expects to receive external messages signed by the wallet's owner.
"""
async with httpx.AsyncClient() as client:
response = await client.post(f'{settings.ton_http_api_endpoint}/sendBocReturnHash', json={'boc': message.boc})
Expand Down Expand Up @@ -80,7 +83,10 @@ async def estimate_fee(
run_get_method_request: schemas.EstimateFeeRequest = Body(..., description='EstimateFee request body')
):
"""
Estimate fee for external message.
Estimate fees required for query processing.
Body, init_code and init_data accepted in base64 encoded format.
"""
async with httpx.AsyncClient() as client:
response = await client.post(f'{settings.ton_http_api_endpoint}/estimateFee', json=run_get_method_request.to_ton_http_api())
Expand Down

0 comments on commit 691c89a

Please sign in to comment.