Documentation ¶
Index ¶
- Constants
- Variables
- func CalcMerkleRoot(txs []*types.Transaction) []byte
- func CalcMerkleRootCache(txs []*types.TransactionCache) []byte
- func Computation(leaves [][]byte, flage int, branchpos uint32) (roothash []byte, mutated bool, pbranch [][]byte)
- func Decode(dst *Hash, src string) error
- func GetHashFromTwoHash(left []byte, right []byte) []byte
- func GetMerkleBranch(leaves [][]byte, position uint32) [][]byte
- func GetMerkleRoot(leaves [][]byte) (roothash []byte)
- func GetMerkleRootAndBranch(leaves [][]byte, position uint32) (roothash []byte, branchs [][]byte)
- func GetMerkleRootFromBranch(merkleBranch [][]byte, leaf []byte, Index uint32) []byte
- type Hash
Constants ¶
const HashSize = 32
const MaxHashStringSize = HashSize * 2
Variables ¶
var ErrHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxHashStringSize)
Functions ¶
func CalcMerkleRoot ¶
func CalcMerkleRoot(txs []*types.Transaction) []byte
func CalcMerkleRootCache ¶
func CalcMerkleRootCache(txs []*types.TransactionCache) []byte
func Computation ¶
func Computation(leaves [][]byte, flage int, branchpos uint32) (roothash []byte, mutated bool, pbranch [][]byte)
This implements a constant-space merkle root/path calculator, limited to 2^32 leaves.
flage =1 只计算roothash flage =2 只计算branch flage =3 计算roothash 和 branch
func Decode ¶
Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.
func GetHashFromTwoHash ¶
计算左右节点hash的父hash
func GetMerkleBranch ¶
获取指定txindex的branch position 从0开始
func GetMerkleRootAndBranch ¶
获取merkle roothash 以及指定tx index的branch,注释:position从0开始
Types ¶
type 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 cheaper to just slice the hash directly thereby reusing the same bytes rather than calling this method.