Skip to content

Commit

Permalink
refactor: Improve and clarify API around AccountAddressById (#13460)
Browse files Browse the repository at this point in the history
* Revert "chore: change id to use uint64 in `AccountAddressByID` (#13411)"

This reverts commit 3d0e214.

* Add since

* Update CLI command

* make proto-gen

* id->accNum

* No API breaking changes

* improve err msg

* Update CHANGELOG.md

Co-authored-by: Julien Robert <julien@rbrt.fr>

* Update CHANGELOG.md

Co-authored-by: Julien Robert <julien@rbrt.fr>

Co-authored-by: Julien Robert <julien@rbrt.fr>
(cherry picked from commit 90bd316)

# Conflicts:
#	CHANGELOG.md
#	api/cosmos/auth/v1beta1/query.pulsar.go
#	api/cosmos/auth/v1beta1/query_grpc.pb.go
#	api/cosmos/distribution/v1beta1/query_grpc.pb.go
#	api/cosmos/group/v1/types.pulsar.go
#	proto/cosmos/auth/v1beta1/query.proto
#	x/auth/client/cli/query.go
#	x/auth/keeper/grpc_query.go
#	x/auth/keeper/grpc_query_test.go
#	x/auth/types/query.pb.go
#	x/distribution/types/query.pb.go
  • Loading branch information
amaury1093 authored and mergify[bot] committed Oct 6, 2022
1 parent 26786a0 commit 10a4f05
Show file tree
Hide file tree
Showing 16 changed files with 18,919 additions and 14 deletions.
140 changes: 140 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

8,869 changes: 8,869 additions & 0 deletions api/cosmos/auth/v1beta1/query.pulsar.go

Large diffs are not rendered by default.

445 changes: 445 additions & 0 deletions api/cosmos/auth/v1beta1/query_grpc.pb.go

Large diffs are not rendered by default.

451 changes: 451 additions & 0 deletions api/cosmos/distribution/v1beta1/query_grpc.pb.go

Large diffs are not rendered by default.

8,645 changes: 8,645 additions & 0 deletions api/cosmos/group/v1/types.pulsar.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/grpc/tmservice/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions proto/cosmos/auth/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ service Query {
option (google.api.http).get = "/cosmos/auth/v1beta1/accounts/{address}";
}

<<<<<<< HEAD
// AccountAddressByID returns account address based on account id
=======
// AccountAddressByID returns account address based on account number.
//
// Since: cosmos-sdk 0.46.2
>>>>>>> 90bd3161a (refactor: Improve and clarify API around `AccountAddressById` (#13460))
rpc AccountAddressByID(QueryAccountAddressByIDRequest) returns (QueryAccountAddressByIDResponse) {
option (google.api.http).get = "/cosmos/auth/v1beta1/address_by_id/{id}";
}
Expand Down Expand Up @@ -159,11 +165,43 @@ message AddressStringToBytesResponse {
}

// QueryAccountAddressByIDRequest is the request type for AccountAddressByID rpc method
<<<<<<< HEAD
message QueryAccountAddressByIDRequest{
=======
//
// Since: cosmos-sdk 0.46.2
message QueryAccountAddressByIDRequest {
// id is the account number of the address to be queried. This field
// should have been an uint64 (like all account numbers), and will be
// updated to uint64 in a future version of the auth query.
>>>>>>> 90bd3161a (refactor: Improve and clarify API around `AccountAddressById` (#13460))
int64 id = 1;
}

// QueryAccountAddressByIDResponse is the response type for AccountAddressByID rpc method
//
// Since: cosmos-sdk 0.46.2
message QueryAccountAddressByIDResponse {
string account_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}
<<<<<<< HEAD
=======

// QueryAccountInfoRequest is the Query/AccountInfo request type.
//
// Since: cosmos-sdk 0.47
message QueryAccountInfoRequest {

// address is the account address string.
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// QueryAccountInfoResponse is the Query/AccountInfo response type.
//
// Since: cosmos-sdk 0.47
message QueryAccountInfoResponse {

// info is the account info which is represented by BaseAccount.
BaseAccount info = 1;
}
>>>>>>> 90bd3161a (refactor: Improve and clarify API around `AccountAddressById` (#13460))
2 changes: 1 addition & 1 deletion store/types/commit_info.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions x/auth/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,28 @@ func GetAccountCmd() *cobra.Command {
// GetAccountAddressByIDCmd returns a query account that will display the account address of a given account id.
func GetAccountAddressByIDCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "address-by-id [id]",
Short: "Query for account address by account id",
Use: "address-by-acc-num [acc-num]",
Aliases: []string{"address-by-id"},
Short: "Query for an address by account number",
Args: cobra.ExactArgs(1),
Example: fmt.Sprintf("%s q auth address-by-id 1", version.AppName),
Example: fmt.Sprintf("%s q auth address-by-acc-num 1", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

<<<<<<< HEAD
id, err := strconv.ParseInt(args[0], 10, 64)
=======
accNum, err := strconv.ParseInt(args[0], 10, 64)
>>>>>>> 90bd3161a (refactor: Improve and clarify API around `AccountAddressById` (#13460))
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.AccountAddressByID(cmd.Context(), &types.QueryAccountAddressByIDRequest{Id: id})
res, err := queryClient.AccountAddressByID(cmd.Context(), &types.QueryAccountAddressByIDRequest{Id: accNum})
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion x/auth/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ func (ak AccountKeeper) AccountAddressByID(c context.Context, req *types.QueryAc
}

if req.Id < 0 {
<<<<<<< HEAD
return nil, status.Error(codes.InvalidArgument, "Invalid account id")
=======
return nil, status.Error(codes.InvalidArgument, "invalid account number")
>>>>>>> 90bd3161a (refactor: Improve and clarify API around `AccountAddressById` (#13460))
}

ctx := sdk.UnwrapSDKContext(c)
address := ak.GetAccountAddressByID(ctx, uint64(req.GetId()))
if len(address) == 0 {
return nil, status.Errorf(codes.NotFound, "account address not found with id %d", req.Id)
return nil, status.Errorf(codes.NotFound, "account address not found with account number %d", req.Id)
}

return &types.QueryAccountAddressByIDResponse{AccountAddress: address}, nil
Expand Down
5 changes: 5 additions & 0 deletions x/auth/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,13 @@ func (suite *KeeperTestSuite) TestGRPCQueryAccountAddressByID() {
{
"valid request",
func() {
<<<<<<< HEAD
account := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr)
suite.app.AccountKeeper.SetAccount(suite.ctx, account)
=======
account := suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr)
suite.accountKeeper.SetAccount(suite.ctx, account)
>>>>>>> 90bd3161a (refactor: Improve and clarify API around `AccountAddressById` (#13460))
req = &types.QueryAccountAddressByIDRequest{Id: int64(account.GetAccountNumber())}
},
true,
Expand Down
178 changes: 178 additions & 0 deletions x/auth/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions x/distribution/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 10a4f05

Please sign in to comment.