Skip to content

Commit

Permalink
fix: add missing paid flag to Bolt11Mint
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Dec 10, 2023
1 parent e0bd115 commit d473f8e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
25 changes: 24 additions & 1 deletion moksha-core/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,31 @@ pub struct PostMintQuoteBolt11Request {
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct PostMintQuoteBolt11Response {
pub quote: String,
pub request: String,
#[serde(rename = "request")]
pub payment_request: String,
pub paid: bool,
pub expiry: u64,
}
impl TryFrom<Quote> for PostMintQuoteBolt11Response {
type Error = &'static str;

fn try_from(quote: Quote) -> Result<Self, Self::Error> {
match quote {
Quote::Bolt11Mint {
quote_id,
payment_request,
expiry,
paid,
} => Ok(Self {
quote: quote_id.to_string(),
payment_request,
expiry,
paid,
}),
_ => Err("Invalid quote variant"),
}
}
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct PostMintBolt11Request {
Expand Down Expand Up @@ -189,6 +210,7 @@ pub enum Quote {
quote_id: Uuid,
payment_request: String,
expiry: u64,
paid: bool,
},
Bolt11Melt {
quote_id: Uuid,
Expand Down Expand Up @@ -222,6 +244,7 @@ impl TryFrom<Quote> for PostMeltQuoteBolt11Response {
}
}
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct PostMeltBolt11Request {
pub quote: String,
Expand Down
1 change: 1 addition & 0 deletions moksha-mint/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ mod tests {
quote_id: key,
payment_request: "12345678".to_owned(),
expiry: 12345678,
paid: false,
};

db.add_quote(key.to_string(), quote.clone())?;
Expand Down
1 change: 0 additions & 1 deletion moksha-mint/src/model.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Debug, Serialize, Deserialize)]
pub struct GetMintQuery {
Expand Down
39 changes: 21 additions & 18 deletions moksha-mint/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,14 @@ async fn post_mint_quote_bolt11(
quote_id: key,
payment_request: pr.clone(),
expiry, // FIXME check if this is correct
paid: false,
};

mint.db.add_quote(key.to_string(), quote)?;

Ok(Json(PostMintQuoteBolt11Response {
quote: key.to_string(),
request: pr,
payment_request: pr,
paid: false,
expiry,
}))
Expand Down Expand Up @@ -446,25 +447,27 @@ async fn get_mint_quote_bolt11(
info!("get_quote: {}", quote_id);
let quote = mint.db.get_quote(quote_id.clone())?;

match quote {
Quote::Bolt11Mint {
quote_id,
if let Quote::Bolt11Mint {
quote_id,
payment_request,
expiry,
..
} = quote
{
let paid = mint
.lightning
.is_invoice_paid(payment_request.clone())
.await?;

//FIXME
Ok(Json(PostMintQuoteBolt11Response {
quote: quote_id.to_string(),
payment_request,
paid,
expiry,
} => {
let paid = mint
.lightning
.is_invoice_paid(payment_request.clone())
.await?;

Ok(Json(PostMintQuoteBolt11Response {
quote: quote_id.to_string(),
request: payment_request,
paid,
expiry,
}))
}
_ => Err(crate::error::MokshaMintError::InvalidQuote(quote_id)),
}))
} else {
Err(crate::error::MokshaMintError::InvalidQuote(quote_id))
}
}

Expand Down

0 comments on commit d473f8e

Please sign in to comment.