Skip to content

Commit

Permalink
Check MRH has already been paid (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeross authored Dec 13, 2024
1 parent 8540cfe commit a57083f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/core/src/persist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,17 @@ impl Persister {
)?;

if let Some(destination) = destination {
// Only store the destination if there is no payment_details entry else
// the destination is overwritten by the tx script_pubkey
con.execute(
"INSERT OR REPLACE INTO payment_details (
"INSERT INTO payment_details (
tx_id,
destination,
description
)
VALUES (?, ?, ?)
VALUES (?1, ?2, ?3)
ON CONFLICT (tx_id)
DO UPDATE SET description = COALESCE(?3, description)
",
(ptx.tx_id, destination, description),
)?;
Expand Down
19 changes: 17 additions & 2 deletions lib/core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ impl LiquidSdk {
PaymentError::InsufficientFunds
);

self.pay_liquid(liquid_address_data.clone(), amount_sat, *fees_sat)
self.pay_liquid(liquid_address_data.clone(), amount_sat, *fees_sat, true)
.await
}
SendDestination::Bolt11 { invoice } => {
Expand Down Expand Up @@ -1074,6 +1074,7 @@ impl LiquidSdk {
},
amount_sat,
fees_sat,
false,
)
.await
}
Expand Down Expand Up @@ -1127,7 +1128,22 @@ impl LiquidSdk {
address_data: LiquidAddressData,
receiver_amount_sat: u64,
fees_sat: u64,
skip_already_paid_check: bool,
) -> Result<SendPaymentResponse, PaymentError> {
let destination = address_data
.to_uri()
.unwrap_or(address_data.address.clone());
let payments = self.persister.get_payments(&ListPaymentsRequest {
details: Some(ListPaymentDetails::Liquid {
destination: destination.clone(),
}),
..Default::default()
})?;
ensure_sdk!(
skip_already_paid_check || payments.is_empty(),
PaymentError::AlreadyPaid
);

let tx = self
.onchain_wallet
.build_tx_or_drain_tx(
Expand Down Expand Up @@ -1159,7 +1175,6 @@ impl LiquidSdk {
is_confirmed: false,
};

let destination = address_data.to_uri().unwrap_or(address_data.address);
let description = address_data.message;

self.persister.insert_or_update_payment(
Expand Down

0 comments on commit a57083f

Please sign in to comment.