Refactoring out redundant enums (#1060)
* Fix metric ordering (#1043) * Remove redunant enums * Remove checkpoint fn that was not actually in usepull/1078/head
parent
00feef0a69
commit
9cc91d9c51
@ -1,113 +0,0 @@ |
||||
use abacus_core::{ |
||||
CheckpointWithMeta, Indexer, InterchainGasPaymasterIndexer, InterchainGasPaymentWithMeta, |
||||
OutboxIndexer, RawCommittedMessage, |
||||
}; |
||||
use abacus_test::mocks::indexer::MockAbacusIndexer; |
||||
use async_trait::async_trait; |
||||
use eyre::Result; |
||||
|
||||
/// OutboxIndexer type
|
||||
#[derive(Debug)] |
||||
pub enum OutboxIndexers { |
||||
/// Ethereum contract indexer
|
||||
Ethereum(Box<dyn OutboxIndexer>), |
||||
/// Mock indexer
|
||||
Mock(Box<dyn OutboxIndexer>), |
||||
/// Other indexer variant
|
||||
Other(Box<dyn OutboxIndexer>), |
||||
} |
||||
|
||||
impl From<MockAbacusIndexer> for OutboxIndexers { |
||||
fn from(mock_indexer: MockAbacusIndexer) -> Self { |
||||
OutboxIndexers::Mock(Box::new(mock_indexer)) |
||||
} |
||||
} |
||||
|
||||
#[async_trait] |
||||
impl Indexer for OutboxIndexers { |
||||
async fn get_finalized_block_number(&self) -> Result<u32> { |
||||
match self { |
||||
OutboxIndexers::Ethereum(indexer) => indexer.get_finalized_block_number().await, |
||||
OutboxIndexers::Mock(indexer) => indexer.get_finalized_block_number().await, |
||||
OutboxIndexers::Other(indexer) => indexer.get_finalized_block_number().await, |
||||
} |
||||
} |
||||
} |
||||
|
||||
#[async_trait] |
||||
impl OutboxIndexer for OutboxIndexers { |
||||
async fn fetch_sorted_messages(&self, from: u32, to: u32) -> Result<Vec<RawCommittedMessage>> { |
||||
match self { |
||||
OutboxIndexers::Ethereum(indexer) => indexer.fetch_sorted_messages(from, to).await, |
||||
OutboxIndexers::Mock(indexer) => indexer.fetch_sorted_messages(from, to).await, |
||||
OutboxIndexers::Other(indexer) => indexer.fetch_sorted_messages(from, to).await, |
||||
} |
||||
} |
||||
|
||||
async fn fetch_sorted_cached_checkpoints( |
||||
&self, |
||||
from: u32, |
||||
to: u32, |
||||
) -> Result<Vec<CheckpointWithMeta>> { |
||||
match self { |
||||
OutboxIndexers::Ethereum(indexer) => { |
||||
indexer.fetch_sorted_cached_checkpoints(from, to).await |
||||
} |
||||
OutboxIndexers::Mock(indexer) => { |
||||
indexer.fetch_sorted_cached_checkpoints(from, to).await |
||||
} |
||||
OutboxIndexers::Other(indexer) => { |
||||
indexer.fetch_sorted_cached_checkpoints(from, to).await |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// InterchainGasPaymasterIndexer type
|
||||
#[derive(Debug)] |
||||
pub enum InterchainGasPaymasterIndexers { |
||||
/// Ethereum contract indexer
|
||||
Ethereum(Box<dyn InterchainGasPaymasterIndexer>), |
||||
/// Mock indexer
|
||||
Mock(Box<dyn InterchainGasPaymasterIndexer>), |
||||
/// Other indexer variant
|
||||
Other(Box<dyn InterchainGasPaymasterIndexer>), |
||||
} |
||||
|
||||
#[async_trait] |
||||
impl Indexer for InterchainGasPaymasterIndexers { |
||||
async fn get_finalized_block_number(&self) -> Result<u32> { |
||||
match self { |
||||
InterchainGasPaymasterIndexers::Ethereum(indexer) => { |
||||
indexer.get_finalized_block_number().await |
||||
} |
||||
InterchainGasPaymasterIndexers::Mock(indexer) => { |
||||
indexer.get_finalized_block_number().await |
||||
} |
||||
InterchainGasPaymasterIndexers::Other(indexer) => { |
||||
indexer.get_finalized_block_number().await |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
#[async_trait] |
||||
impl InterchainGasPaymasterIndexer for InterchainGasPaymasterIndexers { |
||||
async fn fetch_gas_payments( |
||||
&self, |
||||
from_block: u32, |
||||
to_block: u32, |
||||
) -> Result<Vec<InterchainGasPaymentWithMeta>> { |
||||
match self { |
||||
InterchainGasPaymasterIndexers::Ethereum(indexer) => { |
||||
indexer.fetch_gas_payments(from_block, to_block).await |
||||
} |
||||
InterchainGasPaymasterIndexers::Mock(indexer) => { |
||||
indexer.fetch_gas_payments(from_block, to_block).await |
||||
} |
||||
InterchainGasPaymasterIndexers::Other(indexer) => { |
||||
indexer.fetch_gas_payments(from_block, to_block).await |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,105 +0,0 @@ |
||||
use async_trait::async_trait; |
||||
use std::sync::Arc; |
||||
|
||||
use abacus_core::{ |
||||
accumulator::merkle::Proof, AbacusMessage, Address, ChainCommunicationError, |
||||
InboxValidatorManager, MultisigSignedCheckpoint, TxOutcome, |
||||
}; |
||||
|
||||
#[derive(Debug, Clone)] |
||||
/// Arc wrapper for InboxValidatorManagerVariants enum
|
||||
pub struct InboxValidatorManagers(Arc<InboxValidatorManagerVariants>); |
||||
|
||||
impl From<InboxValidatorManagerVariants> for InboxValidatorManagers { |
||||
fn from(inbox_validator_managers: InboxValidatorManagerVariants) -> Self { |
||||
Self(Arc::new(inbox_validator_managers)) |
||||
} |
||||
} |
||||
|
||||
impl std::ops::Deref for InboxValidatorManagers { |
||||
type Target = Arc<InboxValidatorManagerVariants>; |
||||
|
||||
fn deref(&self) -> &Self::Target { |
||||
&self.0 |
||||
} |
||||
} |
||||
|
||||
impl std::ops::DerefMut for InboxValidatorManagers { |
||||
fn deref_mut(&mut self) -> &mut Self::Target { |
||||
&mut self.0 |
||||
} |
||||
} |
||||
|
||||
/// InboxValidatorManager type
|
||||
#[derive(Debug)] |
||||
pub enum InboxValidatorManagerVariants { |
||||
/// Ethereum InboxValidatorManager contract
|
||||
Ethereum(Box<dyn InboxValidatorManager>), |
||||
/// Mock InboxValidatorManager contract
|
||||
Mock(Box<dyn InboxValidatorManager>), |
||||
/// Other InboxValidatorManager variant
|
||||
Other(Box<dyn InboxValidatorManager>), |
||||
} |
||||
|
||||
#[async_trait] |
||||
impl InboxValidatorManager for InboxValidatorManagerVariants { |
||||
/// Submit a signed checkpoint for inclusion
|
||||
async fn process( |
||||
&self, |
||||
multisig_signed_checkpoint: &MultisigSignedCheckpoint, |
||||
message: &AbacusMessage, |
||||
proof: &Proof, |
||||
) -> Result<TxOutcome, ChainCommunicationError> { |
||||
match self { |
||||
InboxValidatorManagerVariants::Ethereum(validator_manager) => { |
||||
validator_manager |
||||
.process(multisig_signed_checkpoint, message, proof) |
||||
.await |
||||
} |
||||
InboxValidatorManagerVariants::Mock(mock_validator_manager) => { |
||||
mock_validator_manager |
||||
.process(multisig_signed_checkpoint, message, proof) |
||||
.await |
||||
} |
||||
InboxValidatorManagerVariants::Other(validator_manager) => { |
||||
validator_manager |
||||
.process(multisig_signed_checkpoint, message, proof) |
||||
.await |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// Get calldata for a process tx
|
||||
fn process_calldata( |
||||
&self, |
||||
multisig_signed_checkpoint: &MultisigSignedCheckpoint, |
||||
message: &AbacusMessage, |
||||
proof: &Proof, |
||||
) -> Vec<u8> { |
||||
match self { |
||||
InboxValidatorManagerVariants::Ethereum(validator_manager) => { |
||||
validator_manager.process_calldata(multisig_signed_checkpoint, message, proof) |
||||
} |
||||
InboxValidatorManagerVariants::Mock(mock_validator_manager) => { |
||||
mock_validator_manager.process_calldata(multisig_signed_checkpoint, message, proof) |
||||
} |
||||
InboxValidatorManagerVariants::Other(validator_manager) => { |
||||
validator_manager.process_calldata(multisig_signed_checkpoint, message, proof) |
||||
} |
||||
} |
||||
} |
||||
|
||||
fn contract_address(&self) -> Address { |
||||
match self { |
||||
InboxValidatorManagerVariants::Ethereum(validator_manager) => { |
||||
validator_manager.contract_address() |
||||
} |
||||
InboxValidatorManagerVariants::Mock(validator_manager) => { |
||||
validator_manager.contract_address() |
||||
} |
||||
InboxValidatorManagerVariants::Other(validator_manager) => { |
||||
validator_manager.contract_address() |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,10 +1,12 @@ |
||||
use std::fmt::Debug; |
||||
|
||||
use async_trait::async_trait; |
||||
use auto_impl::auto_impl; |
||||
|
||||
use crate::AbacusContract; |
||||
|
||||
/// Interface for the InterchainGasPaymaster chain contract.
|
||||
/// Allows abstraction over different chains.
|
||||
#[async_trait] |
||||
#[auto_impl(Box, Arc)] |
||||
pub trait InterchainGasPaymaster: AbacusContract + Send + Sync + Debug {} |
||||
|
Loading…
Reference in new issue