Documentation ¶
Index ¶
- Variables
- type MemoryStore
- func (s *MemoryStore) Clone() Store
- func (s *MemoryStore) CommitUpdates(nodes []Node) error
- func (s *MemoryStore) ExtendSize(nleaf int)
- func (s *MemoryStore) NodeCount(rowIdx int) int
- func (s *MemoryStore) ReadChildBlock(p Position) []byte
- func (s *MemoryStore) ReadNode(p Position) []byte
- func (s *MemoryStore) ReadRow(rowIdx int) []byte
- func (s *MemoryStore) RowCount() int
- func (s *MemoryStore) SetTreeProps(tp *TreeProps)
- func (s *MemoryStore) WriteNode(p Position, node []byte) error
- func (s *MemoryStore) WriteRow(rowIdx int, nodes []byte) error
- type MerkleTree
- func (m *MerkleTree) Clone() (*MerkleTree, error)
- func (m *MerkleTree) Compute(lnodes []byte) error
- func (m *MerkleTree) GetStore() Store
- func (m *MerkleTree) Height() (int, error)
- func (m *MerkleTree) LeafCount() (int, error)
- func (m MerkleTree) MarshalBinary() ([]byte, error)
- func (m *MerkleTree) Root() ([]byte, error)
- func (m *MerkleTree) SoftUpdate(lnodes map[int][]byte) ([]Node, error)
- func (m *MerkleTree) UnmarshalBinary(b []byte) error
- func (m *MerkleTree) Update(lnodes map[int][]byte) error
- func (m *MerkleTree) Verify(node []byte, p Position) (bool, error)
- func (m *MerkleTree) VerifyLeaf(lnode []byte, idx int) (bool, error)
- func (m *MerkleTree) VerifyTree() (bool, error)
- type Node
- type Position
- type Store
- type TreeProps
- func (t *TreeProps) BlockCount(nodeCount int) int
- func (t *TreeProps) BlockIndex(nodeIdx int) int
- func (t *TreeProps) BlockSize() int
- func (t *TreeProps) BlockStart(blockIdx int) int
- func (t *TreeProps) ByteCount(nodeCount int) int
- func (t *TreeProps) NodeCount(byteCount int) int
- func (t *TreeProps) NodeSize() int
- func (t *TreeProps) TreeHeight(nleaf int) int
- func (t *TreeProps) TreeSize(nleaf int) int
Constants ¶
This section is empty.
Variables ¶
var ( ErrorInvalidInputLength = errors.New("Invalid input length") ErrorInvalidBranchingFactor = errors.New( "Branching factor must be at least 2", ) ErrorBranchingFactorNotMatch = errors.New("Branching Factor doesn't match") ErrorInvalidHashFunc = errors.New("Invalid hash function") )
errors
Functions ¶
This section is empty.
Types ¶
type MemoryStore ¶ added in v0.3.0
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore implements Store interface as on-memory store for the tree
func NewMemoryStore ¶ added in v0.3.1
func NewMemoryStore(tp *TreeProps) *MemoryStore
NewMemoryStore create a new MemoryStore instance
func (*MemoryStore) CommitUpdates ¶ added in v0.3.1
func (s *MemoryStore) CommitUpdates(nodes []Node) error
CommitUpdates commits updated nodes
func (*MemoryStore) ExtendSize ¶ added in v0.3.0
func (s *MemoryStore) ExtendSize(nleaf int)
ExtendSize extends the size of the storage if required for new number of leaf-node
func (*MemoryStore) NodeCount ¶ added in v0.3.0
func (s *MemoryStore) NodeCount(rowIdx int) int
NodeCount gives the node count of the specified row
func (*MemoryStore) ReadChildBlock ¶ added in v0.3.0
func (s *MemoryStore) ReadChildBlock(p Position) []byte
ReadChildBlock gives the child nodes of a node at the specified position as a single byte slice (block)
func (*MemoryStore) ReadNode ¶ added in v0.3.0
func (s *MemoryStore) ReadNode(p Position) []byte
ReadNode gives the node at the specified position
func (*MemoryStore) ReadRow ¶ added in v0.3.0
func (s *MemoryStore) ReadRow(rowIdx int) []byte
ReadRow gives the nodes at the specified row as a single byte slice
func (*MemoryStore) RowCount ¶ added in v0.3.0
func (s *MemoryStore) RowCount() int
RowCount gives the row count (height) of the tree
func (*MemoryStore) SetTreeProps ¶ added in v0.3.0
func (s *MemoryStore) SetTreeProps(tp *TreeProps)
SetTreeProps sets the tree props
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) Clone ¶
func (m *MerkleTree) Clone() (*MerkleTree, error)
Clone create a new tree instance from existing one
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) GetStore ¶ added in v0.3.0
func (m *MerkleTree) GetStore() Store
GetStore gives current store ref
func (*MerkleTree) Height ¶
func (m *MerkleTree) Height() (int, error)
Height returns the merkle tree height
func (*MerkleTree) LeafCount ¶ added in v0.3.0
func (m *MerkleTree) LeafCount() (int, error)
LeafCount returns the leaf-nodes count
func (MerkleTree) MarshalBinary ¶
func (m MerkleTree) MarshalBinary() ([]byte, error)
MarshalBinary encodes the merkle tree
func (*MerkleTree) Root ¶
func (m *MerkleTree) Root() ([]byte, error)
Root returns the merkle root hash
func (*MerkleTree) SoftUpdate ¶ added in v0.3.1
func (m *MerkleTree) SoftUpdate( lnodes map[int][]byte, ) ([]Node, error)
SoftUpdate computes new hashes of affected nodes for the modified leaf nodes. It doesn't commit the changes. Instead, it returns those affected nodes. Use CommitUpdates() to commit the changes.
func (*MerkleTree) UnmarshalBinary ¶
func (m *MerkleTree) UnmarshalBinary(b []byte) error
UnmarshalBinary decoded the merkle tree
func (*MerkleTree) Update ¶
func (m *MerkleTree) Update(lnodes map[int][]byte) error
Update computes new hashes of affected nodes for the modified leaf nodes. It commits the changes during the process.
func (*MerkleTree) Verify ¶
func (m *MerkleTree) Verify(node []byte, p Position) (bool, error)
Verify the integrity of the node at the specified position
func (*MerkleTree) VerifyLeaf ¶ added in v0.3.0
func (m *MerkleTree) VerifyLeaf(lnode []byte, idx int) (bool, error)
VerifyLeaf verifies the integrity of the leaf-node at the specified index
func (*MerkleTree) VerifyTree ¶ added in v0.3.1
func (m *MerkleTree) VerifyTree() (bool, error)
VerifyTree verifies the entire tree
type Store ¶ added in v0.3.0
type Store interface { // SetTreeProps sets the tree props SetTreeProps(tp *TreeProps) // Clone the store Clone() Store // WriteRow inserts the nodes to the specified row WriteRow(rowIdx int, nodes []byte) error // ReadRow gives the nodes at the specified row as a single byte slice ReadRow(rowIdx int) []byte // CommitUpdates commits updated nodes CommitUpdates(nodes []Node) error // WriteNode insert the node to the specified position WriteNode(p Position, node []byte) error // ReadNode gives the node at the specified position ReadNode(p Position) []byte // ReadChildBlock gives the child nodes of a node at the specified position // as a single byte slice (block) ReadChildBlock(p Position) []byte // ExtendSize extends the size of the storage if required // for new number of leaf-node ExtendSize(nleaf int) // RowCount gives the row count (height) of the tree RowCount() int // NodeCount gives the node count of the specified row NodeCount(rowIdx int) int }
Store interface for merkle tree
type TreeProps ¶ added in v0.3.0
type TreeProps struct {
// contains filtered or unexported fields
}
TreeProps contain tree props and related helper methods
func NewTreeProps ¶ added in v0.3.0
NewTreeProps create a pointer to a new TreeProps struct
func (*TreeProps) BlockCount ¶ added in v0.3.0
BlockCount gives how many blocks are required to cover the given node count
func (*TreeProps) BlockIndex ¶ added in v0.3.0
BlockIndex gives the index of the block where the given node exists
func (*TreeProps) BlockStart ¶ added in v0.3.0
BlockStart gives the index of first node in the given block index
func (*TreeProps) ByteCount ¶ added in v0.3.0
ByteCount gives how many bytes are required to cover the given node count
func (*TreeProps) NodeCount ¶ added in v0.3.0
NodeCount gives how many nodes can be put in a given number of bytes
func (*TreeProps) TreeHeight ¶ added in v0.3.0
TreeHeight computes height of the tree