Skip to content

Commit

Permalink
refactor: rename payment_invoice to payment look up id
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Sep 24, 2024
1 parent d36f237 commit 7203c69
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
6 changes: 3 additions & 3 deletions crates/cdk-cln/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl MintLightning for Cln {
};
PayInvoiceResponse {
payment_preimage: Some(hex::encode(pay_response.payment_preimage.to_vec())),
payment_hash: pay_response.payment_hash.to_string(),
payment_lookup_id: pay_response.payment_hash.to_string(),
status,
total_spent: to_unit(
pay_response.amount_sent_msat.msat(),
Expand Down Expand Up @@ -356,7 +356,7 @@ impl MintLightning for Cln {
let status = cln_pays_status_to_mint_state(pays_response.status);

Ok(PayInvoiceResponse {
payment_hash: pays_response.payment_hash.to_string(),
payment_lookup_id: pays_response.payment_hash.to_string(),
payment_preimage: pays_response.preimage.map(|p| hex::encode(p.to_vec())),
status,
total_spent: pays_response
Expand All @@ -366,7 +366,7 @@ impl MintLightning for Cln {
})
}
None => Ok(PayInvoiceResponse {
payment_hash: payment_hash.to_string(),
payment_lookup_id: payment_hash.to_string(),
payment_preimage: None,
status: MeltQuoteState::Unknown,
total_spent: Amount::ZERO,
Expand Down
4 changes: 2 additions & 2 deletions crates/cdk-fake-wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl MintLightning for FakeWallet {
) -> Result<PayInvoiceResponse, Self::Err> {
Ok(PayInvoiceResponse {
payment_preimage: Some("".to_string()),
payment_hash: "".to_string(),
payment_lookup_id: "".to_string(),
status: MeltQuoteState::Paid,
total_spent: melt_quote.amount,
unit: melt_quote.unit,
Expand Down Expand Up @@ -208,7 +208,7 @@ impl MintLightning for FakeWallet {
) -> Result<PayInvoiceResponse, Self::Err> {
Ok(PayInvoiceResponse {
payment_preimage: Some("".to_string()),
payment_hash: request_lookup_id.to_string(),
payment_lookup_id: request_lookup_id.to_string(),
status: MeltQuoteState::Paid,
total_spent: Amount::ZERO,
unit: self.get_settings().unit,
Expand Down
4 changes: 2 additions & 2 deletions crates/cdk-lnbits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl MintLightning for LNbits {
let total_spent = Amount::from((invoice_info.amount + invoice_info.fee).unsigned_abs());

Ok(PayInvoiceResponse {
payment_hash: pay_response.payment_hash,
payment_lookup_id: pay_response.payment_hash,
payment_preimage: Some(invoice_info.payment_hash),
status,
total_spent,
Expand Down Expand Up @@ -280,7 +280,7 @@ impl MintLightning for LNbits {
})?;

let pay_response = PayInvoiceResponse {
payment_hash: payment.details.payment_hash,
payment_lookup_id: payment.details.payment_hash,
payment_preimage: Some(payment.preimage),
status: lnbits_to_melt_status(&payment.details.status, payment.details.pending),
total_spent: Amount::from(
Expand Down
8 changes: 4 additions & 4 deletions crates/cdk-lnd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl MintLightning for Lnd {
};

Ok(PayInvoiceResponse {
payment_hash: hex::encode(payment_response.payment_hash),
payment_lookup_id: hex::encode(payment_response.payment_hash),
payment_preimage,
status,
total_spent: total_amount.into(),
Expand Down Expand Up @@ -309,7 +309,7 @@ impl MintLightning for Lnd {

let response = match status {
PaymentStatus::Unknown => PayInvoiceResponse {
payment_hash: payment_hash.to_string(),
payment_lookup_id: payment_hash.to_string(),
payment_preimage: Some(update.payment_preimage),
status: MeltQuoteState::Unknown,
total_spent: Amount::ZERO,
Expand All @@ -320,14 +320,14 @@ impl MintLightning for Lnd {
continue;
}
PaymentStatus::Succeeded => PayInvoiceResponse {
payment_hash: payment_hash.to_string(),
payment_lookup_id: payment_hash.to_string(),
payment_preimage: Some(update.payment_preimage),
status: MeltQuoteState::Paid,
total_spent: Amount::from((update.value_sat + update.fee_sat) as u64),
unit: CurrencyUnit::Sat,
},
PaymentStatus::Failed => PayInvoiceResponse {
payment_hash: payment_hash.to_string(),
payment_lookup_id: payment_hash.to_string(),
payment_preimage: Some(update.payment_preimage),
status: MeltQuoteState::Unpaid,
total_spent: Amount::ZERO,
Expand Down
4 changes: 2 additions & 2 deletions crates/cdk-phoenixd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl MintLightning for Phoenixd {
let bolt11: Bolt11Invoice = melt_quote.request.parse()?;

Ok(PayInvoiceResponse {
payment_hash: bolt11.payment_hash().to_string(),
payment_lookup_id: bolt11.payment_hash().to_string(),
payment_preimage: Some(pay_response.payment_preimage),
status: MeltQuoteState::Paid,
total_spent: total_spent_sats,
Expand Down Expand Up @@ -253,7 +253,7 @@ impl MintLightning for Phoenixd {
let total_spent = res.sent + (res.fees + 999) / 1000;

PayInvoiceResponse {
payment_hash: res.payment_hash,
payment_lookup_id: res.payment_hash,
payment_preimage: Some(res.preimage),
status,
total_spent: total_spent.into(),
Expand Down
6 changes: 2 additions & 4 deletions crates/cdk-strike/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,8 @@ impl MintLightning for Strike {

let total_spent = from_strike_amount(pay_response.total_amount, &melt_quote.unit)?.into();

let bolt11: Bolt11Invoice = melt_quote.request.parse()?;

Ok(PayInvoiceResponse {
payment_hash: bolt11.payment_hash().to_string(),
payment_lookup_id: pay_response.payment_id,
payment_preimage: None,
status: state,
total_spent,
Expand Down Expand Up @@ -252,7 +250,7 @@ impl MintLightning for Strike {
};

PayInvoiceResponse {
payment_hash: invoice.payment_id,
payment_lookup_id: invoice.payment_id,
payment_preimage: None,
status: state,
total_spent: from_strike_amount(invoice.total_amount, &self.unit)?.into(),
Expand Down
2 changes: 1 addition & 1 deletion crates/cdk/src/cdk_lightning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub struct CreateInvoiceResponse {
#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
pub struct PayInvoiceResponse {
/// Payment hash
pub payment_hash: String,
pub payment_lookup_id: String,
/// Payment Preimage
pub payment_preimage: Option<String>,
/// Status
Expand Down

0 comments on commit 7203c69

Please sign in to comment.