[][src]Struct openalias::CryptoAddress

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.

Displaying 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

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.

Recipient's specified cryptocurrency address. Required.

Corresponds to recipient_address record key.

Recipient's specified user-friendlier name.

Corresponds to recipient_name record key.

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.

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.

"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.

"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.

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.

Set of K-Vs not special-cased above.

Trait Implementations

impl Clone for CryptoAddress
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Eq for CryptoAddress
[src]

impl PartialOrd<CryptoAddress> for CryptoAddress
[src]

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

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

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

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

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

impl PartialEq<CryptoAddress> for CryptoAddress
[src]

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

This method tests for !=.

impl Ord for CryptoAddress
[src]

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

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

impl Hash for CryptoAddress
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl Display for CryptoAddress
[src]

Formats the value using the given formatter. Read more

impl Debug for CryptoAddress
[src]

Formats the value using the given formatter. Read more

impl FromStr for CryptoAddress
[src]

The associated error which can be returned from parsing.

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

Auto Trait Implementations

impl Send for CryptoAddress

impl Sync for CryptoAddress

Blanket Implementations

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

Converts the given value to a String. Read more

impl<T> ToOwned for T where
    T: Clone
[src]

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 This is a nightly-only experimental API. (get_type_id)

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more