Check MRH has already been paid (#596)

This commit is contained in:
Ross Savage
2024-12-13 13:11:56 +01:00
committed by GitHub
parent 8540cfebdb
commit a57083f520
2 changed files with 23 additions and 4 deletions

View File

@@ -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),
)?;

View File

@@ -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 } => {
@@ -1074,6 +1074,7 @@ impl LiquidSdk {
},
amount_sat,
fees_sat,
false,
)
.await
}
@@ -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(
@@ -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(