Skip to content

Latest commit

 

History

History
67 lines (53 loc) · 1.93 KB

README.md

File metadata and controls

67 lines (53 loc) · 1.93 KB

TonStruct

GitHub Actions Workflow Status GitHub License Crates.io Version 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();
}