50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
)
|
|
|
|
var _ types.QueryServer = AccountKeeper{}
|
|
|
|
// Account returns account details based on address
|
|
func (ak AccountKeeper) Account(c context.Context, req *types.QueryAccountRequest) (*types.QueryAccountResponse, error) {
|
|
if req == nil {
|
|
return nil, status.Errorf(codes.InvalidArgument, "empty request")
|
|
}
|
|
|
|
if req.Address.Empty() {
|
|
return nil, status.Error(codes.InvalidArgument, "Address cannot be empty")
|
|
}
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
account := ak.GetAccount(ctx, req.Address)
|
|
if account == nil {
|
|
return nil, status.Errorf(codes.NotFound, "account %s not found", req.Address)
|
|
}
|
|
|
|
any, err := codectypes.NewAnyWithValue(account)
|
|
if err != nil {
|
|
return nil, status.Errorf(codes.Internal, err.Error())
|
|
}
|
|
|
|
return &types.QueryAccountResponse{Account: any}, nil
|
|
}
|
|
|
|
// Params returns parameters of auth module
|
|
func (ak AccountKeeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
|
|
if req == nil {
|
|
return nil, status.Error(codes.InvalidArgument, "empty request")
|
|
}
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
params := ak.GetParams(ctx)
|
|
|
|
return &types.QueryParamsResponse{Params: params}, nil
|
|
}
|