diff --git a/moksha-mint/src/database.rs b/moksha-mint/src/database.rs index 9e85ec28..b38ebbc4 100644 --- a/moksha-mint/src/database.rs +++ b/moksha-mint/src/database.rs @@ -185,6 +185,7 @@ mod tests { dhke, proof::{Proof, Proofs}, }; + use uuid::Uuid; use crate::{ database::Database, @@ -263,7 +264,7 @@ mod tests { let tmp_dir = tmp.path().to_str().expect("Could not create tmp dir"); let db = super::RocksDB::new(tmp_dir.to_owned()); - let quote = Quote::new("12345678".to_owned()); + let quote = Quote::new(Uuid::new_v4(), "12345678".to_owned()); let key = quote.quote_id.to_string(); db.add_quote(key.clone(), quote.clone())?; let lookup_quote = db.get_quote(key.to_string())?; diff --git a/moksha-mint/src/mint.rs b/moksha-mint/src/mint.rs index 8de916ee..d59f69f3 100644 --- a/moksha-mint/src/mint.rs +++ b/moksha-mint/src/mint.rs @@ -3,7 +3,7 @@ use std::{collections::HashSet, sync::Arc}; use moksha_core::{ blind::{BlindedMessage, BlindedSignature, TotalAmount}, dhke::Dhke, - keyset::{generate_hash, MintKeyset}, + keyset::MintKeyset, primitives::PostSplitResponse, proof::Proofs, }; @@ -102,9 +102,12 @@ impl Mint { Ok(promises) } - pub async fn create_invoice(&self, amount: u64) -> Result<(String, String), MokshaMintError> { + pub async fn create_invoice( + &self, + key: String, + amount: u64, + ) -> Result<(String, String), MokshaMintError> { let pr = self.lightning.create_invoice(amount).await?.payment_request; - let key = generate_hash(); self.db .add_pending_invoice(key.clone(), Invoice::new(amount, pr.clone()))?; Ok((pr, key)) diff --git a/moksha-mint/src/model.rs b/moksha-mint/src/model.rs index 695133bc..97f20087 100644 --- a/moksha-mint/src/model.rs +++ b/moksha-mint/src/model.rs @@ -54,9 +54,9 @@ pub struct Quote { } impl Quote { - pub fn new(payment_request: String) -> Self { + pub fn new(quote_id: Uuid, payment_request: String) -> Self { Self { - quote_id: Uuid::new_v4(), + quote_id, payment_request, } } diff --git a/moksha-mint/src/server.rs b/moksha-mint/src/server.rs index 0419c8f9..6dc94f01 100644 --- a/moksha-mint/src/server.rs +++ b/moksha-mint/src/server.rs @@ -10,7 +10,8 @@ use axum::response::IntoResponse; use axum::routing::{get_service, post}; use axum::{middleware, Router}; use axum::{routing::get, Json}; -use moksha_core::keyset::{Keysets, V1Keysets}; +use moksha_core::keyset::{generate_hash, Keysets, V1Keysets}; +use uuid::Uuid; use crate::mint::Mint; use crate::model::{GetMintQuery, PostMintQuery, Quote}; @@ -217,7 +218,9 @@ async fn get_legacy_mint( State(mint): State, Query(mint_query): Query, ) -> Result, MokshaMintError> { - let (pr, hash) = mint.create_invoice(mint_query.amount).await?; + let (pr, hash) = mint + .create_invoice(generate_hash(), mint_query.amount) + .await?; Ok(Json(PaymentRequest { pr, hash })) } @@ -272,12 +275,11 @@ async fn post_mint_quote_bolt11( Json(request): Json, ) -> Result, MokshaMintError> { // FIXME check currency unit - // FIXME use uuid to store invoice - let (pr, _hash) = mint.create_invoice(request.amount).await?; - + let key = Uuid::new_v4(); + let (pr, _hash) = mint.create_invoice(key.to_string(), request.amount).await?; let invoice = mint.lightning.decode_invoice(pr.clone()).await?; - let quote = Quote::new(pr.clone()); + let quote = Quote::new(key, pr.clone()); let quote_id = quote.quote_id.to_string(); mint.db.add_quote(quote_id.clone(), quote)?; @@ -299,7 +301,7 @@ async fn post_mint_bolt11( .ok_or_else(|| crate::error::MokshaMintError::InvalidQuote(request.quote.clone()))?; let signatures = mint - .mint_tokens(quote.payment_request.clone(), &request.outputs) + .mint_tokens(quote.quote_id.to_string(), &request.outputs) .await?; Ok(Json(PostMintBolt11Response { signatures })) }