1use ethereum::Log;
2use primitive_types::{H160, H256, U256};
3
4use crate::types::Address;
5
6pub trait ToLog {
11 fn to_log(&self, contract: H160) -> Log;
15}
16
17pub trait ToTopic {
22 fn to_topic(&self) -> H256;
24}
25
26impl ToTopic for H256 {
27 fn to_topic(&self) -> H256 {
28 *self
29 }
30}
31
32impl ToTopic for U256 {
33 fn to_topic(&self) -> H256 {
34 let mut out = [0u8; 32];
35 self.to_big_endian(&mut out);
36 H256(out)
37 }
38}
39
40impl ToTopic for Address {
41 fn to_topic(&self) -> H256 {
42 let mut out = [0u8; 32];
43 out[12..32].copy_from_slice(&self.0);
44 H256(out)
45 }
46}
47
48impl ToTopic for u32 {
49 fn to_topic(&self) -> H256 {
50 let mut out = [0u8; 32];
51 out[28..32].copy_from_slice(&self.to_be_bytes());
52 H256(out)
53 }
54}