Skip to content

Commit

Permalink
code review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: tomg10 <[email protected]>
  • Loading branch information
tomg10 committed Jul 31, 2024
1 parent 7c2de0c commit 1c05cd3
Showing 1 changed file with 52 additions and 49 deletions.
101 changes: 52 additions & 49 deletions core/lib/dal/src/eth_sender_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,55 +56,6 @@ impl EthSenderDal<'_, '_> {
Ok(txs.into_iter().map(|tx| tx.into()).collect())
}

pub async fn get_eth_txs_history_entries_max_id(&mut self) -> usize {
sqlx::query!(
r#"
SELECT
MAX(id)
FROM
eth_txs_history
"#
)
.fetch_one(self.storage.conn())
.await
.unwrap()
.max
.unwrap()
.try_into()
.unwrap()
}

pub async fn get_last_sent_eth_tx_hash(
&mut self,
l1_batch_number: L1BatchNumber,
op_type: AggregatedActionType,
) -> Option<TxHistory> {
let row = sqlx::query!(
r#"
SELECT
eth_commit_tx_id,
eth_prove_tx_id,
eth_execute_tx_id
FROM
l1_batches
WHERE
number = $1
"#,
i64::from(l1_batch_number.0)
)
.fetch_optional(self.storage.conn())
.await
.unwrap()
.unwrap();
let eth_tx_id = match op_type {
AggregatedActionType::Commit => row.eth_commit_tx_id,
AggregatedActionType::PublishProofOnchain => row.eth_prove_tx_id,
AggregatedActionType::Execute => row.eth_execute_tx_id,
}
.unwrap() as u32;
self.get_last_sent_eth_tx(eth_tx_id).await.unwrap()
}

pub async fn get_eth_l1_batches(&mut self) -> sqlx::Result<L1BatchEthSenderStats> {
struct EthTxRow {
number: i64,
Expand Down Expand Up @@ -734,3 +685,55 @@ impl EthSenderDal<'_, '_> {
Ok(())
}
}

/// These methods should only be used for tests.
impl EthSenderDal<'_, '_> {
pub async fn get_eth_txs_history_entries_max_id(&mut self) -> usize {
sqlx::query!(
r#"
SELECT
MAX(id)
FROM
eth_txs_history
"#
)
.fetch_one(self.storage.conn())
.await
.unwrap()
.max
.unwrap()
.try_into()
.unwrap()
}

pub async fn get_last_sent_eth_tx_hash(
&mut self,
l1_batch_number: L1BatchNumber,
op_type: AggregatedActionType,
) -> Option<TxHistory> {
let row = sqlx::query!(
r#"
SELECT
eth_commit_tx_id,
eth_prove_tx_id,
eth_execute_tx_id
FROM
l1_batches
WHERE
number = $1
"#,
i64::from(l1_batch_number.0)
)
.fetch_optional(self.storage.conn())
.await
.unwrap()
.unwrap();
let eth_tx_id = match op_type {
AggregatedActionType::Commit => row.eth_commit_tx_id,
AggregatedActionType::PublishProofOnchain => row.eth_prove_tx_id,
AggregatedActionType::Execute => row.eth_execute_tx_id,
}
.unwrap() as u32;
self.get_last_sent_eth_tx(eth_tx_id).await.unwrap()
}
}

0 comments on commit 1c05cd3

Please sign in to comment.