Skip to content

Commit

Permalink
revert Protobuf methods accidentally cherry-picked in a41e36b
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker committed Nov 6, 2020
1 parent f9b2a2d commit ae64a8b
Showing 1 changed file with 0 additions and 60 deletions.
60 changes: 0 additions & 60 deletions proof_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,66 +303,6 @@ func (proof *RangeProof) _computeRootHash() (rootHash []byte, treeEnd bool, err
return rootHash, treeEnd, nil
}

// toProto converts the proof to a Protobuf representation, for use in ValueOp and AbsenceOp.
func (proof *RangeProof) ToProto() *iavlproto.RangeProof {
pb := &iavlproto.RangeProof{
LeftPath: make([]*iavlproto.ProofInnerNode, 0, len(proof.LeftPath)),
InnerNodes: make([]*iavlproto.PathToLeaf, 0, len(proof.InnerNodes)),
Leaves: make([]*iavlproto.ProofLeafNode, 0, len(proof.Leaves)),
}
for _, inner := range proof.LeftPath {
pb.LeftPath = append(pb.LeftPath, inner.toProto())
}
for _, path := range proof.InnerNodes {
pbPath := make([]*iavlproto.ProofInnerNode, 0, len(path))
for _, inner := range path {
pbPath = append(pbPath, inner.toProto())
}
pb.InnerNodes = append(pb.InnerNodes, &iavlproto.PathToLeaf{Inners: pbPath})
}
for _, leaf := range proof.Leaves {
pb.Leaves = append(pb.Leaves, leaf.toProto())
}

return pb
}

// rangeProofFromProto generates a RangeProof from a Protobuf RangeProof.
func RangeProofFromProto(pbProof *iavlproto.RangeProof) (RangeProof, error) {
proof := RangeProof{}

for _, pbInner := range pbProof.LeftPath {
inner, err := proofInnerNodeFromProto(pbInner)
if err != nil {
return proof, err
}
proof.LeftPath = append(proof.LeftPath, inner)
}

for _, pbPath := range pbProof.InnerNodes {
var path PathToLeaf // leave as nil unless populated, for Amino compatibility
if pbPath != nil {
for _, pbInner := range pbPath.Inners {
inner, err := proofInnerNodeFromProto(pbInner)
if err != nil {
return proof, err
}
path = append(path, inner)
}
}
proof.InnerNodes = append(proof.InnerNodes, path)
}

for _, pbLeaf := range pbProof.Leaves {
leaf, err := proofLeafNodeFromProto(pbLeaf)
if err != nil {
return proof, err
}
proof.Leaves = append(proof.Leaves, leaf)
}
return proof, nil
}

// keyStart is inclusive and keyEnd is exclusive.
// If keyStart or keyEnd don't exist, the leaf before keyStart
// or after keyEnd will also be included, but not be included in values.
Expand Down

0 comments on commit ae64a8b

Please sign in to comment.