From 4dbde804668f8e5145886a24bc1de81dbddf37b5 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Mon, 5 Feb 2024 22:38:06 +0000 Subject: [PATCH] fix: total spent amoun --- Cargo.lock | 2 -- Cargo.toml | 4 ++-- src/main.rs | 29 +++++++++++++++++++++++------ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6852f87..e566cb5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -398,7 +398,6 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cashu" version = "0.4.1-ALPHA" -source = "git+https://github.com/thesimplekid/cashu-crab?rev=be2b51b#be2b51b25a508f1e85486b0d65dbd48186c0606b" dependencies = [ "base64 0.21.4", "bip32", @@ -457,7 +456,6 @@ dependencies = [ [[package]] name = "cashu-sdk" version = "0.1.0" -source = "git+https://github.com/thesimplekid/cashu-crab?rev=be2b51b#be2b51b25a508f1e85486b0d65dbd48186c0606b" dependencies = [ "async-trait", "bip39", diff --git a/Cargo.toml b/Cargo.toml index 4355567..196edbf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,8 +33,8 @@ time = "0.3.22" chrono = "0.4.26" clap = { version = "4.3.14", features = ["env", "default", "derive"]} anyhow = "1.0.71" -cashu-sdk = { git = "https://github.com/thesimplekid/cashu-crab", rev = "be2b51b", default-features = false, features = ["mint", "all-nuts", "redb"] } -# cashu-sdk = { path = "../cashu-crab/main/crates/cashu-sdk", default-features = false, features = ["mint", "all-nuts", "redb"] } +# cashu-sdk = { git = "https://github.com/thesimplekid/cashu-crab", rev = "be2b51b", default-features = false, features = ["mint", "all-nuts", "redb"] } +cashu-sdk = { path = "../cashu-crab/main/crates/cashu-sdk", default-features = false, features = ["mint", "all-nuts", "redb"] } bitcoin = { version = "0.30.0", features = ["no-std"] } serde = "1.0.164" serde_json = "1.0.96" diff --git a/src/main.rs b/src/main.rs index f4c2af5..50f9de6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ use cashu_sdk::nuts::{ use cashu_sdk::types::MintQuote; use clap::Parser; use futures::StreamExt; -use ln_rs::Ln; +use ln_rs::{Bolt11Invoice, Ln}; use tokio::sync::Mutex; use tower_http::cors::CorsLayer; use tracing::{debug, warn}; @@ -160,7 +160,7 @@ async fn main() -> anyhow::Result<()> { get(get_check_mint_bolt11_quote), ) .route("/v1/mint/bolt11", post(post_mint_bolt11)) - .route("/v1/melt/quote/bolt11", get(get_melt_bolt11_quote)) + .route("/v1/melt/quote/bolt11", post(get_melt_bolt11_quote)) .route( "/v1/melt/quote/bolt11/:quote_id", get(get_check_melt_bolt11_quote), @@ -256,8 +256,6 @@ async fn get_mint_bolt11_quote( ) .await; - println!("Invoice {:?}", invoice); - let invoice = invoice.unwrap(); let quote = state @@ -347,12 +345,31 @@ async fn post_melt_bolt11( State(state): State, Json(payload): Json, ) -> Result, StatusCode> { - let preimage = ""; + let quote = state + .mint + .lock() + .await + .verify_melt_request(&payload) + .await + .map_err(|_| StatusCode::NOT_ACCEPTABLE)?; + + let pre = state + .ln + .ln_processor + .pay_invoice(Bolt11Invoice::from_str("e.request).unwrap(), None) + .await + .unwrap(); + + let preimage = pre.payment_preimage; let res = state .mint .lock() .await - .process_melt_request(&payload, preimage, Amount::ZERO) + .process_melt_request( + &payload, + &preimage.unwrap(), + Amount::from(pre.total_spent.to_sat()), + ) .await .unwrap();