2015-03-16 05:27:38 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
type (
|
|
|
|
Hash [32]byte
|
|
|
|
Address [20]byte
|
|
|
|
)
|
2015-03-16 05:59:52 -05:00
|
|
|
|
|
|
|
// 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]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-16 06:20:17 -05:00
|
|
|
func (h Hash) SetString(s string) { h.SetBytes([]byte(s)) }
|
|
|
|
|
2015-03-16 05:59:52 -05:00
|
|
|
// 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
|
2015-03-16 06:20:17 -05:00
|
|
|
func (a Address) SetBytes(b []byte) {
|
|
|
|
if len(b) > len(a) {
|
2015-03-16 05:59:52 -05:00
|
|
|
panic("unable to set bytes. too big")
|
|
|
|
}
|
|
|
|
|
|
|
|
// reverse loop
|
|
|
|
for i := len(b); i >= 0; i-- {
|
2015-03-16 06:20:17 -05:00
|
|
|
a[i] = b[i]
|
2015-03-16 05:59:52 -05:00
|
|
|
}
|
|
|
|
}
|
2015-03-16 06:20:17 -05:00
|
|
|
func (a Address) SetString(s string) { h.SetBytes([]byte(a)) }
|