Przeglądaj źródła

refactor: add PaymentType enum

thesimplekid 1 rok temu
rodzic
commit
5d8f35c053

+ 1 - 1
crates/cashu/src/nuts/mod.rs

@@ -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};

+ 10 - 1
crates/cashu/src/nuts/nut00.rs

@@ -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),
         }
     }

+ 2 - 2
crates/cashu/src/nuts/nut04.rs

@@ -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,
 }