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

Commit

Permalink
feat: mpp
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Jun 10, 2024
1 parent c6da2a1 commit 57b8e92
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ time = "0.3.22"
chrono = "0.4.26"
clap = { version = "4.3.14", features = ["env", "default", "derive"]}
anyhow = "1.0.71"
cdk = { git = "https://github.com/cashubtc/cdk", rev = "e1506c4", default-features = false, features = ["mint"] }
cdk-redb = { git = "https://github.com/cashubtc/cdk", rev = "e1506c4", default-features = false, features = ["mint"] }
cdk-sqlite = { git = "https://github.com/cashubtc/cdk", rev = "e1506c4", default-features = false, features = ["mint"] }
# cdk-sqlite = { path = "../../cdk/sql/crates/cdk-sqlite", default-features = false, features = ["mint"] }
# cdk-redb = { path = "../../cdk/nut14/crates/cdk-redb", default-features = false, features = ["mint"] }

# cdk = { git = "https://github.com/cashubtc/cdk", rev = "1cc3fa7", default-features = false, features = ["mint"] }
# cdk-redb = { git = "https://github.com/cashubtc/cdk", rev = "1cc3fa7", default-features = false, features = ["mint"] }
# cdk-sqlite = { git = "https://github.com/cashubtc/cdk", rev = "1cc3fa7", default-features = false, features = ["mint"] }
cdk = { git = "https://github.com/thesimplekid/cdk", branch = "mpp", default-features = false, features = ["mint"] }
cdk-redb = { git = "https://github.com/thesimplekid/cdk", branch = "mpp", default-features = false, features = ["mint"] }
cdk-sqlite = { git = "https://github.com/thesimplekid/cdk", branch = "mpp", default-features = false, features = ["mint"] }
# cdk = { path = "../../cdk/mpp/crates/cdk", default-features = false, features = ["mint"] }
# cdk-sqlite = { path = "../../cdk/mpp/crates/cdk-sqlite", default-features = false, features = ["mint"] }
# cdk-redb = { path = "../../cdk/mpp/crates/cdk-redb", default-features = false, features = ["mint"] }
bitcoin = { version = "0.30.0", features = ["no-std"] }
serde = "1.0.164"
serde_json = "1.0.96"
Expand Down
31 changes: 27 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,20 @@ async fn get_melt_bolt11_quote(
State(state): State<MintState>,
Json(payload): Json<MeltQuoteBolt11Request>,
) -> Result<Json<MeltQuoteBolt11Response>, Response> {
let amount = payload.request.amount_milli_satoshis().unwrap() / 1000;
assert!(amount > 0);
let amount = match payload.options {
Some(mpp) => mpp.amount,
None => Amount::from(payload.request.amount_milli_satoshis().unwrap() / 1000),
};

assert!(amount > Amount::ZERO);
let quote = state
.mint
.lock()
.await
.new_melt_quote(
payload.request.to_string(),
payload.unit,
Amount::from(amount),
amount,
Amount::ZERO,
unix_time() + 1800,
)
Expand Down Expand Up @@ -377,10 +381,29 @@ async fn post_melt_bolt11(
.await
.map_err(|_| StatusCode::NOT_ACCEPTABLE)?;

let invoice = Bolt11Invoice::from_str(&quote.request).unwrap();
let invoice_amount = ln_rs::Amount::from_msat(
Bolt11Invoice::from_str(&quote.request)
.unwrap()
.amount_milli_satoshis()
.unwrap(),
);

let partial_msat = match u64::from(invoice_amount) > u64::from(quote.amount) {
true => {
assert!(payload.proofs_amount() >= quote.amount);
Some(ln_rs::Amount::from_sat(u64::from(quote.amount)))
}
false => {
assert!(u64::from(payload.proofs_amount()) >= u64::from(invoice_amount));
None
}
};

let pre = state
.ln
.ln_processor
.pay_invoice(Bolt11Invoice::from_str(&quote.request).unwrap(), None, None)
.pay_invoice(invoice, partial_msat, None)
.await
.unwrap();

Expand Down

0 comments on commit 57b8e92

Please sign in to comment.