Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert nonces in a single batch #248

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions core/src/database/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{EVMAddress, UTXO};
use bitcoin::address::NetworkUnchecked;
use bitcoin::{Address, OutPoint, Txid};
use secp256k1::schnorr;
use sqlx::{Pool, Postgres};
use sqlx::{Pool, Postgres, QueryBuilder};
use std::fs;

use super::wrapper::{AddressDB, EVMAddressDB, OutPointDB, SignatureDB, TxOutDB, TxidDB, UTXODB};
Expand Down Expand Up @@ -290,17 +290,17 @@ impl Database {
deposit_outpoint: OutPoint,
nonces: &[(MuSigSecNonce, MuSigPubNonce)],
) -> Result<(), BridgeError> {
// TODO: Use batch insert
for (sec, pub_nonce) in nonces {
sqlx::query(
"INSERT INTO nonces (deposit_outpoint, sec_nonce, pub_nonce) VALUES ($1, $2, $3);",
)
.bind(OutPointDB(deposit_outpoint))
.bind(hex::encode(sec))
.bind(pub_nonce)
QueryBuilder::new("INSERT INTO nonces (deposit_outpoint, sec_nonce, pub_nonce) ")
.push_values(nonces, |mut builder, (sec, pub_nonce)| {
builder
.push_bind(OutPointDB(deposit_outpoint))
.push_bind(hex::encode(sec))
.push_bind(pub_nonce);
})
.build()
.execute(&self.connection)
.await?;
}

Ok(())
}

Expand Down
Loading