From 5ffcc72a3dfa9896ec4d418fd332d8609624952a Mon Sep 17 00:00:00 2001 From: ngutech21 Date: Sat, 16 Dec 2023 07:48:53 +0100 Subject: [PATCH] fix: use absolute expiry date in quote --- Cargo.lock | 30 ++++++++++++++---------------- moksha-mint/Cargo.toml | 1 + moksha-mint/src/server.rs | 21 ++++++++++----------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9f26a5f6..af7d1cb2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -712,9 +712,9 @@ dependencies = [ [[package]] name = "const-oid" -version = "0.9.5" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "core-foundation" @@ -1875,11 +1875,11 @@ dependencies = [ [[package]] name = "home" -version = "0.5.5" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -2723,6 +2723,7 @@ dependencies = [ "async-trait", "axum 0.7.2", "bitcoin_hashes 0.12.0", + "chrono", "dotenvy", "envy", "fedimint-tonic-lnd", @@ -4063,8 +4064,6 @@ dependencies = [ "once_cell", "paste", "percent-encoding", - "rustls 0.21.10", - "rustls-pemfile", "serde", "serde_json", "sha2", @@ -4076,7 +4075,6 @@ dependencies = [ "tracing", "url", "uuid", - "webpki-roots 0.25.3", ] [[package]] @@ -4359,18 +4357,18 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" dependencies = [ "proc-macro2", "quote", @@ -5259,18 +5257,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.30" +version = "0.7.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "306dca4455518f1f31635ec308b6b3e4eb1b11758cefafc782827d0aa7acb5c7" +checksum = "1c4061bedbb353041c12f413700357bec76df2c7e2ca8e4df8bac24c6bf68e3d" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.30" +version = "0.7.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be912bf68235a88fbefd1b73415cb218405958d1655b2ece9035a19920bdf6ba" +checksum = "b3c129550b3e6de3fd0ba67ba5c81818f9805e58b8d7fee80a3a59d2c9fc601a" dependencies = [ "proc-macro2", "quote", diff --git a/moksha-mint/Cargo.toml b/moksha-mint/Cargo.toml index ec35c697..1b490fc9 100644 --- a/moksha-mint/Cargo.toml +++ b/moksha-mint/Cargo.toml @@ -46,6 +46,7 @@ uuid = { version = "1.6.1", features = ["serde", "v4"] } utoipa = { version = "4.1.0", features = ["axum_extras"] } utoipa-swagger-ui = { version = "5.0.0", features = ["axum"] } sqlx = { version = "0.7.3", default-features = false, features = ["postgres", "runtime-tokio", "tls-native-tls", "migrate", "macros", "uuid"] } +chrono = "0.4.31" [dev-dependencies] tempfile = "3.8.1" diff --git a/moksha-mint/src/server.rs b/moksha-mint/src/server.rs index 360a7a2b..e679c414 100644 --- a/moksha-mint/src/server.rs +++ b/moksha-mint/src/server.rs @@ -11,6 +11,7 @@ use axum::response::IntoResponse; use axum::routing::{get_service, post}; use axum::{middleware, Router}; use axum::{routing::get, Json}; +use chrono::{Duration, Utc}; use moksha_core::keyset::{generate_hash, Keysets, V1Keyset, V1Keysets}; use moksha_core::proof::Proofs; use moksha_core::proof::{P2SHScript, Proof}; @@ -426,24 +427,16 @@ async fn post_mint_quote_bolt11( // FIXME check currency unit let key = Uuid::new_v4(); let (pr, _hash) = mint.create_invoice(key.to_string(), request.amount).await?; - let invoice = mint.lightning.decode_invoice(pr.clone()).await?; - let expiry = invoice.expiry_time().as_secs(); let quote = Bolt11MintQuote { quote_id: key, payment_request: pr.clone(), - expiry, // FIXME check if this is correct + expiry: quote_expiry(), // FIXME use timestamp type in DB paid: false, }; mint.db.add_bolt11_mint_quote("e).await?; - - Ok(Json(PostMintQuoteBolt11Response { - quote: key.to_string(), - payment_request: pr, - paid: false, - expiry, - })) + Ok(Json(quote.into())) } #[utoipa::path( @@ -507,7 +500,7 @@ async fn post_melt_quote_bolt11( quote_id: key, amount: amount_sat, fee_reserve, - expiry: invoice.expiry_time().as_secs(), // FIXME check if this is correct + expiry: quote_expiry(), payment_request: melt_request.request.clone(), paid: false, }; @@ -518,6 +511,12 @@ async fn post_melt_quote_bolt11( })?)) } +fn quote_expiry() -> u64 { + // FIXME add config option for expiry + let now = Utc::now() + Duration::minutes(30); + now.timestamp() as u64 +} + #[utoipa::path( post, path = "/v1/melt/bolt11",