Documentation ¶
Overview ¶
Package merkle 实现默克尔树相关的hash计算
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(parent []byte, left []byte, right []byte) []byte
- func GetMerkleBranch(leaves [][]byte, position uint32) [][]byte
- func GetMerkleRoot(hashes [][]byte) []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
HashSize hash长度
const MaxHashStringSize = HashSize * 2
MaxHashStringSize 最大hash字符串长度
Variables ¶
var ErrHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxHashStringSize)
ErrHashStrSize error
Functions ¶
func CalcMerkleRoot ¶
func CalcMerkleRoot(txs []*types.Transaction) []byte
CalcMerkleRoot 计算merkle树根
func CalcMerkleRootCache ¶
func CalcMerkleRootCache(txs []*types.TransactionCache) []byte
CalcMerkleRootCache 计算merkle树根缓存
func Computation ¶
func Computation(leaves [][]byte, flage int, branchpos uint32) (roothash []byte, mutated bool, pbranch [][]byte)
Computation 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 ¶
GetHashFromTwoHash 计算左右节点hash的父hash
func GetMerkleBranch ¶
GetMerkleBranch 获取指定txindex的branch position 从0开始
func GetMerkleRoot ¶
GetMerkleRoot 256构成一个组,进行计算 n * step = hashes (hashes / n)
func GetMerkleRootAndBranch ¶
GetMerkleRootAndBranch 获取merkle roothash 以及指定tx index的branch,注释:position从0开始
Types ¶
type Hash ¶
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.