Send: correctly handle TransactionClaimed event

This commit is contained in:
ok300
2024-06-01 07:39:27 +02:00
parent ec51aa99b4
commit 7f73c9a51d
3 changed files with 31 additions and 14 deletions

View File

@@ -224,6 +224,7 @@ impl Swap {
pub(crate) struct SendSwap {
pub(crate) id: String,
pub(crate) invoice: String,
pub(crate) preimage: Option<String>,
pub(crate) payer_amount_sat: u64,
pub(crate) receiver_amount_sat: u64,
/// JSON representation of [crate::persist::send::InternalCreateSubmarineResponse]

View File

@@ -81,6 +81,7 @@ impl Persister {
SELECT
id,
invoice,
preimage,
payer_amount_sat,
receiver_amount_sat,
create_response_json,
@@ -116,14 +117,15 @@ impl Persister {
Ok(SendSwap {
id: row.get(0)?,
invoice: row.get(1)?,
payer_amount_sat: row.get(2)?,
receiver_amount_sat: row.get(3)?,
create_response_json: row.get(4)?,
refund_private_key: row.get(5)?,
lockup_tx_id: row.get(6)?,
refund_tx_id: row.get(7)?,
created_at: row.get(8)?,
state: row.get(9)?,
preimage: row.get(2)?,
payer_amount_sat: row.get(3)?,
receiver_amount_sat: row.get(4)?,
create_response_json: row.get(5)?,
refund_private_key: row.get(6)?,
lockup_tx_id: row.get(7)?,
refund_tx_id: row.get(8)?,
created_at: row.get(9)?,
state: row.get(10)?,
})
}

View File

@@ -612,14 +612,27 @@ impl LiquidSdk {
Ok(())
}
// Boltz announced they successfully broadcast the (cooperative or non-cooperative) claim tx
Ok(SubSwapStates::TransactionClaimed) => {
debug!("Send Swap {id} has been claimed");
let preimage =
self.get_preimage_from_script_path_claim_spend(&ongoing_send_swap)?;
self.validate_send_swap_preimage(id, &ongoing_send_swap.invoice, &preimage)
.await?;
self.try_handle_send_swap_update(id, Complete, Some(&preimage), None, None)
.await?;
match ongoing_send_swap.preimage {
Some(_) => {
debug!("The claim tx was a key path spend (cooperative claim)");
// Preimage was already validated and stored, PaymentSucceeded event emitted,
// when the cooperative claim was handled.
}
None => {
debug!("The claim tx was a script path spend (non-cooperative claim)");
let preimage =
self.get_preimage_from_script_path_claim_spend(&ongoing_send_swap)?;
self.validate_send_swap_preimage(id, &ongoing_send_swap.invoice, &preimage)
.await?;
self.try_handle_send_swap_update(id, Complete, Some(&preimage), None, None)
.await?;
}
}
Ok(())
}
@@ -1000,6 +1013,7 @@ impl LiquidSdk {
let swap = SendSwap {
id: swap_id.clone(),
invoice: req.invoice.clone(),
preimage: None,
payer_amount_sat,
receiver_amount_sat,
create_response_json,