Skip to main content

Crate ton_net

Crate ton_net 

Source
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.
AccountRead
The decoded chain structures, defined in ton-net-block and surfaced here. One account read as a liteserver answered it, ready to be checked.
AccountState
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.
BlockIdExt
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.
DictEntry
The cell model a decoded account carries, defined in ton-net-cell and surfaced here.
DictIter
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.
MasterchainInfo
The read response types, defined in ton-net-lite and surfaced here. A masterchain head as a liteserver reports it.
ServerReported
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.
SyncReport
What one sync reached and what it cost.
Verified
A value proven to sit in the state of a block the caller trusts.

Enums§

AccountStatus
The decoded chain structures, defined in ton-net-block and surfaced here. An account’s status, with the contents that only some statuses have.
CellError
The cell model a decoded account carries, defined in ton-net-cell and surfaced here.
CellType
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.
ErrorCode
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.