-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
192 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cast" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types" | ||
) | ||
|
||
// GetQueryCmd returns the cli query commands for this module. | ||
func GetQueryCmd() *cobra.Command { | ||
// Group x/accountplus queries under a subcommand. | ||
cmd := &cobra.Command{ | ||
Use: types.ModuleName, | ||
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
|
||
cmd.AddCommand( | ||
CmdQueryParam(), | ||
CmdQueryGetAuthenticator(), | ||
CmdQueryGetAllAuthenticators(), | ||
) | ||
return cmd | ||
} | ||
|
||
func CmdQueryParam() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "param", | ||
Short: "Get param", | ||
Args: cobra.ExactArgs(0), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
queryClient := types.NewQueryClient(clientCtx) | ||
res, err := queryClient.Params( | ||
context.Background(), | ||
&types.QueryParamsRequest{}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
flags.AddQueryFlagsToCmd(cmd) | ||
return cmd | ||
} | ||
|
||
func CmdQueryGetAuthenticator() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "get-authenticator [account] [authenticator_id]", | ||
Short: "Get authenticator", | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
id, err := cast.ToUint64E(args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
queryClient := types.NewQueryClient(clientCtx) | ||
res, err := queryClient.GetAuthenticator( | ||
context.Background(), | ||
&types.GetAuthenticatorRequest{ | ||
Account: args[0], | ||
AuthenticatorId: id, | ||
}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
flags.AddQueryFlagsToCmd(cmd) | ||
return cmd | ||
} | ||
|
||
func CmdQueryGetAllAuthenticators() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "get-all-authenticators [account]", | ||
Short: "Get all authenticators for an account", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
queryClient := types.NewQueryClient(clientCtx) | ||
res, err := queryClient.GetAuthenticators( | ||
context.Background(), | ||
&types.GetAuthenticatorsRequest{ | ||
Account: args[0], | ||
}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
flags.AddQueryFlagsToCmd(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types" | ||
"github.com/spf13/cast" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// 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(CmdAddAuthenticator()) | ||
cmd.AddCommand(CmdRemoveAuthenticator()) | ||
return cmd | ||
} | ||
|
||
func CmdAddAuthenticator() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "add-authenticator [account] [authenticator_type] [data]", | ||
Short: "Registers an authenticator", | ||
Args: cobra.ExactArgs(3), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
msg := types.MsgAddAuthenticator{ | ||
Sender: args[0], | ||
AuthenticatorType: args[1], | ||
Data: []byte(args[2]), | ||
} | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) | ||
}, | ||
} | ||
flags.AddTxFlagsToCmd(cmd) | ||
return cmd | ||
} | ||
|
||
func CmdRemoveAuthenticator() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "remove-authenticator [sender] [authenticator_id]", | ||
Short: "Removes an authenticator", | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
id, err := cast.ToUint64E(args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
msg := types.MsgRemoveAuthenticator{ | ||
Sender: args[0], | ||
Id: id, | ||
} | ||
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