feat: Move CommunityPool to its own module (#17657)

This commit is contained in:
Likhita Polavarapu
2023-09-27 09:09:04 +00:00
committed by GitHub
parent ddd26b5dfc
commit 9dd34510e2
117 changed files with 9985 additions and 3540 deletions
+33
View File
@@ -0,0 +1,33 @@
---
sidebar_position: 1
---
# `x/protocolpool`
Functionality to handle community pool funds. This provides a separate module account for community pool making it easier to track the pool assets. We no longer track community pool assets in distribution module, but instead in this protocolpool module. Funds are migrated from the distribution module's community pool to protocolpool's module account.
## Concepts
## State
## State Transitions
## Messages
## Begin Block
## End Block
## Hooks
## Events
## Client
## Params
## Future Improvements
## Tests
## Appendix
+39
View File
@@ -0,0 +1,39 @@
package protocolpool
import (
"fmt"
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
poolv1 "cosmossdk.io/api/cosmos/protocolpool/v1"
"github.com/cosmos/cosmos-sdk/version"
)
// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface.
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
return &autocliv1.ModuleOptions{
Query: &autocliv1.ServiceCommandDescriptor{
Service: poolv1.Query_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "CommunityPool",
Use: "community-pool",
Short: "Query the amount of coins in the community pool",
Example: fmt.Sprintf(`$ %s query pool community-pool`, version.AppName),
},
},
},
Tx: &autocliv1.ServiceCommandDescriptor{
Service: poolv1.Msg_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "FundCommunityPool",
Use: "fund-community-pool [amount]",
Short: "Funds the community pool with the specified amount",
Example: fmt.Sprintf(`$ %s tx pool fund-community-pool 100uatom --from mykey`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "amount"}},
},
},
},
}
}
+159
View File
@@ -0,0 +1,159 @@
module cosmossdk.io/x/protocolpool
go 1.21
require (
cosmossdk.io/api v0.7.1
cosmossdk.io/core v0.12.0
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/errors v1.0.0
cosmossdk.io/log v1.2.1
github.com/cometbft/cometbft v0.38.0
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.51.0
github.com/cosmos/gogoproto v1.4.11
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/stretchr/testify v1.8.4
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d
google.golang.org/grpc v1.58.2
gotest.tools/v3 v3.5.1
)
require (
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/math v1.1.3-rc.1 // indirect
cosmossdk.io/store v1.0.0-rc.0 // indirect
cosmossdk.io/x/tx v0.10.0 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v0.0.0-20230824192853-9bb0864bdb98 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft-db v0.8.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-db v1.0.0 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.0.0-rc.1 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.0 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/emicklei/dot v1.6.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/getsentry/sentry-go v0.23.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-metrics v0.5.1 // indirect
github.com/hashicorp/go-plugin v1.5.1 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.8.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230110094441-db37f07504ce // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/petermattis/goid v0.0.0-20230808133559-b036b712a89b // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/rs/zerolog v1.31.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.16.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.7.0 // indirect
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.1 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v1.1.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
replace github.com/cosmos/cosmos-sdk => ../../.
replace cosmossdk.io/api => ../../api
File diff suppressed because it is too large Load Diff
+29
View File
@@ -0,0 +1,29 @@
package keeper
import (
"context"
"cosmossdk.io/x/protocolpool/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
var _ types.QueryServer = Querier{}
type Querier struct {
Keeper
}
func NewQuerier(keeper Keeper) Querier {
return Querier{Keeper: keeper}
}
// CommunityPool queries the community pool coins
func (k Querier) CommunityPool(ctx context.Context, req *types.QueryCommunityPoolRequest) (*types.QueryCommunityPoolResponse, error) {
amount, err := k.Keeper.GetCommunityPool(ctx)
if err != nil {
return nil, err
}
decCoins := sdk.NewDecCoinsFromCoins(amount...)
return &types.QueryCommunityPoolResponse{Pool: decCoins}, nil
}
+69
View File
@@ -0,0 +1,69 @@
package keeper
import (
"context"
"fmt"
storetypes "cosmossdk.io/core/store"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log"
"cosmossdk.io/x/protocolpool/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
type Keeper struct {
storeService storetypes.KVStoreService
authKeeper types.AccountKeeper
bankKeeper types.BankKeeper
authority string
}
func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService,
ak types.AccountKeeper, bk types.BankKeeper, authority string,
) Keeper {
// ensure pool module account is set
if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}
return Keeper{
storeService: storeService,
authKeeper: ak,
bankKeeper: bk,
authority: authority,
}
}
// GetAuthority returns the x/protocolpool module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
}
// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx context.Context) log.Logger {
sdkCtx := sdk.UnwrapSDKContext(ctx)
return sdkCtx.Logger().With(log.ModuleKey, "x/"+types.ModuleName)
}
// FundCommunityPool allows an account to directly fund the community fund pool.
func (k Keeper) FundCommunityPool(ctx context.Context, amount sdk.Coins, sender sdk.AccAddress) error {
return k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, types.ModuleName, amount)
}
// DistributeFromFeePool distributes funds from the protocolpool module account to
// a receiver address.
func (k Keeper) DistributeFromFeePool(ctx context.Context, amount sdk.Coins, receiveAddr sdk.AccAddress) error {
return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiveAddr, amount)
}
// GetCommunityPool get the community pool balance.
func (k Keeper) GetCommunityPool(ctx context.Context) (sdk.Coins, error) {
moduleAccount := k.authKeeper.GetModuleAccount(ctx, types.ModuleName)
if moduleAccount == nil {
return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", moduleAccount)
}
return k.bankKeeper.GetAllBalances(ctx, moduleAccount.GetAddress()), nil
}
+90
View File
@@ -0,0 +1,90 @@
package keeper
import (
"context"
"cosmossdk.io/errors"
"cosmossdk.io/x/protocolpool/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
type MsgServer struct {
Keeper
}
var _ types.MsgServer = MsgServer{}
// NewMsgServerImpl returns an implementation of the protocolpool MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
return &MsgServer{Keeper: keeper}
}
func (k MsgServer) FundCommunityPool(ctx context.Context, msg *types.MsgFundCommunityPool) (*types.MsgFundCommunityPoolResponse, error) {
depositor, err := k.authKeeper.AddressCodec().StringToBytes(msg.Depositor)
if err != nil {
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid depositor address: %s", err)
}
if err := validateAmount(msg.Amount); err != nil {
return nil, err
}
// send funds to community pool module account
if err := k.Keeper.FundCommunityPool(ctx, msg.Amount, depositor); err != nil {
return nil, err
}
return &types.MsgFundCommunityPoolResponse{}, nil
}
func (k MsgServer) CommunityPoolSpend(ctx context.Context, msg *types.MsgCommunityPoolSpend) (*types.MsgCommunityPoolSpendResponse, error) {
if err := k.validateAuthority(msg.Authority); err != nil {
return nil, err
}
if err := validateAmount(msg.Amount); err != nil {
return nil, err
}
recipient, err := k.authKeeper.AddressCodec().StringToBytes(msg.Recipient)
if err != nil {
return nil, err
}
// distribute funds from community pool module account
if err := k.Keeper.DistributeFromFeePool(ctx, msg.Amount, recipient); err != nil {
return nil, err
}
logger := k.Logger(ctx)
logger.Info("transferred from the community pool to recipient", "amount", msg.Amount.String(), "recipient", msg.Recipient)
return &types.MsgCommunityPoolSpendResponse{}, nil
}
func (k *Keeper) validateAuthority(authority string) error {
if _, err := k.authKeeper.AddressCodec().StringToBytes(authority); err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", err)
}
if k.authority != authority {
return errors.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, authority)
}
return nil
}
func validateAmount(amount sdk.Coins) error {
if amount == nil {
return errors.Wrap(sdkerrors.ErrInvalidCoins, "amount cannot be nil")
}
if err := amount.Validate(); err != nil {
return errors.Wrap(sdkerrors.ErrInvalidCoins, amount.String())
}
return nil
}
+163
View File
@@ -0,0 +1,163 @@
package protocolpool
import (
"context"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
modulev1 "cosmossdk.io/api/cosmos/protocolpool/module/v1"
"cosmossdk.io/core/appmodule"
storetypes "cosmossdk.io/core/store"
"cosmossdk.io/depinject"
"cosmossdk.io/x/protocolpool/keeper"
"cosmossdk.io/x/protocolpool/simulation"
"cosmossdk.io/x/protocolpool/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)
// ConsensusVersion defines the current x/protocolpool module consensus version.
const ConsensusVersion = 1
var (
_ module.AppModuleBasic = AppModule{}
_ module.AppModule = AppModule{}
_ module.AppModuleSimulation = AppModule{}
)
// AppModuleBasic defines the basic application module used by the pool module.
type AppModuleBasic struct {
cdc codec.Codec
}
// Name returns the pool module's name.
func (AppModuleBasic) Name() string { return types.ModuleName }
// RegisterLegacyAminoCodec registers the pool module's types on the LegacyAmino codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
// RegisterInterfaces registers interfaces and implementations of the bank module.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// AppModule implements an application module for the pool module
type AppModule struct {
AppModuleBasic
keeper keeper.Keeper
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
}
var _ appmodule.AppModule = AppModule{}
// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
func (am AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}
// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper))
}
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper,
accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper,
) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc: cdc},
keeper: keeper,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
}
}
// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
//
// App Wiring Setup
//
func init() {
appmodule.Register(
&modulev1.Module{},
appmodule.Provide(ProvideModule),
)
}
type ModuleInputs struct {
depinject.In
Config *modulev1.Module
Codec codec.Codec
StoreService storetypes.KVStoreService
AccountKeeper types.AccountKeeper
BankKeeper types.BankKeeper
}
type ModuleOutputs struct {
depinject.Out
Keeper keeper.Keeper
Module appmodule.AppModule
}
func ProvideModule(in ModuleInputs) ModuleOutputs {
// default to governance authority if not provided
authority := authtypes.NewModuleAddress("gov")
if in.Config.Authority != "" {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}
k := keeper.NewKeeper(in.Codec, in.StoreService, in.AccountKeeper, in.BankKeeper, authority.String())
m := NewAppModule(in.Codec, k, in.AccountKeeper, in.BankKeeper)
return ModuleOutputs{
Keeper: k,
Module: m,
}
}
// ____________________________________________________________________________
// AppModuleSimulation functions
// GenerateGenesisState creates a randomized GenState of the protocolpool module.
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
}
// RegisterStoreDecoder registers a decoder for protocolpool module's types
func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) {
}
// ProposalMsgs returns all the protocolpool msgs used to simulate governance proposals.
func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg {
return simulation.ProposalMsgs()
}
// WeightedOperations returns the all the protocolpool module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
return simulation.WeightedOperations(
simState.AppParams, simState.Cdc, simState.TxConfig,
am.accountKeeper, am.bankKeeper, am.keeper,
)
}
+91
View File
@@ -0,0 +1,91 @@
package simulation
import (
"math/rand"
"cosmossdk.io/x/protocolpool/keeper"
"cosmossdk.io/x/protocolpool/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
)
// Simulation operation weights constants
const (
OpWeightMsgFundCommunityPool = "op_weight_msg_fund_community_pool"
DefaultWeightMsgFundCommunityPool int = 50
)
// WeightedOperations returns all the operations from the module with their respective weights
func WeightedOperations(
appParams simtypes.AppParams,
cdc codec.JSONCodec,
txConfig client.TxConfig,
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper,
) simulation.WeightedOperations {
var weightMsgFundCommunityPool int
appParams.GetOrGenerate(OpWeightMsgFundCommunityPool, &weightMsgFundCommunityPool, nil, func(_ *rand.Rand) {
weightMsgFundCommunityPool = DefaultWeightMsgFundCommunityPool
})
return simulation.WeightedOperations{
simulation.NewWeightedOperation(
weightMsgFundCommunityPool,
SimulateMsgFundCommunityPool(txConfig, ak, bk, k),
),
}
}
// SimulateMsgFundCommunityPool simulates MsgFundCommunityPool execution where
// a random account sends a random amount of its funds to the community pool.
func SimulateMsgFundCommunityPool(txConfig client.TxConfig, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
funder, _ := simtypes.RandomAcc(r, accs)
account := ak.GetAccount(ctx, funder.Address)
spendable := bk.SpendableCoins(ctx, account.GetAddress())
fundAmount := simtypes.RandSubsetCoins(r, spendable)
if fundAmount.Empty() {
return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), "fund amount is empty"), nil, nil
}
var (
fees sdk.Coins
err error
)
coins, hasNeg := spendable.SafeSub(fundAmount...)
if !hasNeg {
fees, err = simtypes.RandomFees(r, coins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), "unable to generate fees"), nil, err
}
}
msg := types.NewMsgFundCommunityPool(fundAmount, funder.Address.String())
txCtx := simulation.OperationInput{
R: r,
App: app,
TxGen: txConfig,
Cdc: nil,
Msg: msg,
Context: ctx,
SimAccount: funder,
AccountKeeper: ak,
ModuleName: types.ModuleName,
}
return simulation.GenAndDeliverTx(txCtx, fees)
}
}
@@ -0,0 +1,156 @@
package simulation_test
import (
"math/rand"
"testing"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/require"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
"cosmossdk.io/x/protocolpool/keeper"
"cosmossdk.io/x/protocolpool/simulation"
pooltestutil "cosmossdk.io/x/protocolpool/testutil"
"cosmossdk.io/x/protocolpool/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/runtime"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
)
type suite struct {
Ctx sdk.Context
App *runtime.App
TxConfig client.TxConfig
Cdc codec.Codec
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
PoolKeeper keeper.Keeper
}
func setUpTest(t *testing.T) suite {
t.Helper()
res := suite{}
var (
appBuilder *runtime.AppBuilder
err error
)
app, err := simtestutil.Setup(
depinject.Configs(
pooltestutil.AppConfig,
depinject.Supply(log.NewNopLogger()),
),
&res.AccountKeeper,
&res.BankKeeper,
&res.Cdc,
&appBuilder,
&res.StakingKeeper,
&res.PoolKeeper,
&res.TxConfig,
)
require.NoError(t, err)
res.App = app
res.Ctx = app.BaseApp.NewContext(false)
return res
}
// TestWeightedOperations tests the weights of the operations.
func TestWeightedOperations(t *testing.T) {
suite := setUpTest(t)
appParams := make(simtypes.AppParams)
weightedOps := simulation.WeightedOperations(appParams, suite.Cdc, suite.TxConfig, suite.AccountKeeper,
suite.BankKeeper, suite.PoolKeeper)
// setup 3 accounts
s := rand.NewSource(1)
r := rand.New(s)
accs := getTestingAccounts(t, r, suite.AccountKeeper, suite.BankKeeper, suite.StakingKeeper, suite.Ctx, 3)
expected := []struct {
weight int
opMsgRoute string
opMsgName string
}{
{simulation.DefaultWeightMsgFundCommunityPool, types.ModuleName, sdk.MsgTypeURL(&types.MsgFundCommunityPool{})},
}
for i, w := range weightedOps {
operationMsg, _, err := w.Op()(r, suite.App.BaseApp, suite.Ctx, accs, "")
require.NoError(t, err)
// the following checks are very much dependent from the ordering of the output given
// by WeightedOperations. if the ordering in WeightedOperations changes some tests
// will fail
require.Equal(t, expected[i].weight, w.Weight(), "weight should be the same")
require.Equal(t, expected[i].opMsgRoute, operationMsg.Route, "route should be the same")
require.Equal(t, expected[i].opMsgName, operationMsg.Name, "operation Msg name should be the same")
}
}
// TestSimulateMsgFundCommunityPool tests the normal scenario of a valid message of type TypeMsgFundCommunityPool.
// Abonormal scenarios, where the message is created by an errors, are not tested here.
func TestSimulateMsgFundCommunityPool(t *testing.T) {
suite := setUpTest(t)
// setup 3 accounts
s := rand.NewSource(1)
r := rand.New(s)
accounts := getTestingAccounts(t, r, suite.AccountKeeper, suite.BankKeeper, suite.StakingKeeper, suite.Ctx, 3)
_, err := suite.App.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: suite.App.LastBlockHeight() + 1,
Hash: suite.App.LastCommitID().Hash,
})
require.NoError(t, err)
// execute operation
op := simulation.SimulateMsgFundCommunityPool(suite.TxConfig, suite.AccountKeeper, suite.BankKeeper, suite.PoolKeeper)
operationMsg, futureOperations, err := op(r, suite.App.BaseApp, suite.Ctx, accounts, "")
require.NoError(t, err)
var msg types.MsgFundCommunityPool
err = proto.Unmarshal(operationMsg.Msg, &msg)
require.NoError(t, err)
require.True(t, operationMsg.OK)
require.Equal(t, "4896096stake", msg.Amount.String())
require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Depositor)
require.Equal(t, sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), sdk.MsgTypeURL(&msg))
require.Len(t, futureOperations, 0)
}
func getTestingAccounts(
t *testing.T, r *rand.Rand,
accountKeeper authkeeper.AccountKeeper, bankKeeper bankkeeper.Keeper,
stakingKeeper *stakingkeeper.Keeper, ctx sdk.Context, n int,
) []simtypes.Account {
t.Helper()
accounts := simtypes.RandomAccounts(r, n)
initAmt := stakingKeeper.TokensFromConsensusPower(ctx, 200)
initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt))
// add coins to the accounts
for _, account := range accounts {
acc := accountKeeper.NewAccountWithAddress(ctx, account.Address)
accountKeeper.SetAccount(ctx, acc)
require.NoError(t, banktestutil.FundAccount(ctx, bankKeeper, account.Address, initCoins))
}
return accounts
}
+47
View File
@@ -0,0 +1,47 @@
package simulation
import (
"math/rand"
pooltypes "cosmossdk.io/x/protocolpool/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
)
const (
OpWeightMsgCommunityPoolSpend = "op_weight_msg_community_pool_spend"
DefaultWeightMsgCommunityPoolSpend int = 50
)
func ProposalMsgs() []simtypes.WeightedProposalMsg {
return []simtypes.WeightedProposalMsg{
simulation.NewWeightedProposalMsg(
OpWeightMsgCommunityPoolSpend,
DefaultWeightMsgCommunityPoolSpend,
SimulateMsgCommunityPoolSpend,
),
}
}
func SimulateMsgCommunityPoolSpend(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg {
// use the default gov module account address as authority
var authority sdk.AccAddress = address.Module("gov")
accs := simtypes.RandomAccounts(r, 5)
acc, _ := simtypes.RandomAcc(r, accs)
coins, err := sdk.ParseCoinsNormalized("100stake,2testtoken")
if err != nil {
panic(err)
}
return &pooltypes.MsgCommunityPoolSpend{
Authority: authority.String(),
Recipient: acc.Address.String(),
Amount: coins,
}
}
@@ -0,0 +1,44 @@
package simulation_test
import (
"math/rand"
"testing"
"gotest.tools/v3/assert"
"cosmossdk.io/x/protocolpool/simulation"
pooltypes "cosmossdk.io/x/protocolpool/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
)
func TestProposalMsgs(t *testing.T) {
// initialize parameters
s := rand.NewSource(1)
r := rand.New(s)
ctx := sdk.NewContext(nil, true, nil)
accounts := simtypes.RandomAccounts(r, 3)
// execute ProposalMsgs function
weightedProposalMsgs := simulation.ProposalMsgs()
assert.Assert(t, len(weightedProposalMsgs) == 1)
w0 := weightedProposalMsgs[0]
// tests w0 interface:
assert.Equal(t, simulation.OpWeightMsgCommunityPoolSpend, w0.AppParamsKey())
assert.Equal(t, simulation.DefaultWeightMsgCommunityPoolSpend, w0.DefaultWeight())
msg := w0.MsgSimulatorFn()(r, ctx, accounts)
msgCommunityPoolSpend, ok := msg.(*pooltypes.MsgCommunityPoolSpend)
assert.Assert(t, ok)
coins, err := sdk.ParseCoinsNormalized("100stake,2testtoken")
assert.NilError(t, err)
assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgCommunityPoolSpend.Authority)
assert.Assert(t, msgCommunityPoolSpend.Amount.Equal(coins))
}
+14
View File
@@ -0,0 +1,14 @@
sonar.projectKey=cosmos-sdk-x-protocolpool
sonar.organization=cosmos
sonar.projectName=Cosmos SDK - x/protocolpool
sonar.project.monorepo.enabled=true
sonar.sources=.
sonar.exclusions=**/*_test.go
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.go.coverage.reportPaths=coverage.out
sonar.sourceEncoding=UTF-8
sonar.scm.provider=git
+31
View File
@@ -0,0 +1,31 @@
package testutil
import (
_ "cosmossdk.io/x/protocolpool" // import as blank for app wiring
"github.com/cosmos/cosmos-sdk/testutil/configurator"
_ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/consensus" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/distribution" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/gov" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/mint" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring
)
var AppConfig = configurator.NewAppConfig(
configurator.AuthModule(),
configurator.BankModule(),
configurator.StakingModule(),
configurator.TxModule(),
configurator.ConsensusModule(),
configurator.ParamsModule(),
configurator.GenutilModule(),
configurator.DistributionModule(),
configurator.MintModule(),
configurator.ProtocolPoolModule(),
configurator.GovModule(),
)
@@ -0,0 +1,172 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: x/protocolpool/types/expected_keepers.go
// Package testutil is a generated GoMock package.
package testutil
import (
context "context"
reflect "reflect"
address "cosmossdk.io/core/address"
types "github.com/cosmos/cosmos-sdk/types"
gomock "github.com/golang/mock/gomock"
)
// MockAccountKeeper is a mock of AccountKeeper interface.
type MockAccountKeeper struct {
ctrl *gomock.Controller
recorder *MockAccountKeeperMockRecorder
}
// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper.
type MockAccountKeeperMockRecorder struct {
mock *MockAccountKeeper
}
// NewMockAccountKeeper creates a new mock instance.
func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper {
mock := &MockAccountKeeper{ctrl: ctrl}
mock.recorder = &MockAccountKeeperMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder {
return m.recorder
}
// AddressCodec mocks base method.
func (m *MockAccountKeeper) AddressCodec() address.Codec {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "AddressCodec")
ret0, _ := ret[0].(address.Codec)
return ret0
}
// AddressCodec indicates an expected call of AddressCodec.
func (mr *MockAccountKeeperMockRecorder) AddressCodec() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddressCodec", reflect.TypeOf((*MockAccountKeeper)(nil).AddressCodec))
}
// GetAccount mocks base method.
func (m *MockAccountKeeper) GetAccount(ctx context.Context, addr types.AccAddress) types.AccountI {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAccount", ctx, addr)
ret0, _ := ret[0].(types.AccountI)
return ret0
}
// GetAccount indicates an expected call of GetAccount.
func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr)
}
// GetModuleAccount mocks base method.
func (m *MockAccountKeeper) GetModuleAccount(ctx context.Context, name string) types.ModuleAccountI {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetModuleAccount", ctx, name)
ret0, _ := ret[0].(types.ModuleAccountI)
return ret0
}
// GetModuleAccount indicates an expected call of GetModuleAccount.
func (mr *MockAccountKeeperMockRecorder) GetModuleAccount(ctx, name interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAccount), ctx, name)
}
// GetModuleAddress mocks base method.
func (m *MockAccountKeeper) GetModuleAddress(name string) types.AccAddress {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetModuleAddress", name)
ret0, _ := ret[0].(types.AccAddress)
return ret0
}
// GetModuleAddress indicates an expected call of GetModuleAddress.
func (mr *MockAccountKeeperMockRecorder) GetModuleAddress(name interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAddress", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAddress), name)
}
// MockBankKeeper is a mock of BankKeeper interface.
type MockBankKeeper struct {
ctrl *gomock.Controller
recorder *MockBankKeeperMockRecorder
}
// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper.
type MockBankKeeperMockRecorder struct {
mock *MockBankKeeper
}
// NewMockBankKeeper creates a new mock instance.
func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper {
mock := &MockBankKeeper{ctrl: ctrl}
mock.recorder = &MockBankKeeperMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder {
return m.recorder
}
// GetAllBalances mocks base method.
func (m *MockBankKeeper) GetAllBalances(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllBalances", ctx, addr)
ret0, _ := ret[0].(types.Coins)
return ret0
}
// GetAllBalances indicates an expected call of GetAllBalances.
func (mr *MockBankKeeperMockRecorder) GetAllBalances(ctx, addr interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllBalances", reflect.TypeOf((*MockBankKeeper)(nil).GetAllBalances), ctx, addr)
}
// SendCoinsFromAccountToModule mocks base method.
func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt)
ret0, _ := ret[0].(error)
return ret0
}
// SendCoinsFromAccountToModule indicates an expected call of SendCoinsFromAccountToModule.
func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, amt interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromAccountToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromAccountToModule), ctx, senderAddr, recipientModule, amt)
}
// SendCoinsFromModuleToAccount mocks base method.
func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt)
ret0, _ := ret[0].(error)
return ret0
}
// SendCoinsFromModuleToAccount indicates an expected call of SendCoinsFromModuleToAccount.
func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, amt interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromModuleToAccount", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromModuleToAccount), ctx, senderModule, recipientAddr, amt)
}
// SpendableCoins mocks base method.
func (m *MockBankKeeper) SpendableCoins(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr)
ret0, _ := ret[0].(types.Coins)
return ret0
}
// SpendableCoins indicates an expected call of SpendableCoins.
func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoins", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoins), ctx, addr)
}
+17
View File
@@ -0,0 +1,17 @@
package types
import (
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
)
func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgFundCommunityPool{},
&MsgCommunityPoolSpend{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}
+5
View File
@@ -0,0 +1,5 @@
package types
import "cosmossdk.io/errors"
var ErrInvalidSigner = errors.Register(ModuleName, 2, "expected authority account as only signer for community pool spend message")
+24
View File
@@ -0,0 +1,24 @@
package types
import (
context "context"
"cosmossdk.io/core/address"
sdk "github.com/cosmos/cosmos-sdk/types"
)
type AccountKeeper interface {
AddressCodec() address.Codec
GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI
GetModuleAddress(name string) sdk.AccAddress
GetModuleAccount(ctx context.Context, name string) sdk.ModuleAccountI
}
// BankKeeper defines the expected interface needed to retrieve account balances.
type BankKeeper interface {
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
}
+15
View File
@@ -0,0 +1,15 @@
package types
const (
// ModuleName is the module name constant used in many places
ModuleName = "protocolpool"
// StoreKey is the store key string for protocolpool
StoreKey = ModuleName
// RouterKey is the message route for protocolpool
RouterKey = ModuleName
// GovModuleName is the name of the gov module
GovModuleName = "gov"
)
+29
View File
@@ -0,0 +1,29 @@
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
var (
_ sdk.Msg = (*MsgFundCommunityPool)(nil)
_ sdk.Msg = (*MsgCommunityPoolSpend)(nil)
)
// NewMsgFundCommunityPool returns a new MsgFundCommunityPool with a sender and
// a funding amount.
func NewMsgFundCommunityPool(amount sdk.Coins, depositor string) *MsgFundCommunityPool {
return &MsgFundCommunityPool{
Amount: amount,
Depositor: depositor,
}
}
// NewCommunityPoolSpend returns a new CommunityPoolSpend with authority, recipient and
// a spending amount.
func NewCommunityPoolSpend(amount sdk.Coins, authority, recipient string) *MsgCommunityPoolSpend {
return &MsgCommunityPoolSpend{
Authority: authority,
Recipient: recipient,
Amount: amount,
}
}
+553
View File
@@ -0,0 +1,553 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: cosmos/protocolpool/v1/query.proto
package types
import (
context "context"
fmt "fmt"
github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types"
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
// QueryCommunityPoolRequest is the request type for the Query/CommunityPool RPC
// method.
type QueryCommunityPoolRequest struct {
}
func (m *QueryCommunityPoolRequest) Reset() { *m = QueryCommunityPoolRequest{} }
func (m *QueryCommunityPoolRequest) String() string { return proto.CompactTextString(m) }
func (*QueryCommunityPoolRequest) ProtoMessage() {}
func (*QueryCommunityPoolRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_51500a0a77d57843, []int{0}
}
func (m *QueryCommunityPoolRequest) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *QueryCommunityPoolRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_QueryCommunityPoolRequest.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 *QueryCommunityPoolRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_QueryCommunityPoolRequest.Merge(m, src)
}
func (m *QueryCommunityPoolRequest) XXX_Size() int {
return m.Size()
}
func (m *QueryCommunityPoolRequest) XXX_DiscardUnknown() {
xxx_messageInfo_QueryCommunityPoolRequest.DiscardUnknown(m)
}
var xxx_messageInfo_QueryCommunityPoolRequest proto.InternalMessageInfo
// QueryCommunityPoolResponse is the response type for the Query/CommunityPool
// RPC method.
type QueryCommunityPoolResponse struct {
// pool defines community pool's coins.
Pool github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,1,rep,name=pool,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"pool"`
}
func (m *QueryCommunityPoolResponse) Reset() { *m = QueryCommunityPoolResponse{} }
func (m *QueryCommunityPoolResponse) String() string { return proto.CompactTextString(m) }
func (*QueryCommunityPoolResponse) ProtoMessage() {}
func (*QueryCommunityPoolResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_51500a0a77d57843, []int{1}
}
func (m *QueryCommunityPoolResponse) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *QueryCommunityPoolResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_QueryCommunityPoolResponse.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 *QueryCommunityPoolResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_QueryCommunityPoolResponse.Merge(m, src)
}
func (m *QueryCommunityPoolResponse) XXX_Size() int {
return m.Size()
}
func (m *QueryCommunityPoolResponse) XXX_DiscardUnknown() {
xxx_messageInfo_QueryCommunityPoolResponse.DiscardUnknown(m)
}
var xxx_messageInfo_QueryCommunityPoolResponse proto.InternalMessageInfo
func (m *QueryCommunityPoolResponse) GetPool() github_com_cosmos_cosmos_sdk_types.DecCoins {
if m != nil {
return m.Pool
}
return nil
}
func init() {
proto.RegisterType((*QueryCommunityPoolRequest)(nil), "cosmos.protocolpool.v1.QueryCommunityPoolRequest")
proto.RegisterType((*QueryCommunityPoolResponse)(nil), "cosmos.protocolpool.v1.QueryCommunityPoolResponse")
}
func init() {
proto.RegisterFile("cosmos/protocolpool/v1/query.proto", fileDescriptor_51500a0a77d57843)
}
var fileDescriptor_51500a0a77d57843 = []byte{
// 335 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x51, 0x3f, 0x4e, 0xf3, 0x30,
0x14, 0x8f, 0xbf, 0x0f, 0x18, 0x82, 0x58, 0x22, 0x84, 0x20, 0x54, 0x2e, 0x64, 0x40, 0x95, 0x10,
0x7e, 0x4a, 0x3b, 0xb2, 0xb5, 0x1c, 0x00, 0x3a, 0xb2, 0xa0, 0x24, 0xb5, 0x82, 0xd5, 0xc4, 0x2f,
0xad, 0x9d, 0x8a, 0xae, 0x70, 0x01, 0x24, 0xee, 0xc0, 0xc0, 0xc4, 0x31, 0x3a, 0x56, 0x62, 0x61,
0x02, 0xd4, 0x72, 0x10, 0x94, 0x38, 0x95, 0xa8, 0xd4, 0x0e, 0x4c, 0xb6, 0x7e, 0xef, 0xfd, 0xfe,
0xd9, 0xb6, 0x17, 0xa1, 0x4a, 0x51, 0x41, 0x36, 0x44, 0x8d, 0x11, 0x26, 0x19, 0x62, 0x02, 0x23,
0x1f, 0x06, 0x39, 0x1f, 0x8e, 0x59, 0x89, 0x3a, 0x7b, 0x66, 0x87, 0xfd, 0xde, 0x61, 0x23, 0xdf,
0xdd, 0x8d, 0x31, 0xc6, 0x12, 0x84, 0xe2, 0x66, 0xe6, 0x6e, 0x2d, 0x46, 0x8c, 0x13, 0x0e, 0x41,
0x26, 0x20, 0x90, 0x12, 0x75, 0xa0, 0x05, 0xca, 0x8a, 0xed, 0xd2, 0xca, 0x2f, 0x0c, 0x14, 0x87,
0x91, 0x1f, 0x72, 0x1d, 0xf8, 0x10, 0xa1, 0x90, 0x66, 0xee, 0x1d, 0xda, 0x07, 0x57, 0x85, 0x75,
0x07, 0xd3, 0x34, 0x97, 0x42, 0x8f, 0x2f, 0x11, 0x93, 0x2e, 0x1f, 0xe4, 0x5c, 0x69, 0xef, 0x81,
0xd8, 0xee, 0xaa, 0xa9, 0xca, 0x50, 0x2a, 0xee, 0x70, 0x7b, 0xa3, 0x88, 0xb6, 0x4f, 0x8e, 0xfe,
0x37, 0xb6, 0x9b, 0x35, 0x56, 0xc5, 0x2e, 0xac, 0x58, 0x65, 0xc5, 0x2e, 0x78, 0xd4, 0x41, 0x21,
0xdb, 0xad, 0xc9, 0x47, 0xdd, 0x7a, 0xf9, 0xac, 0x9f, 0xc6, 0x42, 0xdf, 0xe6, 0x21, 0x8b, 0x30,
0x85, 0x2a, 0x9a, 0x39, 0xce, 0x54, 0xaf, 0x0f, 0x7a, 0x9c, 0x71, 0xb5, 0xe0, 0xa8, 0x6e, 0x29,
0xdf, 0x7c, 0x25, 0xf6, 0x66, 0x99, 0xc2, 0x79, 0x26, 0xf6, 0xce, 0x52, 0x14, 0xc7, 0x67, 0xab,
0xdf, 0x8a, 0xad, 0x2d, 0xe5, 0x36, 0xff, 0x42, 0x31, 0x4d, 0x3d, 0x76, 0xff, 0xf6, 0xfd, 0xf4,
0xaf, 0xe1, 0x9c, 0xc0, 0x9a, 0xef, 0x8b, 0x16, 0xb4, 0x9b, 0x02, 0x69, 0x9f, 0x4f, 0x66, 0x94,
0x4c, 0x67, 0x94, 0x7c, 0xcd, 0x28, 0x79, 0x9c, 0x53, 0x6b, 0x3a, 0xa7, 0xd6, 0xfb, 0x9c, 0x5a,
0xd7, 0xc7, 0x46, 0x40, 0xf5, 0xfa, 0x4c, 0x20, 0xdc, 0x2d, 0x0b, 0x95, 0xf5, 0xc3, 0xad, 0x12,
0x6b, 0xfd, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0xc7, 0xae, 0xa2, 0x2b, 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 {
// CommunityPool queries the community pool coins.
CommunityPool(ctx context.Context, in *QueryCommunityPoolRequest, opts ...grpc.CallOption) (*QueryCommunityPoolResponse, error)
}
type queryClient struct {
cc grpc1.ClientConn
}
func NewQueryClient(cc grpc1.ClientConn) QueryClient {
return &queryClient{cc}
}
func (c *queryClient) CommunityPool(ctx context.Context, in *QueryCommunityPoolRequest, opts ...grpc.CallOption) (*QueryCommunityPoolResponse, error) {
out := new(QueryCommunityPoolResponse)
err := c.cc.Invoke(ctx, "/cosmos.protocolpool.v1.Query/CommunityPool", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// QueryServer is the server API for Query service.
type QueryServer interface {
// CommunityPool queries the community pool coins.
CommunityPool(context.Context, *QueryCommunityPoolRequest) (*QueryCommunityPoolResponse, error)
}
// UnimplementedQueryServer can be embedded to have forward compatible implementations.
type UnimplementedQueryServer struct {
}
func (*UnimplementedQueryServer) CommunityPool(ctx context.Context, req *QueryCommunityPoolRequest) (*QueryCommunityPoolResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method CommunityPool not implemented")
}
func RegisterQueryServer(s grpc1.Server, srv QueryServer) {
s.RegisterService(&_Query_serviceDesc, srv)
}
func _Query_CommunityPool_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(QueryCommunityPoolRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(QueryServer).CommunityPool(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/cosmos.protocolpool.v1.Query/CommunityPool",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(QueryServer).CommunityPool(ctx, req.(*QueryCommunityPoolRequest))
}
return interceptor(ctx, in, info, handler)
}
var _Query_serviceDesc = grpc.ServiceDesc{
ServiceName: "cosmos.protocolpool.v1.Query",
HandlerType: (*QueryServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "CommunityPool",
Handler: _Query_CommunityPool_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "cosmos/protocolpool/v1/query.proto",
}
func (m *QueryCommunityPoolRequest) 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 *QueryCommunityPoolRequest) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *QueryCommunityPoolRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
return len(dAtA) - i, nil
}
func (m *QueryCommunityPoolResponse) 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 *QueryCommunityPoolResponse) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *QueryCommunityPoolResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if len(m.Pool) > 0 {
for iNdEx := len(m.Pool) - 1; iNdEx >= 0; iNdEx-- {
{
size, err := m.Pool[iNdEx].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 *QueryCommunityPoolRequest) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
return n
}
func (m *QueryCommunityPoolResponse) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if len(m.Pool) > 0 {
for _, e := range m.Pool {
l = e.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 *QueryCommunityPoolRequest) 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: QueryCommunityPoolRequest: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: QueryCommunityPoolRequest: 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 *QueryCommunityPoolResponse) 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: QueryCommunityPoolResponse: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: QueryCommunityPoolResponse: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Pool", 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
}
m.Pool = append(m.Pool, types.DecCoin{})
if err := m.Pool[len(m.Pool)-1].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")
)
+153
View File
@@ -0,0 +1,153 @@
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: cosmos/protocolpool/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_CommunityPool_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryCommunityPoolRequest
var metadata runtime.ServerMetadata
msg, err := client.CommunityPool(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Query_CommunityPool_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryCommunityPoolRequest
var metadata runtime.ServerMetadata
msg, err := server.CommunityPool(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_CommunityPool_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_CommunityPool_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_CommunityPool_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_CommunityPool_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_CommunityPool_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_CommunityPool_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_Query_CommunityPool_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "protocolpool", "v1", "community_pool"}, "", runtime.AssumeColonVerbOpt(false)))
)
var (
forward_Query_CommunityPool_0 = runtime.ForwardResponseMessage
)
File diff suppressed because it is too large Load Diff