feat!: Add bech32 prefix to authkeeper (#9759)

<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->

## Description

Closes **Step1** from #9690

<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->

- Add auth keeper methods and gRPC queries:
  - the `NewAccountKeeper` should take a `string bech32Prefix` argument
  - ` auth AccountKeeper` implements `Codec` interface that contains 2 methods:  `ConvertAddressStringToBytes` and `ConvertAddressBytesToString` 
  - Add the 3 following gRPC queries:
    - Get bech32 prefix
    - `AddressStringToBytes` (converts `AccountAddr` string to `AccountAddr` bytes)
    - `AddressBytesToString` ( converts `AccountAddr` bytes to `AccountAddr` str)
  - Add the corresponding keeper methods
  - Add tests
---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [x] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
This commit is contained in:
Andrei Ivasko 2021-08-25 14:17:18 +03:00 committed by GitHub
parent 147d798048
commit 59640fb858
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 2080 additions and 357 deletions

View File

@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### API Breaking Changes
* [\#9759](https://github.com/cosmos/cosmos-sdk/pull/9759) `NewAccountKeeeper` in `x/auth` now takes an additional `bech32Prefix` argument that represents `sdk.Bech32MainPrefix`.
* [\#9628](https://github.com/cosmos/cosmos-sdk/pull/9628) Rename `x/{mod}/legacy` to `x/{mod}/migrations`.
* [\#9571](https://github.com/cosmos/cosmos-sdk/pull/9571) Implemented error handling for staking hooks, which now return an error on failure.
* [\#9427](https://github.com/cosmos/cosmos-sdk/pull/9427) Move simapp `FundAccount` and `FundModuleAccount` to `x/bank/testutil`

File diff suppressed because one or more lines are too long

View File

@ -11,8 +11,8 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/network"
qtypes "github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/testutil/rest"
qtypes "github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/version"
)

View File

@ -17,6 +17,12 @@
- [PageResponse](#cosmos.base.query.v1beta1.PageResponse)
- [cosmos/auth/v1beta1/query.proto](#cosmos/auth/v1beta1/query.proto)
- [AddressBytesToStringRequest](#cosmos.auth.v1beta1.AddressBytesToStringRequest)
- [AddressBytesToStringResponse](#cosmos.auth.v1beta1.AddressBytesToStringResponse)
- [AddressStringToBytesRequest](#cosmos.auth.v1beta1.AddressStringToBytesRequest)
- [AddressStringToBytesResponse](#cosmos.auth.v1beta1.AddressStringToBytesResponse)
- [Bech32PrefixRequest](#cosmos.auth.v1beta1.Bech32PrefixRequest)
- [Bech32PrefixResponse](#cosmos.auth.v1beta1.Bech32PrefixResponse)
- [QueryAccountRequest](#cosmos.auth.v1beta1.QueryAccountRequest)
- [QueryAccountResponse](#cosmos.auth.v1beta1.QueryAccountResponse)
- [QueryAccountsRequest](#cosmos.auth.v1beta1.QueryAccountsRequest)
@ -846,6 +852,91 @@ corresponding request message has used PageRequest.
<a name="cosmos.auth.v1beta1.AddressBytesToStringRequest"></a>
### AddressBytesToStringRequest
AddressBytesToStringRequest is the request type for AddressString rpc method
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `address_bytes` | [bytes](#bytes) | | |
<a name="cosmos.auth.v1beta1.AddressBytesToStringResponse"></a>
### AddressBytesToStringResponse
AddressBytesToStringResponse is the response type for AddressString rpc method
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `address_string` | [string](#string) | | |
<a name="cosmos.auth.v1beta1.AddressStringToBytesRequest"></a>
### AddressStringToBytesRequest
AddressStringToBytesRequest is the request type for AccountBytes rpc method
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `address_string` | [string](#string) | | |
<a name="cosmos.auth.v1beta1.AddressStringToBytesResponse"></a>
### AddressStringToBytesResponse
AddressStringToBytesResponse is the response type for AddressBytes rpc method
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `address_bytes` | [bytes](#bytes) | | |
<a name="cosmos.auth.v1beta1.Bech32PrefixRequest"></a>
### Bech32PrefixRequest
Bech32PrefixRequest is the request type for Bech32Prefix rpc method
<a name="cosmos.auth.v1beta1.Bech32PrefixResponse"></a>
### Bech32PrefixResponse
Bech32PrefixResponse is the response type for Bech32Prefix rpc method
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `bech32_prefix` | [string](#string) | | |
<a name="cosmos.auth.v1beta1.QueryAccountRequest"></a>
### QueryAccountRequest
@ -974,6 +1065,9 @@ 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|
| `ModuleAccounts` | [QueryModuleAccountsRequest](#cosmos.auth.v1beta1.QueryModuleAccountsRequest) | [QueryModuleAccountsResponse](#cosmos.auth.v1beta1.QueryModuleAccountsResponse) | ModuleAccounts returns all the existing module accounts. | GET|/cosmos/auth/v1beta1/module_accounts|
| `Bech32Prefix` | [Bech32PrefixRequest](#cosmos.auth.v1beta1.Bech32PrefixRequest) | [Bech32PrefixResponse](#cosmos.auth.v1beta1.Bech32PrefixResponse) | Bech32 queries bech32Prefix | GET|/cosmos/auth/v1beta1/bech32|
| `AddressBytesToString` | [AddressBytesToStringRequest](#cosmos.auth.v1beta1.AddressBytesToStringRequest) | [AddressBytesToStringResponse](#cosmos.auth.v1beta1.AddressBytesToStringResponse) | AddressBytesToString converts Account Address bytes to string | GET|/cosmos/auth/v1beta1/bech32/{address_bytes}|
| `AddressStringToBytes` | [AddressStringToBytesRequest](#cosmos.auth.v1beta1.AddressStringToBytesRequest) | [AddressStringToBytesResponse](#cosmos.auth.v1beta1.AddressStringToBytesResponse) | AddressStringToBytes converts Address string to bytes | GET|/cosmos/auth/v1beta1/bech32/{address_string}|
<!-- end services -->

View File

@ -31,6 +31,21 @@ service Query {
rpc ModuleAccounts(QueryModuleAccountsRequest) returns (QueryModuleAccountsResponse) {
option (google.api.http).get = "/cosmos/auth/v1beta1/module_accounts";
}
// Bech32 queries bech32Prefix
rpc Bech32Prefix(Bech32PrefixRequest) returns (Bech32PrefixResponse) {
option (google.api.http).get = "/cosmos/auth/v1beta1/bech32";
}
// AddressBytesToString converts Account Address bytes to string
rpc AddressBytesToString(AddressBytesToStringRequest) returns (AddressBytesToStringResponse) {
option (google.api.http).get = "/cosmos/auth/v1beta1/bech32/{address_bytes}";
}
// AddressStringToBytes converts Address string to bytes
rpc AddressStringToBytes(AddressStringToBytesRequest) returns (AddressStringToBytesResponse) {
option (google.api.http).get = "/cosmos/auth/v1beta1/bech32/{address_string}";
}
}
// QueryAccountsRequest is the request type for the Query/Accounts RPC method.
@ -57,6 +72,15 @@ message QueryAccountRequest {
string address = 1;
}
// QueryModuleAccountsRequest is the request type for the Query/ModuleAccounts RPC method.
message QueryModuleAccountsRequest {}
// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];
}
// QueryAccountResponse is the response type for the Query/Account RPC method.
message QueryAccountResponse {
// account defines the account of the corresponding address.
@ -66,16 +90,35 @@ message QueryAccountResponse {
// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}
// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];
}
// QueryModuleAccountsRequest is the request type for the Query/ModuleAccounts RPC method.
message QueryModuleAccountsRequest {}
// QueryModuleAccountsResponse is the response type for the Query/ModuleAccounts RPC method.
message QueryModuleAccountsResponse {
repeated google.protobuf.Any accounts = 1 [(cosmos_proto.accepts_interface) = "ModuleAccountI"];
}
}
// Bech32PrefixRequest is the request type for Bech32Prefix rpc method
message Bech32PrefixRequest {}
// Bech32PrefixResponse is the response type for Bech32Prefix rpc method
message Bech32PrefixResponse {
string bech32_prefix = 1;
}
// AddressBytesToStringRequest is the request type for AddressString rpc method
message AddressBytesToStringRequest {
bytes address_bytes = 1;
}
// AddressBytesToStringResponse is the response type for AddressString rpc method
message AddressBytesToStringResponse {
string address_string = 1;
}
// AddressStringToBytesRequest is the request type for AccountBytes rpc method
message AddressStringToBytesRequest {
string address_string = 1;
}
// AddressStringToBytesResponse is the response type for AddressBytes rpc method
message AddressStringToBytesResponse {
bytes address_bytes = 1;
}

View File

@ -234,7 +234,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), authtypes.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix,
)
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(),

View File

@ -136,7 +136,9 @@ func AccAddressFromHex(address string) (addr AccAddress, err error) {
// VerifyAddressFormat verifies that the provided bytes form a valid address
// according to the default address rules or a custom address verifier set by
// GetConfig().SetAddressVerifier()
// GetConfig().SetAddressVerifier().
// TODO make an issue to get rid of global Config
// ref: https://github.com/cosmos/cosmos-sdk/issues/9690
func VerifyAddressFormat(bz []byte) error {
verifier := GetConfig().GetAddressVerifier()
if verifier != nil {

9
types/address/codec.go Normal file
View File

@ -0,0 +1,9 @@
package address
// Codec defines an interface to convert addresses from and to string/bytes.
type Codec interface {
// StringToBytes decodes text to bytes
StringToBytes(text string) ([]byte, error)
// BytesToString encodes bytes to text
BytesToString(bz []byte) (string, error)
}

View File

@ -0,0 +1,46 @@
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
"github.com/cosmos/cosmos-sdk/types/bech32"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
type bech32Codec struct {
bech32Prefix string
}
var _ address.Codec = &bech32Codec{}
func newBech32Codec(prefix string) bech32Codec {
return bech32Codec{prefix}
}
// StringToBytes encodes text to bytes
func (bc bech32Codec) StringToBytes(text string) ([]byte, error) {
hrp, bz, err := bech32.DecodeAndConvert(text)
if err != nil {
return nil, err
}
if hrp != bc.bech32Prefix {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "hrp does not match bech32Prefix")
}
if err := sdk.VerifyAddressFormat(bz); err != nil {
return nil, err
}
return bz, nil
}
// BytesToString decodes bytes to text
func (bc bech32Codec) BytesToString(bz []byte) (string, error) {
text, err := bech32.ConvertAndEncode(bc.bech32Prefix, bz)
if err != nil {
return "", err
}
return text, nil
}

View File

@ -2,6 +2,8 @@ package keeper
import (
"context"
"errors"
"strings"
"github.com/cosmos/cosmos-sdk/store/prefix"
"github.com/cosmos/cosmos-sdk/types/query"
@ -108,3 +110,46 @@ func (ak AccountKeeper) ModuleAccounts(c context.Context, req *types.QueryModule
return &types.QueryModuleAccountsResponse{Accounts: modAccounts}, nil
}
func (ak AccountKeeper) Bech32Prefix(ctx context.Context, req *types.Bech32PrefixRequest) (*types.Bech32PrefixResponse, error) {
bech32Prefix, err := ak.getBech32Prefix()
if err != nil {
return nil, err
}
return &types.Bech32PrefixResponse{Bech32Prefix: bech32Prefix}, nil
}
func (ak AccountKeeper) AddressBytesToString(ctx context.Context, req *types.AddressBytesToStringRequest) (*types.AddressBytesToStringResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.AddressBytes) == 0 {
return nil, errors.New("empty address bytes is not allowed")
}
text, err := ak.addressCdc.BytesToString(req.AddressBytes)
if err != nil {
return nil, err
}
return &types.AddressBytesToStringResponse{AddressString: text}, nil
}
func (ak AccountKeeper) AddressStringToBytes(ctx context.Context, req *types.AddressStringToBytesRequest) (*types.AddressStringToBytesResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(strings.TrimSpace(req.AddressString)) == 0 {
return nil, errors.New("empty address string is not allowed")
}
bz, err := ak.addressCdc.StringToBytes(req.AddressString)
if err != nil {
return nil, err
}
return &types.AddressStringToBytesResponse{AddressBytes: bz}, nil
}

View File

@ -2,12 +2,17 @@ package keeper_test
import (
"fmt"
"context"
"bytes"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)
const addrStr = "cosmos13c3d4wq2t22dl0dstraf8jc3f902e3fsy9n3wv"
var addrBytes = []byte{0x8e, 0x22, 0xda, 0xb8, 0xa, 0x5a, 0x94, 0xdf, 0xbd, 0xb0, 0x58, 0xfa, 0x93, 0xcb, 0x11, 0x49, 0x5e, 0xac, 0xc5, 0x30}
func (suite *KeeperTestSuite) TestGRPCQueryAccounts() {
var (
req *types.QueryAccountsRequest
@ -272,3 +277,102 @@ func (suite *KeeperTestSuite) TestGRPCQueryModuleAccounts() {
})
}
}
func (suite *KeeperTestSuite) TestBech32Prefix() {
suite.SetupTest() // reset
req := &types.Bech32PrefixRequest{}
res, err := suite.queryClient.Bech32Prefix(context.Background(), req)
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(sdk.Bech32MainPrefix, res.Bech32Prefix)
}
func (suite *KeeperTestSuite) TestAddressBytesToString() {
testCases := []struct {
msg string
req *types.AddressBytesToStringRequest
expPass bool
}{
{
"success",
&types.AddressBytesToStringRequest{AddressBytes: addrBytes},
true,
},
{
"request is empty",
&types.AddressBytesToStringRequest{},
false,
},
{
"empty account address in request",
&types.AddressBytesToStringRequest{AddressBytes: []byte{}},
false,
},
}
for _, tc := range testCases {
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
suite.SetupTest() // reset
res, err := suite.queryClient.AddressBytesToString(context.Background(), tc.req)
if tc.expPass {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(res.AddressString, addrStr)
} else {
suite.Require().Error(err)
suite.Require().Nil(res)
}
})
}
}
func (suite *KeeperTestSuite) TestAddressStringToBytes() {
testCases := []struct {
msg string
req *types.AddressStringToBytesRequest
expPass bool
}{
{
"success",
&types.AddressStringToBytesRequest{AddressString: addrStr},
true,
},
{
"request is empty",
&types.AddressStringToBytesRequest{},
false,
},
{
"AddressString field in request is empty",
&types.AddressStringToBytesRequest{AddressString: ""},
false,
},
{
"address prefix is incorrect",
&types.AddressStringToBytesRequest{AddressString: "regen13c3d4wq2t22dl0dstraf8jc3f902e3fsy9n3wv" },
false,
},
}
for _, tc := range testCases {
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
suite.SetupTest() // reset
res, err := suite.queryClient.AddressStringToBytes(context.Background(), tc.req)
if tc.expPass {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().True(bytes.Equal(res.AddressBytes, addrBytes))
} else {
suite.Require().Error(err)
suite.Require().Nil(res)
}
})
}
}

View File

@ -1,6 +1,7 @@
package keeper
import (
"errors"
"fmt"
gogotypes "github.com/gogo/protobuf/types"
@ -9,6 +10,8 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
@ -53,7 +56,8 @@ type AccountKeeper struct {
permAddrs map[string]types.PermissionsForAddress
// The prototypical AccountI constructor.
proto func() types.AccountI
proto func() types.AccountI
addressCdc address.Codec
}
var _ AccountKeeperI = &AccountKeeper{}
@ -66,7 +70,7 @@ var _ AccountKeeperI = &AccountKeeper{}
// may use auth.Keeper to access the accounts permissions map.
func NewAccountKeeper(
cdc codec.BinaryCodec, key sdk.StoreKey, paramstore paramtypes.Subspace, proto func() types.AccountI,
maccPerms map[string][]string,
maccPerms map[string][]string, bech32Prefix string,
) AccountKeeper {
// set KeyTable if it has not already been set
@ -79,12 +83,15 @@ func NewAccountKeeper(
permAddrs[name] = types.NewPermissionsForAddress(name, perms)
}
bech32Codec := newBech32Codec(bech32Prefix)
return AccountKeeper{
key: key,
proto: proto,
cdc: cdc,
paramSubspace: paramstore,
permAddrs: permAddrs,
addressCdc: bech32Codec,
}
}
@ -233,3 +240,13 @@ func (ak AccountKeeper) UnmarshalAccount(bz []byte) (types.AccountI, error) {
// GetCodec return codec.Codec object used by the keeper
func (ak AccountKeeper) GetCodec() codec.BinaryCodec { return ak.cdc }
// add getter for bech32Prefix
func (ak AccountKeeper) getBech32Prefix() (string, error) {
bech32Codec, ok := ak.addressCdc.(bech32Codec)
if !ok {
return "", errors.New("unable cast addressCdc to bech32Codec")
}
return bech32Codec.bech32Prefix, nil
}

View File

@ -132,7 +132,7 @@ func TestSupply_ValidatePermissions(t *testing.T) {
cdc := simapp.MakeTestEncodingConfig().Codec
keeper := keeper.NewAccountKeeper(
cdc, app.GetKey(types.StoreKey), app.GetSubspace(types.ModuleName),
types.ProtoBaseAccount, maccPerms,
types.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix,
)
err := keeper.ValidatePermissions(multiPermAcc)

File diff suppressed because it is too large Load Diff

View File

@ -157,6 +157,132 @@ func local_request_Query_ModuleAccounts_0(ctx context.Context, marshaler runtime
}
func request_Query_Bech32Prefix_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq Bech32PrefixRequest
var metadata runtime.ServerMetadata
msg, err := client.Bech32Prefix(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Query_Bech32Prefix_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq Bech32PrefixRequest
var metadata runtime.ServerMetadata
msg, err := server.Bech32Prefix(ctx, &protoReq)
return msg, metadata, err
}
func request_Query_AddressBytesToString_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq AddressBytesToStringRequest
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["address_bytes"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address_bytes")
}
protoReq.AddressBytes, err = runtime.Bytes(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address_bytes", err)
}
msg, err := client.AddressBytesToString(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Query_AddressBytesToString_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq AddressBytesToStringRequest
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["address_bytes"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address_bytes")
}
protoReq.AddressBytes, err = runtime.Bytes(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address_bytes", err)
}
msg, err := server.AddressBytesToString(ctx, &protoReq)
return msg, metadata, err
}
func request_Query_AddressStringToBytes_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq AddressStringToBytesRequest
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["address_string"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address_string")
}
protoReq.AddressString, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address_string", err)
}
msg, err := client.AddressStringToBytes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Query_AddressStringToBytes_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq AddressStringToBytesRequest
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["address_string"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address_string")
}
protoReq.AddressString, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address_string", err)
}
msg, err := server.AddressStringToBytes(ctx, &protoReq)
return msg, metadata, err
}
// RegisterQueryHandlerServer registers the http handlers for service Query to "mux".
// UnaryRPC :call QueryServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
@ -243,6 +369,66 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv
})
mux.Handle("GET", pattern_Query_Bech32Prefix_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Query_Bech32Prefix_0(rctx, inboundMarshaler, server, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_Bech32Prefix_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_Query_AddressBytesToString_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Query_AddressBytesToString_0(rctx, inboundMarshaler, server, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_AddressBytesToString_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_Query_AddressStringToBytes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Query_AddressStringToBytes_0(rctx, inboundMarshaler, server, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_AddressStringToBytes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@ -364,6 +550,66 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie
})
mux.Handle("GET", pattern_Query_Bech32Prefix_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Query_Bech32Prefix_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_Bech32Prefix_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_Query_AddressBytesToString_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Query_AddressBytesToString_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_AddressBytesToString_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_Query_AddressStringToBytes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Query_AddressStringToBytes_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_AddressStringToBytes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@ -375,6 +621,12 @@ var (
pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "auth", "v1beta1", "params"}, "", runtime.AssumeColonVerbOpt(false)))
pattern_Query_ModuleAccounts_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "auth", "v1beta1", "module_accounts"}, "", runtime.AssumeColonVerbOpt(false)))
pattern_Query_Bech32Prefix_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "auth", "v1beta1", "bech32"}, "", runtime.AssumeColonVerbOpt(false)))
pattern_Query_AddressBytesToString_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"cosmos", "auth", "v1beta1", "bech32", "address_bytes"}, "", runtime.AssumeColonVerbOpt(false)))
pattern_Query_AddressStringToBytes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"cosmos", "auth", "v1beta1", "bech32", "address_string"}, "", runtime.AssumeColonVerbOpt(false)))
)
var (
@ -385,4 +637,10 @@ var (
forward_Query_Params_0 = runtime.ForwardResponseMessage
forward_Query_ModuleAccounts_0 = runtime.ForwardResponseMessage
forward_Query_Bech32Prefix_0 = runtime.ForwardResponseMessage
forward_Query_AddressBytesToString_0 = runtime.ForwardResponseMessage
forward_Query_AddressStringToBytes_0 = runtime.ForwardResponseMessage
)

View File

@ -83,7 +83,7 @@ func (suite *IntegrationTestSuite) initKeepersWithmAccPerms(blockedAddrs map[str
maccPerms[randomPerm] = []string{"random"}
authKeeper := authkeeper.NewAccountKeeper(
appCodec, app.GetKey(types.StoreKey), app.GetSubspace(types.ModuleName),
authtypes.ProtoBaseAccount, maccPerms,
authtypes.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix,
)
keeper := keeper.NewBaseKeeper(
appCodec, app.GetKey(types.StoreKey), authKeeper,
@ -1043,7 +1043,7 @@ func (suite *IntegrationTestSuite) TestBalanceTrackingEvents() {
suite.app.AccountKeeper = authkeeper.NewAccountKeeper(
suite.app.AppCodec(), suite.app.GetKey(authtypes.StoreKey), suite.app.GetSubspace(authtypes.ModuleName),
authtypes.ProtoBaseAccount, maccPerms,
authtypes.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix,
)
suite.app.BankKeeper = keeper.NewBaseKeeper(suite.app.AppCodec(), suite.app.GetKey(types.StoreKey),