Struct fractal_utils::wallet_address::WalletAddress
[−]
[src]
pub struct WalletAddress { // some 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]
fn from_data(addr: [u8; 7]) -> WalletAddress
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
.
fn get_raw(&self) -> &[u8]
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]
fn eq(&self, __arg_0: &WalletAddress) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &WalletAddress) -> bool
This method tests for !=
.
impl PartialOrd for WalletAddress
[src]
fn partial_cmp(&self, __arg_0: &WalletAddress) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &WalletAddress) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &WalletAddress) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &WalletAddress) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &WalletAddress) -> bool
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]
fn cmp(&self, __arg_0: &WalletAddress) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl Debug for WalletAddress
[src]
impl Clone for WalletAddress
[src]
fn clone(&self) -> WalletAddress
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Copy for WalletAddress
[src]
impl Encodable for WalletAddress
[src]
impl Decodable for WalletAddress
[src]
fn decode<__D: Decoder>(__arg_0: &mut __D) -> Result<WalletAddress, __D::Error>
impl From<[u8; 7]> for WalletAddress
[src]
fn from(other: [u8; 7]) -> WalletAddress
Performs the conversion.
impl FromStr for WalletAddress
[src]
type Err = WalletAddressParseError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<WalletAddress, WalletAddressParseError>
Parses a string s
to return a value of this type. Read more