blob: 911be9b9bcd0c543c047c3e22f9819465ba2a87f (
plain) (
blame)
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
|
package common
type (
Hash [32]byte
Address [20]byte
)
// Don't use the default 'String' method in case we want to overwrite
// Get the string representation of the underlying hash
func (h Hash) Str() string {
return string(h[:])
}
// Sets the hash to the value of b. If b is larger than len(h) it will panic
func (h Hash) SetBytes(b []byte) {
if len(b) > len(h) {
panic("unable to set bytes. too big")
}
// reverse loop
for i := len(b); i >= 0; i-- {
h[i] = b[i]
}
}
func (h Hash) SetString(s string) { h.SetBytes([]byte(s)) }
// Get the string representation of the underlying address
func (a Address) Str() string {
return string(a[:])
}
// Sets the address to the value of b. If b is larger than len(a) it will panic
func (a Address) SetBytes(b []byte) {
if len(b) > len(a) {
panic("unable to set bytes. too big")
}
// reverse loop
for i := len(b); i >= 0; i-- {
a[i] = b[i]
}
}
func (a Address) SetString(s string) { h.SetBytes([]byte(a)) }
|