Crates.io | ton-address |
lib.rs | ton-address |
version | 0.1.3 |
source | src |
created_at | 2024-07-17 15:41:06.552442 |
updated_at | 2024-07-20 22:40:47.408177 |
description | A simple library for working with addresses on The Open Network (TON). |
homepage | |
repository | https://github.com/RichardWGNR/ton-address |
max_upload_size | |
id | 1306278 |
size | 26,331 |
A simple library for working with addresses on The Open Network (TON).
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
);
}
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:...
}