Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored functionality of handle_paid_invoice into mint. #287

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions crates/cdk-mintd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;

use anyhow::{anyhow, Result};
use anyhow::{anyhow, Ok, Result};
use axum::Router;
use bip39::Mnemonic;
use cdk::cdk_database::{self, MintDatabase};
Expand Down Expand Up @@ -370,20 +370,7 @@ async fn main() -> anyhow::Result<()> {
/// Update mint quote when called for a paid invoice
async fn handle_paid_invoice(mint: Arc<Mint>, request_lookup_id: &str) -> Result<()> {
tracing::debug!("Invoice with lookup id paid: {}", request_lookup_id);
if let Ok(Some(mint_quote)) = mint
.localstore
.get_mint_quote_by_request_lookup_id(request_lookup_id)
.await
{
tracing::debug!(
"Quote {} paid by lookup id {}",
mint_quote.id,
request_lookup_id
);
mint.localstore
.update_mint_quote_state(&mint_quote.id, cdk::nuts::MintQuoteState::Paid)
.await?;
}
mint.pay_mint_quote_for_request_id(request_lookup_id).await?;
Ok(())
}

Expand Down
20 changes: 20 additions & 0 deletions crates/cdk/src/mint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,26 @@ impl Mint {
Ok(())
}

/// Flag mint quote as paid
#[instrument(skip_all)]
pub async fn pay_mint_quote_for_request_id(&self, request_lookup_id: &str) -> Result<(), Error>{
if let Ok(Some(mint_quote)) = self
.localstore
.get_mint_quote_by_request_lookup_id(request_lookup_id)
.await
{
tracing::debug!(
"Quote {} paid by lookup id {}",
mint_quote.id,
request_lookup_id
);
self.localstore
.update_mint_quote_state(&mint_quote.id, MintQuoteState::Paid)
.await?;
}
Ok(())
}

/// New melt quote
#[instrument(skip_all)]
pub async fn new_melt_quote(
Expand Down
Loading