Skip to content

Commit

Permalink
chore: update phd-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Oct 2, 2024
1 parent 813896e commit 9ef723d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/cdk-phoenixd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ tracing = { version = "0.1", default-features = false, features = ["attributes",
thiserror = "1"
lightning = { version = "0.0.124", default-features = false, features = ["std"]}
# phoenixd-rs = "0.3.0"
phoenixd-rs = { git = "https://github.com/thesimplekid/phoenixd-rs", rev = "959af4"}
phoenixd-rs = { git = "https://github.com/thesimplekid/phoenixd-rs", rev = "91dc766f"}
uuid = { version = "1", features = ["v4"] }
18 changes: 15 additions & 3 deletions crates/cdk-phoenixd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl MintLightning for Phoenixd {
Ok(PayInvoiceResponse {
payment_lookup_id: bolt11.payment_hash().to_string(),
payment_preimage: Some(pay_response.payment_preimage),
status: MeltQuoteState::Paid,
status: check_outgoing_response.status,
total_spent: check_outgoing_response.total_spent,
unit: CurrencyUnit::Sat,
})
Expand Down Expand Up @@ -329,20 +329,32 @@ impl MintLightning for Phoenixd {
PaymentRequest::Bolt11 { .. } => return Err(Error::WrongRequestType.into()),
};

let amount = match amount {
Some(amount) => amount,
None => amount_for_offer(&offer, &CurrencyUnit::Sat)?,
};

let pay_response = self
.phoenixd_api
.pay_bolt12_offer(offer.to_string(), amount.map(|a| a.into()), None)
.pay_bolt12_offer(offer.to_string(), amount.into(), None)
.await?;

// The pay invoice response does not give the needed fee info so we have to check.
let check_outgoing_response = self
.check_outgoing_payment(&pay_response.payment_id)
.await?;

tracing::debug!(
"Phd invoice {} for {} with amount {}",
check_outgoing_response.status,
amount,
check_outgoing_response.total_spent - amount
);

Ok(PayInvoiceResponse {
payment_lookup_id: pay_response.payment_id,
payment_preimage: Some(pay_response.payment_preimage),
status: MeltQuoteState::Paid,
status: check_outgoing_response.status,
total_spent: check_outgoing_response.total_spent,
unit: CurrencyUnit::Sat,
})
Expand Down

0 comments on commit 9ef723d

Please sign in to comment.