1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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"),
}
}
}