mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-05 04:55:18 +00:00
proto: reorganize Protobuf schemas (#5102)
Reorganizes the Protobuf schemas. It is mostly bikeshedding, so if something is contentious or causes a lot of extra work then I'm fine with reverting. Some Protobuf and Go import paths will change. * Move `abci/types/types.proto` to `abci/types.proto`. * Move `crypto/keys/types.proto` and `crypto/merkle/types.proto` to `crypto/keys.proto` and `crypto/proof.proto`. * Drop the use of `msgs` in filenames, as "message" is a very overloaded term (all Protobuf types are messages, and we also have `message Message`). Use `types.proto` as a catch-all, and otherwise name files by conceptual grouping instead of message kind.
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
pc "github.com/tendermint/tendermint/proto/tendermint/crypto/keys"
|
||||
pc "github.com/tendermint/tendermint/proto/tendermint/crypto"
|
||||
)
|
||||
|
||||
// PubKeyToProto takes crypto.PubKey and transforms it to a protobuf Pubkey
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
tmmerkle "github.com/tendermint/tendermint/proto/tendermint/crypto/merkle"
|
||||
tmcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -116,11 +116,11 @@ func (sp *Proof) ValidateBasic() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sp *Proof) ToProto() *tmmerkle.Proof {
|
||||
func (sp *Proof) ToProto() *tmcrypto.Proof {
|
||||
if sp == nil {
|
||||
return nil
|
||||
}
|
||||
pb := new(tmmerkle.Proof)
|
||||
pb := new(tmcrypto.Proof)
|
||||
|
||||
pb.Total = sp.Total
|
||||
pb.Index = sp.Index
|
||||
@@ -130,7 +130,7 @@ func (sp *Proof) ToProto() *tmmerkle.Proof {
|
||||
return pb
|
||||
}
|
||||
|
||||
func ProofFromProto(pb *tmmerkle.Proof) (*Proof, error) {
|
||||
func ProofFromProto(pb *tmcrypto.Proof) (*Proof, error) {
|
||||
if pb == nil {
|
||||
return nil, errors.New("nil proof")
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
tmmerkle "github.com/tendermint/tendermint/proto/tendermint/crypto/merkle"
|
||||
tmcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto"
|
||||
)
|
||||
|
||||
//----------------------------------------
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
type ProofOperator interface {
|
||||
Run([][]byte) ([][]byte, error)
|
||||
GetKey() []byte
|
||||
ProofOp() tmmerkle.ProofOp
|
||||
ProofOp() tmcrypto.ProofOp
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
@@ -71,7 +71,7 @@ func (poz ProofOperators) Verify(root []byte, keypath string, args [][]byte) (er
|
||||
//----------------------------------------
|
||||
// ProofRuntime - main entrypoint
|
||||
|
||||
type OpDecoder func(tmmerkle.ProofOp) (ProofOperator, error)
|
||||
type OpDecoder func(tmcrypto.ProofOp) (ProofOperator, error)
|
||||
|
||||
type ProofRuntime struct {
|
||||
decoders map[string]OpDecoder
|
||||
@@ -91,7 +91,7 @@ func (prt *ProofRuntime) RegisterOpDecoder(typ string, dec OpDecoder) {
|
||||
prt.decoders[typ] = dec
|
||||
}
|
||||
|
||||
func (prt *ProofRuntime) Decode(pop tmmerkle.ProofOp) (ProofOperator, error) {
|
||||
func (prt *ProofRuntime) Decode(pop tmcrypto.ProofOp) (ProofOperator, error) {
|
||||
decoder := prt.decoders[pop.Type]
|
||||
if decoder == nil {
|
||||
return nil, fmt.Errorf("unrecognized proof type %v", pop.Type)
|
||||
@@ -99,7 +99,7 @@ func (prt *ProofRuntime) Decode(pop tmmerkle.ProofOp) (ProofOperator, error) {
|
||||
return decoder(pop)
|
||||
}
|
||||
|
||||
func (prt *ProofRuntime) DecodeProof(proof *tmmerkle.ProofOps) (ProofOperators, error) {
|
||||
func (prt *ProofRuntime) DecodeProof(proof *tmcrypto.ProofOps) (ProofOperators, error) {
|
||||
poz := make(ProofOperators, 0, len(proof.Ops))
|
||||
for _, pop := range proof.Ops {
|
||||
operator, err := prt.Decode(pop)
|
||||
@@ -111,17 +111,17 @@ func (prt *ProofRuntime) DecodeProof(proof *tmmerkle.ProofOps) (ProofOperators,
|
||||
return poz, nil
|
||||
}
|
||||
|
||||
func (prt *ProofRuntime) VerifyValue(proof *tmmerkle.ProofOps, root []byte, keypath string, value []byte) (err error) {
|
||||
func (prt *ProofRuntime) VerifyValue(proof *tmcrypto.ProofOps, root []byte, keypath string, value []byte) (err error) {
|
||||
return prt.Verify(proof, root, keypath, [][]byte{value})
|
||||
}
|
||||
|
||||
// TODO In the long run we'll need a method of classifcation of ops,
|
||||
// whether existence or absence or perhaps a third?
|
||||
func (prt *ProofRuntime) VerifyAbsence(proof *tmmerkle.ProofOps, root []byte, keypath string) (err error) {
|
||||
func (prt *ProofRuntime) VerifyAbsence(proof *tmcrypto.ProofOps, root []byte, keypath string) (err error) {
|
||||
return prt.Verify(proof, root, keypath, nil)
|
||||
}
|
||||
|
||||
func (prt *ProofRuntime) Verify(proof *tmmerkle.ProofOps, root []byte, keypath string, args [][]byte) (err error) {
|
||||
func (prt *ProofRuntime) Verify(proof *tmcrypto.ProofOps, root []byte, keypath string, args [][]byte) (err error) {
|
||||
poz, err := prt.DecodeProof(proof)
|
||||
if err != nil {
|
||||
return fmt.Errorf("decoding proof: %w", err)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
tmmerkle "github.com/tendermint/tendermint/proto/tendermint/crypto/merkle"
|
||||
tmcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto"
|
||||
)
|
||||
|
||||
const ProofOpDomino = "test:domino"
|
||||
@@ -29,8 +29,8 @@ func NewDominoOp(key, input, output string) DominoOp {
|
||||
}
|
||||
}
|
||||
|
||||
func (dop DominoOp) ProofOp() tmmerkle.ProofOp {
|
||||
dopb := tmmerkle.DominoOp{
|
||||
func (dop DominoOp) ProofOp() tmcrypto.ProofOp {
|
||||
dopb := tmcrypto.DominoOp{
|
||||
Key: dop.key,
|
||||
Input: dop.Input,
|
||||
Output: dop.Output,
|
||||
@@ -40,7 +40,7 @@ func (dop DominoOp) ProofOp() tmmerkle.ProofOp {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return tmmerkle.ProofOp{
|
||||
return tmcrypto.ProofOp{
|
||||
Type: ProofOpDomino,
|
||||
Key: []byte(dop.key),
|
||||
Data: bz,
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
tmmerkle "github.com/tendermint/tendermint/proto/tendermint/crypto/merkle"
|
||||
tmcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto"
|
||||
)
|
||||
|
||||
const ProofOpValue = "simple:v"
|
||||
@@ -37,11 +37,11 @@ func NewValueOp(key []byte, proof *Proof) ValueOp {
|
||||
}
|
||||
}
|
||||
|
||||
func ValueOpDecoder(pop tmmerkle.ProofOp) (ProofOperator, error) {
|
||||
func ValueOpDecoder(pop tmcrypto.ProofOp) (ProofOperator, error) {
|
||||
if pop.Type != ProofOpValue {
|
||||
return nil, fmt.Errorf("unexpected ProofOp.Type; got %v, want %v", pop.Type, ProofOpValue)
|
||||
}
|
||||
var pbop tmmerkle.ValueOp // a bit strange as we'll discard this, but it works.
|
||||
var pbop tmcrypto.ValueOp // a bit strange as we'll discard this, but it works.
|
||||
err := pbop.Unmarshal(pop.Data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("decoding ProofOp.Data into ValueOp: %w", err)
|
||||
@@ -54,8 +54,8 @@ func ValueOpDecoder(pop tmmerkle.ProofOp) (ProofOperator, error) {
|
||||
return NewValueOp(pop.Key, sp), nil
|
||||
}
|
||||
|
||||
func (op ValueOp) ProofOp() tmmerkle.ProofOp {
|
||||
pbval := tmmerkle.ValueOp{
|
||||
func (op ValueOp) ProofOp() tmcrypto.ProofOp {
|
||||
pbval := tmcrypto.ValueOp{
|
||||
Key: op.key,
|
||||
Proof: op.Proof.ToProto(),
|
||||
}
|
||||
@@ -63,7 +63,7 @@ func (op ValueOp) ProofOp() tmmerkle.ProofOp {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return tmmerkle.ProofOp{
|
||||
return tmcrypto.ProofOp{
|
||||
Type: ProofOpValue,
|
||||
Key: op.key,
|
||||
Data: bz,
|
||||
|
||||
Reference in New Issue
Block a user