From 90adb3f481f452eebfe1d53c85e9e1e138855cc3 Mon Sep 17 00:00:00 2001 From: Caleb Beery Date: Mon, 12 Aug 2024 15:44:26 -0700 Subject: [PATCH] feat: refactored functionality of handle_paid_invoice into mint. --- crates/cdk-mintd/src/main.rs | 16 ++-------------- crates/cdk/src/mint/mod.rs | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/crates/cdk-mintd/src/main.rs b/crates/cdk-mintd/src/main.rs index c67e3df7..74faeed4 100644 --- a/crates/cdk-mintd/src/main.rs +++ b/crates/cdk-mintd/src/main.rs @@ -370,20 +370,8 @@ async fn main() -> anyhow::Result<()> { /// Update mint quote when called for a paid invoice async fn handle_paid_invoice(mint: Arc, 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(()) } diff --git a/crates/cdk/src/mint/mod.rs b/crates/cdk/src/mint/mod.rs index 358d4e1e..0bcb53f5 100644 --- a/crates/cdk/src/mint/mod.rs +++ b/crates/cdk/src/mint/mod.rs @@ -286,6 +286,29 @@ 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(