Skip to content

Commit

Permalink
feat(lightclient): Add tx for setting canonical light client (#1681)
Browse files Browse the repository at this point in the history
* Added tx for setting canonical light client.

* linter

---------

Co-authored-by: Michael Tsitrin <michael@dymension.xyz>
  • Loading branch information
omritoptix and mtsitrin authored Jan 9, 2025
1 parent 94744a9 commit eaffb0e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
59 changes: 59 additions & 0 deletions x/lightclient/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"

"github.com/dymensionxyz/dymension/v3/x/lightclient/types"
)

// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(NewSetCanonicalClientTxCmd())

return cmd
}

func NewSetCanonicalClientTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "set-canonical-client [client-id]",
Short: "Try and set the canonical client for a rollapp",
Example: "dymd tx lightclient set-canonical-client <client-id>",
Long: `Try and set the canonical client for a rollapp.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
clientId := args[0]

msg := &types.MsgSetCanonicalClient{
Signer: clientCtx.GetFromAddress().String(),
ClientId: clientId,
}

if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
2 changes: 1 addition & 1 deletion x/lightclient/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r

// GetTxCmd returns the module's root tx command.
func (a AppModuleBasic) GetTxCmd() *cobra.Command {
return nil
return cli.GetTxCmd()
}

// GetQueryCmd returns the module's root query command.
Expand Down

0 comments on commit eaffb0e

Please sign in to comment.