aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/bytes.go2
-rw-r--r--common/types.go36
2 files changed, 37 insertions, 1 deletions
diff --git a/common/bytes.go b/common/bytes.go
index 4aef9a223..5e553d23c 100644
--- a/common/bytes.go
+++ b/common/bytes.go
@@ -211,7 +211,7 @@ func RightPadString(str string, l int) string {
}
-func Address(slice []byte) (addr []byte) {
+func ToAddress(slice []byte) (addr []byte) {
if len(slice) < 20 {
addr = LeftPadBytes(slice, 20)
} else if len(slice) > 20 {
diff --git a/common/types.go b/common/types.go
index 7646b2c34..11ac39815 100644
--- a/common/types.go
+++ b/common/types.go
@@ -4,3 +4,39 @@ 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]
+ }
+}
+
+// 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 (h Address) 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]
+ }
+}