merkle

package
v0.0.0-...-1c4572a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2018 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const HashSize = 32
View Source
const MaxHashStringSize = HashSize * 2

Variables

View Source
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

func Decode(dst *Hash, src string) error

Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.

func GetHashFromTwoHash

func GetHashFromTwoHash(left []byte, right []byte) []byte

计算左右节点hash的父hash

func GetMerkleBranch

func GetMerkleBranch(leaves [][]byte, position uint32) [][]byte

获取指定txindex的branch position 从0开始

func GetMerkleRoot

func GetMerkleRoot(leaves [][]byte) (roothash []byte)

获取merkle roothash

func GetMerkleRootAndBranch

func GetMerkleRootAndBranch(leaves [][]byte, position uint32) (roothash []byte, branchs [][]byte)

获取merkle roothash 以及指定tx index的branch,注释:position从0开始

func GetMerkleRootFromBranch

func GetMerkleRootFromBranch(merkleBranch [][]byte, leaf []byte, Index uint32) []byte

通过branch 获取对应的roothash 用于指定txhash的proof证明

Types

type Hash

type Hash [HashSize]byte

func NewHash

func NewHash(newHash []byte) (*Hash, error)

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

func NewHashFromStr(hash string) (*Hash, error)

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

func (hash *Hash) CloneBytes() []byte

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.

func (*Hash) SetBytes

func (hash *Hash) SetBytes(newHash []byte) error

SetBytes sets the bytes which represent the hash. An error is returned if the number of bytes passed in is not HashSize.

func (Hash) String

func (hash Hash) String() string

String returns the Hash as the hexadecimal string of the byte-reversed hash.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL