Skip to content

Commit

Permalink
refactor: change ampd finalizer variant names (#301)
Browse files Browse the repository at this point in the history
* refactor: change ampd finalizer variant names

* refactor: rename ConfirmationFinalizer

* fix: address lint issue with cargo fmt

* refactor: rename RPCFinalizer
  • Loading branch information
maancham authored Mar 14, 2024
1 parent d7b4ca1 commit 9c139de
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions ampd/src/evm/finalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,32 @@ where
H: Into<U64>,
{
match finalizer_type {
Finalization::RPCFinalizedBlock => Box::new(EthereumFinalizer::new(rpc_client)),
Finalization::ConfirmationHeight => {
Box::new(PoWFinalizer::new(rpc_client, confirmation_height))
}
Finalization::RPCFinalizedBlock => Box::new(RPCFinalizer::new(rpc_client)),
Finalization::ConfirmationHeight => Box::new(ConfirmationHeightFinalizer::new(
rpc_client,
confirmation_height,
)),
}
}

pub struct EthereumFinalizer<'a, C>
pub struct RPCFinalizer<'a, C>
where
C: EthereumClient,
{
rpc_client: &'a C,
}

impl<'a, C> EthereumFinalizer<'a, C>
impl<'a, C> RPCFinalizer<'a, C>
where
C: EthereumClient,
{
pub fn new(rpc_client: &'a C) -> Self {
EthereumFinalizer { rpc_client }
RPCFinalizer { rpc_client }
}
}

#[async_trait]
impl<'a, C> Finalizer for EthereumFinalizer<'a, C>
impl<'a, C> Finalizer for RPCFinalizer<'a, C>
where
C: EthereumClient + Send + Sync,
{
Expand All @@ -70,31 +71,31 @@ where
}
}

pub struct PoWFinalizer<'a, C>
pub struct ConfirmationHeightFinalizer<'a, C>
where
C: EthereumClient,
{
rpc_client: &'a C,
confirmation_height: U64,
}

impl<'a, C> PoWFinalizer<'a, C>
impl<'a, C> ConfirmationHeightFinalizer<'a, C>
where
C: EthereumClient,
{
pub fn new<H>(rpc_client: &'a C, confirmation_height: H) -> Self
where
H: Into<U64>,
{
PoWFinalizer {
ConfirmationHeightFinalizer {
rpc_client,
confirmation_height: confirmation_height.into(),
}
}
}

#[async_trait]
impl<'a, C> Finalizer for PoWFinalizer<'a, C>
impl<'a, C> Finalizer for ConfirmationHeightFinalizer<'a, C>
where
C: EthereumClient + Send + Sync,
{
Expand All @@ -111,7 +112,7 @@ where

#[cfg(test)]
mod tests {
use crate::evm::finalizer::{pick, Finalization, Finalizer, PoWFinalizer};
use crate::evm::finalizer::{pick, ConfirmationHeightFinalizer, Finalization, Finalizer};
use crate::evm::json_rpc::MockEthereumClient;
use ethers::{
abi::Hash,
Expand All @@ -128,7 +129,7 @@ mod tests {
.returning(move || Ok(block_number));
assert_eq!(
block_number,
PoWFinalizer::new(&rpc_client, 1)
ConfirmationHeightFinalizer::new(&rpc_client, 1)
.latest_finalized_block_height()
.await
.unwrap()
Expand All @@ -141,7 +142,7 @@ mod tests {
.returning(move || Ok(block_number));
assert_eq!(
block_number + 1,
PoWFinalizer::new(&rpc_client, 0)
ConfirmationHeightFinalizer::new(&rpc_client, 0)
.latest_finalized_block_height()
.await
.unwrap()
Expand All @@ -154,7 +155,7 @@ mod tests {
.returning(move || Ok(block_number));
assert_eq!(
block_number - 1,
PoWFinalizer::new(&rpc_client, 2)
ConfirmationHeightFinalizer::new(&rpc_client, 2)
.latest_finalized_block_height()
.await
.unwrap()
Expand All @@ -167,7 +168,7 @@ mod tests {
.returning(move || Ok(block_number));
assert_eq!(
U64::from(1),
PoWFinalizer::new(&rpc_client, block_number)
ConfirmationHeightFinalizer::new(&rpc_client, block_number)
.latest_finalized_block_height()
.await
.unwrap()
Expand Down

0 comments on commit 9c139de

Please sign in to comment.