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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Log module

use byteorder::{BigEndian, ByteOrder};
use super::types::*;

/// As log trait for how primitive types are represented as indexed arguments
/// of the event log
pub trait AsLog {
	/// Convert type to hash representation for the event log.
	fn as_log(&self) -> H256;
}

impl AsLog for u32 {
	fn as_log(&self) -> H256 {
		let mut result = H256::zero();
		BigEndian::write_u32(&mut result.as_mut()[28..32], *self);
		result
	}
}

impl AsLog for u64 {
	fn as_log(&self) -> H256 {
		let mut result = H256::zero();
		BigEndian::write_u64(&mut result.as_mut()[24..32], *self);
		result
	}
}

impl AsLog for i64 {
	fn as_log(&self) -> H256 {
		let mut result = H256::zero();
		BigEndian::write_i64(&mut result.as_mut()[24..32], *self);
		result
	}
}

impl AsLog for i32 {
	fn as_log(&self) -> H256 {
		let mut result = H256::zero();
		BigEndian::write_i32(&mut result.as_mut()[28..32], *self);
		result
	}
}


impl AsLog for bool {
	fn as_log(&self) -> H256 {
		let mut result = H256::zero();
		result.as_mut()[32] = if *self { 1 } else { 0 };
		result
	}
}

impl AsLog for U256 {
	fn as_log(&self) -> H256 {
		let mut result = H256::zero();
		self.to_big_endian(result.as_mut());
		result
	}
}

impl AsLog for H256 {
	fn as_log(&self) -> H256 {
		self.clone()
	}
}

impl AsLog for Address {
	fn as_log(&self) -> H256 {
		self.into()
	}
}