Skip to content

Commit

Permalink
Rename binaries to blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
cichaczem committed Apr 25, 2024
1 parent 624e732 commit aa4f3cd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion db/migrations/004_transactions_binaries.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ALTER TABLE transactions ADD COLUMN binaries BYTEA[]
ALTER TABLE transactions ADD COLUMN blobs BYTEA[]
20 changes: 10 additions & 10 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl Database {
value: U256,
gas_limit: U256,
priority: TransactionPriority,
binaries: Option<Vec<Vec<u8>>>,
blobs: Option<Vec<Vec<u8>>>,
relayer_id: &str,
) -> eyre::Result<()> {
let mut tx = self.pool.begin().await?;
Expand All @@ -289,7 +289,7 @@ impl Database {

sqlx::query(
r#"
INSERT INTO transactions (id, tx_to, data, value, gas_limit, priority, relayer_id, nonce, binaries)
INSERT INTO transactions (id, tx_to, data, value, gas_limit, priority, relayer_id, nonce, blobs)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
"#,
)
Expand All @@ -301,7 +301,7 @@ impl Database {
.bind(priority)
.bind(relayer_id)
.bind(nonce)
.bind(binaries.map(|b| b))
.bind(blobs)
.execute(tx.as_mut())
.await?;

Expand All @@ -314,7 +314,7 @@ impl Database {
pub async fn get_unsent_txs(&self) -> eyre::Result<Vec<UnsentTx>> {
Ok(sqlx::query_as(
r#"
SELECT r.id as relayer_id, t.id, t.tx_to, t.data, t.value, t.gas_limit, t.priority, t.nonce, t.binaries, r.key_id, r.chain_id
SELECT r.id as relayer_id, t.id, t.tx_to, t.data, t.value, t.gas_limit, t.priority, t.nonce, t.blobs, r.key_id, r.chain_id
FROM transactions t
LEFT JOIN sent_transactions s ON (t.id = s.tx_id)
INNER JOIN relayers r ON (t.relayer_id = r.id)
Expand Down Expand Up @@ -765,7 +765,7 @@ impl Database {
Ok(sqlx::query_as(
r#"
SELECT r.id as relayer_id, t.id, t.tx_to, t.data, t.value, t.gas_limit, t.nonce,
t.binaries, r.key_id, r.chain_id,
t.blobs, r.key_id, r.chain_id,
s.initial_max_fee_per_gas, s.initial_max_priority_fee_per_gas, s.escalation_count
FROM transactions t
JOIN sent_transactions s ON t.id = s.tx_id
Expand Down Expand Up @@ -849,7 +849,7 @@ impl Database {
Ok(sqlx::query_as(
r#"
SELECT t.id as tx_id, t.tx_to as to, t.data, t.value, t.gas_limit, t.nonce,
t.binaries, h.tx_hash, s.status
t.blobs, h.tx_hash, s.status
FROM transactions t
LEFT JOIN sent_transactions s ON t.id = s.tx_id
LEFT JOIN tx_hashes h ON s.valid_tx_hash = h.tx_hash
Expand All @@ -875,7 +875,7 @@ impl Database {
Ok(sqlx::query_as(
r#"
SELECT t.id as tx_id, t.tx_to as to, t.data, t.value, t.gas_limit, t.nonce,
t. binaries, h.tx_hash, s.status
t. blobs, h.tx_hash, s.status
FROM transactions t
LEFT JOIN sent_transactions s ON t.id = s.tx_id
LEFT JOIN tx_hashes h ON s.valid_tx_hash = h.tx_hash
Expand Down Expand Up @@ -1407,13 +1407,13 @@ mod tests {
let value = U256::from(0);
let gas_limit = U256::from(0);
let priority = TransactionPriority::Regular;
let binaries = None;
let blobs = None;

let tx = db.read_tx(tx_id).await?;
assert!(tx.is_none(), "Tx has not been sent yet");

db.create_transaction(
tx_id, to, data, value, gas_limit, priority, binaries, relayer_id,
tx_id, to, data, value, gas_limit, priority, blobs, relayer_id,
)
.await?;

Expand All @@ -1426,7 +1426,7 @@ mod tests {
assert_eq!(tx.gas_limit.0, gas_limit);
assert_eq!(tx.nonce, 0);
assert_eq!(tx.tx_hash, None);
assert_eq!(tx.binaries, None);
assert_eq!(tx.blobs, None);

let unsent_txs = db.read_txs(relayer_id, None).await?;
assert_eq!(unsent_txs.len(), 1, "1 unsent tx");
Expand Down
6 changes: 3 additions & 3 deletions src/db/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct UnsentTx {
pub priority: TransactionPriority,
#[sqlx(try_from = "i64")]
pub nonce: u64,
pub binaries: Option<Vec<Vec<u8>>>,
pub blobs: Option<Vec<Vec<u8>>>,
pub key_id: String,
#[sqlx(try_from = "i64")]
pub chain_id: u64,
Expand All @@ -35,7 +35,7 @@ pub struct TxForEscalation {
pub gas_limit: U256Wrapper,
#[sqlx(try_from = "i64")]
pub nonce: u64,
pub binaries: Option<Vec<Vec<u8>>>,
pub blobs: Option<Vec<Vec<u8>>>,
pub key_id: String,
#[sqlx(try_from = "i64")]
pub chain_id: u64,
Expand All @@ -54,7 +54,7 @@ pub struct ReadTxData {
pub gas_limit: U256Wrapper,
#[sqlx(try_from = "i64")]
pub nonce: u64,
pub binaries: Option<Vec<Vec<u8>>>,
pub blobs: Option<Vec<Vec<u8>>>,

// Sent tx data
pub tx_hash: Option<H256Wrapper>,
Expand Down
8 changes: 4 additions & 4 deletions src/serde_utils/base64_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use base64::Engine as _;
use serde::Deserialize;

pub fn serialize<S>(
binaries: &Option<Vec<Vec<u8>>>,
blobs: &Option<Vec<Vec<u8>>>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match binaries {
Some(binaries) => {
let base64_vec: Vec<String> = binaries
match blobs {
Some(blobs) => {
let base64_vec: Vec<String> = blobs
.iter()
.map(|binary| general_purpose::STANDARD.encode(binary))
.collect();
Expand Down
4 changes: 2 additions & 2 deletions src/server/routes/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct SendTxRequest {
#[serde(default)]
pub tx_id: Option<String>,
#[serde(default, with = "crate::serde_utils::base64_binary")]
pub binaries: Option<Vec<Vec<u8>>>,
pub blobs: Option<Vec<Vec<u8>>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -118,7 +118,7 @@ pub async fn send_tx(
req.value,
req.gas_limit,
req.priority,
req.binaries,
req.blobs,
api_token.relayer_id(),
)
.await?;
Expand Down
6 changes: 3 additions & 3 deletions tests/send_too_many_txs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async fn send_too_many_txs() -> eyre::Result<()> {
gas_limit: U256::from(21_000),
priority: TransactionPriority::Regular,
tx_id: None,
binaries: None,
blobs: None,
},
)
.await?;
Expand All @@ -76,7 +76,7 @@ async fn send_too_many_txs() -> eyre::Result<()> {
gas_limit: U256::from(21_000),
priority: TransactionPriority::Regular,
tx_id: None,
binaries: None,
blobs: None,
},
)
.await;
Expand Down Expand Up @@ -104,7 +104,7 @@ async fn send_too_many_txs() -> eyre::Result<()> {
gas_limit: U256::from(21_000),
priority: TransactionPriority::Regular,
tx_id: None,
binaries: None,
blobs: None,
},
)
.await?;
Expand Down

0 comments on commit aa4f3cd

Please sign in to comment.