소스 검색

fix: mint info v1 enpoint

thesimplekid 1 년 전
부모
커밋
5493745675
3개의 변경된 파일33개의 추가작업 그리고 9개의 파일을 삭제
  1. 8 2
      crates/cashu-sdk/src/client/minreq_client.rs
  2. 1 0
      crates/cashu/src/nuts/nut00.rs
  3. 24 7
      crates/cashu/src/nuts/nut06.rs

+ 8 - 2
crates/cashu-sdk/src/client/minreq_client.rs

@@ -150,7 +150,10 @@ impl Client for HttpClient {
     /// Get Mint Info [NUT-09]
     /// Get Mint Info [NUT-09]
     #[cfg(feature = "nut09")]
     #[cfg(feature = "nut09")]
     async fn get_mint_info(&self, mint_url: Url) -> Result<MintInfo, Error> {
     async fn get_mint_info(&self, mint_url: Url) -> Result<MintInfo, Error> {
-        let url = join_url(mint_url, "info")?;
+        let url = join_url(mint_url, "v1")?;
+        let url = join_url(url, "info")?;
+
+        println!("{}", url);
 
 
         let res = minreq::get(url).send()?.json::<Value>()?;
         let res = minreq::get(url).send()?.json::<Value>()?;
 
 
@@ -158,7 +161,10 @@ impl Client for HttpClient {
 
 
         match response {
         match response {
             Ok(res) => Ok(res),
             Ok(res) => Ok(res),
-            Err(_) => Err(Error::from_json(&res.to_string())?),
+            Err(_) => {
+                println!("{:?}", response);
+                Err(Error::from_json(&res.to_string())?)
+            }
         }
         }
     }
     }
 }
 }

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

@@ -27,6 +27,7 @@ pub struct BlindedMessage {
 #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
 #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
 pub enum CurrencyUnit {
 pub enum CurrencyUnit {
     #[default]
     #[default]
+    #[serde(rename = "sat")]
     Sat,
     Sat,
     Custom(String),
     Custom(String),
 }
 }

+ 24 - 7
crates/cashu/src/nuts/nut06.rs

@@ -4,7 +4,7 @@
 use std::collections::HashMap;
 use std::collections::HashMap;
 
 
 use serde::{Deserialize, Deserializer, Serialize, Serializer};
 use serde::{Deserialize, Deserializer, Serialize, Serializer};
-use serde_json::Value;
+use serde_json::{Map, Value};
 
 
 use super::nut01::PublicKey;
 use super::nut01::PublicKey;
 use super::{nut04, nut05};
 use super::{nut04, nut05};
@@ -85,31 +85,35 @@ fn deserialize_nuts<'de, D>(deserializer: D) -> Result<HashMap<u8, NutSettings>,
 where
 where
     D: Deserializer<'de>,
     D: Deserializer<'de>,
 {
 {
-    let b: Vec<_> = Deserialize::deserialize(deserializer)?;
+    let b: Map<_, _> = Deserialize::deserialize(deserializer).unwrap();
 
 
-    let h: HashMap<u8, String> = HashMap::from_iter(b);
+    let h: HashMap<u8, Value> = b
+        .into_iter()
+        .map(|(v, k)| (v.parse().unwrap(), k))
+        .collect();
 
 
     let mut nuts: HashMap<u8, NutSettings> = HashMap::with_capacity(h.capacity());
     let mut nuts: HashMap<u8, NutSettings> = HashMap::with_capacity(h.capacity());
 
 
     for (num, nut) in h {
     for (num, nut) in h {
         let nut_settings = match num {
         let nut_settings = match num {
             4 => {
             4 => {
-                let settings: nut04::Settings = serde_json::from_str(&nut).unwrap();
+                let settings: nut04::Settings = serde_json::from_value(nut).unwrap();
 
 
                 NutSettings::Nut04(settings)
                 NutSettings::Nut04(settings)
             }
             }
             5 => {
             5 => {
-                let settings: nut05::Settings = serde_json::from_str(&nut).unwrap();
+                let settings: nut05::Settings = serde_json::from_value(nut).unwrap();
 
 
                 NutSettings::Nut05(settings)
                 NutSettings::Nut05(settings)
             }
             }
             7..=10 | 12 => {
             7..=10 | 12 => {
-                let settings: OptionalSettings = serde_json::from_str(&nut).unwrap();
+                println!("{}", nut);
+                let settings: OptionalSettings = serde_json::from_value(nut).unwrap();
 
 
                 NutSettings::Optional(settings)
                 NutSettings::Optional(settings)
             }
             }
             _ => {
             _ => {
-                let settings: Value = serde_json::from_str(&nut).unwrap();
+                let settings: Value = serde_json::from_value(nut).unwrap();
 
 
                 NutSettings::UnknownNut(settings)
                 NutSettings::UnknownNut(settings)
             }
             }
@@ -126,3 +130,16 @@ where
 pub struct OptionalSettings {
 pub struct OptionalSettings {
     supported: bool,
     supported: bool,
 }
 }
+
+#[cfg(test)]
+mod tests {
+
+    use super::*;
+
+    #[test]
+    fn test_mint_info() {
+        let mint_info = r#"{"name":"moksha-mint","pubkey":"02b3d8d8280b26f1223dc603a9b2a69618dc26821bef8ee22d419c44d710007cbc","version":"0.1.2","description":"mutiny signet mint v1 api","contact":[["[[email"],["ngutech21@pm.me]]"]],"nuts":{"4":{"methods":[["bolt11","sat"]],"disabled":false},"5":{"methods":[["bolt11","sat"]]},"6":{"supported":true},"7":{"supported":false},"8":{"supported":true},"9":{"supported":false},"10":{"supported":false},"11":{"supported":false},"12":{"supported":false}}}"#;
+
+        let _info: MintInfo = serde_json::from_str(mint_info).unwrap();
+    }
+}