Skip to content

Commit

Permalink
fix: use absolute expiry date in quote
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Dec 16, 2023
1 parent 4f4e8f3 commit 5ffcc72
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
30 changes: 14 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions moksha-mint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 10 additions & 11 deletions moksha-mint/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(&quote).await?;

Ok(Json(PostMintQuoteBolt11Response {
quote: key.to_string(),
payment_request: pr,
paid: false,
expiry,
}))
Ok(Json(quote.into()))
}

#[utoipa::path(
Expand Down Expand Up @@ -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,
};
Expand All @@ -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",
Expand Down

0 comments on commit 5ffcc72

Please sign in to comment.