Architecture Overview
tonutils is a native Rust TON SDK. Its core design constraint is autonomy: implement TON-specific protocols in this repository instead of delegating to another Rust TON SDK.
Goals
- Pure Rust TON-specific implementation.
- No runtime
.sodependency. - High-performance serialization, hashing, and networking.
- Feature-gated optional modules.
- Low-level protocol access and ergonomic high-level APIs.
- Clear separation between transport errors, LiteAPI errors, TVM decoding errors, and proof verification failures.
Layer Stack
From bottom to top:
- Hashes, CRC, crypto helpers.
- TL primitive and boxed serialization.
- ADNL transport and ADNL message types.
- LiteAPI requests and responses.
- LiteClient request execution.
- LiteBalancer peer selection and failover.
- TVM cells, BoC, TLB, dictionaries, stack values.
- Smart-contract get-method and message APIs.
- Wallet, jetton, NFT, DHT, overlay, and mempool utilities.
Dependency Direction
Lower layers must not depend on higher layers.
Allowed directions:
liteclientmay depend onadnl,tl, andtvm.contractsmay depend onliteclientandtvm.network-configmay depend on serde JSON support.climay depend on everything needed for user commands.
Forbidden directions:
tvmmust not depend onliteclient.tlmust not depend onliteclientexcept current temporary response conversion helpers; this should be removed.- ADNL primitives must not depend on LiteAPI semantics.
Current Implementation Anchors
src/adnl/: ADNL crypto, handshake, codec, peer wrapper.src/tl/: TL request, response, common, ADNL message types.src/liteclient/: client, peer, balancer, service layers.src/tvm/: cells, BoC, addresses, dictionaries, stack.src/network_config/: global config parser.src/cli/: optional CLI.
Public API Principles
- Expose typed methods for stable, common workflows.
- Expose raw byte escape hatches for schema-forward compatibility.
- Preserve proof bytes even when full verification is not implemented.
- Do not silently trust data just because it came from a liteserver.
- Use explicit mode/flag builders where boolean argument lists become ambiguous.
Missing Architecture Work
- Split TL response conversion out of
tl::utilsto remove thetl -> liteclientdependency. - Add a shared request-executor trait so
LiteClientandLiteBalancerdo not duplicate every method. - Add
contractsmodule as a high-level API layer. - Define stable error enums per subsystem.