-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(accountplus): Add query for accountplus account state (#2659)
(cherry picked from commit 5fd53fc) # Conflicts: # protocol/x/accountplus/client/cli/query.go
- Loading branch information
1 parent
34c8f71
commit 49e4f5e
Showing
8 changed files
with
866 additions
and
40 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
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,144 @@ | ||
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(), | ||
CmdQueryAccountState(), | ||
) | ||
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 | ||
} | ||
|
||
func CmdQueryAccountState() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "account-state [address]", | ||
Short: "Get account state for an address", | ||
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.AccountState( | ||
context.Background(), | ||
&types.AccountStateRequest{ | ||
Address: args[0], | ||
}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
flags.AddQueryFlagsToCmd(cmd) | ||
return cmd | ||
} |
Oops, something went wrong.