ton-address

Crates.ioton-address
lib.rston-address
version0.1.3
sourcesrc
created_at2024-07-17 15:41:06.552442
updated_at2024-07-20 22:40:47.408177
descriptionA simple library for working with addresses on The Open Network (TON).
homepage
repositoryhttps://github.com/RichardWGNR/ton-address
max_upload_size
id1306278
size26,331
(RichardWGNR)

documentation

README

Build codecov

A simple library for working with addresses on The Open Network (TON).

Examples

Parse address

use ton_address::{Address, ParseError, Base64Decoder};

fn main() {
    // 1. Parse the address in any form via ::parse().
    let result: Result<Address, ParseError> = "EQAOl3l3CEEcKaPLHz+BDvT4P0HZkIOPf5POcILE/5qgJuR2".parse();
    
    // 2. Parse only from base64 with alphabet guessing.
    let result: Result<Address, ParseError> = Address::from_base64(
        "EQAOl3l3CEEcKaPLHz+BDvT4P0HZkIOPf5POcILE/5qgJuR2",
        None // Means that Base64 type will be guessed
    );

    // 3. Parse the address only from base64 using the standard alphabet.
    //    
    //    Note, in this example if the address is encoded in the UrlSafe
    //    alphabet, the method will return an error.
    let result: Result<Address, ParseError> = Address::from_base64(
        "EQAOl3l3CEEcKaPLHz+BDvT4P0HZkIOPf5POcILE/5qgJuR2",
        Some(Base64Decoder::Standard) // or ::UrlSafe alphabet
    );
}

Format address

use ton_address::{Address, ParseError, Base64Encoder, BASE64_STD_DEFAULT, BASE64_URL_DEFAULT};

fn main() {
    let result: Address = "EQAOl3l3CEEcKaPLHz+BDvT4P0HZkIOPf5POcILE/5qgJuR2"
        .parse()
        .unwrap();
    
    // Manual control of Base64 encoding
    println!("{}", result.to_base64(Base64Encoder::Standard {
        bounceable: false,
        production: true,
    })); // UQAOl3l3CEEcKaPLHz+BDvT4P0HZkIOPf5POcILE/5qg....

    // Constants for fast conversion (bounceable & production by default)
    println!("{}", result.to_base64(BASE64_STD_DEFAULT)); // EQAOl3l3CEEcKaPLHz-BDvT4P0HZkIOPf5POcILE_5qgJuR2
    println!("{}", result.to_base64(BASE64_URL_DEFAULT)); // EQAOl3l3CEEcKaPLHz+BDvT4P0HZkIOPf5POcILE/5qgJuR2

    // Or convert it to a raw address
    println!("{}", result.to_raw_address()); // 0:...
}
Commit count: 0

cargo fmt