Skip to content

Commit

Permalink
Fix solomachine cmds (#7581)
Browse files Browse the repository at this point in the history
* fix solo machine cli cmds

* polish

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored and clevinson committed Oct 19, 2020
1 parent 0de50cc commit 2f1764c
Showing 1 changed file with 20 additions and 29 deletions.
49 changes: 20 additions & 29 deletions x/ibc/light-clients/06-solomachine/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/version"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
"github.com/cosmos/cosmos-sdk/x/ibc/light-clients/06-solomachine/types"
Expand All @@ -25,11 +24,12 @@ const (
// NewCreateClientCmd defines the command to create a new solo machine client.
func NewCreateClientCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create [client-id] [sequence] [path/to/public-key.json] [diversifier] [timestamp]",
Short: "create new solo machine client",
Long: "create a new solo machine client with the specified identifier and public key",
Example: fmt.Sprintf("%s tx ibc %s create [client-id] [sequence] [public-key] [diversifier] [timestamp] --from node0 --home ../node0/<app>cli --chain-id $CID", version.AppName, types.SubModuleName),
Args: cobra.ExactArgs(5),
Use: "create [client-id] [sequence] [path/to/consensus_state.json]",
Short: "create new solo machine client",
Long: `create a new solo machine client with the specified identifier and public key
- ConsensusState json example: {"public_key":{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A/3SXL2ONYaOkxpdR5P8tHTlSlPv1AwQwSFxKRee5JQW"},"diversifier":"diversifier","timestamp":"10"}`,
Example: fmt.Sprintf("%s tx ibc %s create [client-id] [sequence] [path/to/consensus_state] --from node0 --home ../node0/<app>cli --chain-id $CID", version.AppName, types.SubModuleName),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
Expand All @@ -38,42 +38,29 @@ func NewCreateClientCmd() *cobra.Command {
}

clientID := args[0]
diversifier := args[3]

sequence, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return err
}

timestamp, err := strconv.ParseUint(args[4], 10, 64)
if err != nil {
return err
}

cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

var publicKey *codectypes.Any

// attempt to unmarshal public key argument
if err := cdc.UnmarshalJSON([]byte(args[2]), publicKey); err != nil {
// attempt to unmarshal consensus state argument
consensusState := &types.ConsensusState{}
if err := cdc.UnmarshalJSON([]byte(args[2]), consensusState); err != nil {

// check for file path if JSON input is not provided
contents, err := ioutil.ReadFile(args[2])
if err != nil {
return errors.New("neither JSON input nor path to .json file for public key were provided")
return errors.Wrap(err, "neither JSON input nor path to .json file for consensus state were provided")
}

if err := cdc.UnmarshalJSON(contents, publicKey); err != nil {
return errors.Wrap(err, "error unmarshalling public key file")
if err := cdc.UnmarshalJSON(contents, consensusState); err != nil {
return errors.Wrap(err, "error unmarshalling consensus state file")
}
}

consensusState := &types.ConsensusState{
PublicKey: publicKey,
Diversifier: diversifier,
Timestamp: timestamp,
}

allowUpdateAfterProposal, _ := cmd.Flags().GetBool(flagAllowUpdateAfterProposal)

clientState := types.NewClientState(sequence, consensusState, allowUpdateAfterProposal)
Expand Down Expand Up @@ -115,13 +102,15 @@ func NewUpdateClientCmd() *cobra.Command {

cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

var header *types.Header
header := &types.Header{}
if err := cdc.UnmarshalJSON([]byte(args[1]), header); err != nil {

// check for file path if JSON input is not provided
contents, err := ioutil.ReadFile(args[1])
if err != nil {
return errors.New("neither JSON input nor path to .json file were provided")
return errors.Wrap(err, "neither JSON input nor path to .json file for header were provided")
}

if err := cdc.UnmarshalJSON(contents, header); err != nil {
return errors.Wrap(err, "error unmarshalling header file")
}
Expand Down Expand Up @@ -159,13 +148,15 @@ func NewSubmitMisbehaviourCmd() *cobra.Command {

cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

var m *types.Misbehaviour
m := &types.Misbehaviour{}
if err := cdc.UnmarshalJSON([]byte(args[0]), m); err != nil {

// check for file path if JSON input is not provided
contents, err := ioutil.ReadFile(args[0])
if err != nil {
return errors.New("neither JSON input nor path to .json file were provided")
return errors.Wrap(err, "neither JSON input nor path to .json file for misbehaviour were provided")
}

if err := cdc.UnmarshalJSON(contents, m); err != nil {
return errors.Wrap(err, "error unmarshalling misbehaviour file")
}
Expand Down

0 comments on commit 2f1764c

Please sign in to comment.