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 ethereum::Log;
use primitive_types::{H160, H256, U256};
use crate::types::Address;
pub trait ToLog {
fn to_log(&self, contract: H160) -> Log;
}
pub trait ToTopic {
fn to_topic(&self) -> H256;
}
impl ToTopic for H256 {
fn to_topic(&self) -> H256 {
*self
}
}
impl ToTopic for U256 {
fn to_topic(&self) -> H256 {
let mut out = [0u8; 32];
self.to_big_endian(&mut out);
H256(out)
}
}
impl ToTopic for Address {
fn to_topic(&self) -> H256 {
let mut out = [0u8; 32];
out[12..32].copy_from_slice(&self.0);
H256(out)
}
}
impl ToTopic for u32 {
fn to_topic(&self) -> H256 {
let mut out = [0u8; 32];
out[28..32].copy_from_slice(&self.to_be_bytes());
H256(out)
}
}