Expand description
ton-net: a direct client for the TON network.
This crate connects to a TON liteserver over ADNL and reads chain state without an HTTP indexer in the path. It speaks the wire protocols directly: the TL codec, the ADNL transport, and the liteserver query layer.
§Verification status
Every read says in its type whether it was proved.
A ServerReported value is the liteserver’s word, returned without checking the
proofs that came with it. A Verified value was checked: its Merkle proofs were
recomputed against a block hash the caller supplied, and the account was bound to that
block’s state. There is no way to turn the first into the second.
What Verified does not settle on its own is where the block hash came from.
Passing Client::account_at a head read from the same liteserver shows only that the
server agrees with itself, which a server making things up can also manage.
Client::sync is what closes that. It walks from the key block the config pins to
the network’s current head, checking a validator signature set at every step, and
leaves the client holding a block it proved rather than one a server named. The block
it starts from is the one thing still taken on trust from the chain’s side, and it
comes from the file that already decides which network a client is on.
The other trusted input is the local clock. A proof establishes that a block is real and was committed; it says nothing about when it was handed over, so a server replaying a genuine chain from last year passes every other check here. The clock is what catches that, which means a client whose clock is wrong has a weaker freshness guarantee than one whose clock is right. A clock far enough behind is reported rather than obeyed, so the check never silently stops running.
Client::account reads against that block, so it is the read to reach for.
Client::account_at proves against a block the caller names, and
Client::account_reported checks nothing at all. The safe one is the one with the
plain name.
§Example
use ton_net::{Address, Client, Config};
let config = Config::mainnet();
let mut client = Client::connect(&config).await?;
let elector = Address::parse("-1:3333333333333333333333333333333333333333333333333333333333333333")?;
// Proved against a block the client walked to itself. The first call pays for the
// walk; save `client.anchor()` and hand it to `connect_from` next time.
let account = client.account(&elector).await?;
println!("proved balance: {}", account.value().balance);
// The server's word, for a caller who asks for it by name.
let reported = client.account_reported(&elector).await?;
println!("reported balance: {}", reported.value().balance);Structs§
- Account
- The decoded chain structures, defined in ton-net-block and surfaced here. An account as it stands at one block.
- Account
Read - The decoded chain structures, defined in ton-net-block and surfaced here. One account read as a liteserver answered it, ready to be checked.
- Account
State - The read response types, defined in ton-net-lite and surfaced here. An account’s state as a liteserver reports it.
- Address
- A TON account address: a workchain id and a 256-bit account id.
- Block
IdExt - The read response types, defined in ton-net-lite and surfaced here. A full block identifier: the id and its shard coordinates plus hashes.
- Builder
- The cell model a decoded account carries, defined in ton-net-cell and surfaced here.
- Cell
- The cell model a decoded account carries, defined in ton-net-cell and surfaced here.
- Client
- A connection to a single TON liteserver.
- Coins
- The decoded chain structures, defined in ton-net-block and surfaced here. An amount of TON, held in nanotons.
- Config
- The public network parameters a client needs to reach TON.
- Dict
- The cell model a decoded account carries, defined in ton-net-cell and surfaced here.
- Dict
Entry - The cell model a decoded account carries, defined in ton-net-cell and surfaced here.
- Dict
Iter - The cell model a decoded account carries, defined in ton-net-cell and surfaced here.
- Identity
- The cell model a decoded account carries, defined in ton-net-cell and surfaced here.
- Masterchain
Info - The read response types, defined in ton-net-lite and surfaced here. A masterchain head as a liteserver reports it.
- Server
Reported - The read response types, defined in ton-net-lite and surfaced here. A value a liteserver returned without a checked proof.
- Slice
- The cell model a decoded account carries, defined in ton-net-cell and surfaced here.
- Sync
Report - What one sync reached and what it cost.
- Verified
- A value proven to sit in the state of a block the caller trusts.
Enums§
- Account
Status - The decoded chain structures, defined in ton-net-block and surfaced here. An account’s status, with the contents that only some statuses have.
- Cell
Error - The cell model a decoded account carries, defined in ton-net-cell and surfaced here.
- Cell
Type - The cell model a decoded account carries, defined in ton-net-cell and surfaced here.
- Error
- The error type for every fallible operation in this crate.
- Error
Code - The stable name for a kind of failure, for a caller that has to branch on one.
- Lookup
- The cell model a decoded account carries, defined in ton-net-cell and surfaced here.
- MsgAddress
- The cell model a decoded account carries, defined in ton-net-cell and surfaced here.
Constants§
- MAX_
BITS - The bag-of-cells codec, defined in ton-net-cell and surfaced here.
- MAX_
CELLS - The bag-of-cells codec, defined in ton-net-cell and surfaced here.
- MAX_
DEPTH - The bag-of-cells codec, defined in ton-net-cell and surfaced here.
- MAX_
REFS - The bag-of-cells codec, defined in ton-net-cell and surfaced here.
- VERIFY_
EPOCH - Which set of things this build will accept as proven.
Functions§
- parse_
boc - The bag-of-cells codec, defined in ton-net-cell and surfaced here.
- serialize_
boc - The bag-of-cells codec, defined in ton-net-cell and surfaced here.
- verify_
account - Proves an account read against the block hash the read was checked to.