feat(x/precisebank): Add query service with TotalFractionalBalances (#1970)

Add query service to precisebank, mostly for e2e test purposes in #1966
Also fix client grpc codec
This commit is contained in:
drklee3 2024-07-19 10:24:23 -07:00 committed by GitHub
parent 7aef2f09e9
commit 3853e276a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 950 additions and 31 deletions

View File

@ -6,6 +6,8 @@ import (
"fmt"
"net/url"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/kava-labs/kava/app"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
@ -28,8 +30,20 @@ func newGrpcConnection(ctx context.Context, endpoint string) (*grpc.ClientConn,
return nil, fmt.Errorf("unknown grpc url scheme: %s", grpcUrl.Scheme)
}
// Ensure the encoding config is set up correctly with the query client
// otherwise it will produce panics like:
// invalid Go type math.Int for field ...
encodingConfig := app.MakeEncodingConfig()
protoCodec := codec.NewProtoCodec(encodingConfig.InterfaceRegistry)
grpcCodec := protoCodec.GRPCCodec()
secureOpt := grpc.WithTransportCredentials(creds)
grpcConn, err := grpc.DialContext(ctx, grpcUrl.Host, secureOpt)
grpcConn, err := grpc.DialContext(
ctx,
grpcUrl.Host,
secureOpt,
grpc.WithDefaultCallOptions(grpc.ForceCodec(grpcCodec)),
)
if err != nil {
return nil, err
}

View File

@ -36,6 +36,7 @@ import (
issuancetypes "github.com/kava-labs/kava/x/issuance/types"
kavadisttypes "github.com/kava-labs/kava/x/kavadist/types"
liquidtypes "github.com/kava-labs/kava/x/liquid/types"
precisebanktypes "github.com/kava-labs/kava/x/precisebank/types"
pricefeedtypes "github.com/kava-labs/kava/x/pricefeed/types"
savingstypes "github.com/kava-labs/kava/x/savings/types"
swaptypes "github.com/kava-labs/kava/x/swap/types"
@ -85,6 +86,7 @@ type QueryClient struct {
Pricefeed pricefeedtypes.QueryClient
Savings savingstypes.QueryClient
Swap swaptypes.QueryClient
Precisebank precisebanktypes.QueryClient
}
// NewQueryClient creates a new QueryClient and initializes all the module query clients
@ -130,6 +132,7 @@ func NewQueryClient(grpcEndpoint string) (*QueryClient, error) {
Pricefeed: pricefeedtypes.NewQueryClient(conn),
Savings: savingstypes.NewQueryClient(conn),
Swap: swaptypes.NewQueryClient(conn),
Precisebank: precisebanktypes.NewQueryClient(conn),
}
return client, nil
}

View File

@ -480,6 +480,12 @@
- [FractionalBalance](#kava.precisebank.v1.FractionalBalance)
- [GenesisState](#kava.precisebank.v1.GenesisState)
- [kava/precisebank/v1/query.proto](#kava/precisebank/v1/query.proto)
- [QueryTotalFractionalBalancesRequest](#kava.precisebank.v1.QueryTotalFractionalBalancesRequest)
- [QueryTotalFractionalBalancesResponse](#kava.precisebank.v1.QueryTotalFractionalBalancesResponse)
- [Query](#kava.precisebank.v1.Query)
- [kava/pricefeed/v1beta1/store.proto](#kava/pricefeed/v1beta1/store.proto)
- [CurrentPrice](#kava.pricefeed.v1beta1.CurrentPrice)
- [Market](#kava.pricefeed.v1beta1.Market)
@ -6676,6 +6682,57 @@ GenesisState defines the precisebank module's genesis state.
<a name="kava/precisebank/v1/query.proto"></a>
<p align="right"><a href="#top">Top</a></p>
## kava/precisebank/v1/query.proto
<a name="kava.precisebank.v1.QueryTotalFractionalBalancesRequest"></a>
### QueryTotalFractionalBalancesRequest
QueryTotalFractionalBalancesRequest defines the request type for Query/TotalFractionalBalances method.
<a name="kava.precisebank.v1.QueryTotalFractionalBalancesResponse"></a>
### QueryTotalFractionalBalancesResponse
QueryTotalFractionalBalancesResponse defines the response type for Query/TotalFractionalBalances method.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `total` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | total is the total sum of all fractional balances managed by the precisebank module. |
<!-- end messages -->
<!-- end enums -->
<!-- end HasExtensions -->
<a name="kava.precisebank.v1.Query"></a>
### Query
Query defines the gRPC querier service for precisebank module
| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `TotalFractionalBalances` | [QueryTotalFractionalBalancesRequest](#kava.precisebank.v1.QueryTotalFractionalBalancesRequest) | [QueryTotalFractionalBalancesResponse](#kava.precisebank.v1.QueryTotalFractionalBalancesResponse) | TotalFractionalBalances returns the total sum of all fractional balances managed by the precisebank module. | GET|/kava/precisebank/v1/total_fractional_balances|
<!-- end services -->
<a name="kava/pricefeed/v1beta1/store.proto"></a>
<p align="right"><a href="#top">Top</a></p>

View File

@ -0,0 +1,28 @@
syntax = "proto3";
package kava.precisebank.v1;
import "cosmos/base/v1beta1/coin.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
option go_package = "github.com/kava-labs/kava/x/precisebank/types";
option (gogoproto.goproto_getters_all) = false;
// Query defines the gRPC querier service for precisebank module
service Query {
// TotalFractionalBalances returns the total sum of all fractional balances
// managed by the precisebank module.
rpc TotalFractionalBalances(QueryTotalFractionalBalancesRequest) returns (QueryTotalFractionalBalancesResponse) {
option (google.api.http).get = "/kava/precisebank/v1/total_fractional_balances";
}
}
// QueryTotalFractionalBalancesRequest defines the request type for Query/TotalFractionalBalances method.
message QueryTotalFractionalBalancesRequest {}
// QueryTotalFractionalBalancesResponse defines the response type for Query/TotalFractionalBalances method.
message QueryTotalFractionalBalancesResponse {
// total is the total sum of all fractional balances managed by the precisebank
// module.
cosmos.base.v1beta1.Coin total = 1 [(gogoproto.nullable) = false];
}

View File

@ -0,0 +1,38 @@
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/x/precisebank/types"
)
type queryServer struct {
keeper Keeper
}
// NewQueryServerImpl creates a new server for handling gRPC queries.
func NewQueryServerImpl(k Keeper) types.QueryServer {
return &queryServer{keeper: k}
}
var _ types.QueryServer = queryServer{}
// TotalFractionalBalances returns the total sum of all fractional balances.
// This is mostly for external verification of the total fractional balances,
// being a multiple of the conversion factor and backed by the reserve.
func (s queryServer) TotalFractionalBalances(
goCtx context.Context,
req *types.QueryTotalFractionalBalancesRequest,
) (*types.QueryTotalFractionalBalancesResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
totalAmount := s.keeper.GetTotalSumFractionalBalances(ctx)
totalCoin := sdk.NewCoin(types.ExtendedCoinDenom, totalAmount)
return &types.QueryTotalFractionalBalancesResponse{
Total: totalCoin,
}, nil
}

View File

@ -0,0 +1,86 @@
package keeper_test
import (
"context"
"strconv"
"testing"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/suite"
"github.com/kava-labs/kava/x/precisebank/keeper"
"github.com/kava-labs/kava/x/precisebank/testutil"
"github.com/kava-labs/kava/x/precisebank/types"
)
type grpcQueryTestSuite struct {
testutil.Suite
queryClient types.QueryClient
}
func (suite *grpcQueryTestSuite) SetupTest() {
suite.Suite.SetupTest()
queryHelper := baseapp.NewQueryServerTestHelper(suite.Ctx, suite.App.InterfaceRegistry())
types.RegisterQueryServer(queryHelper, keeper.NewQueryServerImpl(suite.Keeper))
suite.queryClient = types.NewQueryClient(queryHelper)
}
func TestGrpcQueryTestSuite(t *testing.T) {
suite.Run(t, new(grpcQueryTestSuite))
}
func (suite *grpcQueryTestSuite) TestQueryTotalFractionalBalance() {
testCases := []struct {
name string
giveBalances []sdkmath.Int
}{
{
"empty",
[]sdkmath.Int{},
},
{
"min amount",
[]sdkmath.Int{
types.ConversionFactor().QuoRaw(2),
types.ConversionFactor().QuoRaw(2),
},
},
{
"exceeds conversion factor",
[]sdkmath.Int{
// 4 accounts * 0.5 == 2
types.ConversionFactor().QuoRaw(2),
types.ConversionFactor().QuoRaw(2),
types.ConversionFactor().QuoRaw(2),
types.ConversionFactor().QuoRaw(2),
},
},
}
for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.SetupTest()
total := sdk.NewCoin(types.ExtendedCoinDenom, sdkmath.ZeroInt())
for i, balance := range tc.giveBalances {
addr := sdk.AccAddress([]byte(strconv.Itoa(i)))
suite.Keeper.SetFractionalBalance(suite.Ctx, addr, balance)
total.Amount = total.Amount.Add(balance)
}
res, err := suite.queryClient.TotalFractionalBalances(
context.Background(),
&types.QueryTotalFractionalBalancesRequest{},
)
suite.Require().NoError(err)
suite.Require().Equal(total, res.Total)
})
}
}

View File

@ -1,6 +1,7 @@
package precisebank
import (
"context"
"encoding/json"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
@ -70,6 +71,9 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for precisebank module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
// GetTxCmd returns precisebank module's root tx command.
@ -117,6 +121,7 @@ func (am AppModule) Name() string {
// RegisterServices registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))
}
// RegisterInvariants registers precisebank module's invariants.

View File

@ -0,0 +1,535 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: kava/precisebank/v1/query.proto
package types
import (
context "context"
fmt "fmt"
types "github.com/cosmos/cosmos-sdk/types"
_ "github.com/cosmos/gogoproto/gogoproto"
grpc1 "github.com/cosmos/gogoproto/grpc"
proto "github.com/cosmos/gogoproto/proto"
_ "google.golang.org/genproto/googleapis/api/annotations"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
io "io"
math "math"
math_bits "math/bits"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
// QueryTotalFractionalBalancesRequest defines the request type for Query/TotalFractionalBalances method.
type QueryTotalFractionalBalancesRequest struct {
}
func (m *QueryTotalFractionalBalancesRequest) Reset() { *m = QueryTotalFractionalBalancesRequest{} }
func (m *QueryTotalFractionalBalancesRequest) String() string { return proto.CompactTextString(m) }
func (*QueryTotalFractionalBalancesRequest) ProtoMessage() {}
func (*QueryTotalFractionalBalancesRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_8a91a8caa7551030, []int{0}
}
func (m *QueryTotalFractionalBalancesRequest) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *QueryTotalFractionalBalancesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_QueryTotalFractionalBalancesRequest.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *QueryTotalFractionalBalancesRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_QueryTotalFractionalBalancesRequest.Merge(m, src)
}
func (m *QueryTotalFractionalBalancesRequest) XXX_Size() int {
return m.Size()
}
func (m *QueryTotalFractionalBalancesRequest) XXX_DiscardUnknown() {
xxx_messageInfo_QueryTotalFractionalBalancesRequest.DiscardUnknown(m)
}
var xxx_messageInfo_QueryTotalFractionalBalancesRequest proto.InternalMessageInfo
// QueryTotalFractionalBalancesResponse defines the response type for Query/TotalFractionalBalances method.
type QueryTotalFractionalBalancesResponse struct {
// total is the total sum of all fractional balances managed by the precisebank
// module.
Total types.Coin `protobuf:"bytes,1,opt,name=total,proto3" json:"total"`
}
func (m *QueryTotalFractionalBalancesResponse) Reset() { *m = QueryTotalFractionalBalancesResponse{} }
func (m *QueryTotalFractionalBalancesResponse) String() string { return proto.CompactTextString(m) }
func (*QueryTotalFractionalBalancesResponse) ProtoMessage() {}
func (*QueryTotalFractionalBalancesResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_8a91a8caa7551030, []int{1}
}
func (m *QueryTotalFractionalBalancesResponse) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *QueryTotalFractionalBalancesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_QueryTotalFractionalBalancesResponse.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *QueryTotalFractionalBalancesResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_QueryTotalFractionalBalancesResponse.Merge(m, src)
}
func (m *QueryTotalFractionalBalancesResponse) XXX_Size() int {
return m.Size()
}
func (m *QueryTotalFractionalBalancesResponse) XXX_DiscardUnknown() {
xxx_messageInfo_QueryTotalFractionalBalancesResponse.DiscardUnknown(m)
}
var xxx_messageInfo_QueryTotalFractionalBalancesResponse proto.InternalMessageInfo
func init() {
proto.RegisterType((*QueryTotalFractionalBalancesRequest)(nil), "kava.precisebank.v1.QueryTotalFractionalBalancesRequest")
proto.RegisterType((*QueryTotalFractionalBalancesResponse)(nil), "kava.precisebank.v1.QueryTotalFractionalBalancesResponse")
}
func init() { proto.RegisterFile("kava/precisebank/v1/query.proto", fileDescriptor_8a91a8caa7551030) }
var fileDescriptor_8a91a8caa7551030 = []byte{
// 334 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x91, 0xc1, 0x4a, 0x3b, 0x31,
0x10, 0xc6, 0x37, 0x7f, 0xfe, 0xf5, 0xb0, 0xde, 0x56, 0x41, 0x2d, 0x92, 0x4a, 0x55, 0xf0, 0xd2,
0xc4, 0xad, 0x28, 0x7a, 0xad, 0xe0, 0xc5, 0x93, 0xc5, 0x93, 0x20, 0x65, 0xb2, 0xc4, 0x75, 0xe9,
0x36, 0xb3, 0xdd, 0xa4, 0x8b, 0xbd, 0xfa, 0x04, 0x82, 0xef, 0x24, 0x3d, 0x16, 0xbc, 0x78, 0x12,
0x6d, 0x7d, 0x10, 0xc9, 0xa6, 0x88, 0x42, 0x15, 0xf1, 0x36, 0x64, 0xbe, 0x6f, 0xbe, 0x5f, 0x66,
0xfc, 0x5a, 0x17, 0x0a, 0xe0, 0x59, 0x2e, 0xa3, 0x44, 0x4b, 0x01, 0xaa, 0xcb, 0x8b, 0x90, 0xf7,
0x07, 0x32, 0x1f, 0xb2, 0x2c, 0x47, 0x83, 0xc1, 0x92, 0x15, 0xb0, 0x4f, 0x02, 0x56, 0x84, 0x55,
0x1a, 0xa1, 0xee, 0xa1, 0xe6, 0x02, 0xb4, 0xe4, 0x45, 0x28, 0xa4, 0x81, 0x90, 0x47, 0x98, 0x28,
0x67, 0xaa, 0x2e, 0xc7, 0x18, 0x63, 0x59, 0x72, 0x5b, 0xcd, 0x5e, 0xd7, 0x63, 0xc4, 0x38, 0x95,
0x1c, 0xb2, 0x84, 0x83, 0x52, 0x68, 0xc0, 0x24, 0xa8, 0xb4, 0xeb, 0xd6, 0xb7, 0xfd, 0xcd, 0x33,
0x9b, 0x7b, 0x8e, 0x06, 0xd2, 0x93, 0x1c, 0x22, 0xdb, 0x84, 0xb4, 0x05, 0x29, 0xa8, 0x48, 0xea,
0xb6, 0xec, 0x0f, 0xa4, 0x36, 0xf5, 0x4b, 0x7f, 0xeb, 0x67, 0x99, 0xce, 0x50, 0x69, 0x19, 0xec,
0xfb, 0x15, 0x63, 0x25, 0xab, 0x64, 0x83, 0xec, 0x2c, 0x36, 0xd7, 0x98, 0x43, 0x66, 0x16, 0x99,
0xcd, 0x90, 0xd9, 0x31, 0x26, 0xaa, 0xf5, 0x7f, 0xf4, 0x5c, 0xf3, 0xda, 0x4e, 0xdd, 0x1c, 0x13,
0xbf, 0x52, 0xce, 0x0f, 0x1e, 0x88, 0xbf, 0xf2, 0x4d, 0x48, 0x70, 0xc8, 0xe6, 0x6c, 0x85, 0xfd,
0x02, 0xbf, 0x7a, 0xf4, 0x07, 0xa7, 0xfb, 0x51, 0xfd, 0xe0, 0xf6, 0xf1, 0xed, 0xfe, 0xdf, 0x6e,
0xc0, 0xf8, 0xbc, 0x9b, 0x95, 0xf8, 0x9d, 0xab, 0x0f, 0x7b, 0x47, 0xcc, 0xfc, 0xad, 0xd3, 0xd1,
0x2b, 0xf5, 0x46, 0x13, 0x4a, 0xc6, 0x13, 0x4a, 0x5e, 0x26, 0x94, 0xdc, 0x4d, 0xa9, 0x37, 0x9e,
0x52, 0xef, 0x69, 0x4a, 0xbd, 0x8b, 0x46, 0x9c, 0x98, 0xeb, 0x81, 0x60, 0x11, 0xf6, 0xca, 0xb9,
0x8d, 0x14, 0x84, 0x76, 0x09, 0x37, 0x5f, 0x32, 0xcc, 0x30, 0x93, 0x5a, 0x2c, 0x94, 0xc7, 0xda,
0x7b, 0x0f, 0x00, 0x00, 0xff, 0xff, 0xd1, 0x42, 0xb7, 0x92, 0x38, 0x02, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// QueryClient is the client API for Query service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type QueryClient interface {
// TotalFractionalBalances returns the total sum of all fractional balances
// managed by the precisebank module.
TotalFractionalBalances(ctx context.Context, in *QueryTotalFractionalBalancesRequest, opts ...grpc.CallOption) (*QueryTotalFractionalBalancesResponse, error)
}
type queryClient struct {
cc grpc1.ClientConn
}
func NewQueryClient(cc grpc1.ClientConn) QueryClient {
return &queryClient{cc}
}
func (c *queryClient) TotalFractionalBalances(ctx context.Context, in *QueryTotalFractionalBalancesRequest, opts ...grpc.CallOption) (*QueryTotalFractionalBalancesResponse, error) {
out := new(QueryTotalFractionalBalancesResponse)
err := c.cc.Invoke(ctx, "/kava.precisebank.v1.Query/TotalFractionalBalances", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// QueryServer is the server API for Query service.
type QueryServer interface {
// TotalFractionalBalances returns the total sum of all fractional balances
// managed by the precisebank module.
TotalFractionalBalances(context.Context, *QueryTotalFractionalBalancesRequest) (*QueryTotalFractionalBalancesResponse, error)
}
// UnimplementedQueryServer can be embedded to have forward compatible implementations.
type UnimplementedQueryServer struct {
}
func (*UnimplementedQueryServer) TotalFractionalBalances(ctx context.Context, req *QueryTotalFractionalBalancesRequest) (*QueryTotalFractionalBalancesResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method TotalFractionalBalances not implemented")
}
func RegisterQueryServer(s grpc1.Server, srv QueryServer) {
s.RegisterService(&_Query_serviceDesc, srv)
}
func _Query_TotalFractionalBalances_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(QueryTotalFractionalBalancesRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(QueryServer).TotalFractionalBalances(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/kava.precisebank.v1.Query/TotalFractionalBalances",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(QueryServer).TotalFractionalBalances(ctx, req.(*QueryTotalFractionalBalancesRequest))
}
return interceptor(ctx, in, info, handler)
}
var _Query_serviceDesc = grpc.ServiceDesc{
ServiceName: "kava.precisebank.v1.Query",
HandlerType: (*QueryServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "TotalFractionalBalances",
Handler: _Query_TotalFractionalBalances_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "kava/precisebank/v1/query.proto",
}
func (m *QueryTotalFractionalBalancesRequest) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *QueryTotalFractionalBalancesRequest) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *QueryTotalFractionalBalancesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
return len(dAtA) - i, nil
}
func (m *QueryTotalFractionalBalancesResponse) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *QueryTotalFractionalBalancesResponse) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *QueryTotalFractionalBalancesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
{
size, err := m.Total.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintQuery(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0xa
return len(dAtA) - i, nil
}
func encodeVarintQuery(dAtA []byte, offset int, v uint64) int {
offset -= sovQuery(v)
base := offset
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return base
}
func (m *QueryTotalFractionalBalancesRequest) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
return n
}
func (m *QueryTotalFractionalBalancesResponse) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = m.Total.Size()
n += 1 + l + sovQuery(uint64(l))
return n
}
func sovQuery(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
func sozQuery(x uint64) (n int) {
return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *QueryTotalFractionalBalancesRequest) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowQuery
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: QueryTotalFractionalBalancesRequest: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: QueryTotalFractionalBalancesRequest: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
default:
iNdEx = preIndex
skippy, err := skipQuery(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthQuery
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *QueryTotalFractionalBalancesResponse) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowQuery
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: QueryTotalFractionalBalancesResponse: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: QueryTotalFractionalBalancesResponse: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Total", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowQuery
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthQuery
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthQuery
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := m.Total.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipQuery(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthQuery
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipQuery(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
depth := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowQuery
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
wireType := int(wire & 0x7)
switch wireType {
case 0:
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowQuery
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
iNdEx++
if dAtA[iNdEx-1] < 0x80 {
break
}
}
case 1:
iNdEx += 8
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowQuery
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
length |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if length < 0 {
return 0, ErrInvalidLengthQuery
}
iNdEx += length
case 3:
depth++
case 4:
if depth == 0 {
return 0, ErrUnexpectedEndOfGroupQuery
}
depth--
case 5:
iNdEx += 4
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
if iNdEx < 0 {
return 0, ErrInvalidLengthQuery
}
if depth == 0 {
return iNdEx, nil
}
}
return 0, io.ErrUnexpectedEOF
}
var (
ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow")
ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group")
)

View File

@ -0,0 +1,153 @@
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: kava/precisebank/v1/query.proto
/*
Package types is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
*/
package types
import (
"context"
"io"
"net/http"
"github.com/golang/protobuf/descriptor"
"github.com/golang/protobuf/proto"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/grpc-ecosystem/grpc-gateway/utilities"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
)
// Suppress "imported and not used" errors
var _ codes.Code
var _ io.Reader
var _ status.Status
var _ = runtime.String
var _ = utilities.NewDoubleArray
var _ = descriptor.ForMessage
var _ = metadata.Join
func request_Query_TotalFractionalBalances_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryTotalFractionalBalancesRequest
var metadata runtime.ServerMetadata
msg, err := client.TotalFractionalBalances(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Query_TotalFractionalBalances_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryTotalFractionalBalancesRequest
var metadata runtime.ServerMetadata
msg, err := server.TotalFractionalBalances(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.
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead.
func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error {
mux.Handle("GET", pattern_Query_TotalFractionalBalances_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
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_TotalFractionalBalances_0(rctx, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_TotalFractionalBalances_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
conn, err := grpc.Dial(endpoint, opts...)
if err != nil {
return err
}
defer func() {
if err != nil {
if cerr := conn.Close(); cerr != nil {
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
}
return
}
go func() {
<-ctx.Done()
if cerr := conn.Close(); cerr != nil {
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
}
}()
}()
return RegisterQueryHandler(ctx, mux, conn)
}
// RegisterQueryHandler registers the http handlers for service Query to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn))
}
// RegisterQueryHandlerClient registers the http handlers for service Query
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient".
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient"
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "QueryClient" to call the correct interceptors.
func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error {
mux.Handle("GET", pattern_Query_TotalFractionalBalances_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_TotalFractionalBalances_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_TotalFractionalBalances_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_Query_TotalFractionalBalances_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"kava", "precisebank", "v1", "total_fractional_balances"}, "", runtime.AssumeColonVerbOpt(false)))
)
var (
forward_Query_TotalFractionalBalances_0 = runtime.ForwardResponseMessage
)