TonStruct

ℹ️ 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() {
let cell = ...;
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 {
}
fn main() {
let message = Message {
};
let cell = message.to_cell().unwrap();
let cell = ToCell::to_cell(&message).unwrap();
}