Skip to content

Commit

Permalink
feat: implement nut-06 time
Browse files Browse the repository at this point in the history
  • Loading branch information
prusnak committed Sep 2, 2024
1 parent 1cd80de commit 773192c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
8 changes: 8 additions & 0 deletions bindings/cdk-js/src/nuts/nut06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl JsMintInfo {
nuts: JsValue,
mint_icon_url: Option<String>,
motd: Option<String>,
time: Option<u64>,
) -> Result<JsMintInfo> {
Ok(JsMintInfo {
inner: MintInfo {
Expand All @@ -92,6 +93,7 @@ impl JsMintInfo {
nuts: serde_wasm_bindgen::from_value(nuts).map_err(into_err)?,
mint_icon_url,
motd,
time,
},
})
}
Expand Down Expand Up @@ -152,6 +154,12 @@ impl JsMintInfo {
pub fn motd(&self) -> Option<String> {
self.inner.motd.clone()
}

/// Get time
#[wasm_bindgen(getter)]
pub fn time(&self) -> Option<u64> {
self.inner.time
}
}

#[wasm_bindgen(js_name = ContactInfo)]
Expand Down
2 changes: 1 addition & 1 deletion crates/cdk-axum/src/router_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ pub async fn post_check(
}

pub async fn get_mint_info(State(state): State<MintState>) -> Result<Json<MintInfo>, Response> {
Ok(Json(state.mint.mint_info().clone()))
Ok(Json(state.mint.mint_info().clone().time(unix_time())))
}

pub async fn post_swap(
Expand Down
3 changes: 3 additions & 0 deletions crates/cdk-sqlite/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use cdk::nuts::{
};
use cdk::secret::Secret;
use cdk::types::ProofInfo;
use cdk::util::unix_time;
use cdk::wallet;
use cdk::wallet::MintQuote;
use error::Error;
Expand Down Expand Up @@ -104,6 +105,7 @@ impl WalletDatabase for WalletSqliteDatabase {
nuts,
mint_icon_url,
motd,
time: _,
} = mint_info;

(
Expand Down Expand Up @@ -781,6 +783,7 @@ fn sqlite_row_to_mint_info(row: &SqliteRow) -> Result<MintInfo, Error> {
.unwrap_or_default(),
mint_icon_url,
motd,
time: Some(unix_time()),
})
}

Expand Down
14 changes: 14 additions & 0 deletions crates/cdk/src/nuts/nut06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// server unix timestamp
#[serde(skip_serializing_if = "Option::is_none")]
pub time: Option<u64>,
}

impl MintInfo {
Expand Down Expand Up @@ -170,6 +173,17 @@ impl MintInfo {
..self
}
}

/// Set time
pub fn time<S>(self, time: S) -> Self
where
S: Into<u64>,
{
Self {
time: Some(time.into()),
..self
}
}
}

/// Supported nuts and settings
Expand Down

0 comments on commit 773192c

Please sign in to comment.