Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
fix: total spent amoun
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Feb 5, 2024
1 parent edecf98 commit 4dbde80
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 23 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -256,8 +256,6 @@ async fn get_mint_bolt11_quote(
)
.await;

println!("Invoice {:?}", invoice);

let invoice = invoice.unwrap();

let quote = state
Expand Down Expand Up @@ -347,12 +345,31 @@ async fn post_melt_bolt11(
State(state): State<MintState>,
Json(payload): Json<MeltBolt11Request>,
) -> Result<Json<MeltBolt11Response>, 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(&quote.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();

Expand Down

0 comments on commit 4dbde80

Please sign in to comment.