use ethers_core::{
abi::{Error, RawLog},
types::{Address, Log, TxHash, H256, U256, U64},
};
use serde::{Deserialize, Serialize};
pub trait EthLogDecode: Send + Sync {
fn decode_log(log: &RawLog) -> Result<Self, Error>
where
Self: Sized;
}
pub fn decode_logs<T: EthLogDecode>(logs: &[RawLog]) -> Result<Vec<T>, Error> {
logs.iter().map(T::decode_log).collect()
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct LogMeta {
pub address: Address,
pub block_number: U64,
pub block_hash: H256,
pub transaction_hash: TxHash,
pub transaction_index: U64,
pub log_index: U256,
}
impl From<&Log> for LogMeta {
fn from(src: &Log) -> Self {
LogMeta {
address: src.address,
block_number: src.block_number.expect("should have a block number"),
block_hash: src.block_hash.expect("should have a block hash"),
transaction_hash: src.transaction_hash.expect("should have a tx hash"),
transaction_index: src.transaction_index.expect("should have a tx index"),
log_index: src.log_index.expect("should have a log index"),
}
}
}