refactor: add PaymentType enum

This commit is contained in:
thesimplekid
2023-12-17 22:45:38 +00:00
parent bdb87dd4cd
commit 5d8f35c053
3 changed files with 13 additions and 4 deletions

View File

@@ -12,7 +12,7 @@ pub mod nut08;
#[cfg(feature = "wallet")]
pub use nut00::wallet::{PreMint, PreMintSecrets, Token};
pub use nut00::{BlindedMessage, BlindedSignature, CurrencyUnit, Proof};
pub use nut00::{BlindedMessage, BlindedSignature, CurrencyUnit, PaymentMethod, Proof};
pub use nut01::{Keys, KeysResponse, PublicKey, SecretKey};
pub use nut02::mint::KeySet as MintKeySet;
pub use nut02::{Id, KeySet, KeySetInfo, KeysetResponse};

View File

@@ -25,19 +25,27 @@ pub struct BlindedMessage {
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum CurrencyUnit {
#[default]
#[serde(rename = "sat")]
Sat,
Usd,
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;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"sat" => Ok(Self::Sat),
"usd" => Ok(Self::Usd),
_ => Ok(Self::Custom(s.to_string())),
}
}
@@ -47,6 +55,7 @@ impl fmt::Display for CurrencyUnit {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CurrencyUnit::Sat => write!(f, "sat"),
CurrencyUnit::Usd => write!(f, "usd"),
CurrencyUnit::Custom(unit) => write!(f, "{}", unit),
}
}

View File

@@ -2,7 +2,7 @@
// https://github.com/cashubtc/nuts/blob/main/04.md
use serde::{Deserialize, Serialize};
use super::{BlindedMessage, BlindedSignature, CurrencyUnit};
use super::{BlindedMessage, BlindedSignature, CurrencyUnit, PaymentMethod};
use crate::Amount;
/// Mint quote request [NUT-04]
@@ -55,6 +55,6 @@ pub struct MintBolt11Response {
/// Mint Settings
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Settings {
methods: Vec<(String, CurrencyUnit)>,
methods: Vec<(PaymentMethod, CurrencyUnit)>,
disabled: bool,
}