Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next acc number cli #237

Merged
merged 4 commits into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions proto/cosmos/auth/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ service Query {
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/cosmos/auth/v1beta1/params";
}

// NextAccountNumber queries the next account number assigned
rpc NextAccountNumber(QueryNextAccountNumberRequest) returns (QueryNextAccountNumberResponse) {
option (google.api.http).get = "/cosmos/auth/v1beta1/nextaccountnumber";
}
}

// QueryAccountsRequest is the request type for the Query/Accounts RPC method.
Expand Down Expand Up @@ -72,3 +77,14 @@ message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];
}



// QueryNextAccountRequest is the request type for the Query/NextAccountNumber RPC method.
message QueryNextAccountNumberRequest {}

// QueryNextAccountResponse is the response type for the Query/NextAccountNumber RPC method.
message QueryNextAccountNumberResponse {
// count defines the next account number.
uint64 count = 1;
}
33 changes: 33 additions & 0 deletions x/auth/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func GetQueryCmd() *cobra.Command {
GetAccountCmd(),
GetAccountsCmd(),
QueryParamsCmd(),
QueryNextAccountNumberCmd(),
)

return cmd
Expand Down Expand Up @@ -79,6 +80,38 @@ $ <appd> query auth params
return cmd
}

// QueryNextAccountNumberCmd returns the command handler for evidence parameter querying.
func QueryNextAccountNumberCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "next-account-number",
Short: "Query the next account number",
Args: cobra.NoArgs,
Long: strings.TrimSpace(`Query the next account number parameters:

$ <appd> query auth next-account-number
`),
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.NextAccountNumber(cmd.Context(), &types.QueryNextAccountNumberRequest{})
if err != nil {
return err
}

fmt.Printf("%d\n", res.Count)
return nil
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetAccountCmd returns a query account that will display the state of the
// account at a given address.
func GetAccountCmd() *cobra.Command {
Expand Down
10 changes: 10 additions & 0 deletions x/auth/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,13 @@ func (ak AccountKeeper) Params(c context.Context, req *types.QueryParamsRequest)

return &types.QueryParamsResponse{Params: params}, nil
}

func (ak AccountKeeper) NextAccountNumber(c context.Context, req *types.QueryNextAccountNumberRequest) (*types.QueryNextAccountNumberResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(c)
nextAccountNumber := ak.GetNextAccountNumber(ctx)

return &types.QueryNextAccountNumberResponse{Count: nextAccountNumber}, nil
}
Loading