Documentation ¶
Index ¶
- Variables
- type MerkleTree
- func (m *MerkleTree) CommitUpdates(bundle *UpdateBundle) error
- func (m *MerkleTree) Compute(lnodes [][]byte) error
- func (m *MerkleTree) Height() (int, error)
- func (m *MerkleTree) MarshalBinary() ([]byte, error)
- func (m *MerkleTree) Root() ([]byte, error)
- func (m *MerkleTree) UnmarshalBinary(b []byte) error
- func (m *MerkleTree) Update(lnodes map[int][]byte) (*UpdateBundle, error)
- func (m *MerkleTree) Verify(idx int, value []byte) (bool, error)
- type Position
- type Store
- type UpdateBundle
Constants ¶
This section is empty.
Variables ¶
var ( ErrorInvalidBF = errors.New("Branching factor must be at least 2") ErrorInvalidHashFunc = errors.New("Invalid hash function") ErrorInvalidBinaryLength = errors.New("Binary length is not valid") )
Errors
Functions ¶
This section is empty.
Types ¶
type MerkleTree ¶
type MerkleTree struct {
// contains filtered or unexported fields
}
MerkleTree type
func New ¶
func New(hashFunc crypto.Hash, nbranch int) (*MerkleTree, error)
New creates a new MerkleTree instance
func NewWithStore ¶ added in v0.3.0
NewWithStore creates a new MerkleTree instance with a given store
func (*MerkleTree) CommitUpdates ¶ added in v0.3.3
func (m *MerkleTree) CommitUpdates(bundle *UpdateBundle) error
CommitUpdates calls the store's CommitUpdates method
func (*MerkleTree) Compute ¶
func (m *MerkleTree) Compute(lnodes [][]byte) error
Compute builds the merkle tree from given leaf-nodes It commits the results to the store during the process
func (*MerkleTree) Height ¶
func (m *MerkleTree) Height() (int, error)
Height returns the merkle tree height
func (*MerkleTree) MarshalBinary ¶
func (m *MerkleTree) MarshalBinary() ([]byte, error)
MarshalBinary encodes the merkle tree It directly calls the store's MarshalBinary method
func (*MerkleTree) Root ¶
func (m *MerkleTree) Root() ([]byte, error)
Root returns the merkle root hash
func (*MerkleTree) UnmarshalBinary ¶
func (m *MerkleTree) UnmarshalBinary(b []byte) error
UnmarshalBinary decoded the merkle tree It directly calls the store's UnmarshalBinary method
func (*MerkleTree) Update ¶
func (m *MerkleTree) Update( lnodes map[int][]byte, ) (*UpdateBundle, error)
Update computes the sum of affected nodes for the modified leaf nodes. It doesn't commit the changes. Instead, it returns UpdateBundle, to be used for CommitUpdates() to commit the changes.
type Store ¶ added in v0.3.0
type Store interface { // SetLeafCount sets the new leaf count SetLeafCount(nleaf int) error // GetLeafCount gives the current leaf count GetLeafCount() (int, error) // GetTreeHeight gives the current tree height GetTreeHeight() (int, error) // CommitUpdates commits updated nodes CommitUpdates(bundle *UpdateBundle) error // WriteNode insert the node to the specified position WriteNode(p Position, value []byte) error // ReadNode gives the node at the specified position ReadNode(p Position) ([]byte, error) // MarshalBinary encodes the tree to a []byte slice MarshalBinary() ([]byte, error) // UnmarshalBinary decodes the tree from a []byte slice UnmarshalBinary(b []byte) error }
Store interface for merkle tree
type UpdateBundle ¶ added in v0.3.2
UpdateBundle contains the information to commit updates
func (*UpdateBundle) Root ¶ added in v0.3.3
func (b *UpdateBundle) Root() []byte
Root returns the updated root value