Skip to content

Commit

Permalink
fix(rt-sync): update chain swap payer/receiver amount (#604)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeross authored Dec 13, 2024
1 parent 715075b commit b5fc4a6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 24 additions & 2 deletions lib/core/src/persist/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ impl Persister {
"UPDATE chain_swaps
SET
description = :description,
payer_amount_sat = :payer_amount_sat,
receiver_amount_sat = :receiver_amount_sat,
accept_zero_conf = :accept_zero_conf,
server_lockup_tx_id = :server_lockup_tx_id,
user_lockup_tx_id = :user_lockup_tx_id,
Expand All @@ -76,6 +78,8 @@ impl Persister {
named_params! {
":id": &chain_swap.id,
":description": &chain_swap.description,
":payer_amount_sat": &chain_swap.payer_amount_sat,
":receiver_amount_sat": &chain_swap.receiver_amount_sat,
":accept_zero_conf": &chain_swap.accept_zero_conf,
":server_lockup_tx_id": &chain_swap.server_lockup_tx_id,
":user_lockup_tx_id": &chain_swap.user_lockup_tx_id,
Expand Down Expand Up @@ -274,8 +278,10 @@ impl Persister {
receiver_amount_sat: u64,
) -> Result<(), PaymentError> {
log::info!("Updating chain swap {swap_id}: payer_amount_sat = {payer_amount_sat}, receiver_amount_sat = {receiver_amount_sat}");
let con: Connection = self.get_connection()?;
con.execute(
let mut con: Connection = self.get_connection()?;
let tx = con.transaction_with_behavior(TransactionBehavior::Immediate)?;

tx.execute(
"UPDATE chain_swaps
SET
payer_amount_sat = :payer_amount_sat,
Expand All @@ -288,6 +294,22 @@ impl Persister {
":receiver_amount_sat": receiver_amount_sat,
},
)?;
self.commit_outgoing(
&tx,
swap_id,
RecordType::Chain,
Some(vec![
"payer_amount_sat".to_string(),
"receiver_amount_sat".to_string(),
]),
)?;
tx.commit()?;
self.sync_trigger
.try_send(())
.map_err(|err| PaymentError::Generic {
err: format!("Could not trigger manual sync: {err:?}"),
})?;

Ok(())
}

Expand Down
2 changes: 2 additions & 0 deletions lib/core/src/sync/model/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ impl ChainSyncData {
pub(crate) fn merge(&mut self, other: &Self, updated_fields: &[String]) {
for field in updated_fields {
match field.as_str() {
"payer_amount_sat" => self.payer_amount_sat = other.payer_amount_sat,
"receiver_amount_sat" => self.receiver_amount_sat = other.receiver_amount_sat,
"accept_zero_conf" => self.accept_zero_conf = other.accept_zero_conf,
_ => continue,
}
Expand Down

0 comments on commit b5fc4a6

Please sign in to comment.