diff --git a/x/ibc/23-commitment/exported/exported.go b/x/ibc/23-commitment/exported/exported.go index 9024368fac..b4f2c0c18f 100644 --- a/x/ibc/23-commitment/exported/exported.go +++ b/x/ibc/23-commitment/exported/exported.go @@ -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 "" - } -} diff --git a/x/ibc/23-commitment/types/codec.go b/x/ibc/23-commitment/types/codec.go index a1579a944d..b53c0ce73f 100644 --- a/x/ibc/23-commitment/types/codec.go +++ b/x/ibc/23-commitment/types/codec.go @@ -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) { diff --git a/x/ibc/23-commitment/types/merkle.go b/x/ibc/23-commitment/types/merkle.go index 3636cecf4e..d219130a34 100644 --- a/x/ibc/23-commitment/types/merkle.go +++ b/x/ibc/23-commitment/types/merkle.go @@ -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 { diff --git a/x/ibc/types/codec.go b/x/ibc/types/codec.go index b6537fa8d4..3a337d02f2 100644 --- a/x/ibc/types/codec.go +++ b/x/ibc/types/codec.go @@ -24,4 +24,5 @@ func RegisterCodec(cdc *codec.Codec) { func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { connectiontypes.RegisterInterfaces(registry) channeltypes.RegisterInterfaces(registry) + commitmenttypes.RegisterInterfaces(registry) }