impove: add payment method display

This commit is contained in:
thesimplekid
2023-12-17 22:59:49 +00:00
parent 08a8368f43
commit e76a8b9130

View File

@@ -15,11 +15,12 @@ use crate::Amount;
/// Blinded Message [NUT-00]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BlindedMessage {
/// Amount in satoshi
/// Amount
pub amount: Amount,
/// encrypted secret message (B_)
#[serde(rename = "B_")]
pub b: PublicKey,
/// Keyset Id
#[serde(rename = "id")]
pub keyset_id: Id,
}
@@ -33,12 +34,6 @@ pub enum CurrencyUnit {
Custom(String),
}
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone, Hash)]
#[serde(rename_all = "lowercase")]
pub enum PaymentMethod {
Bolt11,
}
impl FromStr for CurrencyUnit {
type Err = Error;
@@ -61,6 +56,34 @@ impl fmt::Display for CurrencyUnit {
}
}
#[derive(Default, Deserialize, Serialize, Debug, PartialEq, Eq, Clone, Hash)]
#[serde(rename_all = "lowercase")]
pub enum PaymentMethod {
#[default]
Bolt11,
Custom(String),
}
impl FromStr for PaymentMethod {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"bolt11" => Ok(Self::Bolt11),
_ => Ok(Self::Custom(s.to_string())),
}
}
}
impl fmt::Display for PaymentMethod {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PaymentMethod::Bolt11 => write!(f, "bolt11"),
PaymentMethod::Custom(unit) => write!(f, "{}", unit),
}
}
}
#[cfg(feature = "wallet")]
pub mod wallet {
use std::cmp::Ordering;