Skip to content

Commit

Permalink
feat(x/feegrant): add autocli options for tx (#17959)
Browse files Browse the repository at this point in the history
(cherry picked from commit 1d03d89)

# Conflicts:
#	x/feegrant/client/cli/tx.go
#	x/feegrant/client/cli/tx_test.go
  • Loading branch information
julienrbrt authored and mergify[bot] committed Oct 9, 2023
1 parent ef5c356 commit 6ab3024
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
7 changes: 7 additions & 0 deletions client/v2/autocli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ import (

// findSubCommand finds a sub-command of the provided command whose Use
// string is or begins with the provided subCmdName.
// It verifies the command's aliases as well.
func findSubCommand(cmd *cobra.Command, subCmdName string) *cobra.Command {
for _, subCmd := range cmd.Commands() {
use := subCmd.Use
if use == subCmdName || strings.HasPrefix(use, subCmdName+" ") {
return subCmd
}

for _, alias := range subCmd.Aliases {
if alias == subCmdName || strings.HasPrefix(alias, subCmdName+" ") {
return subCmd
}
}
}
return nil
}
Expand Down
10 changes: 7 additions & 3 deletions x/feegrant/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@ func GetTxCmd(ac address.Codec) *cobra.Command {

feegrantTxCmd.AddCommand(
NewCmdFeeGrant(ac),
NewCmdRevokeFeegrant(ac),
)

return feegrantTxCmd
}

// NewCmdFeeGrant returns a CLI command handler to create a MsgGrantAllowance transaction.
// This command is more powerful than AutoCLI generated command as it allows a better input validation.
func NewCmdFeeGrant(ac address.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "grant [granter_key_or_address] [grantee]",
Short: "Grant Fee allowance to an address",
Use: "grant [granter_key_or_address] [grantee]",
Aliases: []string{"grant-allowance"},
Short: "Grant Fee allowance to an address",
Long: strings.TrimSpace(
fmt.Sprintf(
`Grant authorization to pay fees from your address. Note, the '--from' flag is
Expand Down Expand Up @@ -186,6 +187,7 @@ Examples:
return cmd
}

<<<<<<< HEAD
// NewCmdRevokeFeegrant returns a CLI command handler to create a MsgRevokeAllowance transaction.
func NewCmdRevokeFeegrant(ac address.Codec) *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -222,6 +224,8 @@ Example:
return cmd
}

=======
>>>>>>> 1d03d890c (feat(x/feegrant): add autocli options for tx (#17959))
func getPeriodReset(duration int64) time.Time {
return time.Now().Add(getPeriod(duration))
}
Expand Down
3 changes: 3 additions & 0 deletions x/feegrant/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ func (s *CLITestSuite) TestNewCmdFeeGrant() {
}
}

<<<<<<< HEAD
func (s *CLITestSuite) TestNewCmdRevokeFeegrant() {
granter := s.addedGranter
grantee := s.addedGrantee
Expand Down Expand Up @@ -521,6 +522,8 @@ func (s *CLITestSuite) TestNewCmdRevokeFeegrant() {
}
}

=======
>>>>>>> 1d03d890c (feat(x/feegrant): add autocli options for tx (#17959))
func (s *CLITestSuite) TestTxWithFeeGrant() {
clientCtx := s.clientCtx
granter := s.addedGranter
Expand Down
14 changes: 14 additions & 0 deletions x/feegrant/module/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ You can find the fee-grant of a granter and grantee.`),
},
Tx: &autocliv1.ServiceCommandDescriptor{
Service: feegrantv1beta1.Msg_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "RevokeAllowance",
Use: "revoke [granter] [grantee]",
Short: "Revoke a fee grant",
Long: "Revoke fee grant from a granter to a grantee. Note, the '--from' flag is ignored as it is implied from [granter]",
Example: fmt.Sprintf(`$ %s tx feegrant revoke [granter] [grantee]`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "granter"},
{ProtoField: "grantee"},
},
},
},
EnhanceCustomCommand: true,
},
}
}

0 comments on commit 6ab3024

Please sign in to comment.