Skip to content

Commit

Permalink
Next acc number cli (#237)
Browse files Browse the repository at this point in the history
## Describe your changes and provide context
Accounts have a monotonically increasing number associated with it
that's stored in the keeper. Allow this number to be exposed for dau's
## Testing performed to validate your change
Tested locally:
```
 ~  seid q auth next-account-number                                                                              ok | 09:47:12 PM
18
```
  • Loading branch information
philipsu522 authored May 7, 2023
1 parent a9f7ebe commit d9bc47e
Show file tree
Hide file tree
Showing 4 changed files with 412 additions and 35 deletions.
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

0 comments on commit d9bc47e

Please sign in to comment.