Skip to content

Commit

Permalink
add Serialized method to Proof
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing committed Jun 19, 2022
1 parent 9e55669 commit e04be88
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type Proof interface {

// Get retrieves the given key if it's present in the key-value data store.
Get(key []byte) ([]byte, error)

// Serialize returns the serialized proof
Serialize() [][]byte
}

type ProofDB struct {
Expand Down Expand Up @@ -58,6 +61,14 @@ func (w *ProofDB) Get(key []byte) ([]byte, error) {
return val, nil
}

func (w *ProofDB) Serialize() [][]byte {
nodes := make([][]byte, 0, len(w.kv))
for _, value := range w.kv {
nodes = append(nodes, value)
}
return nodes
}

// Prove returns the merkle proof for the given key, which is
func (t *Trie) Prove(key []byte) (Proof, bool) {
proof := NewProofDB()
Expand Down

0 comments on commit e04be88

Please sign in to comment.