diff --git a/scripts/eth_btc/btc_pay.js b/scripts/eth_btc/btc_pay.js index 0395b0b..6641166 100644 --- a/scripts/eth_btc/btc_pay.js +++ b/scripts/eth_btc/btc_pay.js @@ -56,6 +56,9 @@ async function makePayments() { outgoing_amount = Number(outgoing_amount.toFixed(8)); if (walletInfo.balance < outgoing_amount) continue; + const select_deposit = await db.query("SELECT paid FROM bridges WHERE deposit_txid = $1", [bridge.deposit_txid]); + if (select_deposit.rows.length != 1 || select_deposit.rows[0].paid) throw new Error("Double payment? Race condition activated"); + const update_paid = await db.query("UPDATE bridges SET paid=true WHERE deposit_txid = $1", [bridge.deposit_txid]); if (update_paid.rowCount !== 1) throw new Error("Weird failure in paid update"); diff --git a/scripts/eth_btc/eth_pay.js b/scripts/eth_btc/eth_pay.js index e9eb08b..7549484 100644 --- a/scripts/eth_btc/eth_pay.js +++ b/scripts/eth_btc/eth_pay.js @@ -66,6 +66,9 @@ async function makePayments() { const outgoing_amount = ethers.BigNumber.from((bridge.deposit_amount * 0.998 * btc_price / eth_price * 1e18).toFixed(0)).sub(network_fee) if (makerBalance.lt(outgoing_amount)) continue; + const select_deposit = await db.query("SELECT paid FROM bridges WHERE deposit_txid = $1", [bridge.deposit_txid]); + if (select_deposit.rows.length != 1 || select_deposit.rows[0].paid) throw new Error("Double payment? Race condition activated"); + const update_paid = await db.query("UPDATE bridges SET paid=true WHERE deposit_txid = $1", [bridge.deposit_txid]); if (update_paid.rowCount !== 1) throw new Error("Weird failure in paid update");