1 // Copyright 2015 The go-ethereum Authors
2 // This file is part of the go-ethereum library.
4 // The go-ethereum library is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // The go-ethereum library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public License
15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
18 //sed -e 's/_N_/Hash/g' -e 's/_S_/32/g' -e '1d' types_template.go | gofmt -w hash.go
26 func BytesTo_N_(b []byte) _N_ {
31 func StringTo_N_(s string) _N_ { return BytesTo_N_([]byte(s)) }
32 func BigTo_N_(b *big.Int) _N_ { return BytesTo_N_(b.Bytes()) }
33 func HexTo_N_(s string) _N_ { return BytesTo_N_(FromHex(s)) }
35 // Don't use the default 'String' method in case we want to overwrite
37 // Get the string representation of the underlying hash
38 func (h _N_) Str() string { return string(h[:]) }
39 func (h _N_) Bytes() []byte { return h[:] }
40 func (h _N_) Big() *big.Int { return Bytes2Big(h[:]) }
41 func (h _N_) Hex() string { return "0x" + Bytes2Hex(h[:]) }
43 // Sets the hash to the value of b. If b is larger than len(h) it will panic
44 func (h *_N_) SetBytes(b []byte) {
45 // Use the right most bytes
51 for i := len(b) - 1; i >= 0; i-- {
52 h[_S_-len(b)+i] = b[i]
56 // Set string `s` to h. If s is larger than len(h) it will panic
57 func (h *_N_) SetString(s string) { h.SetBytes([]byte(s)) }
60 func (h *_N_) Set(other _N_) {
61 for i, v := range other {