use alloy_primitives::U256;
use async_trait::async_trait;
use crate::conversions::ProtoConversionError;
use crate::deposit::DepositContext;
use crate::evm::EvmChainError;
use crate::proto::v1;
use crate::spend_attestation::SpendAttestationChainContext;
#[derive(Debug, thiserror::Error)]
pub enum ChainHandlerError {
#[error(transparent)]
EvmChain(#[from] EvmChainError),
}
#[derive(Debug, thiserror::Error)]
pub enum ChainHandlerBuildError {
#[error("Invalid proto conversion: {0}")]
ProtoConversion(#[from] ProtoConversionError),
}
#[async_trait]
pub(crate) trait ChainHandler: Send + Sync {
fn delivery_contract(&self) -> v1::MultiChainAddress;
fn deposit_contract(&self) -> v1::MultiChainAddress;
fn signer(&self) -> v1::MultiChainAddress;
async fn sign_spend_intent(
&self,
intent: v1::SpendIntent,
) -> Result<Vec<u8>, ChainHandlerError>;
fn prepare_deposit(
&self,
token: v1::MultiChainAddress,
amount: U256,
) -> Result<DepositContext, ChainHandlerError>;
fn prepare_spend_attestation(&self) -> SpendAttestationChainContext;
}
#[async_trait]
pub(crate) trait ChainHandlerBuilder: Send + Sync {
async fn build(
self: Box<Self>,
delivery_contract: v1::MultiChainAddress,
deposit_contract: v1::MultiChainAddress,
) -> Result<Box<dyn ChainHandler>, ChainHandlerBuildError>;
}