Documentation
¶
Overview ¶
Package chainhash provides a type for representing hashes used in the Bitcoin protocol and provides functions for working with them.
Copyright (c) 2013-2016 The btcsuite developers Copyright (c) 2015 The Decred developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.
Index ¶
- Constants
- Variables
- func Decode(dst *Hash, src string) error
- func DoubleHashB(b []byte) []byte
- func HashB(b []byte) []byte
- type Hash
- func (h *Hash) CloneBytes() []byte
- func (h Hash) Equal(other Hash) bool
- func (h *Hash) IsEqual(target *Hash) bool
- func (h *Hash) Marshal() ([]byte, error)
- func (h *Hash) MarshalJSON() ([]byte, error)
- func (h *Hash) ProtoReflect() protoreflect.Message
- func (h *Hash) Scan(value interface{}) error
- func (h *Hash) SetBytes(newHash []byte) error
- func (h *Hash) Size() int
- func (h Hash) String() string
- func (h *Hash) Unmarshal(data []byte) error
- func (h *Hash) UnmarshalJSON(data []byte) error
- func (h *Hash) Value() (driver.Value, error)
Constants ¶
const HashSize = 32
HashSize of an array used to store hashes. See Hash.
const MaxHashStringSize = HashSize * 2
MaxHashStringSize is the maximum length of a Hash string.
Variables ¶
var ErrHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxHashStringSize)
ErrHashStrSize describes an error that indicates the caller specified a hash string that has too many characters.
Functions ¶
func Decode ¶
Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.
func DoubleHashB ¶
DoubleHashB calculates hash(hash(b)) and returns the resulting bytes.
Types ¶
type Hash ¶
Hash is used in several of the bitcoin messages and common structures. It typically represents the double sha256 of data.
func DoubleHashH ¶
DoubleHashH calculates hash(hash(b)) and returns the resulting bytes as a Hash.
func NewHash ¶
NewHash returns a new Hash from a byte slice. An error is returned if the number of bytes passed in is not HashSize.
func NewHashFromStr ¶
NewHashFromStr creates a Hash from a hash string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the Hash.
func (*Hash) CloneBytes ¶
CloneBytes returns a copy of the bytes which represent the hash as a byte slice.
NOTE: It is generally less expensive to just slice the hash directly thereby reusing the same bytes rather than calling this method.
func (*Hash) MarshalJSON ¶
MarshalJSON returns the JSON encoding of the hash as a hexadecimal
func (*Hash) ProtoReflect ¶
func (h *Hash) ProtoReflect() protoreflect.Message
ProtoReflect implements proto.Message
func (*Hash) SetBytes ¶
SetBytes sets the bytes which represent the hash. An error is returned if the number of bytes passed in is not HashSize.
func (*Hash) UnmarshalJSON ¶
UnmarshalJSON parses the JSON-encoded hash string and sets the hash to the