remove GetCommitmentType and register commitment interfaces (#6927)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
9b61e0947e
commit
cb5c93213c
|
@ -14,7 +14,6 @@ import ics23 "github.com/confio/ics23/go"
|
|||
// and the inclusion or non-inclusion of an arbitrary key-value pair
|
||||
// can be proven with the proof.
|
||||
type Root interface {
|
||||
GetCommitmentType() Type
|
||||
GetHash() []byte
|
||||
Empty() bool
|
||||
}
|
||||
|
@ -22,7 +21,6 @@ type Root interface {
|
|||
// Prefix implements spec:CommitmentPrefix.
|
||||
// Prefix represents the common "prefix" that a set of keys shares.
|
||||
type Prefix interface {
|
||||
GetCommitmentType() Type
|
||||
Bytes() []byte
|
||||
Empty() bool
|
||||
}
|
||||
|
@ -30,7 +28,6 @@ type Prefix interface {
|
|||
// Path implements spec:CommitmentPath.
|
||||
// A path is the additional information provided to the verification function.
|
||||
type Path interface {
|
||||
GetCommitmentType() Type
|
||||
String() string
|
||||
Empty() bool
|
||||
}
|
||||
|
@ -40,34 +37,9 @@ type Path interface {
|
|||
// Each proof has designated key-value pair it is able to prove.
|
||||
// Proofs includes key but value is provided dynamically at the verification time.
|
||||
type Proof interface {
|
||||
GetCommitmentType() Type
|
||||
VerifyMembership([]*ics23.ProofSpec, Root, Path, []byte) error
|
||||
VerifyNonMembership([]*ics23.ProofSpec, Root, Path) error
|
||||
Empty() bool
|
||||
|
||||
ValidateBasic() error
|
||||
}
|
||||
|
||||
// Type defines the type of the commitment
|
||||
type Type byte
|
||||
|
||||
// Registered commitment types
|
||||
const (
|
||||
Merkle Type = iota + 1 // 1
|
||||
)
|
||||
|
||||
// string representation of the commitment types
|
||||
const (
|
||||
TypeMerkle string = "merkle"
|
||||
)
|
||||
|
||||
// String implements the Stringer interface
|
||||
func (ct Type) String() string {
|
||||
switch ct {
|
||||
case Merkle:
|
||||
return TypeMerkle
|
||||
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,43 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
|
||||
)
|
||||
|
||||
// RegisterInterfaces registers the commitment interfaces to protobuf Any.
|
||||
func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
|
||||
registry.RegisterInterface(
|
||||
"cosmos.ibc.commitment.Root",
|
||||
(*exported.Root)(nil),
|
||||
)
|
||||
registry.RegisterInterface(
|
||||
"cosmos.ibc.commitment.Prefix",
|
||||
(*exported.Prefix)(nil),
|
||||
)
|
||||
registry.RegisterInterface(
|
||||
"cosmos.ibc.commitment.Path",
|
||||
(*exported.Path)(nil),
|
||||
)
|
||||
registry.RegisterInterface(
|
||||
"cosmos.ibc.commitment.Proof",
|
||||
(*exported.Proof)(nil),
|
||||
)
|
||||
|
||||
registry.RegisterImplementations(
|
||||
(*exported.Root)(nil),
|
||||
&MerkleRoot{},
|
||||
)
|
||||
registry.RegisterImplementations(
|
||||
(*exported.Prefix)(nil),
|
||||
&MerklePrefix{},
|
||||
)
|
||||
registry.RegisterImplementations(
|
||||
(*exported.Path)(nil),
|
||||
&MerklePath{},
|
||||
)
|
||||
registry.RegisterImplementations(
|
||||
(*exported.Proof)(nil),
|
||||
&MerkleProof{},
|
||||
)
|
||||
}
|
||||
|
||||
// RegisterCodec registers the necessary x/ibc/23-commitment interfaces and concrete types
|
||||
// on the provided Amino codec. These types are used for Amino JSON serialization.
|
||||
func RegisterCodec(cdc *codec.Codec) {
|
||||
|
|
|
@ -41,11 +41,6 @@ func (mr MerkleRoot) GetHash() []byte {
|
|||
return mr.Hash
|
||||
}
|
||||
|
||||
// GetCommitmentType implements RootI interface
|
||||
func (MerkleRoot) GetCommitmentType() exported.Type {
|
||||
return exported.Merkle
|
||||
}
|
||||
|
||||
// Empty returns true if the root is empty
|
||||
func (mr MerkleRoot) Empty() bool {
|
||||
return len(mr.GetHash()) == 0
|
||||
|
@ -60,11 +55,6 @@ func NewMerklePrefix(keyPrefix []byte) MerklePrefix {
|
|||
}
|
||||
}
|
||||
|
||||
// GetCommitmentType implements Prefix interface
|
||||
func (MerklePrefix) GetCommitmentType() exported.Type {
|
||||
return exported.Merkle
|
||||
}
|
||||
|
||||
// Bytes returns the key prefix bytes
|
||||
func (mp MerklePrefix) Bytes() []byte {
|
||||
return mp.KeyPrefix
|
||||
|
@ -89,11 +79,6 @@ func NewMerklePath(keyPathStr []string) MerklePath {
|
|||
}
|
||||
}
|
||||
|
||||
// GetCommitmentType implements PathI
|
||||
func (MerklePath) GetCommitmentType() exported.Type {
|
||||
return exported.Merkle
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (mp MerklePath) String() string {
|
||||
return mp.KeyPath.String()
|
||||
|
@ -132,11 +117,6 @@ func ApplyPrefix(prefix exported.Prefix, path string) (MerklePath, error) {
|
|||
|
||||
var _ exported.Proof = (*MerkleProof)(nil)
|
||||
|
||||
// GetCommitmentType implements ProofI
|
||||
func (MerkleProof) GetCommitmentType() exported.Type {
|
||||
return exported.Merkle
|
||||
}
|
||||
|
||||
// VerifyMembership verifies the membership pf a merkle proof against the given root, path, and value.
|
||||
func (proof MerkleProof) VerifyMembership(specs []*ics23.ProofSpec, root exported.Root, path exported.Path, value []byte) error {
|
||||
if err := proof.validateVerificationArgs(specs, root); err != nil {
|
||||
|
|
|
@ -24,4 +24,5 @@ func RegisterCodec(cdc *codec.Codec) {
|
|||
func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
|
||||
connectiontypes.RegisterInterfaces(registry)
|
||||
channeltypes.RegisterInterfaces(registry)
|
||||
commitmenttypes.RegisterInterfaces(registry)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue