Struct openalias::CryptoAddress
[−]
[src]
pub struct CryptoAddress { pub cryptocurrency: String, pub address: String, pub recipient_name: Option<String>, pub tx_description: Option<String>, pub tx_amount: Option<String>, pub tx_payment_id: Option<String>, pub address_signature: Option<String>, pub checksum: Option<(u32, bool)>, pub additional_values: BTreeMap<String, String>, }
OpenAlias-parsed cryptocurrency address.
Display
ing an address with a checksum will not print out the same sum, but will re-hash the output string
(since the output can, while functionally equivalent, be different).
Examples
Parse a simple example entry:
static MONERO_DONATE_RCRD: &str = "oa1:xmr \ recipient_address=46BeWrHpwXmHDpDEUmZBWZfoQpdc6HaERCNmx1pEYL2rAcu\ wufPN9rXHHtyUA4QVy66qeFQkn6sfK8aHYjA3jk3o1Bv16em; \ recipient_name=Monero Development;"; assert_eq!(MONERO_DONATE_RCRD.parse::<CryptoAddress>().unwrap(), CryptoAddress { cryptocurrency: "xmr".to_string(), address: "46BeWrHpwXmHDpDEUmZBWZfoQpdc6HaERCNmx1pEYL2rAcu\ wufPN9rXHHtyUA4QVy66qeFQkn6sfK8aHYjA3jk3o1Bv16em".to_string(), recipient_name: Some("Monero Development".to_string()), tx_description: None, tx_amount: None, tx_payment_id: None, address_signature: None, checksum: None, additional_values: BTreeMap::new(), });
Parse a more complex record:
static NAB_DONATE_RCRD: &str = "oa1:btc recipient_address=1MoSyGZp3SKpoiXPXfZDFK7cDUFCVtEDeS; \ recipient_name=\"nabijaczleweli; FOSS development\";\ tx_description=Donation for nabijaczleweli:\\ ; \ tx_amount=0.1;checksum=D851342C; kaschism=yass;"; assert_eq!(NAB_DONATE_RCRD.parse::<CryptoAddress>().unwrap(), CryptoAddress { cryptocurrency: "btc".to_string(), address: "1MoSyGZp3SKpoiXPXfZDFK7cDUFCVtEDeS".to_string(), recipient_name: Some("nabijaczleweli; FOSS development".to_string()), tx_description: Some("Donation for nabijaczleweli: ".to_string()), tx_amount: Some("0.1".to_string()), tx_payment_id: None, address_signature: None, checksum: Some((0xD851342C, true)), additional_values: { let mut avs = BTreeMap::new(); avs.insert("kaschism".to_string(), "yass".to_string()); avs }, });
Display
a record:
let mut base_record = CryptoAddress { cryptocurrency: "btc".to_string(), address: "1MoSyGZp3SKpoiXPXfZDFK7cDUFCVtEDeS".to_string(), recipient_name: Some("nabijaczleweli; FOSS development".to_string()), tx_description: Some("Donation for nabijaczleweli: ".to_string()), tx_amount: Some("0.1".to_string()), tx_payment_id: None, address_signature: None, checksum: Some((0xD851342C, true)), additional_values: { let mut avs = BTreeMap::new(); avs.insert("kaschism".to_string(), "yass".to_string()); avs }, }; assert_eq!(&base_record.to_string(), "oa1:btc recipient_address=1MoSyGZp3SKpoiXPXfZDFK7cDUFCVtEDeS; \ recipient_name=\"nabijaczleweli; FOSS development\"; \ tx_description=Donation for nabijaczleweli:\\ ; tx_amount=0.1; \ kaschism=yass; checksum=5AAC58F4;"); base_record.checksum = None; assert_eq!(&base_record.to_string(), "oa1:btc recipient_address=1MoSyGZp3SKpoiXPXfZDFK7cDUFCVtEDeS; \ recipient_name=\"nabijaczleweli; FOSS development\"; \ tx_description=Donation for nabijaczleweli:\\ ; tx_amount=0.1; \ kaschism=yass;"); base_record.recipient_name = None; base_record.tx_description = None; base_record.tx_amount = None; base_record.additional_values.clear(); assert_eq!(&base_record.to_string(), "oa1:btc recipient_address=1MoSyGZp3SKpoiXPXfZDFK7cDUFCVtEDeS;");
Fields
cryptocurrency: String
Specified cryptocurrency's name.
Usually "btc" for Bitcoin, "mxr" for Monero, et caetera.
Note, that:
OpenAlias does not maintain a repository of prefixes at this stage, but may do so in future.
address: String
Recipient's specified cryptocurrency address. Required.
Corresponds to recipient_address
record key.
recipient_name: Option<String>
Recipient's specified user-friendlier name.
Corresponds to recipient_name
record key.
tx_description: Option<String>
Description for the transaction(s) resulting from this record.
Note, that:
Bear in mind that DNS is typically long-lived data and not always updated at request time, so this should only be used if it does not need to be updated constantly.
Corresponds to tx_description
record key.
tx_amount: Option<String>
Amount of the specified cryptocurrency for the transaction(s) resulting from this record.
Exact numeric value/type is usecase-dependent. No restrictions are applied within the realm of the library.
Corresponds to tx_amount
record key.
tx_payment_id: Option<String>
"Particular to Monero, but is standardised as other cryptocurrencies (CryptoNote-based cryptocurrencies in particular) may find it useful."
It is typically a hex string of 32 characters, but that is not enforced in the standard.
Corresponds to tx_payment_id
record key.
address_signature: Option<String>
"If you have a standardised way of signing messages based on the address private key, then this can be used to validate the FQDN."
The message that is signed should be the entire FQDN (eg. donate.getmonero.org) with nothing else. Validation would be to verify that the signature is valid for the FQDN as a message.
Corresponds to address_signature
record key.
checksum: Option<(u32, bool)>
CRC-32 of the record up to this key.
Second value of the pair is whether the checksum verified correctly, provided for convenience.
Depending on your use-case, it may serve little or no purpose, although some may choose to include it for additional validation. In order to calculate or verify the checksum, take the entire record up until the checksum key-value pair (ie. excluding the checksum key-value pair). Strip any spaces from either side, and calculate the CRC-32 on that final record.
Corresponds to checksum
record key.
additional_values: BTreeMap<String, String>
Set of K-Vs not special-cased above.
Trait Implementations
impl Debug for CryptoAddress
[src]
impl Clone for CryptoAddress
[src]
fn clone(&self) -> CryptoAddress
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Hash for CryptoAddress
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialEq for CryptoAddress
[src]
fn eq(&self, __arg_0: &CryptoAddress) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &CryptoAddress) -> bool
[src]
This method tests for !=
.
impl Eq for CryptoAddress
[src]
impl PartialOrd for CryptoAddress
[src]
fn partial_cmp(&self, __arg_0: &CryptoAddress) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &CryptoAddress) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &CryptoAddress) -> bool
[src]
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: &CryptoAddress) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &CryptoAddress) -> bool
[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for CryptoAddress
[src]
fn cmp(&self, __arg_0: &CryptoAddress) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
[src]
ord_max_min
)Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
[src]
ord_max_min
)Compares and returns the minimum of two values. Read more
impl FromStr for CryptoAddress
[src]
type Err = ParseError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<CryptoAddress, ParseError>
[src]
Parses a string s
to return a value of this type. Read more