Skip to content

Commit

Permalink
fix: submit-consumer-misbehaviour command in the provider module CLI (
Browse files Browse the repository at this point in the history
#1496)

* fix misbehaviour cli fix

* fix nits
  • Loading branch information
sainoe authored Dec 19, 2023
1 parent f6d4ca9 commit 5b0307c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 14 additions & 4 deletions x/ccv/provider/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"

Expand Down Expand Up @@ -101,11 +102,18 @@ Example:
txf = txf.WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)

submitter := clientCtx.GetFromAddress()
var misbehaviour ibctmtypes.Misbehaviour
if err := clientCtx.Codec.UnmarshalInterfaceJSON([]byte(args[1]), &misbehaviour); err != nil {
misbJson, err := os.ReadFile(args[0])
if err != nil {
return err
}

cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

misbehaviour := ibctmtypes.Misbehaviour{}
if err := cdc.UnmarshalJSON(misbJson, &misbehaviour); err != nil {
return fmt.Errorf("misbehaviour unmarshalling failed: %s", err)
}

msg, err := types.NewMsgSubmitConsumerMisbehaviour(submitter, &misbehaviour)
if err != nil {
return err
Expand Down Expand Up @@ -164,13 +172,15 @@ Example:
return fmt.Errorf("duplicate vote evidence unmarshalling failed: %s", err)
}

headerRaw, err := os.ReadFile(args[1])
headerJson, err := os.ReadFile(args[1])
if err != nil {
return err
}

cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

header := ibctmtypes.Header{}
if err := types.ModuleCdc.UnmarshalJSON(headerRaw, &header); err != nil {
if err := cdc.UnmarshalJSON(headerJson, &header); err != nil {
return fmt.Errorf("infraction IBC header unmarshalling failed: %s", err)
}

Expand Down
6 changes: 6 additions & 0 deletions x/ccv/provider/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
tendermint "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
)

// RegisterLegacyAminoCodec registers the necessary x/ibc transfer interfaces and concrete types
Expand Down Expand Up @@ -43,6 +45,10 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
(*sdk.Msg)(nil),
&MsgSubmitConsumerDoubleVoting{},
)
registry.RegisterImplementations(
(*exported.ClientMessage)(nil),
&tendermint.Misbehaviour{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

Expand Down

0 comments on commit 5b0307c

Please sign in to comment.