Skip to content

Commit

Permalink
tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberbono3 committed Jul 23, 2021
1 parent 030fc2c commit 556810d
Show file tree
Hide file tree
Showing 10 changed files with 475 additions and 380 deletions.
41 changes: 18 additions & 23 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
- [PageResponse](#cosmos.base.query.v1beta1.PageResponse)

- [cosmos/auth/v1beta1/query.proto](#cosmos/auth/v1beta1/query.proto)
- [AccStringBech32Request](#cosmos.auth.v1beta1.AccStringBech32Request)
- [AccStringBech32Response](#cosmos.auth.v1beta1.AccStringBech32Response)
- [Bech32AccStringRequest](#cosmos.auth.v1beta1.Bech32AccStringRequest)
- [Bech32AccStringResponse](#cosmos.auth.v1beta1.Bech32AccStringResponse)
- [AccAddrFromBech32Request](#cosmos.auth.v1beta1.AccAddrFromBech32Request)
- [AccAddrFromBech32Response](#cosmos.auth.v1beta1.AccAddrFromBech32Response)
- [Bech32FromAccAddrRequest](#cosmos.auth.v1beta1.Bech32FromAccAddrRequest)
- [Bech32FromAccAddrResponse](#cosmos.auth.v1beta1.Bech32FromAccAddrResponse)
- [Bech32PrefixRequest](#cosmos.auth.v1beta1.Bech32PrefixRequest)
- [Bech32PrefixResponse](#cosmos.auth.v1beta1.Bech32PrefixResponse)
- [QueryAccountRequest](#cosmos.auth.v1beta1.QueryAccountRequest)
Expand Down Expand Up @@ -842,60 +842,60 @@ corresponding request message has used PageRequest.



<a name="cosmos.auth.v1beta1.AccStringBech32Request"></a>
<a name="cosmos.auth.v1beta1.AccAddrFromBech32Request"></a>

### AccStringBech32Request
### AccAddrFromBech32Request



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `account` | [string](#string) | | |
| `bech32` | [string](#string) | | |






<a name="cosmos.auth.v1beta1.AccStringBech32Response"></a>
<a name="cosmos.auth.v1beta1.AccAddrFromBech32Response"></a>

### AccStringBech32Response
### AccAddrFromBech32Response



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `bech32` | [string](#string) | | |
| `account_addr` | [bytes](#bytes) | | |






<a name="cosmos.auth.v1beta1.Bech32AccStringRequest"></a>
<a name="cosmos.auth.v1beta1.Bech32FromAccAddrRequest"></a>

### Bech32AccStringRequest
### Bech32FromAccAddrRequest



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `bech32` | [string](#string) | | |
| `account_addr` | [bytes](#bytes) | | |






<a name="cosmos.auth.v1beta1.Bech32AccStringResponse"></a>
<a name="cosmos.auth.v1beta1.Bech32FromAccAddrResponse"></a>

### Bech32AccStringResponse
### Bech32FromAccAddrResponse



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `account` | [string](#string) | | |
| `bech32` | [string](#string) | | |



Expand All @@ -905,13 +905,8 @@ corresponding request message has used PageRequest.
<a name="cosmos.auth.v1beta1.Bech32PrefixRequest"></a>

### Bech32PrefixRequest
should I include account in Bech32PrefixRequest Account or Address?


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `address` | [string](#string) | | |




Expand Down Expand Up @@ -1035,8 +1030,8 @@ Query defines the gRPC querier service.
| `Account` | [QueryAccountRequest](#cosmos.auth.v1beta1.QueryAccountRequest) | [QueryAccountResponse](#cosmos.auth.v1beta1.QueryAccountResponse) | Account returns account details based on address. | GET|/cosmos/auth/v1beta1/accounts/{address}|
| `Params` | [QueryParamsRequest](#cosmos.auth.v1beta1.QueryParamsRequest) | [QueryParamsResponse](#cosmos.auth.v1beta1.QueryParamsResponse) | Params queries all parameters. | GET|/cosmos/auth/v1beta1/params|
| `Bech32Prefix` | [Bech32PrefixRequest](#cosmos.auth.v1beta1.Bech32PrefixRequest) | [Bech32PrefixResponse](#cosmos.auth.v1beta1.Bech32PrefixResponse) | Bech32 queries bech32Prefix | GET|/cosmos/auth/v1beta1/bech32|
| `Bech32AccString` | [Bech32AccStringRequest](#cosmos.auth.v1beta1.Bech32AccStringRequest) | [Bech32AccStringResponse](#cosmos.auth.v1beta1.Bech32AccStringResponse) | Bech32AccString converts Bech32 to Account string | GET|/cosmos/auth/v1beta1/bech32|
| `AccStringBech32` | [AccStringBech32Request](#cosmos.auth.v1beta1.AccStringBech32Request) | [AccStringBech32Response](#cosmos.auth.v1beta1.AccStringBech32Response) | AccStringBech32 converts Bech32 to Account string | GET|/cosmos/auth/v1beta1/bech32|
| `Bech32FromAccAddr` | [Bech32FromAccAddrRequest](#cosmos.auth.v1beta1.Bech32FromAccAddrRequest) | [Bech32FromAccAddrResponse](#cosmos.auth.v1beta1.Bech32FromAccAddrResponse) | Bech32FromAccAddr converts Bech32 to Account string | GET|/cosmos/auth/v1beta1/bech32|
| `AccAddrFromBech32` | [AccAddrFromBech32Request](#cosmos.auth.v1beta1.AccAddrFromBech32Request) | [AccAddrFromBech32Response](#cosmos.auth.v1beta1.AccAddrFromBech32Response) | AccAddrFromBech32 converts Account string to Bech32 | GET|/cosmos/auth/v1beta1/bech32|

<!-- end services -->

Expand Down
35 changes: 13 additions & 22 deletions proto/cosmos/auth/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ service Query {
option (google.api.http).get = "/cosmos/auth/v1beta1/bech32";
}

// Bech32AccString converts Bech32 to Account string
rpc Bech32AccString(Bech32AccStringRequest) returns (Bech32AccStringResponse) {
// Bech32FromAccAddr converts Bech32 to Account string
rpc Bech32FromAccAddr(Bech32FromAccAddrRequest) returns (Bech32FromAccAddrResponse) {
option (google.api.http).get = "/cosmos/auth/v1beta1/bech32";
}

// AccStringBech32 converts Account string to Bech32
rpc AccStringBech32(AccStringBech32Request) returns (AccStringBech32Response) {
// AccAddrFromBech32 converts Account string to Bech32
rpc AccAddrFromBech32(AccAddrFromBech32Request) returns (AccAddrFromBech32Response) {
option (google.api.http).get = "/cosmos/auth/v1beta1/bech32";
}
}
Expand Down Expand Up @@ -84,33 +84,24 @@ message QueryParamsResponse {
Params params = 1 [(gogoproto.nullable) = false];
}

// should I include account in Bech32PrefixRequest Account or Address?
message Bech32PrefixRequest {
string address = 1;
}
message Bech32PrefixRequest {}

message Bech32PrefixResponse {
string bech32_prefix = 1;
}

message Bech32AccStringRequest {
string bech32 = 1;
}

message Bech32AccStringResponse {
string account = 1;
message Bech32FromAccAddrRequest {
bytes account_addr = 1;
}

message AccStringBech32Request {
string account = 1;
message Bech32FromAccAddrResponse {
string bech32 = 1;
}

message AccStringBech32Response {
message AccAddrFromBech32Request {
string bech32 = 1;
}






message AccAddrFromBech32Response {
bytes account_addr = 1;
}
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func NewSimApp(

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms,
appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), "cosmos", authtypes.ProtoBaseAccount, maccPerms,
)
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(),
Expand Down
38 changes: 32 additions & 6 deletions x/auth/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package keeper

import (
"context"
"errors"
"strings"

"github.com/cosmos/cosmos-sdk/store/prefix"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/types/bech32"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -85,21 +88,44 @@ func (ak AccountKeeper) Params(c context.Context, req *types.QueryParamsRequest)
}

func (ak AccountKeeper) Bech32Prefix(ctx context.Context, req *types.Bech32PrefixRequest) (*types.Bech32PrefixResponse, error) {
bech32Prefix := ak.GetBech32Prefix()
return &types.Bech32PrefixResponse{Bech32Prefix: bech32Prefix}, nil
}

func (ak AccountKeeper) Bech32FromAccAddr(ctx context.Context, req *types.Bech32FromAccAddrRequest) (*types.Bech32FromAccAddrResponse, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}

// do we need use UnwrapSDKContext here?
bech32Prefix := ak.GetBech32Prefix()
if len(req.AccountAddr) == 0 {
return nil, errors.New("empty bech32 string is not allowed")
}

return &types.Bech32PrefixResponse{bech32Prefix}, nil
bech32,err := bech32.ConvertAndEncode(ak.bech32Prefix, req.AccountAddr)
if err != nil {
return nil, err
}

return &types.Bech32FromAccAddrResponse{Bech32: bech32},nil
}

func (ak AccountKeeper) Bech32AccString(ctx context.Context, req *types.Bech32AccStringRequest) (*types.Bech32AccStringResponse, error) {
func (ak AccountKeeper) AccAddrFromBech32(ctx context.Context, req *types.AccAddrFromBech32Request) (*types.AccAddrFromBech32Response, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}

}
if len(strings.TrimSpace(req.Bech32)) == 0 {
return nil, errors.New("empty bech32 string is not allowed")
}

func (ak AccountKeeper) AccStringBech32(ctx context.Context, req *types.AccStringBech32Request) (*types.AccStringBech32Response, error)
_, bz, err := bech32.DecodeAndConvert(req.Bech32)
if err != nil {
return nil, err
}

if err := sdk.VerifyAddressFormat(bz); err != nil {
return nil, err
}

return &types.AccAddrFromBech32Response{AccountAddr: bz},nil
}
Loading

0 comments on commit 556810d

Please sign in to comment.