diff --git a/Cargo.toml b/Cargo.toml index 3f4e8a7a..8ca46204 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ default = ["experimental", "taproot"] amplify = "3" base58-monero = { version = "0.3", default-features = false, features = ["check"] } bitvec = { version = "1.0" } +clap = { version = "3", features = ["derive"] } fixed-hash = { version = "0.7", default-features = false } hex = "0.4" inet2_addr = { version = "0.6", default-features = false, features = ["tor", "strict_encoding", "serde"] } diff --git a/src/blockchain.rs b/src/blockchain.rs index 6e61ebf6..117fa093 100644 --- a/src/blockchain.rs +++ b/src/blockchain.rs @@ -10,18 +10,47 @@ use std::fmt::{self, Debug, Display}; use std::io; use std::str::FromStr; +use strict_encoding::{StrictDecode, StrictEncode}; use thiserror::Error; use crate::consensus::{self, deserialize, serialize, CanonicalBytes, Decodable, Encodable}; use crate::transaction::{Buyable, Cancelable, Fundable, Lockable, Punishable, Refundable}; -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Display, Serialize, Deserialize)] +/// The list of supported blockchains (coins) by this library. +#[derive( + Debug, + Clone, + Copy, + Hash, + PartialEq, + Eq, + Parser, + Display, + Serialize, + Deserialize, + StrictEncode, + StrictDecode, +)] #[display(Debug)] pub enum Blockchain { + /// The Bitcoin (BTC) blockchain. Bitcoin, + /// The Monero (XMR) blockchain. Monero, } +impl FromStr for Blockchain { + type Err = consensus::Error; + + fn from_str(s: &str) -> Result { + match s { + "Bitcoin" | "bitcoin" | "btc" | "BTC" => Ok(Blockchain::Bitcoin), + "Monero" | "monero" | "xmr" | "XMR" => Ok(Blockchain::Monero), + _ => Err(consensus::Error::UnknownType), + } + } +} + impl Decodable for Blockchain { fn consensus_decode(d: &mut D) -> Result { match Decodable::consensus_decode(d)? { diff --git a/src/lib.rs b/src/lib.rs index 4707e6d3..ff9eb867 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,6 +60,9 @@ extern crate amplify; #[macro_use] extern crate serde; +#[macro_use] +extern crate clap; + use thiserror::Error; #[macro_use]