-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add missing ibc perm cmd (#275)
* add missing ibc perm cmd * fix test to be determinitic
- Loading branch information
Showing
5 changed files
with
128 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cli | ||
|
||
import ( | ||
"cosmossdk.io/core/address" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
) | ||
|
||
// NewTxCmd returns the transaction commands for IBC non-fungible token transfer | ||
func NewTxCmd(ac address.Codec) *cobra.Command { | ||
txCmd := &cobra.Command{ | ||
Use: "ibc-perm", | ||
Short: "IBC channel permission tx subcommands", | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
|
||
txCmd.AddCommand( | ||
NewUpdateAdminCmd(ac), | ||
NewUpdatePermissionedRelayersCmd(ac), | ||
) | ||
|
||
return txCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"cosmossdk.io/core/address" | ||
"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/version" | ||
|
||
"github.com/initia-labs/initia/x/ibc/perm/types" | ||
) | ||
|
||
// NewUpdateAdmin returns the command to create a MsgUpdateAdmin transaction | ||
func NewUpdateAdminCmd(ac address.Codec) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "update-admin [port] [channel] [admin]", | ||
Short: "Transfer a ownership of a channel to a new admin", | ||
Example: fmt.Sprintf("%s tx ibc-perm update-admin [port] [channel] [admin]", version.AppName), | ||
Args: cobra.ExactArgs(3), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sender, err := ac.BytesToString(clientCtx.GetFromAddress()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
port := args[0] | ||
channel := args[1] | ||
admin := args[2] | ||
|
||
if _, err := ac.StringToBytes(admin); err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgUpdateAdmin(sender, port, channel, admin) | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
return cmd | ||
} | ||
|
||
// NewUpdatePermissionedRelayersCmd returns the command to create a MsgUpdatePermissionedRelayers transaction | ||
func NewUpdatePermissionedRelayersCmd(ac address.Codec) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "update-relayers [port] [channel] [relayer],...,[relayer]", | ||
Short: "Give a list of relayers permission to relay packets on a channel", | ||
Example: fmt.Sprintf("%s tx ibc-perm update-relayers [port] [channel] [relayer],...,[relayer]", version.AppName), | ||
Args: cobra.ExactArgs(3), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sender, err := ac.BytesToString(clientCtx.GetFromAddress()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
port := args[0] | ||
channel := args[1] | ||
relayers := strings.Split(args[2], ",") | ||
|
||
for _, relayer := range relayers { | ||
if _, err := ac.StringToBytes(relayer); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
msg := types.NewMsgUpdatePermissionedRelayers(sender, port, channel, relayers) | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters