From dc864ee3a5baadc0197b8491d55e94bba52a30d9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 16 Mar 2015 12:20:17 +0100 Subject: [PATCH] Added ToString methods --- common/types.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/common/types.go b/common/types.go index 11ac39815..911be9b9b 100644 --- a/common/types.go +++ b/common/types.go @@ -24,19 +24,22 @@ func (h Hash) SetBytes(b []byte) { } } +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 (h Address) SetBytes(b []byte) { - if len(b) > len(h) { +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-- { - h[i] = b[i] + a[i] = b[i] } } +func (a Address) SetString(s string) { h.SetBytes([]byte(a)) }