use alloy_primitives::B256;
use async_trait::async_trait;
use crate::chains::ChainInfo;
use crate::error::{Error, Result};
use crate::types::{Block, BlockId, Filter, Log, Receipt, Transaction};
#[async_trait]
pub trait ChainProvider: Send + Sync {
fn chain(&self) -> &ChainInfo;
async fn block_number(&self) -> Result<u64>;
async fn block(&self, at: BlockId, full: bool) -> Result<Option<Block>>;
async fn transaction(&self, hash: B256) -> Result<Option<Transaction>>;
async fn receipt(&self, hash: B256) -> Result<Option<Receipt>>;
async fn transaction_by_native_id(&self, id: &str) -> Result<Option<Transaction>> {
let hash: B256 = id
.parse()
.map_err(|_| Error::Unsupported(format!("`{id}` is not a 32-byte hex hash")))?;
self.transaction(hash).await
}
async fn receipt_by_native_id(&self, id: &str) -> Result<Option<Receipt>> {
let hash: B256 = id
.parse()
.map_err(|_| Error::Unsupported(format!("`{id}` is not a 32-byte hex hash")))?;
self.receipt(hash).await
}
async fn logs(&self, filter: &Filter) -> Result<Vec<Log>>;
}