diff --git a/bindings/cdk-js/src/nuts/nut06.rs b/bindings/cdk-js/src/nuts/nut06.rs index f88ea324..37e4f7cd 100644 --- a/bindings/cdk-js/src/nuts/nut06.rs +++ b/bindings/cdk-js/src/nuts/nut06.rs @@ -79,6 +79,7 @@ impl JsMintInfo { nuts: JsValue, mint_icon_url: Option, motd: Option, + time: Option, ) -> Result { Ok(JsMintInfo { inner: MintInfo { @@ -92,6 +93,7 @@ impl JsMintInfo { nuts: serde_wasm_bindgen::from_value(nuts).map_err(into_err)?, mint_icon_url, motd, + time, }, }) } @@ -152,6 +154,12 @@ impl JsMintInfo { pub fn motd(&self) -> Option { self.inner.motd.clone() } + + /// Get time + #[wasm_bindgen(getter)] + pub fn time(&self) -> Option { + self.inner.time + } } #[wasm_bindgen(js_name = ContactInfo)] diff --git a/crates/cdk-axum/src/router_handlers.rs b/crates/cdk-axum/src/router_handlers.rs index fe9cd333..1df73a92 100644 --- a/crates/cdk-axum/src/router_handlers.rs +++ b/crates/cdk-axum/src/router_handlers.rs @@ -392,7 +392,7 @@ pub async fn post_check( } pub async fn get_mint_info(State(state): State) -> Result, Response> { - Ok(Json(state.mint.mint_info().clone())) + Ok(Json(state.mint.mint_info().clone().time(unix_time()))) } pub async fn post_swap( diff --git a/crates/cdk-sqlite/src/wallet/migrations/20240902210905_mint_time.sql b/crates/cdk-sqlite/src/wallet/migrations/20240902210905_mint_time.sql new file mode 100644 index 00000000..7768dd30 --- /dev/null +++ b/crates/cdk-sqlite/src/wallet/migrations/20240902210905_mint_time.sql @@ -0,0 +1 @@ +ALTER TABLE mint ADD mint_time INTEGER; diff --git a/crates/cdk-sqlite/src/wallet/mod.rs b/crates/cdk-sqlite/src/wallet/mod.rs index dc483459..e55e18c5 100644 --- a/crates/cdk-sqlite/src/wallet/mod.rs +++ b/crates/cdk-sqlite/src/wallet/mod.rs @@ -92,6 +92,7 @@ impl WalletDatabase for WalletSqliteDatabase { nuts, mint_icon_url, motd, + time, ) = match mint_info { Some(mint_info) => { let MintInfo { @@ -104,6 +105,7 @@ impl WalletDatabase for WalletSqliteDatabase { nuts, mint_icon_url, motd, + time, } = mint_info; ( @@ -116,16 +118,17 @@ impl WalletDatabase for WalletSqliteDatabase { serde_json::to_string(&nuts).ok(), mint_icon_url, motd, + time, ) } - 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, mint_icon_url, motd) -VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?); +(mint_url, name, pubkey, version, description, description_long, contact, nuts, mint_icon_url, motd, mint_time) +VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); "#, ) .bind(mint_url.to_string()) @@ -138,6 +141,7 @@ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?); .bind(nuts) .bind(mint_icon_url) .bind(motd) + .bind(time.map(|v| v as i64)) .execute(&self.pool) .await .map_err(Error::from)?; @@ -771,6 +775,7 @@ fn sqlite_row_to_mint_info(row: &SqliteRow) -> Result { let row_nuts: Option = row.try_get("nuts").map_err(Error::from)?; let mint_icon_url: Option = row.try_get("mint_icon_url").map_err(Error::from)?; let motd: Option = row.try_get("motd").map_err(Error::from)?; + let time: Option = row.try_get("mint_time").map_err(Error::from)?; Ok(MintInfo { name, @@ -784,6 +789,7 @@ fn sqlite_row_to_mint_info(row: &SqliteRow) -> Result { .unwrap_or_default(), mint_icon_url, motd, + time: time.map(|t| t as u64), }) } diff --git a/crates/cdk/src/nuts/nut06.rs b/crates/cdk/src/nuts/nut06.rs index 19adcdb2..9346818f 100644 --- a/crates/cdk/src/nuts/nut06.rs +++ b/crates/cdk/src/nuts/nut06.rs @@ -79,6 +79,9 @@ pub struct MintInfo { /// message of the day that the wallet must display to the user #[serde(skip_serializing_if = "Option::is_none")] pub motd: Option, + /// server unix timestamp + #[serde(skip_serializing_if = "Option::is_none")] + pub time: Option, } impl MintInfo { @@ -170,6 +173,17 @@ impl MintInfo { ..self } } + + /// Set time + pub fn time(self, time: S) -> Self + where + S: Into, + { + Self { + time: Some(time.into()), + ..self + } + } } /// Supported nuts and settings