diff --git a/core/src/database/common.rs b/core/src/database/common.rs index 501dff36..13a6366f 100644 --- a/core/src/database/common.rs +++ b/core/src/database/common.rs @@ -446,23 +446,34 @@ impl Database { } } - pub async fn save_operator_take_sig( + pub async fn save_operator_take_sigs( &self, deposit_outpoint: OutPoint, - kickoff_utxo: UTXO, - operator_take_sig: schnorr::Signature, + kickoff_utxos_and_sigs: impl IntoIterator, ) -> Result<(), BridgeError> { - sqlx::query( + QueryBuilder::new( "UPDATE deposit_kickoff_utxos - SET operator_take_sig = $3 - WHERE deposit_outpoint = $1 AND kickoff_utxo = $2;", + SET operator_take_sig = batch.sig + FROM (", ) - .bind(OutPointDB(deposit_outpoint)) - .bind(sqlx::types::Json(UTXODB { - outpoint_db: OutPointDB(kickoff_utxo.outpoint), - txout_db: TxOutDB(kickoff_utxo.txout), - })) - .bind(SignatureDB(operator_take_sig)) + .push_values( + kickoff_utxos_and_sigs, + |mut builder, (kickoff_utxo, operator_take_sig)| { + builder + .push_bind(sqlx::types::Json(UTXODB { + outpoint_db: OutPointDB(kickoff_utxo.outpoint), + txout_db: TxOutDB(kickoff_utxo.txout), + })) + .push_bind(SignatureDB(operator_take_sig)); + }, + ) + .push( + ") AS batch (kickoff_utxo, sig) + WHERE deposit_kickoff_utxos.deposit_outpoint = ", + ) + .push_bind(OutPointDB(deposit_outpoint)) + .push(" AND deposit_kickoff_utxos.kickoff_utxo = batch.kickoff_utxo;") + .build() .execute(&self.connection) .await?; diff --git a/core/src/verifier.rs b/core/src/verifier.rs index 497cdfe0..90814911 100644 --- a/core/src/verifier.rs +++ b/core/src/verifier.rs @@ -461,16 +461,16 @@ where .unwrap(); }); - for (index, kickoff_utxo) in kickoff_utxos.iter().enumerate() { - self.db - .save_operator_take_sig( - deposit_outpoint, - kickoff_utxo.clone(), - operator_take_sigs[index], - ) - .await - .unwrap(); - } + let kickoff_utxos = kickoff_utxos + .into_iter() + .enumerate() + .map(|(index, utxo)| (utxo, operator_take_sigs[index])); + + self.db + .save_operator_take_sigs(deposit_outpoint, kickoff_utxos) + .await + .unwrap(); + // println!("MOVE_TX: {:?}", move_tx_handler); // println!("MOVE_TXID: {:?}", move_tx_handler.tx.compute_txid()); let move_tx_sighash =