|
1 | | -# TONlib Multiclient |
| 1 | +# TON HTTP API C++ |
2 | 2 |
|
3 | | -The TONlib Multi Client is crafted with modern C++ to serve as a robust and flexible tool for seamless communication with multiple TON blockchain lite servers. It's engineered for efficiency, allowing for streamlined request handling across a diverse array of server endpoints. |
| 3 | +[](https://hub.docker.com/repository/docker/toncenter/ton-http-api-cpp) |
| 4 | +[](https://hub.docker.com/repository/docker/toncenter/ton-http-api-cpp) |
| 5 | + |
4 | 6 |
|
5 | | -## Features |
6 | | - |
7 | | -- Multi-threaded Design: Enhances the ability to handle concurrent connections and requests efficiently. |
8 | | -- Flexible Request Handling: Supports a variety of request types, ensuring robust interaction with blockchain lite servers. |
9 | | -- Dynamic Request Creation: Allows for the creation of customizable requests, enabling tailored blockchain queries and operations. |
10 | | -- Advanced Configuration Options: Offers detailed settings for requests, including server selection and archival data queries, providing users with control over their blockchain interactions. |
11 | | - |
12 | | -## Requirements |
13 | | - |
14 | | -- CMake: Version 3.15 or newer. |
15 | | -- C++ Compiler: Must support the C++20 standard or more recent. |
16 | | -- Python: Version 3.9 or above is required for utilizing Python bindings. |
17 | | - |
18 | | -## Usage |
19 | | - |
20 | | -Examples could be found in the `examples` directory. |
21 | | - |
22 | | -## Building |
| 7 | +The HTTP API C++ for [The Open Network](https://ton.org) is a real-time API to connect to TON blockchain lite servers via ADNL protocol and enable access to lite servers through HTTP requests. |
23 | 8 |
|
24 | | -```bash |
25 | | -mkdir build |
26 | | -cd build |
27 | | -cmake .. |
28 | | -cmake --build . |
29 | | -``` |
| 9 | +This service is the improved version of original [TON HTTP API](https://github.com/toncenter/ton-http-api), written entirely in C++ to achieve outstanding performance and effecient comnsuming of hardware resources. |
30 | 10 |
|
31 | | -Build with Python bindings, pass `-DPY_TONLIB_MULTICLIENT:BOOL=TRUE` to CMake: |
32 | 11 |
|
33 | | -```bash |
34 | | -cmake -DPY_TONLIB_MULTICLIENT:BOOL=TRUE .. |
35 | | -cmake --build . |
36 | | -``` |
37 | | - |
38 | | -To use built python binding you need to copy `tonlib_multiclient` dynamic lib (.so) from `build/py` directory to your python project. |
39 | | -```bash |
40 | | -cp build/py/tonlib_multiclient.so /path/to/your/python/project |
41 | | -``` |
42 | | - |
43 | | -## Requests |
44 | | - |
45 | | -### Request<T> |
46 | | -This structure is suitable for general request operations where the response type is known and directly utilized. |
47 | | - |
48 | | -### RequestFunction<T> |
49 | | -A specialized version of Request for cases where `TonlibClient::make_request` cannot process the request (`raw_getAccountState` etc). |
50 | | - |
51 | | -### RequestCallback |
52 | | -Designed for advanced use cases where the user must initialize and manage the response through your own global callback. Requires explicit setup for callback handling. |
| 12 | +## Features |
53 | 13 |
|
54 | | -### RequestJson |
55 | | -Enables sending requests in raw JSON format, requiring minimal configuration besides the JSON string itself and the standard request parameters. |
| 14 | +TON HTTP API C++ provides following features: |
| 15 | +* Load balances requests to TON nodes |
| 16 | +* Checks availability of Lite Servers, disables unavailable and out-of-synced nodes. |
| 17 | +* Additionally parses data returned by original TONLib. |
| 18 | +* Based on [userver](https://github.com/userver-framework/userver), service provides detailed and Prometheus-compatible usage statistics. |
| 19 | + |
| 20 | + |
| 21 | +### Key differences from [toncenter/ton-http-api](https://github.com/toncenter/ton-http-api) |
| 22 | + |
| 23 | +* C++ version consumes significantly less CPU and memory resources. |
| 24 | +* C++ version uses single instance of TONlib for each Lite server, meanwhile Python version TONLib instances number for each Lite server was equal to number of Gunicorn workers. This significantly decreases the number of healthcheck requests to Lite servers. |
| 25 | +* Cache now is integrated in service, no separate Redis is required to enable caching feature. |
| 26 | + |
| 27 | + |
| 28 | +## Hardware Requirements |
| 29 | + |
| 30 | +- OS: Linux or MacOS (Windows is not supported). |
| 31 | +- CPU: 2 vCPU, x86_64 or arm64 architecture. |
| 32 | +- RAM: minimum 2GB, 8GB recommended for caching. |
| 33 | + |
| 34 | +## Deploy |
| 35 | + |
| 36 | +There are two main ways to run TON HTTP API: |
| 37 | +- __Docker Compose__: flexible configuration, recommended for production environments, works on any x86_64 and arm64 OS with Docker available. |
| 38 | +- __Local__ *(experimental)*: only for development purposes. |
| 39 | + |
| 40 | +### Docker Compose |
| 41 | + |
| 42 | +- (First time) Install required tools: `docker`, `docker-compose`, `curl`. |
| 43 | + - For Ubuntu: run `scripts/setup.sh` from the root of the repo. |
| 44 | + - For MacOS and Windows: install [Docker Desktop](https://www.docker.com/products/docker-desktop/). |
| 45 | + - **Note:** we recommend to use Docker Compose V2. |
| 46 | +- Download TON configuration files to private folder: |
| 47 | + ```bash |
| 48 | + mkdir private |
| 49 | + curl -sL https://ton-blockchain.github.io/global.config.json > private/mainnet.json |
| 50 | + curl -sL https://ton-blockchain.github.io/testnet-global.config.json > private/testnet.json |
| 51 | + ``` |
| 52 | +- Copy service configuration file and adjust params: |
| 53 | + ```bash |
| 54 | + cp config/config_vars.yaml private/config_vars.yaml |
| 55 | + nano private/config_vars.yaml |
| 56 | + ``` |
| 57 | + - To run testnet version or connect to your private TON node, please specify: |
| 58 | + ``` |
| 59 | + export THACPP_GLOBAL_CONFIG_PATH=private/testnet.json |
| 60 | + # or |
| 61 | + echo "THACPP_GLOBAL_CONFIG_PATH=private/testnet.json" > .env |
| 62 | +- Pull or build docker image: |
| 63 | + ```bash |
| 64 | + docker compose pull |
| 65 | + # or |
| 66 | + docker compose build |
| 67 | + ``` |
| 68 | +- Run service: |
| 69 | + ```bash |
| 70 | + docker compose up -d |
| 71 | + # or |
| 72 | + docker compose up |
| 73 | + ``` |
| 74 | +- Additionally check service logs: |
| 75 | + ```bash |
| 76 | + docker compose logs http-api-cpp |
| 77 | + # or |
| 78 | + docker compose logs -n 100 http-api-cpp |
| 79 | + # or |
| 80 | + docker compose logs -f -n 100 http-api-cpp |
| 81 | + ``` |
| 82 | + |
| 83 | +### Local run |
| 84 | + |
| 85 | +- Install dependencies: |
| 86 | + - For Ubuntu: |
| 87 | + ```bash |
| 88 | + apt update -y |
| 89 | + apt install -y wget curl build-essential cmake clang openssl libssl-dev zlib1g-dev gperf wget git ninja-build libsodium-dev libmicrohttpd-dev liblz4-dev pkg-config autoconf automake libtool libjemalloc-dev lsb-release software-properties-common gnupg libabsl-dev libbenchmark-dev libboost-context1.83-dev libboost-coroutine1.83-dev libboost-filesystem1.83-dev libboost-iostreams1.83-dev libboost-locale1.83-dev libboost-program-options1.83-dev libboost-regex1.83-dev libboost-stacktrace1.83-dev libboost1.83-dev libbson-dev libbz2-dev libc-ares-dev libcctz-dev libcrypto++-dev libcurl4-openssl-dev libdouble-conversion-dev libev-dev libfmt-dev libgflags-dev libgmock-dev libgtest-dev libhiredis-dev libidn11-dev libjemalloc2 libjemalloc-dev libkrb5-dev libldap2-dev liblz4-dev libnghttp2-dev libpugixml-dev libsnappy-dev libsasl2-dev libssl-dev libxxhash-dev libyaml-cpp0.8 libyaml-cpp-dev libzstd-dev libssh2-1-dev netbase python3-dev python3-jinja2 python3-venv python3-yaml ragel yasm zlib1g-dev liblzma-dev libre2-dev clang-format ccache gcc g++ gdb |
| 90 | +
|
| 91 | + # for ubuntu 22.04 check https://userver.tech/de/d9c/md_en_2deps_2ubuntu-22_804.html |
| 92 | + ``` |
| 93 | + |
| 94 | + - For MacOS: |
| 95 | + ```bash |
| 96 | + brew install boost@1.89 c-ares ccache cctz clang-format clickhouse-cpp cmake coreutils cryptopp cyrus-sasl fmt gdb git google-benchmark googletest hiredis icu4c jemalloc krb5 libev librdkafka mariadb mongo-c-driver@1 nghttp2 ninja openldap openssl postgresql@16 pugixml rocksdb unixodbc yaml-cpp zlib sqlite pkg-config automake libtool autoconf texinfo lz4 openssl@3 libsodium zlib libmicrohttpd |
| 97 | + ``` |
| 98 | +- Build: |
| 99 | + ```bash |
| 100 | + mkdir build |
| 101 | + cd build |
| 102 | + cmake -DCMAKE_BUILD_TYPE=Release .. |
| 103 | + make -j$(nproc) ton-http-api-cpp |
| 104 | + # optional |
| 105 | + make install |
| 106 | + ``` |
| 107 | +- Run: |
| 108 | + ```bash |
| 109 | + ./build/ton-http-api/ton-http-api-cpp --config ./config/static_config.yaml --config_vars ./private/config_vars.yaml |
| 110 | + ``` |
| 111 | + |
| 112 | +## License |
| 113 | + |
| 114 | +TON HTTP API C++ is licensed under the MIT License. |
0 commit comments