From b61c819ce5bd8fe9ec9ce682aa9fca707acbe931 Mon Sep 17 00:00:00 2001 From: evgeniy-scherbina Date: Tue, 10 Sep 2024 11:03:58 -0400 Subject: [PATCH] Register custom types in encodingConfig --- kava/client.go | 13 +++++++++---- kava/custom_types.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ kava/rpc.go | 5 +++++ 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 kava/custom_types.go diff --git a/kava/client.go b/kava/client.go index 4fc2100..1fa3bff 100644 --- a/kava/client.go +++ b/kava/client.go @@ -26,6 +26,10 @@ import ( "time" "github.com/coinbase/rosetta-sdk-go/types" + abci "github.com/cometbft/cometbft/abci/types" + ctypes "github.com/cometbft/cometbft/rpc/core/types" + tmrpctypes "github.com/cometbft/cometbft/rpc/jsonrpc/types" + tmtypes "github.com/cometbft/cometbft/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authante "github.com/cosmos/cosmos-sdk/x/auth/ante" @@ -34,10 +38,6 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" kava "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/app/params" - abci "github.com/cometbft/cometbft/abci/types" - ctypes "github.com/cometbft/cometbft/rpc/core/types" - tmrpctypes "github.com/cometbft/cometbft/rpc/jsonrpc/types" - tmtypes "github.com/cometbft/cometbft/types" ) var noBlockResultsForHeight = regexp.MustCompile(`could not find results for height #(\d+)`) @@ -52,6 +52,11 @@ type Client struct { // NewClient initialized a new Client with the provided rpc client func NewClient(rpc RPCClient, balanceServiceFactory BalanceServiceFactory) (*Client, error) { encodingConfig := kava.MakeEncodingConfig() + encodingConfig.InterfaceRegistry.RegisterInterface( + "ibc.lightclients.solomachine.v2.ClientState", + (*ClientStateI)(nil), + &ClientState{}, + ) return &Client{ rpc: rpc, diff --git a/kava/custom_types.go b/kava/custom_types.go new file mode 100644 index 0000000..f9a829e --- /dev/null +++ b/kava/custom_types.go @@ -0,0 +1,44 @@ +package kava + +import ( + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/gogo/protobuf/proto" +) + +type ClientStateI interface { + proto.Message +} + +// ClientState defines a solo machine client that tracks the current consensus +// state and if the client is frozen. +type ClientState struct { + // latest sequence of the client state + Sequence uint64 `protobuf:"varint,1,opt,name=sequence,proto3" json:"sequence,omitempty"` + // frozen sequence of the solo machine + IsFrozen bool `protobuf:"varint,2,opt,name=is_frozen,json=isFrozen,proto3" json:"is_frozen,omitempty" yaml:"is_frozen"` + ConsensusState *ConsensusState `protobuf:"bytes,3,opt,name=consensus_state,json=consensusState,proto3" json:"consensus_state,omitempty" yaml:"consensus_state"` + // when set to true, will allow governance to update a solo machine client. + // The client will be unfrozen if it is frozen. + AllowUpdateAfterProposal bool `protobuf:"varint,4,opt,name=allow_update_after_proposal,json=allowUpdateAfterProposal,proto3" json:"allow_update_after_proposal,omitempty" yaml:"allow_update_after_proposal"` +} + +func (m *ClientState) Reset() { *m = ClientState{} } +func (m *ClientState) String() string { return proto.CompactTextString(m) } +func (*ClientState) ProtoMessage() {} + +// ConsensusState defines a solo machine consensus state. The sequence of a +// consensus state is contained in the "height" key used in storing the +// consensus state. +type ConsensusState struct { + // public key of the solo machine + PublicKey *types.Any `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty" yaml:"public_key"` + // diversifier allows the same public key to be re-used across different solo + // machine clients (potentially on different chains) without being considered + // misbehaviour. + Diversifier string `protobuf:"bytes,2,opt,name=diversifier,proto3" json:"diversifier,omitempty"` + Timestamp uint64 `protobuf:"varint,3,opt,name=timestamp,proto3" json:"timestamp,omitempty"` +} + +func (m *ConsensusState) Reset() { *m = ConsensusState{} } +func (m *ConsensusState) String() string { return proto.CompactTextString(m) } +func (*ConsensusState) ProtoMessage() {} diff --git a/kava/rpc.go b/kava/rpc.go index 284cb8e..894837a 100644 --- a/kava/rpc.go +++ b/kava/rpc.go @@ -60,6 +60,11 @@ func NewHTTPClient(remote string) (*HTTPClient, error) { } encodingConfig := kava.MakeEncodingConfig() + encodingConfig.InterfaceRegistry.RegisterInterface( + "ibc.lightclients.solomachine.v2.ClientState", + (*ClientStateI)(nil), + &ClientState{}, + ) return &HTTPClient{ HTTP: http,