diff --git a/app/app.go b/app/app.go index f99bbf890..68d2a28f7 100644 --- a/app/app.go +++ b/app/app.go @@ -161,6 +161,9 @@ import ( "github.com/milkyway-labs/milkyway/x/operators" operatorskeeper "github.com/milkyway-labs/milkyway/x/operators/keeper" operatorstypes "github.com/milkyway-labs/milkyway/x/operators/types" + "github.com/milkyway-labs/milkyway/x/pools" + poolskeeper "github.com/milkyway-labs/milkyway/x/pools/keeper" + poolstypes "github.com/milkyway-labs/milkyway/x/pools/types" "github.com/milkyway-labs/milkyway/x/records" recordskeeper "github.com/milkyway-labs/milkyway/x/records/keeper" recordstypes "github.com/milkyway-labs/milkyway/x/records/types" @@ -284,6 +287,7 @@ type MilkyWayApp struct { ServicesKeeper *serviceskeeper.Keeper OperatorsKeeper *operatorskeeper.Keeper + PoolsKeeper *poolskeeper.Keeper // make scoped keepers public for test purposes ScopedIBCKeeper capabilitykeeper.ScopedKeeper @@ -347,7 +351,7 @@ func NewMilkyWayApp( icacallbackstypes.StoreKey, recordstypes.StoreKey, stakeibctypes.StoreKey, // Custom modules - servicestypes.StoreKey, operatorstypes.StoreKey, + servicestypes.StoreKey, operatorstypes.StoreKey, poolstypes.StoreKey, ) tkeys := storetypes.NewTransientStoreKeys(forwardingtypes.TransientStoreKey) memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -874,6 +878,11 @@ func NewMilkyWayApp( communityPoolKeeper, authorityAddr, ) + app.PoolsKeeper = poolskeeper.NewKeeper( + app.appCodec, + keys[poolstypes.StoreKey], + app.AccountKeeper, + ) /**** Module Options ****/ @@ -923,6 +932,7 @@ func NewMilkyWayApp( // custom modules services.NewAppModule(appCodec, app.ServicesKeeper), operators.NewAppModule(appCodec, app.OperatorsKeeper), + pools.NewAppModule(appCodec, app.PoolsKeeper), ) if err := app.setupIndexer(appOpts, homePath, ac, vc, appCodec); err != nil { @@ -963,6 +973,7 @@ func NewMilkyWayApp( servicestypes.ModuleName, operatorstypes.ModuleName, + poolstypes.ModuleName, ) app.ModuleManager.SetOrderEndBlockers( @@ -979,6 +990,7 @@ func NewMilkyWayApp( servicestypes.ModuleName, operatorstypes.ModuleName, + poolstypes.ModuleName, ) // NOTE: The genutils module must occur after staking so that pools are @@ -998,7 +1010,7 @@ func NewMilkyWayApp( stakeibctypes.ModuleName, epochstypes.ModuleName, icqtypes.ModuleName, recordstypes.ModuleName, ratelimittypes.ModuleName, icacallbackstypes.ModuleName, - servicestypes.ModuleName, operatorstypes.ModuleName, + servicestypes.ModuleName, operatorstypes.ModuleName, poolstypes.ModuleName, } app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...) diff --git a/proto/milkyway/pools/v1/genesis.proto b/proto/milkyway/pools/v1/genesis.proto new file mode 100644 index 000000000..1a0cfa1af --- /dev/null +++ b/proto/milkyway/pools/v1/genesis.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; +package milkyway.pools.v1; + +import "gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; +import "milkyway/pools/v1/models.proto"; + +option go_package = "github.com/milkyway-labs/milkyway/x/pools/types"; + +// GenesisState defines the pools module's genesis state. +message GenesisState { + + // NextPoolID represents the id to be used when creating the next pool. + uint32 next_pool_id = 1 [ + (gogoproto.customname) = "NextPoolID", + (gogoproto.moretags) = "yaml:\"next_pool_id\"" + ]; + + // Operators defines the list of pools. + repeated Pool pools = 2 + [ (gogoproto.moretags) = "yaml:\"pools\"", (gogoproto.nullable) = false ]; +} \ No newline at end of file diff --git a/proto/milkyway/pools/v1/models.proto b/proto/milkyway/pools/v1/models.proto new file mode 100644 index 000000000..cf20ec163 --- /dev/null +++ b/proto/milkyway/pools/v1/models.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; +package milkyway.pools.v1; + +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; + +option go_package = "github.com/milkyway-labs/milkyway/x/pools/types"; + +// Pool defines the structure of a restaking pool +message Pool { + // ID is the auto-generated unique identifier for the pool + uint32 id = 1 [ (gogoproto.customname) = "ID" ]; + + // Denom represents the denomination of the tokens that are staked in the pool + string denom = 2; + + // Address represents the address of the account that is associated with this + // pool. This will be used to store tokens that users delegate to this pool. + string address = 3 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} diff --git a/proto/milkyway/pools/v1/query.proto b/proto/milkyway/pools/v1/query.proto new file mode 100644 index 000000000..db2d1bdca --- /dev/null +++ b/proto/milkyway/pools/v1/query.proto @@ -0,0 +1,62 @@ +syntax = "proto3"; +package milkyway.pools.v1; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; +import "milkyway/pools/v1/models.proto"; + +option go_package = "github.com/milkyway-labs/milkyway/x/pools/types"; + +// Query defines the gRPC querier service. +service Query { + // PoolById defines a gRPC query method that returns the pool by the given ID. + rpc PoolById(QueryPoolByIdRequest) returns (QueryPoolResponse) { + option (google.api.http).get = "/milkyway/pool/v1/pool/{pool_id}"; + } + + // PoolByDenom defines a gRPC query method that returns the pool by the given + // denom. + rpc PoolByDenom(QueryPoolByDenomRequest) returns (QueryPoolResponse) { + option (google.api.http).get = "/milkyway/pool/v1/pool/denom/{denom}"; + } + + // Pools defines a gRPC query method that returns all pools. + rpc Pools(QueryPoolsRequest) returns (QueryPoolsResponse) { + option (google.api.http).get = "/milkyway/pool/v1/pools"; + } +} + +// QueryPoolByIdRequest is the request type for the Query/PoolById RPC method. +message QueryPoolByIdRequest { + // PoolID is the ID of the pool to query + uint32 pool_id = 1; +} + +// QueryPoolByDenomRequest is the request type for the Query/PollByDenom RPC +// method. +message QueryPoolByDenomRequest { + // Denom is the denom for which the pool is to be queried + string denom = 1; +} + +// QueryOperatorRPoolsesponse is the response type for the Query/PoolById and +// Query/PoolByDenom RPC methods. +message QueryPoolResponse { + // Pool is the queried pool + Pool pool = 1 [ (gogoproto.nullable) = false ]; +} + +// QueryPoolsRequest is the request type for the Query/Pools RPC method. +message QueryPoolsRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +// QueryPoolsResponse is the response type for the Query/Pools RPC method. +message QueryPoolsResponse { + // Pools is the list of pool + repeated Pool pools = 1 [ (gogoproto.nullable) = false ]; + + // Pagination defines the pagination response + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} \ No newline at end of file diff --git a/utils/slices.go b/utils/slices.go index 257f85695..795956232 100644 --- a/utils/slices.go +++ b/utils/slices.go @@ -12,3 +12,25 @@ func FindDuplicate[T any](slice []T, compare func(a T, b T) bool) *T { } return nil } + +// Map applies the given function to each element in the slice and returns a new slice with the results. +func Map[T, U any](slice []T, f func(T) U) []U { + result := make([]U, len(slice)) + for i, v := range slice { + result[i] = f(v) + } + return result +} + +// RemoveDuplicates removes all duplicate elements from the slice. +func RemoveDuplicates[T comparable](slice []T) []T { + seen := make(map[T]bool) + result := make([]T, 0, len(slice)) + for _, v := range slice { + if _, ok := seen[v]; !ok { + seen[v] = true + result = append(result, v) + } + } + return result +} diff --git a/x/pools/client/cli/query.go b/x/pools/client/cli/query.go new file mode 100644 index 000000000..aa47d27b7 --- /dev/null +++ b/x/pools/client/cli/query.go @@ -0,0 +1,126 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/version" + "github.com/spf13/cobra" + + "github.com/milkyway-labs/milkyway/x/pools/types" +) + +// GetQueryCmd returns the command allowing to perform queries +func GetQueryCmd() *cobra.Command { + servicesQueryCmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + servicesQueryCmd.AddCommand( + getCmdQueryPoolByID(), + getCmdQueryPoolByDenom(), + getCmdQueryPools(), + ) + + return servicesQueryCmd +} + +// getCmdQueryPoolByID returns the command allowing to query a service +func getCmdQueryPoolByID() *cobra.Command { + cmd := &cobra.Command{ + Use: "pool [pool-id]", + Short: "Query the pool with the given id", + Example: fmt.Sprintf(`%s query %s pool 1`, version.AppName, types.ModuleName), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + poolID, err := types.ParsePoolID(args[0]) + if err != nil { + return err + } + + res, err := queryClient.PoolById(cmd.Context(), types.NewQueryPoolByIdRequest(poolID)) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// getCmdQueryPoolByDenom returns the command allowing to query services +func getCmdQueryPoolByDenom() *cobra.Command { + cmd := &cobra.Command{ + Use: "pool-by-denom [denom]", + Short: "Query the pool associated with the given denom", + Example: fmt.Sprintf(`%s query %s pool umilk`, version.AppName, types.ModuleName), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.PoolByDenom(cmd.Context(), types.NewQueryPoolByDenomRequest(args[0])) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// getCmdQueryPools returns the command to query the stored pools +func getCmdQueryPools() *cobra.Command { + cmd := &cobra.Command{ + Use: "pools", + Short: "Query the pools", + Example: fmt.Sprintf(`%s query %s pools --page=2 --limit=100`, version.AppName, types.ModuleName), + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + res, err := queryClient.Pools(cmd.Context(), types.NewQueryPoolsRequest(pageReq)) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "pools") + + return cmd +} diff --git a/x/pools/keeper/alias_functions.go b/x/pools/keeper/alias_functions.go new file mode 100644 index 000000000..07d6cb609 --- /dev/null +++ b/x/pools/keeper/alias_functions.go @@ -0,0 +1,99 @@ +package keeper + +import ( + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/milkyway-labs/milkyway/x/pools/types" +) + +// createAccountIfNotExists creates an account if it does not exist +func (k *Keeper) createAccountIfNotExists(ctx sdk.Context, address sdk.AccAddress) { + if !k.accountKeeper.HasAccount(ctx, address) { + defer telemetry.IncrCounter(1, "new", "account") + k.accountKeeper.SetAccount(ctx, k.accountKeeper.NewAccountWithAddress(ctx, address)) + } +} + +// IteratePools iterates over the pools in the store and performs a callback function +func (k *Keeper) IteratePools(ctx sdk.Context, cb func(pool types.Pool) (stop bool)) { + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, types.PoolPrefix) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var pool types.Pool + k.cdc.MustUnmarshal(iterator.Value(), &pool) + + if cb(pool) { + break + } + } +} + +// GetPools returns the list of stored pools +func (k *Keeper) GetPools(ctx sdk.Context) []types.Pool { + var pools []types.Pool + k.IteratePools(ctx, func(pool types.Pool) (stop bool) { + pools = append(pools, pool) + return false + }) + return pools +} + +// GetPoolByDenom returns the pool for the given denom if it exists. +// If the pool does not exist, false is returned instead +func (k *Keeper) GetPoolByDenom(ctx sdk.Context, denom string) (types.Pool, bool) { + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, types.PoolPrefix) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var pool types.Pool + k.cdc.MustUnmarshal(iterator.Value(), &pool) + + if pool.Denom == denom { + return pool, true + } + } + + return types.Pool{}, false +} + +// CreateOrGetPoolByDenom creates a new pool for the given denom if it does not exist. +// If the pool already exists, no action is taken. +// In both cases, the pool is returned. +func (k *Keeper) CreateOrGetPoolByDenom(ctx sdk.Context, denom string) (types.Pool, error) { + // If the pool already exists, just return + if pool, found := k.GetPoolByDenom(ctx, denom); found { + return pool, nil + } + + // Get the pool id + poolID, err := k.GetNextPoolID(ctx) + if err != nil { + return types.Pool{}, err + } + + // Create the pool and validate it + pool := types.NewPool(poolID, denom) + err = pool.Validate() + if err != nil { + return types.Pool{}, err + } + + // Save the pool + err = k.SavePool(ctx, pool) + if err != nil { + return types.Pool{}, err + } + + // Increment the pool id + k.SetNextPoolID(ctx, poolID+1) + + // Log the event + k.Logger(ctx).Debug("created pool", "id", poolID, "denom", denom) + + return pool, nil +} diff --git a/x/pools/keeper/alias_functions_test.go b/x/pools/keeper/alias_functions_test.go new file mode 100644 index 000000000..bf0ba736a --- /dev/null +++ b/x/pools/keeper/alias_functions_test.go @@ -0,0 +1,141 @@ +package keeper_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/milkyway-labs/milkyway/x/pools/types" +) + +func (suite *KeeperTestSuite) TestKeeper_GetPoolForDenom() { + testCases := []struct { + name string + setup func() + store func(ctx sdk.Context) + denom string + expFound bool + expPool types.Pool + check func(ctx sdk.Context) + }{ + { + name: "non exiting pool returns error", + denom: "denom", + expFound: false, + }, + { + name: "existing pool is returned properly", + store: func(ctx sdk.Context) { + err := suite.k.SavePool(ctx, types.NewPool(1, "umilk")) + suite.Require().NoError(err) + }, + denom: "umilk", + expFound: true, + expPool: types.NewPool(1, "umilk"), + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + ctx, _ := suite.ctx.CacheContext() + if tc.setup != nil { + tc.setup() + } + if tc.store != nil { + tc.store(ctx) + } + + pool, found := suite.k.GetPoolByDenom(ctx, tc.denom) + suite.Require().Equal(tc.expFound, found) + if tc.expFound { + suite.Require().Equal(tc.expPool, pool) + } + + if tc.check != nil { + tc.check(ctx) + } + }) + } +} + +func (suite *KeeperTestSuite) TestKeeper_CreateOrGetPoolByDenom() { + testCases := []struct { + name string + setup func() + store func(ctx sdk.Context) + denom string + shouldErr bool + expPool types.Pool + check func(ctx sdk.Context) + }{ + { + name: "invalid next pool id returns error", + denom: "umilk", + shouldErr: true, + }, + { + name: "invalid pool returns error", + store: func(ctx sdk.Context) { + suite.k.SetNextPoolID(ctx, 1) + }, + denom: "invalid!", + shouldErr: true, + }, + { + name: "existing pool is returned properly", + store: func(ctx sdk.Context) { + err := suite.k.SavePool(ctx, types.NewPool(1, "umilk")) + suite.Require().NoError(err) + }, + denom: "umilk", + shouldErr: false, + expPool: types.NewPool(1, "umilk"), + }, + { + name: "non existing pool is created properly", + store: func(ctx sdk.Context) { + suite.k.SetNextPoolID(ctx, 2) + err := suite.k.SavePool(ctx, types.NewPool(1, "unit")) + suite.Require().NoError(err) + }, + denom: "umilk", + shouldErr: false, + expPool: types.NewPool(2, "umilk"), + check: func(ctx sdk.Context) { + // Make sure the pool is stored properly + pool, found := suite.k.GetPoolByDenom(ctx, "umilk") + suite.Require().True(found) + suite.Require().Equal(types.NewPool(2, "umilk"), pool) + + // Make sure the next pool id has been incremented + nextPoolID, err := suite.k.GetNextPoolID(ctx) + suite.Require().NoError(err) + suite.Require().Equal(uint32(3), nextPoolID) + }, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + ctx, _ := suite.ctx.CacheContext() + if tc.setup != nil { + tc.setup() + } + if tc.store != nil { + tc.store(ctx) + } + + pool, err := suite.k.CreateOrGetPoolByDenom(ctx, tc.denom) + if tc.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Require().Equal(tc.expPool, pool) + } + + if tc.check != nil { + tc.check(ctx) + } + }) + } +} diff --git a/x/pools/keeper/common_test.go b/x/pools/keeper/common_test.go new file mode 100644 index 000000000..7ba83fab2 --- /dev/null +++ b/x/pools/keeper/common_test.go @@ -0,0 +1,96 @@ +package keeper_test + +import ( + "testing" + + "cosmossdk.io/log" + "cosmossdk.io/store" + "cosmossdk.io/store/metrics" + "github.com/cosmos/cosmos-sdk/runtime" + authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + "github.com/milkyway-labs/milkyway/app" + bankkeeper "github.com/milkyway-labs/milkyway/x/bank/keeper" + "github.com/milkyway-labs/milkyway/x/pools/keeper" + "github.com/milkyway-labs/milkyway/x/pools/types" + + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + + storetypes "cosmossdk.io/store/types" + db "github.com/cosmos/cosmos-db" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/suite" +) + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(KeeperTestSuite)) +} + +type KeeperTestSuite struct { + suite.Suite + + cdc codec.Codec + legacyAminoCdc *codec.LegacyAmino + ctx sdk.Context + + storeKey storetypes.StoreKey + + ak authkeeper.AccountKeeper + bk bankkeeper.Keeper + k *keeper.Keeper +} + +func (suite *KeeperTestSuite) SetupTest() { + // Define store keys + keys := storetypes.NewKVStoreKeys(types.StoreKey, authtypes.StoreKey, banktypes.StoreKey) + suite.storeKey = keys[types.StoreKey] + + // Create logger + logger := log.NewNopLogger() + + // Create an in-memory db + memDB := db.NewMemDB() + ms := store.NewCommitMultiStore(memDB, logger, metrics.NewNoOpMetrics()) + for _, key := range keys { + ms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, memDB) + } + + if err := ms.LoadLatestVersion(); err != nil { + panic(err) + } + + suite.ctx = sdk.NewContext(ms, tmproto.Header{ChainID: "test-chain"}, false, log.NewNopLogger()) + suite.cdc, suite.legacyAminoCdc = app.MakeCodecs() + + // Authority address + authorityAddr := authtypes.NewModuleAddress(govtypes.ModuleName).String() + + // Build keepers + suite.ak = authkeeper.NewAccountKeeper( + suite.cdc, + runtime.NewKVStoreService(keys[authtypes.StoreKey]), + authtypes.ProtoBaseAccount, + app.GetMaccPerms(), + authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), + sdk.GetConfig().GetBech32AccountAddrPrefix(), + authorityAddr, + ) + suite.bk = bankkeeper.NewKeeper( + suite.cdc, + runtime.NewKVStoreService(keys[banktypes.StoreKey]), + suite.ak, + nil, + authorityAddr, + logger, + ) + suite.k = keeper.NewKeeper( + suite.cdc, + suite.storeKey, + suite.ak, + ) +} diff --git a/x/pools/keeper/genesis.go b/x/pools/keeper/genesis.go new file mode 100644 index 000000000..2906a52af --- /dev/null +++ b/x/pools/keeper/genesis.go @@ -0,0 +1,40 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/milkyway-labs/milkyway/x/pools/types" +) + +// ExportGenesis returns a new GenesisState instance containing the information currently present inside the store +func (k *Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + return types.NewGenesis( + k.exportNextPoolID(ctx), + k.GetPools(ctx), + ) +} + +// exportNextPoolID exports the next pool id stored inside the store +func (k *Keeper) exportNextPoolID(ctx sdk.Context) uint32 { + nextPoolID, err := k.GetNextPoolID(ctx) + if err != nil { + panic(err) + } + return nextPoolID +} + +// -------------------------------------------------------------------------------------------------------------------- + +// InitGenesis initializes the genesis store using the provided data +func (k *Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { + // Set the next pool id + k.SetNextPoolID(ctx, data.NextPoolID) + + // Store the pools + for _, pool := range data.Pools { + err := k.SavePool(ctx, pool) + if err != nil { + panic(err) + } + } +} diff --git a/x/pools/keeper/genesis_test.go b/x/pools/keeper/genesis_test.go new file mode 100644 index 000000000..4f37d73cc --- /dev/null +++ b/x/pools/keeper/genesis_test.go @@ -0,0 +1,113 @@ +package keeper_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/milkyway-labs/milkyway/x/pools/types" +) + +func (suite *KeeperTestSuite) TestKeeper_ExportGenesis() { + testCases := []struct { + name string + setup func() + store func(ctx sdk.Context) + expGenesis *types.GenesisState + }{ + { + name: "next pool id is exported properly", + store: func(ctx sdk.Context) { + suite.k.SetNextPoolID(ctx, 10) + }, + expGenesis: &types.GenesisState{ + NextPoolID: 10, + }, + }, + { + name: "pools are exported properly", + store: func(ctx sdk.Context) { + suite.k.SetNextPoolID(ctx, 1) + + err := suite.k.SavePool(ctx, types.NewPool(1, "umilk")) + suite.Require().NoError(err) + err = suite.k.SavePool(ctx, types.NewPool(2, "uatom")) + suite.Require().NoError(err) + }, + expGenesis: &types.GenesisState{ + NextPoolID: 1, + Pools: []types.Pool{ + types.NewPool(1, "umilk"), + types.NewPool(2, "uatom"), + }, + }, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + ctx, _ := suite.ctx.CacheContext() + if tc.setup != nil { + tc.setup() + } + if tc.store != nil { + tc.store(ctx) + } + + genesis := suite.k.ExportGenesis(ctx) + suite.Require().Equal(tc.expGenesis, genesis) + }) + } +} + +func (suite *KeeperTestSuite) TestKeeper_InitGenesis() { + testCases := []struct { + name string + genesis *types.GenesisState + check func(ctx sdk.Context) + }{ + { + name: "default genesis is initialized properly", + genesis: types.DefaultGenesis(), + check: func(ctx sdk.Context) { + nextPoolID, err := suite.k.GetNextPoolID(ctx) + suite.Require().NoError(err) + suite.Require().Equal(uint32(1), nextPoolID) + }, + }, + { + name: "genesis with pools is initialized properly", + genesis: types.NewGenesis( + 10, + []types.Pool{ + types.NewPool(1, "umilk"), + types.NewPool(2, "uatom"), + }, + ), + check: func(ctx sdk.Context) { + nextPoolID, err := suite.k.GetNextPoolID(ctx) + suite.Require().NoError(err) + suite.Require().Equal(uint32(10), nextPoolID) + + pool, found := suite.k.GetPoolByDenom(ctx, "umilk") + suite.Require().True(found) + suite.Require().Equal(types.NewPool(1, "umilk"), pool) + + pool, found = suite.k.GetPoolByDenom(ctx, "uatom") + suite.Require().True(found) + suite.Require().Equal(types.NewPool(2, "uatom"), pool) + }, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + ctx, _ := suite.ctx.CacheContext() + suite.k.InitGenesis(ctx, tc.genesis) + + if tc.check != nil { + tc.check(ctx) + } + }) + } +} diff --git a/x/pools/keeper/grpc_query.go b/x/pools/keeper/grpc_query.go new file mode 100644 index 000000000..077c67b39 --- /dev/null +++ b/x/pools/keeper/grpc_query.go @@ -0,0 +1,73 @@ +package keeper + +import ( + "context" + + "cosmossdk.io/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/milkyway-labs/milkyway/x/pools/types" +) + +var _ types.QueryServer = &Keeper{} + +// PoolById implements the Query/PoolById gRPC method +func (k *Keeper) PoolById(ctx context.Context, request *types.QueryPoolByIdRequest) (*types.QueryPoolResponse, error) { + if request.PoolId == 0 { + return nil, status.Error(codes.InvalidArgument, "invalid pool id") + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + pool, found := k.GetPool(sdkCtx, request.PoolId) + if !found { + return nil, status.Error(codes.NotFound, "pool not found") + } + + return &types.QueryPoolResponse{Pool: pool}, nil +} + +// PoolByDenom implements the Query/PoolByDenom gRPC method +func (k *Keeper) PoolByDenom(ctx context.Context, request *types.QueryPoolByDenomRequest) (*types.QueryPoolResponse, error) { + if err := sdk.ValidateDenom(request.Denom); err != nil { + return nil, status.Error(codes.InvalidArgument, "invalid denom") + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + pool, found := k.GetPoolByDenom(sdkCtx, request.Denom) + if !found { + return nil, status.Error(codes.NotFound, "pool not found") + } + + return &types.QueryPoolResponse{Pool: pool}, nil +} + +// Pools implements the Query/Pools gRPC method +func (k *Keeper) Pools(ctx context.Context, request *types.QueryPoolsRequest) (*types.QueryPoolsResponse, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + store := sdkCtx.KVStore(k.storeKey) + poolsStore := prefix.NewStore(store, types.PoolPrefix) + + var pools []types.Pool + pageRes, err := query.Paginate(poolsStore, request.Pagination, func(key []byte, value []byte) error { + var pool types.Pool + if err := k.cdc.Unmarshal(value, &pool); err != nil { + return status.Error(codes.Internal, err.Error()) + } + + pools = append(pools, pool) + return nil + }) + + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryPoolsResponse{ + Pools: pools, + Pagination: pageRes, + }, nil +} diff --git a/x/pools/keeper/grpc_query_test.go b/x/pools/keeper/grpc_query_test.go new file mode 100644 index 000000000..d615325f8 --- /dev/null +++ b/x/pools/keeper/grpc_query_test.go @@ -0,0 +1,111 @@ +package keeper_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/milkyway-labs/milkyway/x/pools/types" +) + +func (suite *KeeperTestSuite) TestQueryServer_PoolById() { + testCases := []struct { + name string + setup func() + store func(ctx sdk.Context) + request *types.QueryPoolByIdRequest + shouldErr bool + expPool types.Pool + }{ + { + name: "not found pool returns error", + request: &types.QueryPoolByIdRequest{ + PoolId: 1, + }, + shouldErr: true, + }, + { + name: "found pool is returned properly", + store: func(ctx sdk.Context) { + err := suite.k.SavePool(ctx, types.NewPool(1, "umilk")) + suite.Require().NoError(err) + }, + request: &types.QueryPoolByIdRequest{ + PoolId: 1, + }, + shouldErr: false, + expPool: types.NewPool(1, "umilk"), + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + ctx, _ := suite.ctx.CacheContext() + if tc.setup != nil { + tc.setup() + } + if tc.store != nil { + tc.store(ctx) + } + + res, err := suite.k.PoolById(ctx, tc.request) + if tc.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Require().Equal(tc.expPool, res.Pool) + } + }) + } +} + +func (suite *KeeperTestSuite) TestQueryServer_PoolByDenom() { + testCases := []struct { + name string + setup func() + store func(ctx sdk.Context) + request *types.QueryPoolByDenomRequest + shouldErr bool + expPool types.Pool + }{ + { + name: "not found pool returns error", + request: &types.QueryPoolByDenomRequest{ + Denom: "umilk", + }, + shouldErr: true, + }, + { + name: "found pool is returned properly", + store: func(ctx sdk.Context) { + err := suite.k.SavePool(ctx, types.NewPool(1, "umilk")) + suite.Require().NoError(err) + }, + request: &types.QueryPoolByDenomRequest{ + Denom: "umilk", + }, + shouldErr: false, + expPool: types.NewPool(1, "umilk"), + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + ctx, _ := suite.ctx.CacheContext() + if tc.setup != nil { + tc.setup() + } + if tc.store != nil { + tc.store(ctx) + } + + res, err := suite.k.PoolByDenom(ctx, tc.request) + if tc.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Require().Equal(tc.expPool, res.Pool) + } + }) + } +} diff --git a/x/pools/keeper/invariants.go b/x/pools/keeper/invariants.go new file mode 100644 index 000000000..b4b8e52a7 --- /dev/null +++ b/x/pools/keeper/invariants.go @@ -0,0 +1,92 @@ +package keeper + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/milkyway-labs/milkyway/utils" + "github.com/milkyway-labs/milkyway/x/pools/types" +) + +// RegisterInvariants registers all pools module invariants +func RegisterInvariants(ir sdk.InvariantRegistry, keeper *Keeper) { + ir.RegisterRoute(types.ModuleName, "valid-pools", + ValidPoolsInvariant(keeper)) + ir.RegisterRoute(types.ModuleName, "unique-pools", + UniquePoolsInvariant(keeper)) +} + +// -------------------------------------------------------------------------------------------------------------------- + +// formatOutputPools concatenates the given pools information into a string +func formatOutputPools(pools []types.Pool) (output string) { + // Get the unique IDs + uniquePoolIDs := utils.RemoveDuplicates(utils.Map(pools, func(pool types.Pool) uint32 { + return pool.ID + })) + + // Create the message string + for _, poolID := range uniquePoolIDs { + output += fmt.Sprintf("%d\n", poolID) + } + + return output +} + +// ValidPoolsInvariant checks that all the pools are valid +func ValidPoolsInvariant(k *Keeper) sdk.Invariant { + return func(ctx sdk.Context) (message string, broken bool) { + + // Get the next pool id. + nextPoolID, err := k.GetNextPoolID(ctx) + if err != nil { + return sdk.FormatInvariant(types.ModuleName, "invalid pools", "unable to get the next pool ID"), true + } + + var invalidPools []types.Pool + k.IteratePools(ctx, func(pool types.Pool) (stop bool) { + invalid := false + + // Make sure the pool ID is never greater or equal to the next pool ID + if pool.ID >= nextPoolID { + invalid = true + } + + // Make sure the pool is valid + err = pool.Validate() + if err != nil { + invalid = true + } + + if invalid { + invalidPools = append(invalidPools, pool) + } + + return false + }) + + return sdk.FormatInvariant(types.ModuleName, "invalid pools", + fmt.Sprintf("the following pools are invalid:\n %s", formatOutputPools(invalidPools)), + ), invalidPools != nil + } +} + +// UniquePoolsInvariant checks that there are no duplicated pools for the same denom +func UniquePoolsInvariant(k *Keeper) sdk.Invariant { + return func(ctx sdk.Context) (message string, broken bool) { + + var invalidPools []types.Pool + k.IteratePools(ctx, func(pool types.Pool) (stop bool) { + otherPool, found := k.GetPoolByDenom(ctx, pool.Denom) + if found && otherPool.ID != pool.ID { + invalidPools = append(invalidPools, pool) + } + return false + }) + + return sdk.FormatInvariant(types.ModuleName, "invalid pools", + fmt.Sprintf("the following pools have the same denoms:\n %s", formatOutputPools(invalidPools)), + ), invalidPools != nil + } +} diff --git a/x/pools/keeper/invariants_test.go b/x/pools/keeper/invariants_test.go new file mode 100644 index 000000000..7aa632b37 --- /dev/null +++ b/x/pools/keeper/invariants_test.go @@ -0,0 +1,127 @@ +package keeper_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/milkyway-labs/milkyway/x/pools/keeper" + "github.com/milkyway-labs/milkyway/x/pools/types" +) + +func (suite *KeeperTestSuite) TestValidPoolsInvariant() { + testCases := []struct { + name string + setup func() + store func(ctx sdk.Context) + expBroken bool + }{ + { + name: "not found next service id breaks invariant", + store: func(ctx sdk.Context) { + err := suite.k.SavePool(ctx, types.NewPool(1, "umilk")) + suite.Require().NoError(err) + }, + expBroken: true, + }, + { + name: "service with id equals to next service id breaks invariant", + store: func(ctx sdk.Context) { + suite.k.SetNextPoolID(ctx, 1) + err := suite.k.SavePool(ctx, types.NewPool(1, "umilk")) + suite.Require().NoError(err) + }, + expBroken: true, + }, + { + name: "service with id higher than next service id breaks invariant", + store: func(ctx sdk.Context) { + suite.k.SetNextPoolID(ctx, 1) + err := suite.k.SavePool(ctx, types.NewPool(2, "umilk")) + suite.Require().NoError(err) + }, + expBroken: true, + }, + { + name: "invalid service breaks invariant", + store: func(ctx sdk.Context) { + suite.k.SetNextPoolID(ctx, 2) + err := suite.k.SavePool(ctx, types.NewPool(1, "invalid!")) + suite.Require().NoError(err) + }, + expBroken: true, + }, + { + name: "valid data does not break invariant", + store: func(ctx sdk.Context) { + suite.k.SetNextPoolID(ctx, 3) + + err := suite.k.SavePool(ctx, types.NewPool(1, "umilk")) + suite.Require().NoError(err) + err = suite.k.SavePool(ctx, types.NewPool(2, "unit")) + suite.Require().NoError(err) + }, + expBroken: false, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + ctx, _ := suite.ctx.CacheContext() + if tc.setup != nil { + tc.setup() + } + if tc.store != nil { + tc.store(ctx) + } + + _, broken := keeper.ValidPoolsInvariant(suite.k)(ctx) + suite.Require().Equal(tc.expBroken, broken) + }) + } +} + +func (suite *KeeperTestSuite) TestUniquePoolsInvariant() { + testCases := []struct { + name string + setup func() + store func(ctx sdk.Context) + expBroken bool + }{ + { + name: "duplicated pools break invariant", + store: func(ctx sdk.Context) { + err := suite.k.SavePool(ctx, types.NewPool(1, "umilk")) + suite.Require().NoError(err) + err = suite.k.SavePool(ctx, types.NewPool(2, "umilk")) + suite.Require().NoError(err) + }, + expBroken: true, + }, + { + name: "valid data does not break invariant", + store: func(ctx sdk.Context) { + err := suite.k.SavePool(ctx, types.NewPool(1, "umilk")) + suite.Require().NoError(err) + err = suite.k.SavePool(ctx, types.NewPool(2, "unit")) + suite.Require().NoError(err) + }, + expBroken: false, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + ctx, _ := suite.ctx.CacheContext() + if tc.setup != nil { + tc.setup() + } + if tc.store != nil { + tc.store(ctx) + } + + _, broken := keeper.UniquePoolsInvariant(suite.k)(ctx) + suite.Require().Equal(tc.expBroken, broken) + }) + } +} diff --git a/x/pools/keeper/keeper.go b/x/pools/keeper/keeper.go new file mode 100644 index 000000000..72b188143 --- /dev/null +++ b/x/pools/keeper/keeper.go @@ -0,0 +1,30 @@ +package keeper + +import ( + "cosmossdk.io/log" + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/milkyway-labs/milkyway/x/pools/types" +) + +type Keeper struct { + storeKey storetypes.StoreKey + cdc codec.Codec + + accountKeeper types.AccountKeeper +} + +func NewKeeper(cdc codec.Codec, storeKey storetypes.StoreKey, accountKeeper types.AccountKeeper) *Keeper { + return &Keeper{ + storeKey: storeKey, + cdc: cdc, + accountKeeper: accountKeeper, + } +} + +// Logger returns a module-specific logger. +func (k *Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", "x/"+types.ModuleName) +} diff --git a/x/pools/keeper/pools.go b/x/pools/keeper/pools.go new file mode 100644 index 000000000..197155a4a --- /dev/null +++ b/x/pools/keeper/pools.go @@ -0,0 +1,58 @@ +package keeper + +import ( + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/milkyway-labs/milkyway/x/pools/types" +) + +// SetNextPoolID sets the next service ID to be used when registering a new Pool +func (k *Keeper) SetNextPoolID(ctx sdk.Context, serviceID uint32) { + store := ctx.KVStore(k.storeKey) + store.Set(types.NextPoolIDKey, types.GetPoolIDBytes(serviceID)) +} + +// GetNextPoolID returns the next service ID to be used when registering a new Pool +func (k *Keeper) GetNextPoolID(ctx sdk.Context) (serviceID uint32, err error) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.NextPoolIDKey) + if bz == nil { + return 0, errors.Wrapf(types.ErrInvalidGenesis, "initial service id not set") + } + + serviceID = types.GetPoolIDFromBytes(bz) + return serviceID, nil +} + +// -------------------------------------------------------------------------------------------------------------------- + +// SavePool stores the given pool inside the store +func (k *Keeper) SavePool(ctx sdk.Context, pool types.Pool) error { + store := ctx.KVStore(k.storeKey) + store.Set(types.GetPoolStoreKey(pool.ID), k.cdc.MustMarshal(&pool)) + + // Create the pool account if it does not exist + poolAddress, err := sdk.AccAddressFromBech32(pool.Address) + if err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid pool address: %s", pool.Address) + } + k.createAccountIfNotExists(ctx, poolAddress) + + return nil +} + +// GetPool retrieves the pool with the given ID from the store. +// If the pool does not exist, false is returned instead +func (k *Keeper) GetPool(ctx sdk.Context, id uint32) (types.Pool, bool) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.GetPoolStoreKey(id)) + if bz == nil { + return types.Pool{}, false + } + + var pool types.Pool + k.cdc.MustUnmarshal(bz, &pool) + return pool, true +} diff --git a/x/pools/keeper/pools_test.go b/x/pools/keeper/pools_test.go new file mode 100644 index 000000000..7c5a1577d --- /dev/null +++ b/x/pools/keeper/pools_test.go @@ -0,0 +1,219 @@ +package keeper_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/milkyway-labs/milkyway/x/pools/types" +) + +func (suite *KeeperTestSuite) TestKeeper_SetNextPoolID() { + testCases := []struct { + name string + store func(ctx sdk.Context) + id uint32 + check func(ctx sdk.Context) + }{ + { + name: "next pool id is saved correctly", + id: 1, + check: func(ctx sdk.Context) { + store := ctx.KVStore(suite.storeKey) + serviceIDBz := store.Get(types.NextPoolIDKey) + suite.Require().Equal(uint32(1), types.GetPoolIDFromBytes(serviceIDBz)) + }, + }, + { + name: "next pool id is overridden properly", + store: func(ctx sdk.Context) { + suite.k.SetNextPoolID(ctx, 1) + }, + id: 2, + check: func(ctx sdk.Context) { + store := ctx.KVStore(suite.storeKey) + serviceIDBz := store.Get(types.NextPoolIDKey) + suite.Require().Equal(uint32(2), types.GetPoolIDFromBytes(serviceIDBz)) + }, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + ctx, _ := suite.ctx.CacheContext() + if tc.store != nil { + tc.store(ctx) + } + + suite.k.SetNextPoolID(ctx, tc.id) + if tc.check != nil { + tc.check(ctx) + } + }) + } +} + +func (suite *KeeperTestSuite) TestKeeper_GetNextPoolID() { + testCases := []struct { + name string + store func(ctx sdk.Context) + shouldErr bool + expNext uint32 + }{ + { + name: "non existing next pool id returns error", + shouldErr: true, + }, + { + name: "exiting next pool id is returned properly", + store: func(ctx sdk.Context) { + suite.k.SetNextPoolID(ctx, 1) + }, + expNext: 1, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + ctx, _ := suite.ctx.CacheContext() + if tc.store != nil { + tc.store(ctx) + } + + next, err := suite.k.GetNextPoolID(ctx) + if tc.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Require().Equal(tc.expNext, next) + } + }) + } +} + +// -------------------------------------------------------------------------------------------------------------------- + +func (suite *KeeperTestSuite) TestKeeper_SavePool() { + testCases := []struct { + name string + setup func() + store func(ctx sdk.Context) + pool types.Pool + shouldErr bool + check func(ctx sdk.Context) + }{ + { + name: "non existing pool is saved properly", + store: func(ctx sdk.Context) { + suite.k.SetNextPoolID(ctx, 1) + }, + shouldErr: false, + pool: types.NewPool(1, "uatom"), + check: func(ctx sdk.Context) { + // Make sure the pool is saved properly + pool, found := suite.k.GetPool(ctx, 1) + suite.Require().True(found) + suite.Require().Equal(types.NewPool(1, "uatom"), pool) + + // Make sure the pool account is created + hasAccount := suite.ak.HasAccount(ctx, types.GetPoolAddress(1)) + suite.Require().True(hasAccount) + }, + }, + { + name: "existing pool is overridden properly", + setup: func() { + suite.k.SetNextPoolID(suite.ctx, 1) + err := suite.k.SavePool(suite.ctx, types.NewPool(1, "uatom")) + suite.Require().NoError(err) + }, + pool: types.NewPool(1, "usdt"), + shouldErr: false, + check: func(ctx sdk.Context) { + // Make sure the pool is saved properly + pool, found := suite.k.GetPool(ctx, 1) + suite.Require().True(found) + suite.Require().Equal(types.NewPool(1, "usdt"), pool) + + // Make sure the pool account is created + hasAccount := suite.ak.HasAccount(ctx, types.GetPoolAddress(1)) + suite.Require().True(hasAccount) + }, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + ctx, _ := suite.ctx.CacheContext() + if tc.setup != nil { + tc.setup() + } + if tc.store != nil { + tc.store(ctx) + } + + err := suite.k.SavePool(ctx, tc.pool) + if tc.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + } + + if tc.check != nil { + tc.check(ctx) + } + }) + } +} + +func (suite *KeeperTestSuite) TestKeeper_GetPool() { + testCases := []struct { + name string + setup func() + store func(ctx sdk.Context) + poolID uint32 + expFound bool + expPool types.Pool + check func(ctx sdk.Context) + }{ + { + name: "not found pool returns error", + poolID: 1, + expFound: false, + }, + { + name: "found pool is returned properly", + store: func(ctx sdk.Context) { + err := suite.k.SavePool(ctx, types.NewPool(1, "uatom")) + suite.Require().NoError(err) + }, + poolID: 1, + expFound: true, + expPool: types.NewPool(1, "uatom"), + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + ctx, _ := suite.ctx.CacheContext() + if tc.setup != nil { + tc.setup() + } + if tc.store != nil { + tc.store(ctx) + } + + pool, found := suite.k.GetPool(ctx, tc.poolID) + suite.Require().Equal(tc.expFound, found) + if tc.expFound { + suite.Require().Equal(tc.expPool, pool) + } + + if tc.check != nil { + tc.check(ctx) + } + }) + } +} diff --git a/x/pools/module.go b/x/pools/module.go new file mode 100644 index 000000000..3e1d94371 --- /dev/null +++ b/x/pools/module.go @@ -0,0 +1,143 @@ +package pools + +import ( + "context" + "encoding/json" + "fmt" + + "cosmossdk.io/core/appmodule" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + abci "github.com/cometbft/cometbft/abci/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/milkyway-labs/milkyway/x/pools/client/cli" + + "github.com/milkyway-labs/milkyway/x/pools/keeper" + "github.com/milkyway-labs/milkyway/x/pools/types" +) + +const ( + consensusVersion = 1 +) + +var ( + _ appmodule.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface for the pools module. +type AppModuleBasic struct { + cdc codec.BinaryCodec +} + +func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the pools module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +func (AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {} + +// RegisterInterfaces registers the module's interface types +func (a AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {} + +// DefaultGenesis returns the pools module's default genesis state. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis performs genesis state validation for the pools module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err != nil { + panic(err) + } +} + +// GetTxCmd returns the pools module's root tx command. +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return nil +} + +// GetQueryCmd returns the pools module's root query command. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface for the pools module. +type AppModule struct { + AppModuleBasic + + // To ensure setting hooks properly, keeper must be a reference + keeper *keeper.Keeper +} + +func NewAppModule(cdc codec.Codec, keeper *keeper.Keeper) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// Name returns the pools module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} + +// RegisterServices registers a GRPC query service to respond to the module-specific GRPC queries. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) +} + +// RegisterInvariants registers the pools module's invariants. +func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { + keeper.RegisterInvariants(ir, am.keeper) +} + +// InitGenesis performs the pools module's genesis initialization It returns no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + cdc.MustUnmarshalJSON(gs, &genState) + am.keeper.InitGenesis(ctx, &genState) + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the pools module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion implements ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return consensusVersion } + +func (am AppModule) IsOnePerModuleType() {} + +func (am AppModule) IsAppModule() {} diff --git a/x/pools/types/errors.go b/x/pools/types/errors.go new file mode 100644 index 000000000..ab08baa2d --- /dev/null +++ b/x/pools/types/errors.go @@ -0,0 +1,9 @@ +package types + +import ( + "cosmossdk.io/errors" +) + +var ( + ErrInvalidGenesis = errors.Register(ModuleName, 1, "invalid genesis state") +) diff --git a/x/pools/types/expected_keepers.go b/x/pools/types/expected_keepers.go new file mode 100644 index 000000000..cd1e263ff --- /dev/null +++ b/x/pools/types/expected_keepers.go @@ -0,0 +1,13 @@ +package types + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type AccountKeeper interface { + NewAccountWithAddress(ctx context.Context, addr sdk.AccAddress) sdk.AccountI + HasAccount(ctx context.Context, addr sdk.AccAddress) bool + SetAccount(ctx context.Context, acc sdk.AccountI) +} diff --git a/x/pools/types/genesis.go b/x/pools/types/genesis.go new file mode 100644 index 000000000..e1f94a097 --- /dev/null +++ b/x/pools/types/genesis.go @@ -0,0 +1,36 @@ +package types + +import ( + "fmt" +) + +// NewGenesis creates a new GenesisState instance +func NewGenesis(nextPoolID uint32, pools []Pool) *GenesisState { + return &GenesisState{ + NextPoolID: nextPoolID, + Pools: pools, + } +} + +// DefaultGenesis returns the default GenesisState +func DefaultGenesis() *GenesisState { + return NewGenesis(1, nil) +} + +// Validate checks if the GenesisState is valid +func (data *GenesisState) Validate() error { + // Validate the next pool ID + if data.NextPoolID == 0 { + return fmt.Errorf("invalid next pool id") + } + + // Validate the pools + for _, pool := range data.Pools { + err := pool.Validate() + if err != nil { + return fmt.Errorf("invalid pool with id %d: %w", pool.ID, err) + } + } + + return nil +} diff --git a/x/pools/types/genesis.pb.go b/x/pools/types/genesis.pb.go new file mode 100644 index 000000000..6514bf366 --- /dev/null +++ b/x/pools/types/genesis.pb.go @@ -0,0 +1,373 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: milkyway/pools/v1/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/protobuf/types/known/timestamppb" + 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 + +// GenesisState defines the pools module's genesis state. +type GenesisState struct { + // NextPoolID represents the id to be used when creating the next pool. + NextPoolID uint32 `protobuf:"varint,1,opt,name=next_pool_id,json=nextPoolId,proto3" json:"next_pool_id,omitempty" yaml:"next_pool_id"` + // Operators defines the list of pools. + Pools []Pool `protobuf:"bytes,2,rep,name=pools,proto3" json:"pools" yaml:"pools"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_d15ae23e1a0ffba4, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.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 *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetNextPoolID() uint32 { + if m != nil { + return m.NextPoolID + } + return 0 +} + +func (m *GenesisState) GetPools() []Pool { + if m != nil { + return m.Pools + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "milkyway.pools.v1.GenesisState") +} + +func init() { proto.RegisterFile("milkyway/pools/v1/genesis.proto", fileDescriptor_d15ae23e1a0ffba4) } + +var fileDescriptor_d15ae23e1a0ffba4 = []byte{ + // 288 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcf, 0xcd, 0xcc, 0xc9, + 0xae, 0x2c, 0x4f, 0xac, 0xd4, 0x2f, 0xc8, 0xcf, 0xcf, 0x29, 0xd6, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, + 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x84, 0x29, 0xd0, + 0x03, 0x2b, 0xd0, 0x2b, 0x33, 0x94, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xcb, 0xea, 0x83, 0x58, + 0x10, 0x85, 0x52, 0xf2, 0xe9, 0xf9, 0xf9, 0xe9, 0x39, 0xa9, 0xfa, 0x60, 0x5e, 0x52, 0x69, 0x9a, + 0x7e, 0x49, 0x66, 0x6e, 0x6a, 0x71, 0x49, 0x62, 0x6e, 0x01, 0x54, 0x81, 0x1c, 0xa6, 0x55, 0xb9, + 0xf9, 0x29, 0xa9, 0x39, 0x50, 0x9b, 0x94, 0xe6, 0x30, 0x72, 0xf1, 0xb8, 0x43, 0xec, 0x0e, 0x2e, + 0x49, 0x2c, 0x49, 0x15, 0x72, 0xe7, 0xe2, 0xc9, 0x4b, 0xad, 0x28, 0x89, 0x07, 0x29, 0x8f, 0xcf, + 0x4c, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x75, 0x52, 0x7d, 0x74, 0x4f, 0x9e, 0xcb, 0x2f, 0xb5, + 0xa2, 0x24, 0x20, 0x3f, 0x3f, 0xc7, 0xd3, 0xe5, 0xd3, 0x3d, 0x79, 0xe1, 0xca, 0xc4, 0xdc, 0x1c, + 0x2b, 0x25, 0x64, 0xb5, 0x4a, 0x41, 0x5c, 0x79, 0x30, 0x25, 0x29, 0x42, 0xce, 0x5c, 0xac, 0x60, + 0x2b, 0x25, 0x98, 0x14, 0x98, 0x35, 0xb8, 0x8d, 0xc4, 0xf5, 0x30, 0xfc, 0xa4, 0x07, 0x52, 0xe9, + 0x24, 0x72, 0xe2, 0x9e, 0x3c, 0xc3, 0xa7, 0x7b, 0xf2, 0x3c, 0x10, 0x03, 0xc1, 0x92, 0x4a, 0x41, + 0x10, 0xbd, 0x4e, 0x9e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, + 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x9f, + 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0x33, 0x59, 0x37, 0x27, 0x31, + 0xa9, 0x18, 0xce, 0xd3, 0xaf, 0x80, 0xfa, 0xb9, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0xec, + 0x61, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa6, 0x70, 0x7d, 0x2a, 0x7d, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) 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 *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Pools) > 0 { + for iNdEx := len(m.Pools) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Pools[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if m.NextPoolID != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.NextPoolID)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.NextPoolID != 0 { + n += 1 + sovGenesis(uint64(m.NextPoolID)) + } + if len(m.Pools) > 0 { + for _, e := range m.Pools { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) 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 ErrIntOverflowGenesis + } + 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: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NextPoolID", wireType) + } + m.NextPoolID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NextPoolID |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pools", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Pools = append(m.Pools, Pool{}) + if err := m.Pools[len(m.Pools)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(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, ErrIntOverflowGenesis + } + 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, ErrIntOverflowGenesis + } + 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, ErrIntOverflowGenesis + } + 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, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/pools/types/genesis_test.go b/x/pools/types/genesis_test.go new file mode 100644 index 000000000..6ba029c19 --- /dev/null +++ b/x/pools/types/genesis_test.go @@ -0,0 +1,60 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/milkyway-labs/milkyway/x/pools/types" +) + +func TestGenesis_Validate(t *testing.T) { + testCases := []struct { + name string + genesis *types.GenesisState + shouldErr bool + }{ + { + name: "invalid next pool id returns error", + genesis: types.NewGenesis(0, nil), + shouldErr: true, + }, + { + name: "invalid pool returns error", + genesis: types.NewGenesis( + 1, + []types.Pool{ + types.NewPool(0, "uatom"), + }, + ), + shouldErr: true, + }, + { + name: "default genesis does not return errors", + genesis: types.DefaultGenesis(), + shouldErr: false, + }, + { + name: "valid genesis does not return errors", + genesis: types.NewGenesis( + 1, + []types.Pool{ + types.NewPool(1, "uatom"), + }, + ), + shouldErr: false, + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + err := tc.genesis.Validate() + if tc.shouldErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/x/pools/types/keys.go b/x/pools/types/keys.go new file mode 100644 index 000000000..111570c6b --- /dev/null +++ b/x/pools/types/keys.go @@ -0,0 +1,33 @@ +package types + +import ( + "encoding/binary" +) + +const ( + ModuleName = "pools" + StoreKey = ModuleName +) + +var ( + NextPoolIDKey = []byte{0x01} + + PoolPrefix = []byte{0xa1} +) + +// GetPoolIDBytes returns the byte representation of the pool ID +func GetPoolIDBytes(poolID uint32) (poolIDBz []byte) { + poolIDBz = make([]byte, 4) + binary.BigEndian.PutUint32(poolIDBz, poolID) + return poolIDBz +} + +// GetPoolIDFromBytes returns the pool ID from a byte array +func GetPoolIDFromBytes(bz []byte) (poolID uint32) { + return binary.BigEndian.Uint32(bz) +} + +// GetPoolStoreKey turns a pool ID into a key used to store a pool in the KVStore +func GetPoolStoreKey(poolID uint32) []byte { + return append(PoolPrefix, GetPoolIDBytes(poolID)...) +} diff --git a/x/pools/types/models.go b/x/pools/types/models.go new file mode 100644 index 000000000..f2f98181a --- /dev/null +++ b/x/pools/types/models.go @@ -0,0 +1,52 @@ +package types + +import ( + "fmt" + "strconv" + + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +// GetPoolAddress generates a pool address from its id +func GetPoolAddress(poolID uint32) sdk.AccAddress { + return authtypes.NewModuleAddress(fmt.Sprintf("pool-%d", poolID)) +} + +// ParsePoolID parses a pool id from a string +func ParsePoolID(value string) (uint32, error) { + parsed, err := strconv.ParseUint(value, 10, 32) + if err != nil { + return 0, fmt.Errorf("invalid pool id: %s", value) + } + return uint32(parsed), nil +} + +// -------------------------------------------------------------------------------------------------------------------- + +// NewPool creates a new Pool instance +func NewPool(id uint32, denom string) Pool { + return Pool{ + ID: id, + Denom: denom, + Address: GetPoolAddress(id).String(), + } +} + +// Validate checks if the pool is valid +func (p *Pool) Validate() error { + if p.ID == 0 { + return fmt.Errorf("invalid pool id") + } + + if sdk.ValidateDenom(p.Denom) != nil { + return fmt.Errorf("invalid pool denom") + } + + _, err := sdk.AccAddressFromBech32(p.Address) + if err != nil { + return fmt.Errorf("invalid pool address") + } + + return nil +} diff --git a/x/pools/types/models.pb.go b/x/pools/types/models.pb.go new file mode 100644 index 000000000..cb329e852 --- /dev/null +++ b/x/pools/types/models.pb.go @@ -0,0 +1,413 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: milkyway/pools/v1/models.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + 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 + +// Pool defines the structure of a restaking pool +type Pool struct { + // ID is the auto-generated unique identifier for the pool + ID uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + // Denom represents the denomination of the tokens that are staked in the pool + Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty"` + // Address represents the address of the account that is associated with this + // pool. This will be used to store tokens that users delegate to this pool. + Address string `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"` +} + +func (m *Pool) Reset() { *m = Pool{} } +func (m *Pool) String() string { return proto.CompactTextString(m) } +func (*Pool) ProtoMessage() {} +func (*Pool) Descriptor() ([]byte, []int) { + return fileDescriptor_b29c6df2abe9a338, []int{0} +} +func (m *Pool) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Pool) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Pool.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 *Pool) XXX_Merge(src proto.Message) { + xxx_messageInfo_Pool.Merge(m, src) +} +func (m *Pool) XXX_Size() int { + return m.Size() +} +func (m *Pool) XXX_DiscardUnknown() { + xxx_messageInfo_Pool.DiscardUnknown(m) +} + +var xxx_messageInfo_Pool proto.InternalMessageInfo + +func (m *Pool) GetID() uint32 { + if m != nil { + return m.ID + } + return 0 +} + +func (m *Pool) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +func (m *Pool) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func init() { + proto.RegisterType((*Pool)(nil), "milkyway.pools.v1.Pool") +} + +func init() { proto.RegisterFile("milkyway/pools/v1/models.proto", fileDescriptor_b29c6df2abe9a338) } + +var fileDescriptor_b29c6df2abe9a338 = []byte{ + // 242 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcb, 0xcd, 0xcc, 0xc9, + 0xae, 0x2c, 0x4f, 0xac, 0xd4, 0x2f, 0xc8, 0xcf, 0xcf, 0x29, 0xd6, 0x2f, 0x33, 0xd4, 0xcf, 0xcd, + 0x4f, 0x49, 0xcd, 0x29, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x84, 0xc9, 0xeb, 0x81, + 0xe5, 0xf5, 0xca, 0x0c, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0xb2, 0xfa, 0x20, 0x16, 0x44, + 0xa1, 0x94, 0x64, 0x72, 0x7e, 0x71, 0x6e, 0x7e, 0x71, 0x3c, 0x44, 0x02, 0xc2, 0x81, 0x48, 0x29, + 0x65, 0x70, 0xb1, 0x04, 0xe4, 0xe7, 0xe7, 0x08, 0x89, 0x71, 0x31, 0x65, 0xa6, 0x48, 0x30, 0x2a, + 0x30, 0x6a, 0xf0, 0x3a, 0xb1, 0x3d, 0xba, 0x27, 0xcf, 0xe4, 0xe9, 0x12, 0xc4, 0x94, 0x99, 0x22, + 0x24, 0xc2, 0xc5, 0x9a, 0x92, 0x9a, 0x97, 0x9f, 0x2b, 0xc1, 0xa4, 0xc0, 0xa8, 0xc1, 0x19, 0x04, + 0xe1, 0x08, 0x19, 0x71, 0xb1, 0x27, 0xa6, 0xa4, 0x14, 0xa5, 0x16, 0x17, 0x4b, 0x30, 0x83, 0xc4, + 0x9d, 0x24, 0x2e, 0x6d, 0xd1, 0x15, 0x81, 0x1a, 0xec, 0x08, 0x91, 0x09, 0x2e, 0x29, 0xca, 0xcc, + 0x4b, 0x0f, 0x82, 0x29, 0x74, 0xf2, 0x3c, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, + 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, + 0x28, 0xfd, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0x98, 0x97, 0x74, + 0x73, 0x12, 0x93, 0x8a, 0xe1, 0x3c, 0xfd, 0x0a, 0x68, 0x10, 0x94, 0x54, 0x16, 0xa4, 0x16, 0x27, + 0xb1, 0x81, 0xdd, 0x6e, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xee, 0x3f, 0xe7, 0x79, 0x21, 0x01, + 0x00, 0x00, +} + +func (m *Pool) 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 *Pool) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Pool) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintModels(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0x1a + } + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintModels(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0x12 + } + if m.ID != 0 { + i = encodeVarintModels(dAtA, i, uint64(m.ID)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintModels(dAtA []byte, offset int, v uint64) int { + offset -= sovModels(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Pool) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ID != 0 { + n += 1 + sovModels(uint64(m.ID)) + } + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovModels(uint64(l)) + } + l = len(m.Address) + if l > 0 { + n += 1 + l + sovModels(uint64(l)) + } + return n +} + +func sovModels(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozModels(x uint64) (n int) { + return sovModels(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Pool) 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 ErrIntOverflowModels + } + 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: Pool: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Pool: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) + } + m.ID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModels + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ID |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModels + } + 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 ErrInvalidLengthModels + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthModels + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModels + } + 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 ErrInvalidLengthModels + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthModels + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipModels(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthModels + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipModels(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, ErrIntOverflowModels + } + 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, ErrIntOverflowModels + } + 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, ErrIntOverflowModels + } + 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, ErrInvalidLengthModels + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupModels + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthModels + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthModels = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowModels = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupModels = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/pools/types/models_test.go b/x/pools/types/models_test.go new file mode 100644 index 000000000..cd7afff15 --- /dev/null +++ b/x/pools/types/models_test.go @@ -0,0 +1,44 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/milkyway-labs/milkyway/x/pools/types" +) + +func TestPool_Validate(t *testing.T) { + testCases := []struct { + name string + pool types.Pool + shouldErr bool + }{ + { + name: "invalid pool id returns error", + pool: types.NewPool(0, "uatom"), + shouldErr: true, + }, + { + name: "invalid pool denom returns error", + pool: types.NewPool(1, "uatom!"), + shouldErr: true, + }, + { + name: "valid pool does not return errors", + pool: types.NewPool(1, "uatom"), + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + err := tc.pool.Validate() + if tc.shouldErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/x/pools/types/query.go b/x/pools/types/query.go new file mode 100644 index 000000000..72afaace6 --- /dev/null +++ b/x/pools/types/query.go @@ -0,0 +1,26 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/types/query" +) + +// NewQueryPoolByIdRequest creates a new instance of QueryPoolByIdRequest +func NewQueryPoolByIdRequest(poolId uint32) *QueryPoolByIdRequest { + return &QueryPoolByIdRequest{ + PoolId: poolId, + } +} + +// NewQueryPoolByDenomRequest creates a new instance of QueryPoolByDenomRequest +func NewQueryPoolByDenomRequest(denom string) *QueryPoolByDenomRequest { + return &QueryPoolByDenomRequest{ + Denom: denom, + } +} + +// NewQueryPoolsRequest creates a new instance of QueryPoolsRequest +func NewQueryPoolsRequest(pagination *query.PageRequest) *QueryPoolsRequest { + return &QueryPoolsRequest{ + Pagination: pagination, + } +} diff --git a/x/pools/types/query.pb.go b/x/pools/types/query.pb.go new file mode 100644 index 000000000..a32595dc5 --- /dev/null +++ b/x/pools/types/query.pb.go @@ -0,0 +1,1261 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: milkyway/pools/v1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + query "github.com/cosmos/cosmos-sdk/types/query" + _ "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 + +// QueryPoolByIdRequest is the request type for the Query/PoolById RPC method. +type QueryPoolByIdRequest struct { + // PoolID is the ID of the pool to query + PoolId uint32 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` +} + +func (m *QueryPoolByIdRequest) Reset() { *m = QueryPoolByIdRequest{} } +func (m *QueryPoolByIdRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPoolByIdRequest) ProtoMessage() {} +func (*QueryPoolByIdRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_bb7667236b657a7d, []int{0} +} +func (m *QueryPoolByIdRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolByIdRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolByIdRequest.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 *QueryPoolByIdRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolByIdRequest.Merge(m, src) +} +func (m *QueryPoolByIdRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolByIdRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolByIdRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolByIdRequest proto.InternalMessageInfo + +func (m *QueryPoolByIdRequest) GetPoolId() uint32 { + if m != nil { + return m.PoolId + } + return 0 +} + +// QueryPoolByDenomRequest is the request type for the Query/PollByDenom RPC +// method. +type QueryPoolByDenomRequest struct { + // Denom is the denom for which the pool is to be queried + Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` +} + +func (m *QueryPoolByDenomRequest) Reset() { *m = QueryPoolByDenomRequest{} } +func (m *QueryPoolByDenomRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPoolByDenomRequest) ProtoMessage() {} +func (*QueryPoolByDenomRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_bb7667236b657a7d, []int{1} +} +func (m *QueryPoolByDenomRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolByDenomRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolByDenomRequest.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 *QueryPoolByDenomRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolByDenomRequest.Merge(m, src) +} +func (m *QueryPoolByDenomRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolByDenomRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolByDenomRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolByDenomRequest proto.InternalMessageInfo + +func (m *QueryPoolByDenomRequest) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +// QueryOperatorRPoolsesponse is the response type for the Query/PoolById and +// Query/PoolByDenom RPC methods. +type QueryPoolResponse struct { + // Pool is the queried pool + Pool Pool `protobuf:"bytes,1,opt,name=pool,proto3" json:"pool"` +} + +func (m *QueryPoolResponse) Reset() { *m = QueryPoolResponse{} } +func (m *QueryPoolResponse) String() string { return proto.CompactTextString(m) } +func (*QueryPoolResponse) ProtoMessage() {} +func (*QueryPoolResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_bb7667236b657a7d, []int{2} +} +func (m *QueryPoolResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolResponse.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 *QueryPoolResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolResponse.Merge(m, src) +} +func (m *QueryPoolResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolResponse proto.InternalMessageInfo + +func (m *QueryPoolResponse) GetPool() Pool { + if m != nil { + return m.Pool + } + return Pool{} +} + +// QueryPoolsRequest is the request type for the Query/Pools RPC method. +type QueryPoolsRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryPoolsRequest) Reset() { *m = QueryPoolsRequest{} } +func (m *QueryPoolsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPoolsRequest) ProtoMessage() {} +func (*QueryPoolsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_bb7667236b657a7d, []int{3} +} +func (m *QueryPoolsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolsRequest.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 *QueryPoolsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolsRequest.Merge(m, src) +} +func (m *QueryPoolsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolsRequest proto.InternalMessageInfo + +func (m *QueryPoolsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +// QueryPoolsResponse is the response type for the Query/Pools RPC method. +type QueryPoolsResponse struct { + // Pools is the list of pool + Pools []Pool `protobuf:"bytes,1,rep,name=pools,proto3" json:"pools"` + // Pagination defines the pagination response + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryPoolsResponse) Reset() { *m = QueryPoolsResponse{} } +func (m *QueryPoolsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryPoolsResponse) ProtoMessage() {} +func (*QueryPoolsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_bb7667236b657a7d, []int{4} +} +func (m *QueryPoolsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPoolsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPoolsResponse.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 *QueryPoolsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPoolsResponse.Merge(m, src) +} +func (m *QueryPoolsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryPoolsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPoolsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPoolsResponse proto.InternalMessageInfo + +func (m *QueryPoolsResponse) GetPools() []Pool { + if m != nil { + return m.Pools + } + return nil +} + +func (m *QueryPoolsResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +func init() { + proto.RegisterType((*QueryPoolByIdRequest)(nil), "milkyway.pools.v1.QueryPoolByIdRequest") + proto.RegisterType((*QueryPoolByDenomRequest)(nil), "milkyway.pools.v1.QueryPoolByDenomRequest") + proto.RegisterType((*QueryPoolResponse)(nil), "milkyway.pools.v1.QueryPoolResponse") + proto.RegisterType((*QueryPoolsRequest)(nil), "milkyway.pools.v1.QueryPoolsRequest") + proto.RegisterType((*QueryPoolsResponse)(nil), "milkyway.pools.v1.QueryPoolsResponse") +} + +func init() { proto.RegisterFile("milkyway/pools/v1/query.proto", fileDescriptor_bb7667236b657a7d) } + +var fileDescriptor_bb7667236b657a7d = []byte{ + // 487 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x41, 0x6f, 0xd3, 0x30, + 0x14, 0xc7, 0xeb, 0x6d, 0x1d, 0xe0, 0x89, 0xc3, 0xac, 0x4a, 0x1d, 0x15, 0x64, 0x55, 0x34, 0xb6, + 0x69, 0x02, 0x5b, 0xd9, 0xbe, 0xc1, 0x84, 0x86, 0x7a, 0x1b, 0x39, 0xc2, 0x01, 0x39, 0x8b, 0x15, + 0x22, 0x92, 0xbc, 0x6c, 0x4e, 0x0b, 0xd1, 0xb4, 0x0b, 0x9c, 0x91, 0x10, 0xf0, 0xa1, 0x76, 0x9c, + 0xc4, 0x85, 0x13, 0x42, 0x2d, 0x1f, 0x04, 0xf9, 0xc5, 0xd9, 0x32, 0xb5, 0xb4, 0x3b, 0xa5, 0xd6, + 0xfb, 0xff, 0xff, 0xfe, 0xf5, 0xbd, 0x67, 0xfa, 0x24, 0x8d, 0x93, 0xf7, 0xe5, 0x07, 0x59, 0x8a, + 0x1c, 0x20, 0xd1, 0x62, 0xe4, 0x89, 0xd3, 0xa1, 0x3a, 0x2b, 0x79, 0x7e, 0x06, 0x05, 0xb0, 0xf5, + 0xba, 0xcc, 0xb1, 0xcc, 0x47, 0x5e, 0xaf, 0x13, 0x41, 0x04, 0x58, 0x15, 0xe6, 0x57, 0x25, 0xec, + 0x3d, 0x8e, 0x00, 0xa2, 0x44, 0x09, 0x99, 0xc7, 0x42, 0x66, 0x19, 0x14, 0xb2, 0x88, 0x21, 0xd3, + 0xb6, 0xba, 0x77, 0x02, 0x3a, 0x05, 0x2d, 0x02, 0xa9, 0x55, 0x95, 0x2f, 0x46, 0x5e, 0xa0, 0x0a, + 0xe9, 0x89, 0x5c, 0x46, 0x71, 0x86, 0x62, 0xab, 0x75, 0xa6, 0x89, 0x52, 0x08, 0x55, 0x62, 0xb3, + 0x5c, 0x41, 0x3b, 0xaf, 0x4c, 0xc2, 0x31, 0x40, 0x72, 0x58, 0x0e, 0x42, 0x5f, 0x9d, 0x0e, 0x95, + 0x2e, 0x58, 0x97, 0xde, 0x33, 0x86, 0xb7, 0x71, 0xb8, 0x41, 0xfa, 0x64, 0xf7, 0xa1, 0xbf, 0x6a, + 0x8e, 0x83, 0xd0, 0x15, 0xb4, 0xdb, 0x30, 0xbc, 0x50, 0x19, 0xa4, 0xb5, 0xa7, 0x43, 0xdb, 0xa1, + 0x39, 0xa3, 0xe3, 0x81, 0x5f, 0x1d, 0xdc, 0x23, 0xba, 0x7e, 0x6d, 0xf0, 0x95, 0xce, 0x21, 0xd3, + 0x8a, 0x79, 0x74, 0xc5, 0xe4, 0xa1, 0x72, 0x6d, 0xbf, 0xcb, 0xa7, 0x1a, 0xc3, 0x31, 0x7f, 0xe5, + 0xf2, 0xf7, 0x66, 0xcb, 0x47, 0xa9, 0xfb, 0xa6, 0x91, 0xa3, 0xeb, 0x2b, 0x8f, 0x28, 0xbd, 0xf9, + 0xcb, 0x36, 0x6d, 0x9b, 0x57, 0xfd, 0xe1, 0xa6, 0x3f, 0xbc, 0xea, 0xbf, 0xed, 0x0f, 0x3f, 0x96, + 0x91, 0xb2, 0x5e, 0xbf, 0xe1, 0x74, 0xbf, 0x11, 0xca, 0x9a, 0xe9, 0x16, 0xf3, 0x80, 0xb6, 0x11, + 0x68, 0x83, 0xf4, 0x97, 0x17, 0x73, 0x56, 0x5a, 0xf6, 0xf2, 0x16, 0xd3, 0x12, 0x32, 0xed, 0x2c, + 0x64, 0xaa, 0x6e, 0x6c, 0x42, 0xed, 0xff, 0x58, 0xa6, 0x6d, 0x84, 0x62, 0x9f, 0x09, 0xbd, 0x5f, + 0x4f, 0x88, 0xed, 0xcc, 0xa0, 0x98, 0x35, 0xc3, 0xde, 0xd6, 0x3c, 0x61, 0x7d, 0xa3, 0xbb, 0xfb, + 0xe9, 0xe7, 0xdf, 0xef, 0x4b, 0x2e, 0xeb, 0x8b, 0x5b, 0xab, 0x62, 0x36, 0x05, 0xbf, 0xe7, 0x76, + 0x0f, 0x2e, 0xd8, 0x17, 0x42, 0xd7, 0x1a, 0x63, 0x67, 0x7b, 0xf3, 0x41, 0x9a, 0xbb, 0x71, 0x47, + 0x96, 0x67, 0xc8, 0xb2, 0xcd, 0xb6, 0xfe, 0xc3, 0x82, 0x1b, 0x25, 0xce, 0xf1, 0x73, 0xc1, 0x86, + 0xb4, 0x8d, 0xe3, 0x62, 0x73, 0xc3, 0xeb, 0x5d, 0xe9, 0x3d, 0x5d, 0xa0, 0xb2, 0x0c, 0x9b, 0xc8, + 0xf0, 0x88, 0x75, 0x67, 0x33, 0xe8, 0xc3, 0xc1, 0xe5, 0xd8, 0x21, 0x57, 0x63, 0x87, 0xfc, 0x19, + 0x3b, 0xe4, 0xeb, 0xc4, 0x69, 0x5d, 0x4d, 0x9c, 0xd6, 0xaf, 0x89, 0xd3, 0x7a, 0x2d, 0xa2, 0xb8, + 0x78, 0x37, 0x0c, 0xf8, 0x09, 0xa4, 0xd7, 0xe6, 0xe7, 0x89, 0x0c, 0xf4, 0x4d, 0xd4, 0x47, 0xfb, + 0x0e, 0x8b, 0x32, 0x57, 0x3a, 0x58, 0xc5, 0x47, 0x78, 0xf0, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x0b, + 0x98, 0x79, 0xe5, 0x38, 0x04, 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 { + // PoolById defines a gRPC query method that returns the pool by the given ID. + PoolById(ctx context.Context, in *QueryPoolByIdRequest, opts ...grpc.CallOption) (*QueryPoolResponse, error) + // PoolByDenom defines a gRPC query method that returns the pool by the given + // denom. + PoolByDenom(ctx context.Context, in *QueryPoolByDenomRequest, opts ...grpc.CallOption) (*QueryPoolResponse, error) + // Pools defines a gRPC query method that returns all pools. + Pools(ctx context.Context, in *QueryPoolsRequest, opts ...grpc.CallOption) (*QueryPoolsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) PoolById(ctx context.Context, in *QueryPoolByIdRequest, opts ...grpc.CallOption) (*QueryPoolResponse, error) { + out := new(QueryPoolResponse) + err := c.cc.Invoke(ctx, "/milkyway.pools.v1.Query/PoolById", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) PoolByDenom(ctx context.Context, in *QueryPoolByDenomRequest, opts ...grpc.CallOption) (*QueryPoolResponse, error) { + out := new(QueryPoolResponse) + err := c.cc.Invoke(ctx, "/milkyway.pools.v1.Query/PoolByDenom", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Pools(ctx context.Context, in *QueryPoolsRequest, opts ...grpc.CallOption) (*QueryPoolsResponse, error) { + out := new(QueryPoolsResponse) + err := c.cc.Invoke(ctx, "/milkyway.pools.v1.Query/Pools", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // PoolById defines a gRPC query method that returns the pool by the given ID. + PoolById(context.Context, *QueryPoolByIdRequest) (*QueryPoolResponse, error) + // PoolByDenom defines a gRPC query method that returns the pool by the given + // denom. + PoolByDenom(context.Context, *QueryPoolByDenomRequest) (*QueryPoolResponse, error) + // Pools defines a gRPC query method that returns all pools. + Pools(context.Context, *QueryPoolsRequest) (*QueryPoolsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) PoolById(ctx context.Context, req *QueryPoolByIdRequest) (*QueryPoolResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PoolById not implemented") +} +func (*UnimplementedQueryServer) PoolByDenom(ctx context.Context, req *QueryPoolByDenomRequest) (*QueryPoolResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PoolByDenom not implemented") +} +func (*UnimplementedQueryServer) Pools(ctx context.Context, req *QueryPoolsRequest) (*QueryPoolsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Pools not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_PoolById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPoolByIdRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PoolById(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/milkyway.pools.v1.Query/PoolById", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PoolById(ctx, req.(*QueryPoolByIdRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_PoolByDenom_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPoolByDenomRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PoolByDenom(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/milkyway.pools.v1.Query/PoolByDenom", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PoolByDenom(ctx, req.(*QueryPoolByDenomRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Pools_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPoolsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Pools(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/milkyway.pools.v1.Query/Pools", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Pools(ctx, req.(*QueryPoolsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "milkyway.pools.v1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "PoolById", + Handler: _Query_PoolById_Handler, + }, + { + MethodName: "PoolByDenom", + Handler: _Query_PoolByDenom_Handler, + }, + { + MethodName: "Pools", + Handler: _Query_Pools_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "milkyway/pools/v1/query.proto", +} + +func (m *QueryPoolByIdRequest) 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 *QueryPoolByIdRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolByIdRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryPoolByDenomRequest) 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 *QueryPoolByDenomRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolByDenomRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryPoolResponse) 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 *QueryPoolResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Pool.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 (m *QueryPoolsRequest) 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 *QueryPoolsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.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 (m *QueryPoolsResponse) 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 *QueryPoolsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPoolsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Pools) > 0 { + for iNdEx := len(m.Pools) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Pools[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 *QueryPoolByIdRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + return n +} + +func (m *QueryPoolByDenomRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryPoolResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Pool.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryPoolsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryPoolsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Pools) > 0 { + for _, e := range m.Pools { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.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 *QueryPoolByIdRequest) 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: QueryPoolByIdRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolByIdRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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 *QueryPoolByDenomRequest) 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: QueryPoolByDenomRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolByDenomRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", 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.Denom = 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 *QueryPoolResponse) 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: QueryPoolResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolResponse: 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 + } + if err := m.Pool.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 (m *QueryPoolsRequest) 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: QueryPoolsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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 m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.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 (m *QueryPoolsResponse) 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: QueryPoolsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPoolsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pools", 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.Pools = append(m.Pools, Pool{}) + if err := m.Pools[len(m.Pools)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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 m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.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") +) diff --git a/x/pools/types/query.pb.gw.go b/x/pools/types/query.pb.gw.go new file mode 100644 index 000000000..b9116fd2b --- /dev/null +++ b/x/pools/types/query.pb.gw.go @@ -0,0 +1,373 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: milkyway/pools/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_PoolById_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolByIdRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint32(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + msg, err := client.PoolById(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PoolById_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolByIdRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint32(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + msg, err := server.PoolById(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_PoolByDenom_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolByDenomRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["denom"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "denom") + } + + protoReq.Denom, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "denom", err) + } + + msg, err := client.PoolByDenom(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PoolByDenom_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolByDenomRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["denom"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "denom") + } + + protoReq.Denom, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "denom", err) + } + + msg, err := server.PoolByDenom(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_Pools_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Pools_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Pools_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Pools(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Pools_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPoolsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Pools_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Pools(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_PoolById_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_PoolById_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_PoolById_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolByDenom_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_PoolByDenom_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_PoolByDenom_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Pools_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_Pools_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_Pools_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_PoolById_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_PoolById_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_PoolById_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PoolByDenom_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_PoolByDenom_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_PoolByDenom_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Pools_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_Pools_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_Pools_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_PoolById_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 1, 1, 0, 4, 1, 5, 3}, []string{"milkyway", "pool", "v1", "pool_id"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_PoolByDenom_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 1, 2, 3, 1, 0, 4, 1, 5, 3}, []string{"milkyway", "pool", "v1", "denom"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Pools_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"milkyway", "pool", "v1", "pools"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_PoolById_0 = runtime.ForwardResponseMessage + + forward_Query_PoolByDenom_0 = runtime.ForwardResponseMessage + + forward_Query_Pools_0 = runtime.ForwardResponseMessage +)