use std::convert::TryFrom;
use std::str::FromStr;
use farcaster_core::{blockchain::Blockchain, consensus};
use strict_encoding::{StrictDecode, StrictEncode};
#[derive(
Debug,
Clone,
Copy,
Hash,
PartialEq,
Eq,
Parser,
Display,
Serialize,
Deserialize,
StrictEncode,
StrictDecode,
)]
#[serde(crate = "serde_crate")]
#[display(Debug)]
pub enum ArbitratingBlockchain {
Bitcoin,
}
impl FromStr for ArbitratingBlockchain {
type Err = consensus::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Bitcoin" | "bitcoin" | "btc" | "BTC" => Ok(ArbitratingBlockchain::Bitcoin),
_ => Err(consensus::Error::UnknownType),
}
}
}
impl From<ArbitratingBlockchain> for Blockchain {
fn from(val: ArbitratingBlockchain) -> Self {
match val {
ArbitratingBlockchain::Bitcoin => Blockchain::Bitcoin,
}
}
}
impl TryFrom<Blockchain> for ArbitratingBlockchain {
type Error = consensus::Error;
fn try_from(blockchain: Blockchain) -> Result<Self, Self::Error> {
match blockchain {
Blockchain::Bitcoin => Ok(ArbitratingBlockchain::Bitcoin),
_ => Err(consensus::Error::TypeMismatch),
}
}
}
#[derive(
Debug,
Clone,
Copy,
Hash,
PartialEq,
Eq,
Parser,
Display,
Serialize,
Deserialize,
StrictEncode,
StrictDecode,
)]
#[serde(crate = "serde_crate")]
#[display(Debug)]
pub enum AccordantBlockchain {
Monero,
}
impl FromStr for AccordantBlockchain {
type Err = consensus::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Monero" | "monero" | "xmr" | "XMR" => Ok(AccordantBlockchain::Monero),
_ => Err(consensus::Error::UnknownType),
}
}
}
impl From<AccordantBlockchain> for Blockchain {
fn from(val: AccordantBlockchain) -> Self {
match val {
AccordantBlockchain::Monero => Blockchain::Monero,
}
}
}
impl TryFrom<Blockchain> for AccordantBlockchain {
type Error = consensus::Error;
fn try_from(blockchain: Blockchain) -> Result<Self, Self::Error> {
match blockchain {
Blockchain::Monero => Ok(AccordantBlockchain::Monero),
_ => Err(consensus::Error::TypeMismatch),
}
}
}