mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-26 03:01:42 +00:00
General Merkle Follow Up (#2510)
* tmlibs -> libs * update changelog * address some comments from review of #2298
This commit is contained in:
@ -3,17 +3,19 @@ package merkle
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
)
|
||||
|
||||
//----------------------------------------
|
||||
// ProofOp gets converted to an instance of ProofOperator:
|
||||
|
||||
// ProofOperator is a layer for calculating intermediate Merkle root
|
||||
// Run() takes a list of bytes because it can be more than one
|
||||
// for example in range proofs
|
||||
// ProofOp() defines custom encoding which can be decoded later with
|
||||
// OpDecoder
|
||||
// ProofOperator is a layer for calculating intermediate Merkle roots
|
||||
// when a series of Merkle trees are chained together.
|
||||
// Run() takes leaf values from a tree and returns the Merkle
|
||||
// root for the corresponding tree. It takes and returns a list of bytes
|
||||
// to allow multiple leaves to be part of a single proof, for instance in a range proof.
|
||||
// ProofOp() encodes the ProofOperator in a generic way so it can later be
|
||||
// decoded with OpDecoder.
|
||||
type ProofOperator interface {
|
||||
Run([][]byte) ([][]byte, error)
|
||||
GetKey() []byte
|
||||
@ -23,8 +25,8 @@ type ProofOperator interface {
|
||||
//----------------------------------------
|
||||
// Operations on a list of ProofOperators
|
||||
|
||||
// ProofOperators is a slice of ProofOperator(s)
|
||||
// Each operator will be applied to the input value sequencially
|
||||
// ProofOperators is a slice of ProofOperator(s).
|
||||
// Each operator will be applied to the input value sequentially
|
||||
// and the last Merkle root will be verified with already known data
|
||||
type ProofOperators []ProofOperator
|
||||
|
||||
@ -91,8 +93,8 @@ func (prt *ProofRuntime) Decode(pop ProofOp) (ProofOperator, error) {
|
||||
return decoder(pop)
|
||||
}
|
||||
|
||||
func (prt *ProofRuntime) DecodeProof(proof *Proof) (poz ProofOperators, err error) {
|
||||
poz = ProofOperators(nil)
|
||||
func (prt *ProofRuntime) DecodeProof(proof *Proof) (ProofOperators, error) {
|
||||
var poz ProofOperators
|
||||
for _, pop := range proof.Ops {
|
||||
operator, err := prt.Decode(pop)
|
||||
if err != nil {
|
||||
@ -100,7 +102,7 @@ func (prt *ProofRuntime) DecodeProof(proof *Proof) (poz ProofOperators, err erro
|
||||
}
|
||||
poz = append(poz, operator)
|
||||
}
|
||||
return
|
||||
return poz, nil
|
||||
}
|
||||
|
||||
func (prt *ProofRuntime) VerifyValue(proof *Proof, root []byte, keypath string, value []byte) (err error) {
|
||||
|
Reference in New Issue
Block a user