瀏覽代碼

NUT-06: add urls field

Pavol Rusnak 5 月之前
父節點
當前提交
b507ce7201

+ 2 - 0
bindings/cdk-js/src/nuts/nut06.rs

@@ -78,6 +78,7 @@ impl JsMintInfo {
         contact: Option<Vec<JsContactInfo>>,
         nuts: JsValue,
         icon_url: Option<String>,
+        urls: Option<Vec<String>>,
         motd: Option<String>,
         time: Option<u64>,
     ) -> Result<JsMintInfo> {
@@ -92,6 +93,7 @@ impl JsMintInfo {
                     .map(|contacts| contacts.iter().map(|c| c.deref().clone()).collect()),
                 nuts: serde_wasm_bindgen::from_value(nuts).map_err(into_err)?,
                 icon_url,
+                urls,
                 motd,
                 time,
             },

+ 1 - 0
crates/cdk-sqlite/src/wallet/migrations/20241011125207_mint_urls.sql

@@ -0,0 +1 @@
+ALTER TABLE mint ADD urls TEXT;

+ 11 - 3
crates/cdk-sqlite/src/wallet/mod.rs

@@ -91,6 +91,7 @@ impl WalletDatabase for WalletSqliteDatabase {
             contact,
             nuts,
             icon_url,
+            urls,
             motd,
             time,
         ) = match mint_info {
@@ -104,6 +105,7 @@ impl WalletDatabase for WalletSqliteDatabase {
                     contact,
                     nuts,
                     icon_url,
+                    urls,
                     motd,
                     time,
                 } = mint_info;
@@ -117,18 +119,21 @@ impl WalletDatabase for WalletSqliteDatabase {
                     contact.map(|c| serde_json::to_string(&c).ok()),
                     serde_json::to_string(&nuts).ok(),
                     icon_url,
+                    urls.map(|c| serde_json::to_string(&c).ok()),
                     motd,
                     time,
                 )
             }
-            None => (None, None, None, None, None, None, None, None, None, None),
+            None => (
+                None, None, None, None, None, None, None, None, None, None, None,
+            ),
         };
 
         sqlx::query(
             r#"
 INSERT OR REPLACE INTO mint
-(mint_url, name, pubkey, version, description, description_long, contact, nuts, icon_url, motd, mint_time)
-VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
+(mint_url, name, pubkey, version, description, description_long, contact, nuts, icon_url, urls, motd, mint_time)
+VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
         "#,
         )
         .bind(mint_url.to_string())
@@ -140,6 +145,7 @@ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
         .bind(contact)
         .bind(nuts)
         .bind(icon_url)
+        .bind(urls)
         .bind(motd)
         .bind(time.map(|v| v as i64))
         .execute(&self.pool)
@@ -775,6 +781,7 @@ fn sqlite_row_to_mint_info(row: &SqliteRow) -> Result<MintInfo, Error> {
     let row_nuts: Option<String> = row.try_get("nuts").map_err(Error::from)?;
     let icon_url: Option<String> = row.try_get("icon_url").map_err(Error::from)?;
     let motd: Option<String> = row.try_get("motd").map_err(Error::from)?;
+    let row_urls: Option<String> = row.try_get("urls").map_err(Error::from)?;
     let time: Option<i64> = row.try_get("mint_time").map_err(Error::from)?;
 
     Ok(MintInfo {
@@ -788,6 +795,7 @@ fn sqlite_row_to_mint_info(row: &SqliteRow) -> Result<MintInfo, Error> {
             .and_then(|n| serde_json::from_str(&n).ok())
             .unwrap_or_default(),
         icon_url,
+        urls: row_urls.and_then(|c| serde_json::from_str(&c).ok()),
         motd,
         time: time.map(|t| t as u64),
     })

+ 3 - 0
crates/cdk/src/nuts/nut06.rs

@@ -76,6 +76,9 @@ pub struct MintInfo {
     /// Mint's icon URL
     #[serde(skip_serializing_if = "Option::is_none")]
     pub icon_url: Option<String>,
+    /// Mint's endpoint URLs
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub urls: Option<Vec<String>>,
     /// message of the day that the wallet must display to the user
     #[serde(skip_serializing_if = "Option::is_none")]
     pub motd: Option<String>,