diff --git a/Cargo.lock b/Cargo.lock index a56fc323..21308ae6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2646,6 +2646,7 @@ dependencies = [ "serde_with", "thiserror", "url", + "uuid", ] [[package]] diff --git a/moksha-mint/src/database.rs b/moksha-mint/src/database.rs index eefbb28d..522d7f52 100644 --- a/moksha-mint/src/database.rs +++ b/moksha-mint/src/database.rs @@ -1,13 +1,10 @@ use std::{collections::HashMap, sync::Arc}; -use moksha_core::proof::Proofs; +use moksha_core::{primitives::Quote, proof::Proofs}; use rocksdb::DB; use serde::{de::DeserializeOwned, Serialize}; -use crate::{ - error::MokshaMintError, - model::{Invoice, Quote}, -}; +use crate::{error::MokshaMintError, model::Invoice}; #[cfg(test)] use mockall::automock; @@ -183,14 +180,12 @@ mod tests { use moksha_core::{ dhke, + primitives::Quote, proof::{Proof, Proofs}, }; use uuid::Uuid; - use crate::{ - database::Database, - model::{Invoice, Quote}, - }; + use crate::{database::Database, model::Invoice}; #[test] fn test_write_proofs() -> anyhow::Result<()> { diff --git a/moksha-mint/src/model.rs b/moksha-mint/src/model.rs index 9ece6572..d588c555 100644 --- a/moksha-mint/src/model.rs +++ b/moksha-mint/src/model.rs @@ -48,19 +48,3 @@ pub struct CreateInvoiceParams { pub webhook: Option, pub internal: Option, } - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -pub enum Quote { - Bolt11Mint { - quote_id: Uuid, - payment_request: String, - expiry: u64, - }, - Bolt11Melt { - quote_id: Uuid, - amount: u64, - fee_reserve: u64, - payment_request: String, - expiry: u64, - }, -} diff --git a/moksha-mint/src/server.rs b/moksha-mint/src/server.rs index 007b4ffa..569bdc5b 100644 --- a/moksha-mint/src/server.rs +++ b/moksha-mint/src/server.rs @@ -14,14 +14,14 @@ use moksha_core::keyset::{generate_hash, Keysets, V1Keysets}; use uuid::Uuid; use crate::mint::Mint; -use crate::model::{GetMintQuery, PostMintQuery, Quote}; +use crate::model::{GetMintQuery, PostMintQuery}; use moksha_core::primitives::{ CheckFeesRequest, CheckFeesResponse, CurrencyUnit, KeyResponse, KeysResponse, MintInfoNut, MintInfoResponse, MintLegacyInfoResponse, PaymentMethod, PaymentRequest, PostMeltBolt11Request, PostMeltBolt11Response, PostMeltQuoteBolt11Request, PostMeltQuoteBolt11Response, PostMeltRequest, PostMeltResponse, PostMintBolt11Request, PostMintBolt11Response, PostMintQuoteBolt11Request, PostMintQuoteBolt11Response, PostMintRequest, PostMintResponse, - PostSplitRequest, PostSplitResponse, PostSwapRequest, PostSwapResponse, + PostSplitRequest, PostSplitResponse, PostSwapRequest, PostSwapResponse, Quote, }; use secp256k1::PublicKey; @@ -376,7 +376,6 @@ async fn post_melt_quote_bolt11( info!("fee_reserve: {}", fee_reserve); let amount_sat = amount / 1_000; - // Store quote in db let key = Uuid::new_v4(); let quote = Quote::Bolt11Melt { quote_id: key, @@ -384,17 +383,13 @@ async fn post_melt_quote_bolt11( fee_reserve, expiry: invoice.expiry_time().as_secs(), // FIXME check if this is correct payment_request: melt_request.request.clone(), + paid: false, }; - mint.db.add_quote(key.to_string(), quote)?; + mint.db.add_quote(key.to_string(), quote.clone())?; // FIXME get rid of clone - // TODO implement into for Quote - Ok(Json(PostMeltQuoteBolt11Response { - amount: amount_sat, - fee_reserve, - quote: key.to_string(), - paid: false, - expiry: invoice.expiry_time().as_secs(), // FIXME check if this is correct - })) + Ok(Json(quote.try_into().map_err(|_| { + crate::error::MokshaMintError::InvalidQuote("".to_string()) + })?)) } async fn post_melt_bolt11( @@ -405,16 +400,32 @@ async fn post_melt_bolt11( match quote { Quote::Bolt11Melt { - payment_request, .. + quote_id, + payment_request, + amount, + expiry, + fee_reserve, + .. } => { let (paid, payment_preimage, change) = mint .melt( - payment_request, + payment_request.to_owned(), &melt_request.inputs, &melt_request.outputs, &mint.keyset, ) .await?; + let updated_quote = Quote::Bolt11Melt { + quote_id, + amount, + fee_reserve, + expiry, + payment_request, + paid, + }; + // FIXME simplify code + + mint.db.add_quote(quote_id.to_string(), updated_quote)?; Ok(Json(PostMeltBolt11Response { paid,