Skip to content

Commit

Permalink
Merge pull request #398 from prusnak/mint-info-urls
Browse files Browse the repository at this point in the history
NUT-06: add urls field
thesimplekid authored Nov 6, 2024
2 parents fbb77e6 + b507ce7 commit 479b4e7
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions bindings/cdk-js/src/nuts/nut06.rs
Original file line number Diff line number Diff line change
@@ -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,
},
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE mint ADD urls TEXT;
14 changes: 11 additions & 3 deletions crates/cdk-sqlite/src/wallet/mod.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions crates/cdk/src/nuts/nut06.rs
Original file line number Diff line number Diff line change
@@ -78,6 +78,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>,

0 comments on commit 479b4e7

Please sign in to comment.