Skip to content

Commit

Permalink
feat: get mint quote status
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Dec 5, 2023
1 parent 71ff188 commit ba6e007
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion moksha-mint/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::net::SocketAddr;
use std::path::PathBuf;

use crate::error::MokshaMintError;
use axum::extract::{Query, Request, State};
use axum::extract::{Path, Query, Request, State};
use axum::http::{HeaderName, HeaderValue, StatusCode};
use axum::middleware::Next;
use axum::response::IntoResponse;
Expand Down Expand Up @@ -85,6 +85,7 @@ fn app(mint: Mint, serve_wallet_path: Option<PathBuf>, prefix: Option<String>) -
.route("/v1/keys", get(get_keys))
.route("/v1/keysets", get(get_keysets))
.route("/v1/mint/quote/bolt11", post(post_mint_quote_bolt11))
.route("/v1/mint/quote/bolt11/:quote_id", get(get_mint_quote))
.route("/v1/mint/bolt11", post(post_mint_bolt11))
.route("/v1/melt/quote/bolt11", post(post_melt_quote_bolt11))
.route("/v1/melt/bolt11", post(post_melt_bolt11))
Expand Down Expand Up @@ -271,6 +272,7 @@ async fn post_mint_quote_bolt11(
Json(request): Json<PostMintQuoteBolt11Request>,
) -> Result<Json<PostMintQuoteBolt11Response>, MokshaMintError> {
// FIXME check currency unit
// FIXME use uuid to store invoice
let (pr, _hash) = mint.create_invoice(request.amount).await?;

let invoice = mint.lightning.decode_invoice(pr.clone()).await?;
Expand Down Expand Up @@ -339,6 +341,31 @@ async fn post_melt_bolt11(
}))
}

async fn get_mint_quote(
Path(quote_id): Path<String>,
State(mint): State<Mint>,
) -> Result<Json<PostMintQuoteBolt11Response>, MokshaMintError> {
info!("get_quote: {}", quote_id);
let quote = mint.db.get_quote(quote_id.clone())?;

let invoice = mint
.lightning
.decode_invoice(quote.payment_request.clone())
.await?;

let is_paid = mint
.lightning
.is_invoice_paid(quote.payment_request.clone())
.await?;

Ok(Json(PostMintQuoteBolt11Response {
quote: quote_id,
request: quote.payment_request,
paid: is_paid,
expiry: invoice.expiry_time().as_secs(), // FIXME check if this is correct
}))
}

#[cfg(test)]
mod tests {
use std::{collections::HashMap, sync::Arc};
Expand Down

0 comments on commit ba6e007

Please sign in to comment.