Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( EmptyNodeRaw = []byte{} EmptyNodeHash, _ = hex.DecodeString("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") )
Functions ¶
func NibblesToBytes ¶
func PrefixMatchedLen ¶
func Serialize ¶
Example ¶
key := []byte{0xa7, 0x11, 0x35, 0x51} value := []byte("45") key2 := []byte{0xa7, 0x7d, 0x33, 0x71} value2 := []byte("1") key3 := []byte{0xa7, 0xf9, 0x36, 0x51} value3 := []byte("2") key4 := []byte{0xa7, 0x7d, 0x39, 0x71} value4 := []byte("3") trie := NewTrie() _ = trie.Put(key, value) _ = trie.Put(key2, value2) _ = trie.Put(key3, value3) _ = trie.Put(key4, value4) i := Serialize(trie.Root) var e []interface{} err := rlp.DecodeBytes(i, &e) if err != nil { log.Panic("Failed to DecodeBytes:", err) } trie2 := NewTrieWithDecodeData(e) v, _ := trie2.Get(key) fmt.Println(v)
Output: [52 53]
Types ¶
type BranchNode ¶
func NewBranchNode ¶
func NewBranchNode() *BranchNode
func NewBranchNodeWithDecodeData ¶
func NewBranchNodeWithDecodeData(is interface{}) *BranchNode
func (*BranchNode) HasValue ¶
func (b *BranchNode) HasValue() bool
func (*BranchNode) Hash ¶
func (b *BranchNode) Hash() []byte
func (*BranchNode) Raw ¶
func (b *BranchNode) Raw() []interface{}
func (*BranchNode) Serialize ¶
func (b *BranchNode) Serialize() []byte
func (*BranchNode) SetBranch ¶
func (b *BranchNode) SetBranch(nb Nibble, n Node)
func (*BranchNode) SetValue ¶
func (b *BranchNode) SetValue(v []byte)
type ExtensionNode ¶
type ExtensionNode struct { Next Node }
func NewExtensionNode ¶
func NewExtensionNode(nibbles []Nibble, next Node) *ExtensionNode
func NewExtensionNodeWithDecodeData ¶
func NewExtensionNodeWithDecodeData(ns []Nibble, is interface{}) *ExtensionNode
func (*ExtensionNode) Hash ¶
func (e *ExtensionNode) Hash() []byte
func (*ExtensionNode) Raw ¶
func (e *ExtensionNode) Raw() []interface{}
func (*ExtensionNode) Serialize ¶
func (e *ExtensionNode) Serialize() []byte
type Nibble ¶
type Nibble byte
func AddPrefixedByIsLeafNode ¶
func ByteToNibbles ¶
func BytesToNibbles ¶
type Trie ¶
type Trie struct {
Root Node
}
func NewTrieWithDecodeData ¶
func NewTrieWithDecodeData(is []interface{}) *Trie
func (*Trie) Put ¶
Put inserts a key -> value in the merkle tree EmptyNode -> replace with a leaf node with the path LeafNode -> transform into a Extension Node add a new branch node and a new leaf node ExtensionNode -> convert to a Extension Node with a shorter path, create a branch node that points to a new Extension Node
Click to show internal directories.
Click to hide internal directories.