#comments #cell #field #blockchain #partial-eq #web3

tonstruct

TON blockchain types serialization tool for Rust

3 releases

0.0.3 Feb 25, 2025
0.0.2 Feb 22, 2025
0.0.1 Feb 15, 2025

#13 in #comment

Download history 87/week @ 2025-02-10 158/week @ 2025-02-17 162/week @ 2025-02-24 33/week @ 2025-03-03 5/week @ 2025-03-10 8/week @ 2025-03-17

266 downloads per month

MIT and LGPL-3.0+

41KB
1K SLoC

TonStruct

GitHub Actions Workflow Status GitHub License Crates.io Version Codecov Work in progress

ℹ️ The Open Network deserialization crate for Rust language.

❤️ Any contributions are welcome. Feel free to open pull requests, issues, bug reports, feature proposals or anything else

Example

To parse transaction body you need to derive FromCell macro. In example below we parse transaction body from jetton transfer

use tonstruct::{FromCell, fields::{Uint, Coins, Address, Int, CellRef, Comment}};

#[derive(FromCell, Debug, PartialEq)]
struct ForwardPayload {
    is_right: bool,
    text_comment: CellRef<Comment>,
}

#[derive(FromCell, Debug, PartialEq)]
struct JettonTransfer {
    op_code: Uint<32>,
    query_id: Uint<64>,
    amount: Coins,
    destination: Address,
    response_destination: Address,
    custom_payload: Option<Int<0>>,
    forward_ton_amount: Coins,
    forward_payload: ForwardPayload,
}

fn main() {
    // Transaction body Cell
    let cell = ...;
    // Parsed body
    let message = <Message as FromCell>::from_cell(cell).unwrap();
}

To serialize structure into Cell use derived macro ToCell and call to_cell() method.

use tonstruct::ToCell;

#[derive(ToCell)]
struct JettonTransfer {
    /// Fields
}

fn main() {
    // Message body
    let message = Message {
        /// Fields 
    };

    let cell = message.to_cell().unwrap();
    /// OR
    let cell = ToCell::to_cell(&message).unwrap();
}

Dependencies

~5MB
~91K SLoC