Crate tonstruct

Source
Expand description

TON transaction body deserialization crate

These docs are not 100% ready. You can help us to improve it

§Example

§Deserialization from Cell

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 CustomPayload {}

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

fn parse_body(cell: tonlib_core::cell::Cell) -> Message {
    <Message as FromCell>::from_cell(cell).unwrap()
}

§Serialization to Cell

use tonstruct::{ToCell, fields::{Comment}};

#[derive(ToCell)]
struct Message {
    field: Comment
}

fn struct_to_cell(message: Message) -> tonlib_core::cell::Cell {
    message.to_cell().unwrap()
}

§Implemented TON types

To see all implemented TON types and its documentation open fields page

Modules§

fields
Implemented TON types

Traits§

FromCell
ToCell

Derive Macros§

FromCell
ToCell