1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
//! Look up and parse [OpenAlias](https://openalias.org) data.
//!
//! # openalias.rs as а library
//!
//! This library can be used on a couple different levels (basic->high-level):
//!
//! 1. Parsing/validating OpenAlias "names" (e.g. "donate@getmonero.org", "nabijaczleweli.xyz")
//! 2. Parsing/validating OpenAlias records (e.g. "oa1:btc recipient_address=1KTexdemPdxSBcG55heUuTjDRYqbC5ZL8H;
//! recipient_name=Monero Development; tx_description=Donation to Monero Core Team;")
//! 3. Looking up OpenAliases with the DNS (e.g. "donate.nabijaczleweli.xyz" -> `CryptoAddress`)
//!
//! In that order, examples:
//!
//! ```
//! // Normally a user would type this in.
//! let address = "donate@getmonero.org";
//!
//! if let Some(fqdn) = openalias::alias_to_fqdn(address) {
//!     println!("{} maps to {}", address, fqdn);
//! #   assert_eq!(fqdn, "donate.getmonero.org.");
//! } else {
//!     // Address is not an OpenAlias
//! #   assert!(false);
//! }
//! ```
//!
//! Consult the [`alias_to_fqdn()`](fn.alias_to_fqdn.html) documentation for more information and examples.
//!
//! ```
//! # use std::collections::BTreeMap;
//! let record = "oa1:btc recipient_address=1KTexdemPdxSBcG55heUuTjDRYqbC5ZL8H; \
//!                       recipient_name=Monero Development; \
//!                       tx_description=Donation to Monero Core Team;";
//!
//! match record.parse::<openalias::CryptoAddress>() {
//!     Ok(ca) => {
//!         println!("{} address: {}", ca.cryptocurrency.to_uppercase(), ca.address);
//!         // Probably also handle more fields
//! #       assert_eq!(ca, openalias::CryptoAddress {
//! #           cryptocurrency: "btc".to_string(),
//! #           address: "1KTexdemPdxSBcG55heUuTjDRYqbC5ZL8H".to_string(),
//! #           recipient_name: Some("Monero Development".to_string()),
//! #           tx_description: Some("Donation to Monero Core Team".to_string()),
//! #           tx_amount: None,
//! #           tx_payment_id: None,
//! #           address_signature: None,
//! #           checksum: None,
//! #           additional_values: BTreeMap::new(),
//! #       });
//!     }
//!     Err(err) => {
//!         // The record is not an OpenAlias record,
//!         //   see err variable so as to the position of failure.
//! #       assert!(false);
//!     }
//! }
//! ```
//!
//! Consult the [`CryptoAddress`](struct.CryptoAddress.html) documentation for more information and examples.
//!
//! ```
//! # use std::collections::BTreeMap;
//! // Normally a user would type this in.
//! let alias = "donate.nabijaczleweli.xyz";
//!
//! match openalias::address_strings(alias) {
//!     Ok(cas) => {
//!         println!("{} addresses", cas.len());
//!         // cas contains "oa1:"-prefixed records
//! #       assert_eq!(cas, vec!["oa1:btc recipient_address=1CgLs6CxXMAY4Pj4edQq5vyaFoP9NdqVKH; recipient_name=nabijaczleweli; \
//! #                                      tx_description=Donation to nabijaczleweli;"]);
//!     }
//!     Err(err) => {
//!         // alias isn't an OpenAlias, or there was an error talking with a DNS server
//! #       assert!(false);
//!     }
//! }
//!
//! match openalias::addresses(alias) {
//!     Ok(cas) => {
//!         println!("{} addresses", cas.len());
//!         // cas contains CryptoAddresses
//! #       assert_eq!(cas, vec![openalias::CryptoAddress {
//! #           cryptocurrency: "btc".to_string(),
//! #           address: "1CgLs6CxXMAY4Pj4edQq5vyaFoP9NdqVKH".to_string(),
//! #           recipient_name: Some("nabijaczleweli".to_string()),
//! #           tx_description: Some("Donation to nabijaczleweli".to_string()),
//! #           tx_amount: None,
//! #           tx_payment_id: None,
//! #           address_signature: None,
//! #           checksum: None,
//! #           additional_values: BTreeMap::new(),
//! #       }]);
//!     }
//!     Err(err) => {
//!         // alias isn't an OpenAlias,
//!         //   or there was an error talking with a DNS server,
//!         //   or an "oa1:"-prefixed record isn't an OpenAlias record.
//! #       assert!(false);
//!     }
//! }
//! ```
//!
//! Consult the [`address_strings()`](fn.address_strings.html) and [`addresses()`](fn.addresses.html)
//! documentation for more information and examples.
//!
//! # openalias.rs as аn executable
//!
//! This is just a very short synopsis of
//! [the manpage](https://cdn.rawgit.com/nabijaczleweli/openalias.rs/man/openalias.1.html),
//! so consult that for more data.
//!
//! ## OPTIONS
//!
//! | Option                   | Description                                           |
//! |--------------------------|-------------------------------------------------------|
//! | &lt;OPEN_ALIAS&gt;...    | FQDN or email-style aliases to look up addresses for. |
//! | --verbose                | Print more data about what's happenning to stderr.    |
//! | --raw                    | Print just the record text.                           |
//! | --currency=[CURRENCY]... | Limit results to specified currencies.                |
//!
//! ## EXAMPLES
//!
//! `openalias nabijaczleweli.xyz donate.getmonero.org`
//!
//! ```text
//! Addresses of nabijaczleweli.xyz:
//!   btc:
//!     nabijaczleweli
//!     1CgLs6CxXMAY4Pj4edQq5vyaFoP9NdqVKH
//!
//! Addresses of donate.getmonero.org:
//!   xmr:
//!     Monero Development
//!     44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3
//!       XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A
//!     Donation to Monero Core Team
//!   btc:
//!     Monero Development
//!     1KTexdemPdxSBcG55heUuTjDRYqbC5ZL8H
//!     Donation to Monero Core Team
//! ```
//!
//! `openalias -rv nabijaczleweli.xyz donate@getmonero.org`
//!
//! ```text
//! Looking up nabijaczleweli.xyz...
//! Addresses for nabijaczleweli.xyz:
//!   oa1:btc recipient_address=1CgLs6CxXMAY4Pj4edQq5vyaFoP9NdqVKH; recipient_name=nabijaczleweli;
//!
//! Looking up donate@getmonero.org...
//! Addresses for donate@getmonero.org:
//!   oa1:xmr recipient_address=44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3
//!                               XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A;
//!           recipient_name=Monero Development; tx_description=Donation to Monero Core Team;
//!   oa1:btc recipient_address=1KTexdemPdxSBcG55heUuTjDRYqbC5ZL8H; recipient_name=Monero Development;
//!           tx_description=Donation to Monero Core Team;
//! ```
//!
//! `openalias -cxmr -c doge nabijaczleweli.xyz donate.getmonero.org`
//!
//! ```text
//! No xmr, nor doge addresses found for nabijaczleweli.xyz.
//!
//! Addresses of donate.getmonero.org:
//!   xmr:
//!     Monero Development
//!     44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3
//!       XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A
//!     Donation to Monero Core Team
//! ```


extern crate resolve;
#[macro_use]
extern crate clap;
extern crate crc;

mod error;
mod grammar;
mod address;
mod options;
mod resolving;
mod crypto_addr;

pub use self::error::Error;
pub use self::options::Options;
pub use self::grammar::ParseError;
pub use self::address::alias_to_fqdn;
pub use self::crypto_addr::CryptoAddress;
pub use self::resolving::{address_strings, addresses};