Add Vested Delegated API endpoint (#1327)

* add empty grpc endpoint

* add basic implementation

* remove unbonding from returned balance

* fix test typo

* resolve todo, use better method from staking mod
This commit is contained in:
Ruaridh 2022-10-05 23:56:39 +01:00 committed by GitHub
parent 55284aa575
commit a39c413a82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 1367 additions and 9 deletions

View File

@ -148,6 +148,23 @@
]
}
},
{
"url": "./tmp-swagger-gen/kava/liquid/v1beta1/query.swagger.json",
"tags": {
"rename": {
"Query": "Liquid"
}
},
"operationIds": {
"rename": [
{
"type": "regex",
"from": "(.*)",
"to": "Liquid$1"
}
]
}
},
{
"url": "./tmp-swagger-gen/kava/pricefeed/v1beta1/query.swagger.json",
"tags": {

View File

@ -10827,6 +10827,9 @@ paths:
format: byte
weight:
type: string
description: >-
CoreReward defines the reward weights for core
infrastructure providers.
partner_rewards:
type: array
items:
@ -10851,6 +10854,12 @@ paths:
implements the custom method
signatures required by gogoproto.
description: >-
PartnerRewards defines the reward schedule for
partner infrastructure providers.
description: >-
InfrastructureParams define the parameters for
infrastructure rewards.
title: Params governance parameters for kavadist module
description: >-
QueryParamsResponse defines the response type for querying
@ -10879,6 +10888,89 @@ paths:
format: byte
tags:
- Kavadist
/kava/liquid/v1beta1/delegated_balance/{delegator}:
get:
summary: >-
DelegatedBalance returns an account's vesting and vested coins currently
delegated to validators.
It ignores coins in unbonding delegations.
operationId: LiquidDelegatedBalance
responses:
'200':
description: A successful response.
schema:
type: object
properties:
vested:
title: >-
vested is the amount of all delegated coins that have vested
(ie not locked)
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.
NOTE: The amount field is an Int which implements the custom
method
signatures required by gogoproto.
vesting:
title: >-
vesting is the amount of all delegated coins that are still
vesting (ie locked)
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.
NOTE: The amount field is an Int which implements the custom
method
signatures required by gogoproto.
description: >-
DelegatedBalanceResponse defines the response type for the
Query/DelegatedBalance method.
default:
description: An unexpected error response
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: delegator
description: delegator is the address of the account to query
in: path
required: true
type: string
tags:
- Liquid
/kava/pricefeed/v1beta1/markets:
get:
summary: Markets queries all markets
@ -55908,6 +56000,7 @@ definitions:
format: byte
weight:
type: string
description: CoreReward defines the reward weights for core infrastructure providers.
kava.kavadist.v1beta1.InfrastructureParams:
type: object
properties:
@ -55944,6 +56037,9 @@ definitions:
format: byte
weight:
type: string
description: >-
CoreReward defines the reward weights for core infrastructure
providers.
partner_rewards:
type: array
items:
@ -55967,6 +56063,10 @@ definitions:
method
signatures required by gogoproto.
description: >-
PartnerRewards defines the reward schedule for partner
infrastructure providers.
description: InfrastructureParams define the parameters for infrastructure rewards.
kava.kavadist.v1beta1.Params:
type: object
properties:
@ -56032,6 +56132,9 @@ definitions:
format: byte
weight:
type: string
description: >-
CoreReward defines the reward weights for core infrastructure
providers.
partner_rewards:
type: array
items:
@ -56055,6 +56158,10 @@ definitions:
method
signatures required by gogoproto.
description: >-
PartnerRewards defines the reward schedule for partner
infrastructure providers.
description: InfrastructureParams define the parameters for infrastructure rewards.
title: Params governance parameters for kavadist module
kava.kavadist.v1beta1.PartnerReward:
type: object
@ -56074,6 +56181,9 @@ definitions:
NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
description: >-
PartnerRewards defines the reward schedule for partner infrastructure
providers.
kava.kavadist.v1beta1.Period:
type: object
properties:
@ -56183,6 +56293,9 @@ definitions:
format: byte
weight:
type: string
description: >-
CoreReward defines the reward weights for core
infrastructure providers.
partner_rewards:
type: array
items:
@ -56206,10 +56319,52 @@ definitions:
custom method
signatures required by gogoproto.
description: >-
PartnerRewards defines the reward schedule for partner
infrastructure providers.
description: >-
InfrastructureParams define the parameters for infrastructure
rewards.
title: Params governance parameters for kavadist module
description: >-
QueryParamsResponse defines the response type for querying x/kavadist
parameters.
kava.liquid.v1beta1.QueryDelegatedBalanceResponse:
type: object
properties:
vested:
title: >-
vested is the amount of all delegated coins that have vested (ie not
locked)
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.
NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
vesting:
title: >-
vesting is the amount of all delegated coins that are still vesting
(ie locked)
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.
NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
description: >-
DelegatedBalanceResponse defines the response type for the
Query/DelegatedBalance method.
kava.pricefeed.v1beta1.CurrentPriceResponse:
type: object
properties:

View File

@ -397,6 +397,12 @@
- [Query](#kava.kavadist.v1beta1.Query)
- [kava/liquid/v1beta1/query.proto](#kava/liquid/v1beta1/query.proto)
- [QueryDelegatedBalanceRequest](#kava.liquid.v1beta1.QueryDelegatedBalanceRequest)
- [QueryDelegatedBalanceResponse](#kava.liquid.v1beta1.QueryDelegatedBalanceResponse)
- [Query](#kava.liquid.v1beta1.Query)
- [kava/liquid/v1beta1/tx.proto](#kava/liquid/v1beta1/tx.proto)
- [MsgBurnDerivative](#kava.liquid.v1beta1.MsgBurnDerivative)
- [MsgBurnDerivativeResponse](#kava.liquid.v1beta1.MsgBurnDerivativeResponse)
@ -5332,7 +5338,7 @@ Msg defines the issuance Msg service.
<a name="kava.kavadist.v1beta1.CoreReward"></a>
### CoreReward
CoreReward defines the reward weights for core infrastructure providers.
| Field | Type | Label | Description |
@ -5348,7 +5354,7 @@ Msg defines the issuance Msg service.
<a name="kava.kavadist.v1beta1.InfrastructureParams"></a>
### InfrastructureParams
InfrastructureParams define the parameters for infrastructure rewards.
| Field | Type | Label | Description |
@ -5382,7 +5388,7 @@ Params governance parameters for kavadist module
<a name="kava.kavadist.v1beta1.PartnerReward"></a>
### PartnerReward
PartnerRewards defines the reward schedule for partner infrastructure providers.
| Field | Type | Label | Description |
@ -5599,6 +5605,63 @@ Query defines the gRPC querier service.
<a name="kava/liquid/v1beta1/query.proto"></a>
<p align="right"><a href="#top">Top</a></p>
## kava/liquid/v1beta1/query.proto
<a name="kava.liquid.v1beta1.QueryDelegatedBalanceRequest"></a>
### QueryDelegatedBalanceRequest
QueryDelegatedBalanceRequest defines the request type for Query/DelegatedBalance method.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `delegator` | [string](#string) | | delegator is the address of the account to query |
<a name="kava.liquid.v1beta1.QueryDelegatedBalanceResponse"></a>
### QueryDelegatedBalanceResponse
DelegatedBalanceResponse defines the response type for the Query/DelegatedBalance method.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `vested` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | vested is the amount of all delegated coins that have vested (ie not locked) |
| `vesting` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | vesting is the amount of all delegated coins that are still vesting (ie locked) |
<!-- end messages -->
<!-- end enums -->
<!-- end HasExtensions -->
<a name="kava.liquid.v1beta1.Query"></a>
### Query
Query defines the gRPC querier service for liquid module
| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `DelegatedBalance` | [QueryDelegatedBalanceRequest](#kava.liquid.v1beta1.QueryDelegatedBalanceRequest) | [QueryDelegatedBalanceResponse](#kava.liquid.v1beta1.QueryDelegatedBalanceResponse) | DelegatedBalance returns an account's vesting and vested coins currently delegated to validators. It ignores coins in unbonding delegations. | GET|/kava/liquid/v1beta1/delegated_balance/{delegator}|
<!-- end services -->
<a name="kava/liquid/v1beta1/tx.proto"></a>
<p align="right"><a href="#top">Top</a></p>

View File

@ -18,6 +18,7 @@ message Params {
InfrastructureParams infrastructure_params = 4 [(gogoproto.nullable) = false];
}
// InfrastructureParams define the parameters for infrastructure rewards.
message InfrastructureParams {
repeated Period infrastructure_periods = 1 [(gogoproto.castrepeated) = "Periods", (gogoproto.nullable) = false];
repeated CoreReward core_rewards = 2 [(gogoproto.castrepeated) = "CoreRewards", (gogoproto.nullable) = false];
@ -26,6 +27,7 @@ message InfrastructureParams {
option (gogoproto.goproto_stringer) = true;
}
// CoreReward defines the reward weights for core infrastructure providers.
message CoreReward {
bytes address = 1 [
(cosmos_proto.scalar) = "cosmos.AddressBytes",
@ -39,6 +41,7 @@ message CoreReward {
option (gogoproto.goproto_stringer) = true;
}
// PartnerRewards defines the reward schedule for partner infrastructure providers.
message PartnerReward {
bytes address = 1 [
(cosmos_proto.scalar) = "cosmos.AddressBytes",

View File

@ -0,0 +1,33 @@
syntax = "proto3";
package kava.liquid.v1beta1;
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
option go_package = "github.com/kava-labs/kava/x/liquid/types";
option (gogoproto.goproto_getters_all) = false;
// Query defines the gRPC querier service for liquid module
service Query {
// DelegatedBalance returns an account's vesting and vested coins currently delegated to validators.
// It ignores coins in unbonding delegations.
rpc DelegatedBalance(QueryDelegatedBalanceRequest) returns (QueryDelegatedBalanceResponse) {
option (google.api.http).get = "/kava/liquid/v1beta1/delegated_balance/{delegator}";
}
}
// QueryDelegatedBalanceRequest defines the request type for Query/DelegatedBalance method.
message QueryDelegatedBalanceRequest {
// delegator is the address of the account to query
string delegator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}
// DelegatedBalanceResponse defines the response type for the Query/DelegatedBalance method.
message QueryDelegatedBalanceResponse {
// vested is the amount of all delegated coins that have vested (ie not locked)
cosmos.base.v1beta1.Coin vested = 1 [(gogoproto.nullable) = false];
// vesting is the amount of all delegated coins that are still vesting (ie locked)
cosmos.base.v1beta1.Coin vesting = 2 [(gogoproto.nullable) = false];
}

View File

@ -69,6 +69,7 @@ func (m *Params) XXX_DiscardUnknown() {
var xxx_messageInfo_Params proto.InternalMessageInfo
// InfrastructureParams define the parameters for infrastructure rewards.
type InfrastructureParams struct {
InfrastructurePeriods Periods `protobuf:"bytes,1,rep,name=infrastructure_periods,json=infrastructurePeriods,proto3,castrepeated=Periods" json:"infrastructure_periods"`
CoreRewards CoreRewards `protobuf:"bytes,2,rep,name=core_rewards,json=coreRewards,proto3,castrepeated=CoreRewards" json:"core_rewards"`
@ -108,6 +109,7 @@ func (m *InfrastructureParams) XXX_DiscardUnknown() {
var xxx_messageInfo_InfrastructureParams proto.InternalMessageInfo
// CoreReward defines the reward weights for core infrastructure providers.
type CoreReward struct {
Address github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=address,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"address,omitempty"`
Weight github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=weight,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"weight"`
@ -146,6 +148,7 @@ func (m *CoreReward) XXX_DiscardUnknown() {
var xxx_messageInfo_CoreReward proto.InternalMessageInfo
// PartnerRewards defines the reward schedule for partner infrastructure providers.
type PartnerReward struct {
Address github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=address,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"address,omitempty"`
RewardsPerSecond types.Coin `protobuf:"bytes,2,opt,name=rewards_per_second,json=rewardsPerSecond,proto3" json:"rewards_per_second"`

View File

@ -0,0 +1,81 @@
package keeper
import (
"context"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
vestingexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/kava-labs/kava/x/liquid/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{}
func (s queryServer) DelegatedBalance(
goCtx context.Context,
req *types.QueryDelegatedBalanceRequest,
) (*types.QueryDelegatedBalanceResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
delegator, err := sdk.AccAddressFromBech32(req.Delegator)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid delegator address: %s", err)
}
delegated := s.getDelegatedBalance(ctx, delegator)
bondDenom := s.keeper.stakingKeeper.BondDenom(ctx)
vesting := s.getVesting(ctx, delegator).AmountOf(bondDenom)
vestingDelegated := sdk.MinInt(vesting, delegated)
vestedDelegated := delegated.Sub(vestingDelegated)
res := types.QueryDelegatedBalanceResponse{
Vested: sdk.NewCoin(bondDenom, vestedDelegated),
Vesting: sdk.NewCoin(bondDenom, vestingDelegated),
}
return &res, nil
}
func (s queryServer) getDelegatedBalance(ctx sdk.Context, delegator sdk.AccAddress) sdk.Int {
balance := sdk.ZeroDec()
s.keeper.stakingKeeper.IterateDelegatorDelegations(ctx, delegator, func(delegation stakingtypes.Delegation) bool {
validator, found := s.keeper.stakingKeeper.GetValidator(ctx, delegation.GetValidatorAddr())
if !found {
panic(fmt.Sprintf("validator %s for delegation not found", delegation.GetValidatorAddr()))
}
tokens := validator.TokensFromSharesTruncated(delegation.GetShares())
balance = balance.Add(tokens)
return false
})
return balance.TruncateInt()
}
func (s queryServer) getVesting(ctx sdk.Context, delegator sdk.AccAddress) sdk.Coins {
acc := s.keeper.accountKeeper.GetAccount(ctx, delegator)
if acc == nil {
// account doesn't exist so amount vesting is 0
return nil
}
vestAcc, ok := acc.(vestingexported.VestingAccount)
if !ok {
// account is not vesting type, so amount vesting is 0
return nil
}
return vestAcc.GetVestingCoins(ctx.BlockTime())
}

View File

@ -0,0 +1,168 @@
package keeper_test
import (
"context"
"testing"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/stretchr/testify/suite"
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/x/liquid/keeper"
"github.com/kava-labs/kava/x/liquid/types"
)
type grpcQueryTestSuite struct {
KeeperTestSuite
queryClient types.QueryClient
}
func (suite *grpcQueryTestSuite) SetupTest() {
suite.KeeperTestSuite.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) TestQueryDelegatedBalance() {
zeroResponse := &types.QueryDelegatedBalanceResponse{
Vested: suite.NewBondCoin(sdk.ZeroInt()),
Vesting: suite.NewBondCoin(sdk.ZeroInt()),
}
testCases := []struct {
name string
setup func() string
expectedRes *types.QueryDelegatedBalanceResponse
expectedErr error
}{
{
name: "vesting account with stake less than vesting",
setup: func() string {
initBalance := suite.NewBondCoin(i(1e9))
_, addrs := app.GeneratePrivKeyAddressPairs(2)
valAddr, delAddr := addrs[0], addrs[1]
suite.CreateAccountWithAddress(valAddr, sdk.NewCoins(initBalance))
suite.CreateVestingAccountWithAddress(delAddr, sdk.NewCoins(initBalance), suite.NewBondCoins(initBalance.Amount.QuoRaw(2)))
suite.CreateNewUnbondedValidator(sdk.ValAddress(valAddr), initBalance.Amount)
suite.CreateDelegation(sdk.ValAddress(valAddr), delAddr, initBalance.Amount.QuoRaw(4))
staking.EndBlocker(suite.Ctx, suite.StakingKeeper) // bond the validator
return delAddr.String()
},
expectedRes: &types.QueryDelegatedBalanceResponse{
Vested: suite.NewBondCoin(sdk.ZeroInt()),
Vesting: suite.NewBondCoin(i(250e6)),
},
},
{
name: "vesting account with stake greater than vesting",
setup: func() string {
initBalance := suite.NewBondCoin(i(1e9))
_, addrs := app.GeneratePrivKeyAddressPairs(2)
valAddr, delAddr := addrs[0], addrs[1]
suite.CreateAccountWithAddress(valAddr, sdk.NewCoins(initBalance))
suite.CreateVestingAccountWithAddress(delAddr, sdk.NewCoins(initBalance), suite.NewBondCoins(initBalance.Amount.QuoRaw(2)))
suite.CreateNewUnbondedValidator(sdk.ValAddress(valAddr), initBalance.Amount)
threeQuarters := initBalance.Amount.QuoRaw(4).MulRaw(3)
suite.CreateDelegation(sdk.ValAddress(valAddr), delAddr, threeQuarters)
staking.EndBlocker(suite.Ctx, suite.StakingKeeper) // bond the validator
return delAddr.String()
},
expectedRes: &types.QueryDelegatedBalanceResponse{
Vested: suite.NewBondCoin(i(250e6)),
Vesting: suite.NewBondCoin(i(500e6)),
},
},
{
name: "no account returns zeros",
setup: func() string {
return "kava10wlnqzyss4accfqmyxwx5jy5x9nfkwh6qm7n4t"
},
expectedRes: zeroResponse,
},
{
name: "base account no delegations returns zeros",
setup: func() string {
acc := suite.CreateAccount(suite.NewBondCoins(i(1e9)), 0)
return acc.GetAddress().String()
},
expectedRes: zeroResponse,
},
{
name: "base account with delegations returns delegated",
setup: func() string {
initBalance := suite.NewBondCoin(i(1e9))
val1Acc := suite.CreateAccount(sdk.NewCoins(initBalance), 0)
val2Acc := suite.CreateAccount(sdk.NewCoins(initBalance), 1)
delAcc := suite.CreateAccount(sdk.NewCoins(initBalance), 2)
suite.CreateNewUnbondedValidator(val1Acc.GetAddress().Bytes(), initBalance.Amount)
suite.CreateNewUnbondedValidator(val2Acc.GetAddress().Bytes(), initBalance.Amount)
suite.CreateDelegation(val1Acc.GetAddress().Bytes(), delAcc.GetAddress(), initBalance.Amount.QuoRaw(2))
suite.CreateDelegation(val2Acc.GetAddress().Bytes(), delAcc.GetAddress(), initBalance.Amount.QuoRaw(2))
return delAcc.GetAddress().String()
},
expectedRes: &types.QueryDelegatedBalanceResponse{
Vested: suite.NewBondCoin(i(1e9)),
Vesting: suite.NewBondCoin(sdk.ZeroInt()),
},
},
{
name: "base account with delegations and unbonding delegations returns only delegations",
setup: func() string {
initBalance := suite.NewBondCoin(i(1e9))
valAcc := suite.CreateAccount(sdk.NewCoins(initBalance), 0)
delAcc := suite.CreateAccount(sdk.NewCoins(initBalance), 1)
suite.CreateNewUnbondedValidator(valAcc.GetAddress().Bytes(), initBalance.Amount)
suite.CreateDelegation(valAcc.GetAddress().Bytes(), delAcc.GetAddress(), initBalance.Amount)
staking.EndBlocker(suite.Ctx, suite.StakingKeeper) // bond the validator
suite.CreateUnbondingDelegation(delAcc.GetAddress(), valAcc.GetAddress().Bytes(), initBalance.Amount.QuoRaw(2))
return delAcc.GetAddress().String()
},
expectedRes: &types.QueryDelegatedBalanceResponse{
Vested: suite.NewBondCoin(i(500e6)),
Vesting: suite.NewBondCoin(sdk.ZeroInt()),
},
},
}
for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.SetupTest()
address := tc.setup()
res, err := suite.queryClient.DelegatedBalance(
context.Background(),
&types.QueryDelegatedBalanceRequest{
Delegator: address,
},
)
suite.ErrorIs(err, tc.expectedErr)
if err == nil {
suite.Equal(tc.expectedRes, res)
}
})
}
}

View File

@ -47,10 +47,10 @@ func (suite *KeeperTestSuite) SetupTest() {
}
// CreateAccount creates a new account (with a fixed address) from the provided balance.
func (suite *KeeperTestSuite) CreateAccount(initialBalance sdk.Coins) authtypes.AccountI {
_, addrs := app.GeneratePrivKeyAddressPairs(1)
func (suite *KeeperTestSuite) CreateAccount(initialBalance sdk.Coins, index int) authtypes.AccountI {
_, addrs := app.GeneratePrivKeyAddressPairs(index + 1)
return suite.CreateAccountWithAddress(addrs[0], initialBalance)
return suite.CreateAccountWithAddress(addrs[index], initialBalance)
}
// CreateAccount creates a new account from the provided balance and address
@ -189,6 +189,19 @@ func (suite *KeeperTestSuite) CreateRedelegation(delegator sdk.AccAddress, fromV
suite.Require().NoError(err)
}
// CreateUnbondingDelegation undelegates tokens from a validator.
func (suite *KeeperTestSuite) CreateUnbondingDelegation(delegator sdk.AccAddress, validator sdk.ValAddress, amount sdk.Int) {
stakingDenom := suite.StakingKeeper.BondDenom(suite.Ctx)
msg := stakingtypes.NewMsgUndelegate(
delegator,
validator,
sdk.NewCoin(stakingDenom, amount),
)
msgServer := stakingkeeper.NewMsgServerImpl(suite.StakingKeeper)
_, err := msgServer.Undelegate(sdk.WrapSDKContext(suite.Ctx), msg)
suite.Require().NoError(err)
}
// DelegationSharesEqual checks if a delegation has the specified shares.
// It expects delegations with zero shares to not be stored in state.
func (suite *KeeperTestSuite) DelegationSharesEqual(valAddr sdk.ValAddress, delegator sdk.AccAddress, shares sdk.Dec) bool {

View File

@ -1,6 +1,7 @@
package liquid
import (
"context"
"encoding/json"
"github.com/gorilla/mux"
@ -57,7 +58,11 @@ func (a AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry
func (a AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module.
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {}
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
// GetTxCmd returns the root tx command for the module.
func (AppModuleBasic) GetTxCmd() *cobra.Command {
@ -117,6 +122,7 @@ func (AppModule) ConsensusVersion() uint64 {
// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))
}
// InitGenesis module init-genesis

View File

@ -3,7 +3,6 @@ package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
@ -26,6 +25,7 @@ type BankKeeper interface {
type AccountKeeper interface {
GetModuleAddress(moduleName string) sdk.AccAddress
GetModuleAccount(ctx sdk.Context, name string) authtypes.ModuleAccountI
GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
}
// StakingKeeper defines the expected keeper interface for interacting with staking
@ -33,7 +33,8 @@ type StakingKeeper interface {
BondDenom(ctx sdk.Context) (res string)
GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, found bool)
GetDelegation(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (delegation types.Delegation, found bool)
GetDelegation(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (delegation stakingtypes.Delegation, found bool)
IterateDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddress, cb func(delegation stakingtypes.Delegation) (stop bool))
HasReceivingRedelegation(ctx sdk.Context, delAddr sdk.AccAddress, valDstAddr sdk.ValAddress) bool
ValidateUnbondAmount(

631
x/liquid/types/query.pb.go Normal file
View File

@ -0,0 +1,631 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: kava/liquid/v1beta1/query.proto
package types
import (
context "context"
fmt "fmt"
_ "github.com/cosmos/cosmos-proto"
types "github.com/cosmos/cosmos-sdk/types"
_ "github.com/gogo/protobuf/gogoproto"
grpc1 "github.com/gogo/protobuf/grpc"
proto "github.com/gogo/protobuf/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
// QueryDelegatedBalanceRequest defines the request type for Query/DelegatedBalance method.
type QueryDelegatedBalanceRequest struct {
// delegator is the address of the account to query
Delegator string `protobuf:"bytes,1,opt,name=delegator,proto3" json:"delegator,omitempty"`
}
func (m *QueryDelegatedBalanceRequest) Reset() { *m = QueryDelegatedBalanceRequest{} }
func (m *QueryDelegatedBalanceRequest) String() string { return proto.CompactTextString(m) }
func (*QueryDelegatedBalanceRequest) ProtoMessage() {}
func (*QueryDelegatedBalanceRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_0d745428489be444, []int{0}
}
func (m *QueryDelegatedBalanceRequest) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *QueryDelegatedBalanceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_QueryDelegatedBalanceRequest.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 *QueryDelegatedBalanceRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_QueryDelegatedBalanceRequest.Merge(m, src)
}
func (m *QueryDelegatedBalanceRequest) XXX_Size() int {
return m.Size()
}
func (m *QueryDelegatedBalanceRequest) XXX_DiscardUnknown() {
xxx_messageInfo_QueryDelegatedBalanceRequest.DiscardUnknown(m)
}
var xxx_messageInfo_QueryDelegatedBalanceRequest proto.InternalMessageInfo
// DelegatedBalanceResponse defines the response type for the Query/DelegatedBalance method.
type QueryDelegatedBalanceResponse struct {
// vested is the amount of all delegated coins that have vested (ie not locked)
Vested types.Coin `protobuf:"bytes,1,opt,name=vested,proto3" json:"vested"`
// vesting is the amount of all delegated coins that are still vesting (ie locked)
Vesting types.Coin `protobuf:"bytes,2,opt,name=vesting,proto3" json:"vesting"`
}
func (m *QueryDelegatedBalanceResponse) Reset() { *m = QueryDelegatedBalanceResponse{} }
func (m *QueryDelegatedBalanceResponse) String() string { return proto.CompactTextString(m) }
func (*QueryDelegatedBalanceResponse) ProtoMessage() {}
func (*QueryDelegatedBalanceResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_0d745428489be444, []int{1}
}
func (m *QueryDelegatedBalanceResponse) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *QueryDelegatedBalanceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_QueryDelegatedBalanceResponse.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 *QueryDelegatedBalanceResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_QueryDelegatedBalanceResponse.Merge(m, src)
}
func (m *QueryDelegatedBalanceResponse) XXX_Size() int {
return m.Size()
}
func (m *QueryDelegatedBalanceResponse) XXX_DiscardUnknown() {
xxx_messageInfo_QueryDelegatedBalanceResponse.DiscardUnknown(m)
}
var xxx_messageInfo_QueryDelegatedBalanceResponse proto.InternalMessageInfo
func init() {
proto.RegisterType((*QueryDelegatedBalanceRequest)(nil), "kava.liquid.v1beta1.QueryDelegatedBalanceRequest")
proto.RegisterType((*QueryDelegatedBalanceResponse)(nil), "kava.liquid.v1beta1.QueryDelegatedBalanceResponse")
}
func init() { proto.RegisterFile("kava/liquid/v1beta1/query.proto", fileDescriptor_0d745428489be444) }
var fileDescriptor_0d745428489be444 = []byte{
// 389 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0x3d, 0x6f, 0xd3, 0x40,
0x1c, 0xc6, 0x7d, 0x11, 0x04, 0xe5, 0x58, 0x90, 0xc9, 0x90, 0x44, 0xe1, 0x82, 0x32, 0x65, 0xc9,
0x9d, 0x62, 0x10, 0x08, 0x36, 0x0c, 0x62, 0x27, 0x48, 0x0c, 0x2c, 0xd1, 0xd9, 0x3e, 0x1d, 0x27,
0x9c, 0x3b, 0xc7, 0x77, 0x8e, 0x88, 0x10, 0x0b, 0x9f, 0xa0, 0x52, 0xbe, 0x4a, 0x3b, 0x77, 0xcd,
0x18, 0xb5, 0x4b, 0xa7, 0xaa, 0x4d, 0xfa, 0x41, 0x2a, 0xfb, 0xec, 0x54, 0xaa, 0xd2, 0xaa, 0xdd,
0xce, 0x7a, 0x7e, 0xcf, 0xf3, 0x7f, 0x33, 0xec, 0xfd, 0xa6, 0x73, 0x4a, 0x62, 0x31, 0xcb, 0x44,
0x44, 0xe6, 0xa3, 0x80, 0x19, 0x3a, 0x22, 0xb3, 0x8c, 0xa5, 0x0b, 0x9c, 0xa4, 0xca, 0x28, 0xf7,
0x65, 0x0e, 0x60, 0x0b, 0xe0, 0x12, 0xe8, 0x34, 0xb9, 0xe2, 0xaa, 0xd0, 0x49, 0xfe, 0xb2, 0x68,
0xa7, 0xcb, 0x95, 0xe2, 0x31, 0x23, 0x34, 0x11, 0x84, 0x4a, 0xa9, 0x0c, 0x35, 0x42, 0x49, 0x5d,
0xaa, 0x28, 0x54, 0x7a, 0xaa, 0x34, 0x09, 0xa8, 0x66, 0xbb, 0x4a, 0xa1, 0x12, 0xb2, 0xd4, 0xdb,
0x56, 0x9f, 0xd8, 0x58, 0xfb, 0x61, 0xa5, 0xfe, 0x0f, 0xd8, 0xfd, 0x96, 0xb7, 0xf4, 0x85, 0xc5,
0x8c, 0x53, 0xc3, 0x22, 0x9f, 0xc6, 0x54, 0x86, 0x6c, 0xcc, 0x66, 0x19, 0xd3, 0xc6, 0x7d, 0x07,
0x1b, 0x91, 0x95, 0x54, 0xda, 0x02, 0xaf, 0xc1, 0xa0, 0xe1, 0xb7, 0x4e, 0x0e, 0x87, 0xcd, 0x32,
0xe4, 0x53, 0x14, 0xa5, 0x4c, 0xeb, 0xef, 0x26, 0x15, 0x92, 0x8f, 0x6f, 0xd0, 0xfe, 0x12, 0xc0,
0x57, 0x77, 0x04, 0xeb, 0x44, 0x49, 0xcd, 0xdc, 0xf7, 0xb0, 0x3e, 0x67, 0xda, 0xb0, 0xa8, 0x88,
0x7d, 0xee, 0xb5, 0x71, 0x99, 0x99, 0x4f, 0x51, 0xad, 0x03, 0x7f, 0x56, 0x42, 0xfa, 0x4f, 0x56,
0xe7, 0x3d, 0x67, 0x5c, 0xe2, 0xee, 0x07, 0xf8, 0x2c, 0x7f, 0x09, 0xc9, 0x5b, 0xb5, 0x87, 0x39,
0x2b, 0xde, 0x3b, 0x06, 0xf0, 0x69, 0xd1, 0x95, 0x7b, 0x04, 0xe0, 0x8b, 0xdb, 0xad, 0xb9, 0x23,
0xbc, 0xe7, 0x22, 0xf8, 0xbe, 0xfd, 0x74, 0xbc, 0xc7, 0x58, 0xec, 0xe4, 0xfd, 0x8f, 0xff, 0x4f,
0xaf, 0x96, 0xb5, 0xb7, 0xae, 0x47, 0xf6, 0xfd, 0x21, 0x51, 0x65, 0x9b, 0x04, 0xd6, 0x47, 0xfe,
0xee, 0xd6, 0xfa, 0xcf, 0xff, 0xba, 0xba, 0x44, 0xce, 0x6a, 0x83, 0xc0, 0x7a, 0x83, 0xc0, 0xc5,
0x06, 0x81, 0x83, 0x2d, 0x72, 0xd6, 0x5b, 0xe4, 0x9c, 0x6d, 0x91, 0xf3, 0x73, 0xc0, 0x85, 0xf9,
0x95, 0x05, 0x38, 0x54, 0xd3, 0x22, 0x7b, 0x18, 0xd3, 0x40, 0xdb, 0x2a, 0x7f, 0xaa, 0x3a, 0x66,
0x91, 0x30, 0x1d, 0xd4, 0x8b, 0xf3, 0xbf, 0xb9, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x32, 0x91, 0xae,
0x51, 0xa5, 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 {
// DelegatedBalance returns an account's vesting and vested coins currently delegated to validators.
// It ignores coins in unbonding delegations.
DelegatedBalance(ctx context.Context, in *QueryDelegatedBalanceRequest, opts ...grpc.CallOption) (*QueryDelegatedBalanceResponse, error)
}
type queryClient struct {
cc grpc1.ClientConn
}
func NewQueryClient(cc grpc1.ClientConn) QueryClient {
return &queryClient{cc}
}
func (c *queryClient) DelegatedBalance(ctx context.Context, in *QueryDelegatedBalanceRequest, opts ...grpc.CallOption) (*QueryDelegatedBalanceResponse, error) {
out := new(QueryDelegatedBalanceResponse)
err := c.cc.Invoke(ctx, "/kava.liquid.v1beta1.Query/DelegatedBalance", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// QueryServer is the server API for Query service.
type QueryServer interface {
// DelegatedBalance returns an account's vesting and vested coins currently delegated to validators.
// It ignores coins in unbonding delegations.
DelegatedBalance(context.Context, *QueryDelegatedBalanceRequest) (*QueryDelegatedBalanceResponse, error)
}
// UnimplementedQueryServer can be embedded to have forward compatible implementations.
type UnimplementedQueryServer struct {
}
func (*UnimplementedQueryServer) DelegatedBalance(ctx context.Context, req *QueryDelegatedBalanceRequest) (*QueryDelegatedBalanceResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method DelegatedBalance not implemented")
}
func RegisterQueryServer(s grpc1.Server, srv QueryServer) {
s.RegisterService(&_Query_serviceDesc, srv)
}
func _Query_DelegatedBalance_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(QueryDelegatedBalanceRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(QueryServer).DelegatedBalance(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/kava.liquid.v1beta1.Query/DelegatedBalance",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(QueryServer).DelegatedBalance(ctx, req.(*QueryDelegatedBalanceRequest))
}
return interceptor(ctx, in, info, handler)
}
var _Query_serviceDesc = grpc.ServiceDesc{
ServiceName: "kava.liquid.v1beta1.Query",
HandlerType: (*QueryServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "DelegatedBalance",
Handler: _Query_DelegatedBalance_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "kava/liquid/v1beta1/query.proto",
}
func (m *QueryDelegatedBalanceRequest) 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 *QueryDelegatedBalanceRequest) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *QueryDelegatedBalanceRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if len(m.Delegator) > 0 {
i -= len(m.Delegator)
copy(dAtA[i:], m.Delegator)
i = encodeVarintQuery(dAtA, i, uint64(len(m.Delegator)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func (m *QueryDelegatedBalanceResponse) 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 *QueryDelegatedBalanceResponse) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *QueryDelegatedBalanceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
{
size, err := m.Vesting.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintQuery(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x12
{
size, err := m.Vested.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 *QueryDelegatedBalanceRequest) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.Delegator)
if l > 0 {
n += 1 + l + sovQuery(uint64(l))
}
return n
}
func (m *QueryDelegatedBalanceResponse) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = m.Vested.Size()
n += 1 + l + sovQuery(uint64(l))
l = m.Vesting.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 *QueryDelegatedBalanceRequest) 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: QueryDelegatedBalanceRequest: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: QueryDelegatedBalanceRequest: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Delegator", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowQuery
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthQuery
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthQuery
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Delegator = string(dAtA[iNdEx:postIndex])
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 (m *QueryDelegatedBalanceResponse) 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: QueryDelegatedBalanceResponse: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: QueryDelegatedBalanceResponse: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Vested", 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.Vested.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Vesting", 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.Vesting.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,184 @@
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: kava/liquid/v1beta1/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/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
func request_Query_DelegatedBalance_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryDelegatedBalanceRequest
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["delegator"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "delegator")
}
protoReq.Delegator, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "delegator", err)
}
msg, err := client.DelegatedBalance(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Query_DelegatedBalance_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryDelegatedBalanceRequest
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["delegator"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "delegator")
}
protoReq.Delegator, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "delegator", err)
}
msg, err := server.DelegatedBalance(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 (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead.
func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error {
mux.Handle("GET", pattern_Query_DelegatedBalance_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_DelegatedBalance_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_DelegatedBalance_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_DelegatedBalance_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_DelegatedBalance_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_DelegatedBalance_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_Query_DelegatedBalance_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"kava", "liquid", "v1beta1", "delegated_balance", "delegator"}, "", runtime.AssumeColonVerbOpt(false)))
)
var (
forward_Query_DelegatedBalance_0 = runtime.ForwardResponseMessage
)