Struct fractal_utils::wallet_address::WalletAddress [] [src]

pub struct WalletAddress { /* fields omitted */ }

The object representation of a wallet address.

Wallet addresses are structs that act as as an easy manipulation object for wallet addresses. Addresses that come from user input can be verified, and made sure they are correct.

Address can be used as strings or displayed using the Display trait:

use fractal_utils::{WalletAddress, WALLET_ADDRESS_LEN};

let addr = WalletAddress::from_data([0u8; WALLET_ADDRESS_LEN]);
let addr_str = format!("{}", addr);
assert_eq!(addr_str, "fr111111111");

All Fractal wallet addresses start with fr, and then they have a base-58 encoded string representing WALLET_ADDRESS_LEN+2 bytes. The first byte will be 0x00, that the rest bytes until WALLET_ADDRESS_LEN will compose the actual address, while the other two are the checksum. That way addresses coming from user input can be verified:

use std::str::FromStr;
use std::result::Result;
use fractal_utils::{WalletAddress, WALLET_ADDRESS_LEN};

let wallet: Result<WalletAddress, _> = "fr111111111".parse();
assert!(wallet.is_ok());

let wallet: Result<WalletAddress, _> = "fr111111112".parse();
assert!(wallet.is_err());

The checksums are calculated by doing the XOR operation in all the bytes of the wallet address and doing XOR of the checksum's first byte with the second one for each byte:

let check_addr = [0x00, 0x11, 0x2A, 0x44, 0xCD, 0xFF, 0xE0];
let mut checksum = [0u8; 2];

for b in &check_addr {
    checksum[0] ^= *b;
    checksum[1] ^= checksum[0];
}

assert_eq!(checksum, [0xAD, 0x07]);

Methods

impl WalletAddress
[src]

[src]

Creates a new wallet address from raw data.

This should only be used if the raw input data is verified to be correct, ir it could lead o a false address.

It will panic if the address does not start with byte 0x00.

[src]

Returns the wallet address bytes.

This could be useful to store the bytes in databases where space can be an issue, or where fast search is required. It does not contain checksums nor any other verification mechanism.

Trait Implementations

impl Eq for WalletAddress
[src]

impl PartialEq for WalletAddress
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl PartialOrd for WalletAddress
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Ord for WalletAddress
[src]

[src]

This method returns an Ordering between self and other. Read more

1.22.0
[src]

Compares and returns the maximum of two values. Read more

1.22.0
[src]

Compares and returns the minimum of two values. Read more

impl Debug for WalletAddress
[src]

[src]

Formats the value using the given formatter.

impl Clone for WalletAddress
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Copy for WalletAddress
[src]

impl Encodable for WalletAddress
[src]

[src]

Serialize a value using an Encoder.

impl Decodable for WalletAddress
[src]

[src]

Deserialize a value using a Decoder.

impl From<[u8; 7]> for WalletAddress
[src]

[src]

Performs the conversion.

impl FromStr for WalletAddress
[src]

The associated error which can be returned from parsing.

[src]

Parses a string s to return a value of this type. Read more

impl Display for WalletAddress
[src]

[src]

Formats the value using the given formatter. Read more