pub struct WalletAddress { /* private fields */ }Expand description
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]);Implementations§
Source§impl WalletAddress
impl WalletAddress
Sourcepub fn from_data(addr: [u8; 7]) -> WalletAddress
pub 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.
Trait Implementations§
Source§impl Clone for WalletAddress
impl Clone for WalletAddress
Source§fn clone(&self) -> WalletAddress
fn clone(&self) -> WalletAddress
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WalletAddress
impl Debug for WalletAddress
Source§impl Decodable for WalletAddress
impl Decodable for WalletAddress
Source§impl Display for WalletAddress
impl Display for WalletAddress
Source§impl Encodable for WalletAddress
impl Encodable for WalletAddress
Source§impl FromStr for WalletAddress
impl FromStr for WalletAddress
Source§type Err = WalletAddressParseError
type Err = WalletAddressParseError
Source§fn from_str(s: &str) -> Result<WalletAddress, WalletAddressParseError>
fn from_str(s: &str) -> Result<WalletAddress, WalletAddressParseError>
s to return a value of this type. Read moreSource§impl Ord for WalletAddress
impl Ord for WalletAddress
Source§fn cmp(&self, other: &WalletAddress) -> Ordering
fn cmp(&self, other: &WalletAddress) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for WalletAddress
impl PartialEq for WalletAddress
Source§impl PartialOrd for WalletAddress
impl PartialOrd for WalletAddress
impl Copy for WalletAddress
impl Eq for WalletAddress
impl StructuralPartialEq for WalletAddress
Auto Trait Implementations§
impl Freeze for WalletAddress
impl RefUnwindSafe for WalletAddress
impl Send for WalletAddress
impl Sync for WalletAddress
impl Unpin for WalletAddress
impl UnwindSafe for WalletAddress
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)