Skip to content

Commit

Permalink
Merge pull request #600 from breez/rt-sync-swap-update
Browse files Browse the repository at this point in the history
Real-time Sync: fix swap update flow
  • Loading branch information
roeierez authored Dec 13, 2024
2 parents ba31956 + 61dc6f3 commit 715075b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
11 changes: 8 additions & 3 deletions lib/core/src/persist/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Persister {
let id_hash = sha256::Hash::hash(chain_swap.id.as_bytes()).to_hex();
con.execute(
"
INSERT OR REPLACE INTO chain_swaps (
INSERT INTO chain_swaps (
id,
id_hash,
direction,
Expand All @@ -38,7 +38,8 @@ impl Persister {
created_at,
state
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT DO NOTHING",
(
&chain_swap.id,
&id_hash,
Expand All @@ -63,21 +64,25 @@ impl Persister {
"UPDATE chain_swaps
SET
description = :description,
accept_zero_conf = :accept_zero_conf,
server_lockup_tx_id = :server_lockup_tx_id,
user_lockup_tx_id = :user_lockup_tx_id,
claim_tx_id = :claim_tx_id,
refund_tx_id = :refund_tx_id,
pair_fees_json = :pair_fees_json
pair_fees_json = :pair_fees_json,
state = :state
WHERE
id = :id",
named_params! {
":id": &chain_swap.id,
":description": &chain_swap.description,
":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,
":claim_tx_id": &chain_swap.claim_tx_id,
":refund_tx_id": &chain_swap.refund_tx_id,
":pair_fees_json": &chain_swap.pair_fees_json,
":state": &chain_swap.state,
},
)?;

Expand Down
10 changes: 7 additions & 3 deletions lib/core/src/persist/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Persister {
let id_hash = sha256::Hash::hash(receive_swap.id.as_bytes()).to_hex();
con.execute(
"
INSERT OR REPLACE INTO receive_swaps (
INSERT INTO receive_swaps (
id,
id_hash,
preimage,
Expand All @@ -34,7 +34,9 @@ impl Persister {
state,
pair_fees_json
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT DO NOTHING
",
(
&receive_swap.id,
id_hash,
Expand All @@ -59,7 +61,8 @@ impl Persister {
description = :description,
claim_tx_id = :claim_tx_id,
lockup_tx_id = :lockup_tx_id,
mrh_tx_id = :mrh_tx_id
mrh_tx_id = :mrh_tx_id,
state = :state
WHERE
id = :id",
named_params! {
Expand All @@ -68,6 +71,7 @@ impl Persister {
":claim_tx_id": &receive_swap.claim_tx_id,
":lockup_tx_id": &receive_swap.lockup_tx_id,
":mrh_tx_id": &receive_swap.mrh_tx_id,
":state": &receive_swap.state,
},
)?;

Expand Down
34 changes: 24 additions & 10 deletions lib/core/src/persist/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,59 @@ impl Persister {
let id_hash = sha256::Hash::hash(send_swap.id.as_bytes()).to_hex();
con.execute(
"
INSERT OR REPLACE INTO send_swaps (
INSERT INTO send_swaps (
id,
id_hash,
invoice,
bolt12_offer,
preimage,
payment_hash,
description,
payer_amount_sat,
receiver_amount_sat,
create_response_json,
refund_private_key,
lockup_tx_id,
refund_tx_id,
created_at,
state,
pair_fees_json
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT DO NOTHING
",
(
&send_swap.id,
&id_hash,
&send_swap.invoice,
&send_swap.bolt12_offer,
&send_swap.preimage,
&send_swap.payment_hash,
&send_swap.description,
&send_swap.payer_amount_sat,
&send_swap.receiver_amount_sat,
&send_swap.create_response_json,
&send_swap.refund_private_key,
&send_swap.lockup_tx_id,
&send_swap.refund_tx_id,
&send_swap.created_at,
&send_swap.state,
&send_swap.pair_fees_json,
),
)?;

con.execute(
"UPDATE send_swaps
SET
description = :description,
preimage = :preimage,
lockup_tx_id = :lockup_tx_id,
refund_tx_id = :refund_tx_id,
state = :state
WHERE
id = :id",
named_params! {
":id": &send_swap.id,
":description": &send_swap.description,
":preimage": &send_swap.preimage,
":lockup_tx_id": &send_swap.lockup_tx_id,
":refund_tx_id": &send_swap.refund_tx_id,
":state": &send_swap.state,
},
)?;

Ok(())
}

Expand Down

0 comments on commit 715075b

Please sign in to comment.