diff --git a/app/app.go b/app/app.go index 36eec513..f8351deb 100644 --- a/app/app.go +++ b/app/app.go @@ -126,6 +126,9 @@ import ( epochsmodulekeeper "github.com/mycel-domain/mycel/x/epochs/keeper" epochsmoduletypes "github.com/mycel-domain/mycel/x/epochs/types" + furnacemodule "github.com/mycel-domain/mycel/x/furnace" + furnacemodulekeeper "github.com/mycel-domain/mycel/x/furnace/keeper" + furnacemoduletypes "github.com/mycel-domain/mycel/x/furnace/types" resolvermodule "github.com/mycel-domain/mycel/x/resolver" resolvermodulekeeper "github.com/mycel-domain/mycel/x/resolver/keeper" resolvermoduletypes "github.com/mycel-domain/mycel/x/resolver/types" @@ -236,6 +239,7 @@ var ( registrymodule.AppModuleBasic{}, epochsmodule.AppModuleBasic{}, resolvermodule.AppModuleBasic{}, + furnacemodule.AppModuleBasic{}, // this line is used by starport scaffolding # stargate/app/moduleBasic ) @@ -253,6 +257,7 @@ var ( wasmtypes.ModuleName: {authtypes.Burner}, // my modules registrymoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking}, + furnacemoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking}, // this line is used by starport scaffolding # stargate/app/maccPerms } ) @@ -323,6 +328,8 @@ type App struct { EpochsKeeper epochsmodulekeeper.Keeper ResolverKeeper resolvermodulekeeper.Keeper + + FurnaceKeeper furnacemodulekeeper.Keeper // this line is used by starport scaffolding # stargate/app/keeperDeclaration // mm is the module manager @@ -410,6 +417,7 @@ func NewApp( registrymoduletypes.StoreKey, epochsmoduletypes.StoreKey, resolvermoduletypes.StoreKey, + furnacemoduletypes.StoreKey, // this line is used by starport scaffolding # stargate/app/storeKey ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) @@ -671,14 +679,22 @@ func NewApp( ), ) - // my modules + // My module's keepers app.EpochsKeeper = *epochsmodulekeeper.NewKeeper( appCodec, keys[epochsmoduletypes.StoreKey], keys[epochsmoduletypes.MemStoreKey], app.GetSubspace(epochsmoduletypes.ModuleName), ) - epochsModule := epochsmodule.NewAppModule(appCodec, app.EpochsKeeper, app.AccountKeeper, app.BankKeeper) + + app.ResolverKeeper = *resolvermodulekeeper.NewKeeper( + appCodec, + keys[resolvermoduletypes.StoreKey], + keys[resolvermoduletypes.MemStoreKey], + app.GetSubspace(resolvermoduletypes.ModuleName), + + app.RegistryKeeper, + ) app.RegistryKeeper = *registrymodulekeeper.NewKeeper( appCodec, @@ -688,7 +704,6 @@ func NewApp( app.BankKeeper, ) - registryModule := registrymodule.NewAppModule(appCodec, app.RegistryKeeper, app.AccountKeeper, app.BankKeeper) app.ResolverKeeper = *resolvermodulekeeper.NewKeeper( appCodec, @@ -698,7 +713,27 @@ func NewApp( app.RegistryKeeper, ) + + app.FurnaceKeeper = *furnacemodulekeeper.NewKeeper( + appCodec, + keys[furnacemoduletypes.StoreKey], + keys[furnacemoduletypes.MemStoreKey], + app.GetSubspace(furnacemoduletypes.ModuleName), + + app.BankKeeper, + app.EpochsKeeper, + ) + + app.EpochsKeeper.SetHooks( + epochsmoduletypes.NewMultiEpochHooks( + // insert hooks here + app.FurnaceKeeper.Hooks(), + )) + + epochsModule := epochsmodule.NewAppModule(appCodec, app.EpochsKeeper, app.AccountKeeper, app.BankKeeper) + registryModule := registrymodule.NewAppModule(appCodec, app.RegistryKeeper, app.AccountKeeper, app.BankKeeper) resolverModule := resolvermodule.NewAppModule(appCodec, app.ResolverKeeper, app.AccountKeeper, app.BankKeeper) + furnaceModule := furnacemodule.NewAppModule(appCodec, app.FurnaceKeeper, app.AccountKeeper, app.BankKeeper) // this line is used by starport scaffolding # stargate/app/keeperDefinition @@ -726,11 +761,6 @@ func NewApp( ), ) - app.EpochsKeeper.SetHooks( - epochsmodulekeeper.NewMultiEpochHooks( - // insert hooks here - )) - /**** Module Options ****/ // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment @@ -772,6 +802,7 @@ func NewApp( registryModule, epochsModule, resolverModule, + furnaceModule, // this line is used by starport scaffolding # stargate/app/appModule crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them @@ -810,6 +841,7 @@ func NewApp( registrymoduletypes.ModuleName, epochsmoduletypes.ModuleName, resolvermoduletypes.ModuleName, + furnacemoduletypes.ModuleName, // this line is used by starport scaffolding # stargate/app/beginBlockers ) @@ -841,6 +873,7 @@ func NewApp( registrymoduletypes.ModuleName, epochsmoduletypes.ModuleName, resolvermoduletypes.ModuleName, + furnacemoduletypes.ModuleName, // this line is used by starport scaffolding # stargate/app/endBlockers ) @@ -878,6 +911,7 @@ func NewApp( registrymoduletypes.ModuleName, epochsmoduletypes.ModuleName, resolvermoduletypes.ModuleName, + furnacemoduletypes.ModuleName, // this line is used by starport scaffolding # stargate/app/initGenesis } app.mm.SetOrderInitGenesis(genesisModuleOrder...) @@ -1141,6 +1175,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(registrymoduletypes.ModuleName) paramsKeeper.Subspace(epochsmoduletypes.ModuleName) paramsKeeper.Subspace(resolvermoduletypes.ModuleName) + paramsKeeper.Subspace(furnacemoduletypes.ModuleName) // this line is used by starport scaffolding # stargate/app/paramSubspace return paramsKeeper diff --git a/cmd/myceld/cmd/root.go b/cmd/myceld/cmd/root.go index 83109891..eabb16b0 100644 --- a/cmd/myceld/cmd/root.go +++ b/cmd/myceld/cmd/root.go @@ -215,7 +215,6 @@ func txCommand() *cobra.Command { return cmd } - func addModuleInitFlags(startCmd *cobra.Command) { crisis.AddModuleInitFlags(startCmd) // this line is used by starport scaffolding # root/arguments diff --git a/cmd/myceld/main.go b/cmd/myceld/main.go index 9fcae419..862867f8 100644 --- a/cmd/myceld/main.go +++ b/cmd/myceld/main.go @@ -12,7 +12,7 @@ import ( func main() { rootCmd, _ := cmd.NewRootCmd() - + if err := svrcmd.Execute(rootCmd, "", app.DefaultNodeHome); err != nil { switch e := err.(type) { case server.ErrorCode: diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index afda1489..51ffa319 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -49691,6 +49691,326 @@ paths: additionalProperties: {} tags: - Query + /mycel-domain/mycel/furnace/burn_amount: + get: + operationId: MycelFurnaceBurnAmountAll + responses: + '200': + description: A successful response. + schema: + type: object + properties: + burnAmount: + type: array + items: + type: object + properties: + index: + type: string + format: uint64 + burnStarted: + type: boolean + totalEpochs: + type: string + format: uint64 + currentEpoch: + type: string + format: uint64 + totalBurnAmount: + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the + custom method + + signatures required by gogoproto. + cumulativeBurntAmount: + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the + custom method + + signatures required by gogoproto. + pagination: + type: object + properties: + next_key: + type: string + format: byte + description: |- + next_key is the key to be passed to PageRequest.key to + query the next page most efficiently. It will be empty if + there are no more results. + total: + type: string + format: uint64 + title: >- + total is total number of results available if + PageRequest.count_total + + was set, its value is undefined otherwise + description: >- + PageResponse is to be embedded in gRPC response messages where + the + + corresponding request message has used PageRequest. + + message SomeResponse { + repeated Bar results = 1; + PageResponse page = 2; + } + default: + description: An unexpected error response. + schema: + type: object + properties: + code: + type: integer + format: int32 + message: + type: string + details: + type: array + items: + type: object + properties: + '@type': + type: string + additionalProperties: {} + parameters: + - name: pagination.key + description: |- + key is a value returned in PageResponse.next_key to begin + querying the next page most efficiently. Only one of offset or key + should be set. + in: query + required: false + type: string + format: byte + - name: pagination.offset + description: >- + offset is a numeric offset that can be used when key is unavailable. + + It is less efficient than using key. Only one of offset or key + should + + be set. + in: query + required: false + type: string + format: uint64 + - name: pagination.limit + description: >- + limit is the total number of results to be returned in the result + page. + + If left empty it will default to a value to be set by each app. + in: query + required: false + type: string + format: uint64 + - name: pagination.count_total + description: >- + count_total is set to true to indicate that the result set should + include + + a count of the total number of items available for pagination in + UIs. + + count_total is only respected when offset is used. It is ignored + when key + + is set. + in: query + required: false + type: boolean + - name: pagination.reverse + description: >- + reverse is set to true if results are to be returned in the + descending order. + + + Since: cosmos-sdk 0.43 + in: query + required: false + type: boolean + tags: + - Query + /mycel-domain/mycel/furnace/burn_amount/{index}: + get: + summary: Queries a list of BurnAmount items. + operationId: MycelFurnaceBurnAmount + responses: + '200': + description: A successful response. + schema: + type: object + properties: + burnAmount: + type: object + properties: + index: + type: string + format: uint64 + burnStarted: + type: boolean + totalEpochs: + type: string + format: uint64 + currentEpoch: + type: string + format: uint64 + totalBurnAmount: + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the + custom method + + signatures required by gogoproto. + cumulativeBurntAmount: + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the + custom method + + signatures required by gogoproto. + default: + description: An unexpected error response. + schema: + type: object + properties: + code: + type: integer + format: int32 + message: + type: string + details: + type: array + items: + type: object + properties: + '@type': + type: string + additionalProperties: {} + parameters: + - name: index + in: path + required: true + type: string + format: uint64 + tags: + - Query + /mycel-domain/mycel/furnace/epoch_burn_config: + get: + summary: Queries a EpochBurnConfig by index. + operationId: MycelFurnaceEpochBurnConfig + responses: + '200': + description: A successful response. + schema: + type: object + properties: + EpochBurnConfig: + type: object + properties: + epochIdentifier: + type: string + currentBurnAmountIndex: + type: string + format: uint64 + defaultTotalEpochs: + type: string + format: uint64 + startTime: + type: string + format: date-time + default: + description: An unexpected error response. + schema: + type: object + properties: + code: + type: integer + format: int32 + message: + type: string + details: + type: array + items: + type: object + properties: + '@type': + type: string + additionalProperties: {} + tags: + - Query + /mycel-domain/mycel/furnace/params: + get: + summary: Parameters queries the parameters of the module. + operationId: MycelFurnaceParams + responses: + '200': + description: A successful response. + schema: + type: object + properties: + params: + description: params holds all the parameters of this module. + type: object + description: >- + QueryParamsResponse is response type for the Query/Params RPC + method. + default: + description: An unexpected error response. + schema: + type: object + properties: + code: + type: integer + format: int32 + message: + type: string + details: + type: array + items: + type: object + properties: + '@type': + type: string + additionalProperties: {} + tags: + - Query /mycel-domain/mycel/registry/domain_ownership: get: operationId: MycelRegistryDomainOwnershipAll @@ -80645,6 +80965,207 @@ definitions: description: params holds all the parameters of this module. type: object description: QueryParamsResponse is response type for the Query/Params RPC method. + mycel.furnace.BurnAmount: + type: object + properties: + index: + type: string + format: uint64 + burnStarted: + type: boolean + totalEpochs: + type: string + format: uint64 + currentEpoch: + type: string + format: uint64 + totalBurnAmount: + type: object + properties: + denom: + type: string + amount: + type: string + description: |- + Coin defines a token with a denomination and an amount. + + NOTE: The amount field is an Int which implements the custom method + signatures required by gogoproto. + cumulativeBurntAmount: + type: object + properties: + denom: + type: string + amount: + type: string + description: |- + Coin defines a token with a denomination and an amount. + + NOTE: The amount field is an Int which implements the custom method + signatures required by gogoproto. + mycel.furnace.EpochBurnConfig: + type: object + properties: + epochIdentifier: + type: string + currentBurnAmountIndex: + type: string + format: uint64 + defaultTotalEpochs: + type: string + format: uint64 + startTime: + type: string + format: date-time + mycel.furnace.Params: + type: object + description: Params defines the parameters for the module. + mycel.furnace.QueryAllBurnAmountResponse: + type: object + properties: + burnAmount: + type: array + items: + type: object + properties: + index: + type: string + format: uint64 + burnStarted: + type: boolean + totalEpochs: + type: string + format: uint64 + currentEpoch: + type: string + format: uint64 + totalBurnAmount: + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. + cumulativeBurntAmount: + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. + pagination: + type: object + properties: + next_key: + type: string + format: byte + description: |- + next_key is the key to be passed to PageRequest.key to + query the next page most efficiently. It will be empty if + there are no more results. + total: + type: string + format: uint64 + title: >- + total is total number of results available if + PageRequest.count_total + + was set, its value is undefined otherwise + description: |- + PageResponse is to be embedded in gRPC response messages where the + corresponding request message has used PageRequest. + + message SomeResponse { + repeated Bar results = 1; + PageResponse page = 2; + } + mycel.furnace.QueryGetBurnAmountResponse: + type: object + properties: + burnAmount: + type: object + properties: + index: + type: string + format: uint64 + burnStarted: + type: boolean + totalEpochs: + type: string + format: uint64 + currentEpoch: + type: string + format: uint64 + totalBurnAmount: + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. + cumulativeBurntAmount: + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. + mycel.furnace.QueryGetEpochBurnConfigResponse: + type: object + properties: + EpochBurnConfig: + type: object + properties: + epochIdentifier: + type: string + currentBurnAmountIndex: + type: string + format: uint64 + defaultTotalEpochs: + type: string + format: uint64 + startTime: + type: string + format: date-time + mycel.furnace.QueryParamsResponse: + type: object + properties: + params: + description: params holds all the parameters of this module. + type: object + description: QueryParamsResponse is response type for the Query/Params RPC method. mycel.registry.DnsRecord: type: object properties: diff --git a/proto/mycel/furnace/burn_amount.proto b/proto/mycel/furnace/burn_amount.proto new file mode 100644 index 00000000..67b14d55 --- /dev/null +++ b/proto/mycel/furnace/burn_amount.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; +package mycel.furnace; + +option go_package = "github.com/mycel-domain/mycel/x/furnace/types"; +import "gogoproto/gogo.proto"; +import "cosmos/base/v1beta1/coin.proto"; + +message BurnAmount { + uint64 index = 1; + bool burnStarted = 2; + uint64 totalEpochs = 3; + uint64 currentEpoch = 4; + cosmos.base.v1beta1.Coin totalBurnAmount = 5 [(gogoproto.nullable) = false]; + cosmos.base.v1beta1.Coin cumulativeBurntAmount = 6 [(gogoproto.nullable) = false]; +} + diff --git a/proto/mycel/furnace/epoch_burn_config.proto b/proto/mycel/furnace/epoch_burn_config.proto new file mode 100644 index 00000000..3bbcfb43 --- /dev/null +++ b/proto/mycel/furnace/epoch_burn_config.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; +package mycel.furnace; + + +import "gogoproto/gogo.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "github.com/mycel-domain/mycel/x/furnace/types"; + +message EpochBurnConfig { + string epochIdentifier = 1; + uint64 currentBurnAmountIndex = 2; + uint64 defaultTotalEpochs = 3; + google.protobuf.Timestamp startTime = 4 [ + (gogoproto.stdtime) = true, + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"start_time\"" + ]; +} diff --git a/proto/mycel/furnace/genesis.proto b/proto/mycel/furnace/genesis.proto new file mode 100644 index 00000000..3b247ec6 --- /dev/null +++ b/proto/mycel/furnace/genesis.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package mycel.furnace; + +import "gogoproto/gogo.proto"; +import "mycel/furnace/params.proto"; +import "mycel/furnace/epoch_burn_config.proto"; +import "mycel/furnace/burn_amount.proto"; + +option go_package = "github.com/mycel-domain/mycel/x/furnace/types"; + +// GenesisState defines the furnace module's genesis state. +message GenesisState { + Params params = 1 [(gogoproto.nullable) = false]; + EpochBurnConfig epochBurnConfig = 2 [(gogoproto.nullable) = false]; + repeated BurnAmount burnAmounts = 3 [(gogoproto.nullable) = false]; +} + diff --git a/proto/mycel/furnace/params.proto b/proto/mycel/furnace/params.proto new file mode 100644 index 00000000..5fbdc34f --- /dev/null +++ b/proto/mycel/furnace/params.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package mycel.furnace; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/mycel-domain/mycel/x/furnace/types"; + +// Params defines the parameters for the module. +message Params { + option (gogoproto.goproto_stringer) = false; + +} diff --git a/proto/mycel/furnace/query.proto b/proto/mycel/furnace/query.proto new file mode 100644 index 00000000..05f8fa3d --- /dev/null +++ b/proto/mycel/furnace/query.proto @@ -0,0 +1,72 @@ +syntax = "proto3"; + +package mycel.furnace; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; +import "mycel/furnace/params.proto"; +import "mycel/furnace/epoch_burn_config.proto"; +import "mycel/furnace/burn_amount.proto"; +import "cosmos/base/v1beta1/coin.proto"; + +option go_package = "github.com/mycel-domain/mycel/x/furnace/types"; + +// Query defines the gRPC querier service. +service Query { + + // Parameters queries the parameters of the module. + rpc Params (QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/mycel-domain/mycel/furnace/params"; + + } + + // Queries a EpochBurnConfig by index. + rpc EpochBurnConfig (QueryGetEpochBurnConfigRequest) returns (QueryGetEpochBurnConfigResponse) { + option (google.api.http).get = "/mycel-domain/mycel/furnace/epoch_burn_config"; + + } + + // Queries a list of BurnAmount items. + rpc BurnAmount (QueryGetBurnAmountRequest) returns (QueryGetBurnAmountResponse) { + option (google.api.http).get = "/mycel-domain/mycel/furnace/burn_amount/{index}"; + + } + rpc BurnAmountAll (QueryAllBurnAmountRequest) returns (QueryAllBurnAmountResponse) { + option (google.api.http).get = "/mycel-domain/mycel/furnace/burn_amount"; + + } +} +// QueryParamsRequest is request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is response type for the Query/Params RPC method. +message QueryParamsResponse { + + // params holds all the parameters of this module. + Params params = 1 [(gogoproto.nullable) = false]; +} + +message QueryGetEpochBurnConfigRequest {} + +message QueryGetEpochBurnConfigResponse { + EpochBurnConfig EpochBurnConfig = 1 [(gogoproto.nullable) = false]; +} + +message QueryGetBurnAmountRequest { + uint64 index = 1; +} + +message QueryGetBurnAmountResponse { + BurnAmount burnAmount = 1 [(gogoproto.nullable) = false]; +} + +message QueryAllBurnAmountRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +message QueryAllBurnAmountResponse { + repeated BurnAmount burnAmount = 1 [(gogoproto.nullable) = false]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + diff --git a/proto/mycel/furnace/tx.proto b/proto/mycel/furnace/tx.proto new file mode 100644 index 00000000..8f2c7dea --- /dev/null +++ b/proto/mycel/furnace/tx.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; +package mycel.furnace; + +option go_package = "github.com/mycel-domain/mycel/x/furnace/types"; + +// Msg defines the Msg service. +service Msg {} \ No newline at end of file diff --git a/testutil/events.go b/testutil/events.go new file mode 100644 index 00000000..01f70de2 --- /dev/null +++ b/testutil/events.go @@ -0,0 +1,31 @@ +package testutil + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func FindEventsByType(events []sdk.Event, eventType string) (foundEvents []sdk.Event, found bool) { + for _, event := range events { + if event.Type == eventType { + foundEvents = append(foundEvents, event) + } + } + found = len(foundEvents) > 0 + return foundEvents, found +} + +func EventHasAttributes(event sdk.Event, attributes map[string]string) bool { + for key, value := range attributes { + found := false + for _, attr := range event.Attributes { + if attr.Key == key && attr.Value == value { + found = true + break + } + } + if !found { + return false + } + } + return true +} diff --git a/testutil/keeper/furnace.go b/testutil/keeper/furnace.go new file mode 100644 index 00000000..219adffa --- /dev/null +++ b/testutil/keeper/furnace.go @@ -0,0 +1,54 @@ +package keeper + +import ( + "testing" + + tmdb "github.com/cometbft/cometbft-db" + "github.com/cometbft/cometbft/libs/log" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/store" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + typesparams "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/mycel-domain/mycel/x/furnace/keeper" + "github.com/mycel-domain/mycel/x/furnace/types" + "github.com/stretchr/testify/require" +) + +func FurnaceKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { + storeKey := sdk.NewKVStoreKey(types.StoreKey) + memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + + db := tmdb.NewMemDB() + stateStore := store.NewCommitMultiStore(db) + stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) + require.NoError(t, stateStore.LoadLatestVersion()) + + registry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(registry) + + paramsSubspace := typesparams.NewSubspace(cdc, + types.Amino, + storeKey, + memStoreKey, + "FurnaceParams", + ) + k := keeper.NewKeeper( + cdc, + storeKey, + memStoreKey, + paramsSubspace, + nil, + nil, + ) + + ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) + + // Initialize params + k.SetParams(ctx, types.DefaultParams()) + + return k, ctx +} diff --git a/x/README.md b/x/README.md index 603ebb68..91281db8 100644 --- a/x/README.md +++ b/x/README.md @@ -1,6 +1,6 @@ -# mycel Modules -mycel implements the following modules: +# Mycel Modules +Mycel implements the following modules: - `epochs`: Makes on-chain timers which other modules can execute code during. -- `incentives`: Controls distribution of rewards. - `registry`: Manages domain records and registrations. +- `resolver`: Resolves domain name diff --git a/x/epochs/README.md b/x/epochs/README.md index 41af4251..121c3498 100644 --- a/x/epochs/README.md +++ b/x/epochs/README.md @@ -1,7 +1,7 @@ # Epochs ## Abstract -Epochs module provides the following feature: +[Osmosis's](https://github.com/osmosis-labs/osmosis/tree/x/epochs/v0.0.2/x/epochs) Epochs module provides the following feature: - On-chain Timers that execute at fixed time intervals ## Stores @@ -69,16 +69,3 @@ func (k MyModuleKeeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, e } } ``` - -## Queries - -### list-epoch-info -List all epoch info -``` -myceld q epochs list-epoch-info -``` - -### show-epoch -``` -myceld q epochs show-epochs [identifier] -``` diff --git a/x/epochs/keeper/abci.go b/x/epochs/keeper/abci.go index 16a97dd6..1efc253f 100644 --- a/x/epochs/keeper/abci.go +++ b/x/epochs/keeper/abci.go @@ -1,62 +1,67 @@ package keeper import ( - "github.com/mycel-domain/mycel/x/epochs/types" - "strconv" + "fmt" "time" + "github.com/mycel-domain/mycel/x/epochs/types" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" ) +// BeginBlocker of epochs module. func (k Keeper) BeginBlocker(ctx sdk.Context) { defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + k.IterateEpochInfo(ctx, func(index int64, epochInfo types.EpochInfo) (stop bool) { + logger := k.Logger(ctx) - logger := k.Logger(ctx) - - k.IterateEpochInfo(ctx, func(_ int64, epochInfo types.EpochInfo) (stop bool) { - // Has it not started, and is the block time > initial epoch start time - shouldInitialEpochStart := !epochInfo.EpochCountingStarted && !epochInfo.StartTime.After(ctx.BlockTime()) + // If blocktime < initial epoch start time, return + if ctx.BlockTime().Before(epochInfo.StartTime) { + return + } + // if epoch counting hasn't started, signal we need to start. + shouldInitialEpochStart := !epochInfo.EpochCountingStarted epochEndTime := epochInfo.CurrentEpochStartTime.Add(epochInfo.Duration) - shouldEpochEnd := ctx.BlockTime().After(epochEndTime) && !shouldInitialEpochStart && !epochInfo.StartTime.After(ctx.BlockTime()) + shouldEpochStart := (ctx.BlockTime().After(epochEndTime)) || shouldInitialEpochStart + if !shouldEpochStart { + return false + } epochInfo.CurrentEpochStartHeight = ctx.BlockHeight() - switch { - case shouldInitialEpochStart: - epochInfo.StartInitialEpoch() - - logger.Info("starting epoch", "identifier", epochInfo.Identifier) - case shouldEpochEnd: - epochInfo.EndEpoch() - - logger.Info("ending epoch", "identifier", epochInfo.Identifier) - + if shouldInitialEpochStart { + epochInfo.EpochCountingStarted = true + epochInfo.CurrentEpoch = 1 + epochInfo.CurrentEpochStartTime = epochInfo.StartTime + logger.Info(fmt.Sprintf("Starting new epoch with identifier %s epoch number %d", epochInfo.Identifier, epochInfo.CurrentEpoch)) + } else { ctx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypeEpochEnd, - sdk.NewAttribute(types.AttributeEpochNumber, strconv.FormatInt(epochInfo.CurrentEpoch, 10)), + sdk.NewAttribute(types.AttributeEpochNumber, fmt.Sprintf("%d", epochInfo.CurrentEpoch)), ), ) k.AfterEpochEnd(ctx, epochInfo.Identifier, epochInfo.CurrentEpoch) - default: - // continue - return false + epochInfo.CurrentEpoch += 1 + epochInfo.CurrentEpochStartTime = epochInfo.CurrentEpochStartTime.Add(epochInfo.Duration) + logger.Info(fmt.Sprintf("Starting epoch with identifier %s epoch number %d", epochInfo.Identifier, epochInfo.CurrentEpoch)) } - k.SetEpochInfo(ctx, epochInfo) - + // emit new epoch start event, set epoch info, and run BeforeEpochStart hook ctx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypeEpochStart, - sdk.NewAttribute(types.AttributeEpochNumber, strconv.FormatInt(epochInfo.CurrentEpoch, 10)), - sdk.NewAttribute(types.AttributeEpochStartTime, strconv.FormatInt(epochInfo.CurrentEpochStartTime.Unix(), 10)), + sdk.NewAttribute(types.AttributeEpochNumber, fmt.Sprintf("%d", epochInfo.CurrentEpoch)), + sdk.NewAttribute(types.AttributeEpochStartTime, fmt.Sprintf("%d", epochInfo.CurrentEpochStartTime.Unix())), ), ) - + k.SetEpochInfo(ctx, epochInfo) k.BeforeEpochStart(ctx, epochInfo.Identifier, epochInfo.CurrentEpoch) return false }) } + +func (k Keeper) EndBlocker(ctx sdk.Context) {} diff --git a/x/epochs/keeper/hooks.go b/x/epochs/keeper/hooks.go index a7387f68..5200cbf6 100644 --- a/x/epochs/keeper/hooks.go +++ b/x/epochs/keeper/hooks.go @@ -1,42 +1,21 @@ package keeper import ( - "github.com/mycel-domain/mycel/x/epochs/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) -var _ types.EpochHooks = MultiEpochHooks{} - -// combine multiple epoch hooks, all hook functions are run in array sequence -type MultiEpochHooks []types.EpochHooks - -func NewMultiEpochHooks(hooks ...types.EpochHooks) MultiEpochHooks { - return hooks -} - -// AfterEpochEnd is called when epoch is going to be ended, epochNumber is the -// number of epoch that is ending -func (mh MultiEpochHooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) { - for i := range mh { - mh[i].AfterEpochEnd(ctx, epochIdentifier, epochNumber) - } -} - -// BeforeEpochStart is called when epoch is going to be started, epochNumber is -// the number of epoch that is starting -func (mh MultiEpochHooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) { - for i := range mh { - mh[i].BeforeEpochStart(ctx, epochIdentifier, epochNumber) - } -} - -// AfterEpochEnd executes the indicated hook after epochs ends +// AfterEpochEnd epoch hook func (k Keeper) AfterEpochEnd(ctx sdk.Context, identifier string, epochNumber int64) { + if k.hooks == nil { + panic("hooks not set in keeper") + } k.hooks.AfterEpochEnd(ctx, identifier, epochNumber) } -// BeforeEpochStart executes the indicated hook before the epochs +// BeforeEpochStart epoch hook func (k Keeper) BeforeEpochStart(ctx sdk.Context, identifier string, epochNumber int64) { + if k.hooks == nil { + panic("hooks not set in keeper") + } k.hooks.BeforeEpochStart(ctx, identifier, epochNumber) } diff --git a/x/epochs/keeper/hooks_test.go b/x/epochs/keeper/hooks_test.go new file mode 100644 index 00000000..d1c879b7 --- /dev/null +++ b/x/epochs/keeper/hooks_test.go @@ -0,0 +1,164 @@ +package keeper_test + +import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/mycel-domain/mycel/testutil" + "github.com/mycel-domain/mycel/x/epochs/types" + "strconv" + "time" +) + +type MockHooks struct{} + +const ( + EpochIdentifier = types.DailyEpochId + BeforeEpochStartEventType = "BeforeEpochStart" + AfterEpochEndEventType = "AfterEpochEnd" +) + +func (h *MockHooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) { + if epochIdentifier == EpochIdentifier { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + AfterEpochEndEventType, + sdk.NewAttribute("epochIdentifier", epochIdentifier), + sdk.NewAttribute("epochNumber", strconv.FormatInt(epochNumber, 10)), + ), + ) + } +} + +func (h *MockHooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) { + if epochIdentifier == EpochIdentifier { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + BeforeEpochStartEventType, + sdk.NewAttribute("epochIdentifier", epochIdentifier), + sdk.NewAttribute("epochNumber", strconv.FormatInt(epochNumber, 10)), + ), + ) + } +} + +type ExpEvent struct { + EpochNumber string +} + +func (suite *KeeperTestSuite) TestAfterEpochHooks() { + var ( + now = time.Now() + oneDayDuration = time.Hour*24 + time.Second + ) + testCases := []struct { + expEpochNumber string + expBeforeEpochStartEvents []ExpEvent + expAfterEpochEndEvents []ExpEvent + fn func() + }{ + { + expBeforeEpochStartEvents: []ExpEvent{ + { + EpochNumber: "2", + }, + }, + expAfterEpochEndEvents: []ExpEvent{ + { + EpochNumber: "1", + }, + }, + fn: func() { + // Begin first block + suite.ctx = suite.ctx.WithBlockHeight(2).WithBlockTime(now.Add(time.Second)) + suite.app.EpochsKeeper.BeginBlocker(suite.ctx) + + // Check if curent epoch is expected + epochInfo, found := suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, types.DailyEpochId) + suite.Require().True(found) + suite.Require().Equal(int64(2), epochInfo.CurrentEpoch) + }, + }, + { + expBeforeEpochStartEvents: []ExpEvent{ + { + EpochNumber: "2", + }, + { + EpochNumber: "3", + }, + }, + expAfterEpochEndEvents: []ExpEvent{ + { + EpochNumber: "1", + }, + { + EpochNumber: "2", + }, + }, + fn: func() { + // Begin first block + suite.ctx = suite.ctx.WithBlockHeight(2).WithBlockTime(now.Add(time.Second)) + suite.app.EpochsKeeper.BeginBlocker(suite.ctx) + + // Check if curent epoch is expected + epochInfo, found := suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, types.DailyEpochId) + suite.Require().True(found) + suite.Require().Equal(int64(2), epochInfo.CurrentEpoch) + + // Begin second block + suite.ctx = suite.ctx.WithBlockHeight(3).WithBlockTime(now.Add(oneDayDuration)) + suite.app.EpochsKeeper.BeginBlocker(suite.ctx) + + // Check if curent epoch is expected + epochInfo, found = suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, types.DailyEpochId) + suite.Require().True(found) + suite.Require().Equal(int64(3), epochInfo.CurrentEpoch) + }, + }, + } + + for i, tc := range testCases { + suite.Run(fmt.Sprintf("Case %d", i), func() { + suite.SetupTest() + + // Remove hooks + suite.app.EpochsKeeper.RemoveHooks() + + // Register hooks + hook := new(MockHooks) + suite.app.EpochsKeeper.SetHooks(hook) + + // Run test Case + tc.fn() + + // Check before epoch start events + if len(tc.expBeforeEpochStartEvents) != 0 { + beforeEpochStartEvents, found := testutil.FindEventsByType(suite.ctx.EventManager().Events(), BeforeEpochStartEventType) + suite.Require().True(found) + for i, expEvent := range tc.expBeforeEpochStartEvents { + event := beforeEpochStartEvents[i] + suite.Require().Equal(BeforeEpochStartEventType, event.Type) + suite.Require().Equal(EpochIdentifier, event.Attributes[0].Value) + suite.Require().Equal(expEvent.EpochNumber, event.Attributes[1].Value) + suite.Require().True(found) + } + } + + // Check after epoch end events + if len(tc.expAfterEpochEndEvents) != 0 { + afterEpochEndEvents, found := testutil.FindEventsByType(suite.ctx.EventManager().Events(), AfterEpochEndEventType) + suite.Require().True(found) + for i, expEvent := range tc.expAfterEpochEndEvents { + event := afterEpochEndEvents[i] + suite.Require().Equal(AfterEpochEndEventType, event.Type) + suite.Require().Equal(EpochIdentifier, event.Attributes[0].Value) + suite.Require().Equal(expEvent.EpochNumber, event.Attributes[1].Value) + suite.Require().True(found) + } + + } + + }) + } + +} diff --git a/x/epochs/keeper/keeper.go b/x/epochs/keeper/keeper.go index eee861bb..7c711c82 100644 --- a/x/epochs/keeper/keeper.go +++ b/x/epochs/keeper/keeper.go @@ -52,6 +52,12 @@ func (k *Keeper) SetHooks(eh types.EpochHooks) *Keeper { return k } +// Remove all hooks. Only used for testing. +func (k *Keeper) RemoveHooks() *Keeper { + k.hooks = nil + return k +} + func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } diff --git a/x/epochs/keeper/setup_test.go b/x/epochs/keeper/setup_test.go index 669060ee..b236b353 100644 --- a/x/epochs/keeper/setup_test.go +++ b/x/epochs/keeper/setup_test.go @@ -38,13 +38,4 @@ func (suite *KeeperTestSuite) SetupTest() { queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) types.RegisterQueryServer(queryHelper, suite.app.EpochsKeeper) suite.queryClient = types.NewQueryClient(queryHelper) - - identifiers := []string{types.IncentiveEpochId} - for _, identifier := range identifiers { - epoch, found := suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, identifier) - suite.Require().True(found) - epoch.StartTime = suite.ctx.BlockTime() - epoch.CurrentEpochStartHeight = suite.ctx.BlockHeight() - suite.app.EpochsKeeper.SetEpochInfo(suite.ctx, epoch) - } } diff --git a/x/epochs/module.go b/x/epochs/module.go index 318382e5..a7c10c26 100644 --- a/x/epochs/module.go +++ b/x/epochs/module.go @@ -140,9 +140,12 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw func (AppModule) ConsensusVersion() uint64 { return 1 } // BeginBlock contains the logic that is automatically triggered at the beginning of each block -func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} +func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { + am.keeper.BeginBlocker(ctx) +} // EndBlock contains the logic that is automatically triggered at the end of each block -func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + am.keeper.EndBlocker(ctx) return []abci.ValidatorUpdate{} } diff --git a/x/epochs/types/epoch_identifier.go b/x/epochs/types/epoch_identifier.go index 3a4bec15..791951dc 100644 --- a/x/epochs/types/epoch_identifier.go +++ b/x/epochs/types/epoch_identifier.go @@ -1,5 +1,29 @@ package types +import ( + errorsmod "cosmossdk.io/errors" +) + const ( - IncentiveEpochId = "incentive" + WeeklyEpochId = "weekly" + DailyEpochId = "daily" ) + +func ValidateEpochIdentifierInterface(i interface{}) error { + v, ok := i.(string) + if !ok { + return errorsmod.Wrapf(ErrInvalidParameterType, "%T", i) + } + if err := ValidateEpochIdentifierString(v); err != nil { + return err + } + + return nil +} + +func ValidateEpochIdentifierString(s string) error { + if s == "" { + return errorsmod.Wrapf(ErrEmptyDistributionEpochIdentifier, "%v", s) + } + return nil +} diff --git a/x/epochs/types/epoch_info.go b/x/epochs/types/epoch_info.go index 18a730bd..da9461c7 100644 --- a/x/epochs/types/epoch_info.go +++ b/x/epochs/types/epoch_info.go @@ -8,32 +8,32 @@ import ( errorsmod "cosmossdk.io/errors" ) -// StartInitialEpoch sets the epoch info fields to their start values -func (ei *EpochInfo) StartInitialEpoch() { - ei.EpochCountingStarted = true - ei.CurrentEpoch = 1 - ei.CurrentEpochStartTime = ei.StartTime +// StartInitialEpoch sets the epoch info fields to ther start values +func (e *EpochInfo) StartInitialEpoch() { + e.EpochCountingStarted = true + e.CurrentEpoch = 1 + e.CurrentEpochStartTime = e.StartTime } // EndEpoch increments the epoch counter and resets the epoch start time -func (ei *EpochInfo) EndEpoch() { - ei.CurrentEpoch++ - ei.CurrentEpochStartTime = ei.CurrentEpochStartTime.Add(ei.Duration) +func (e *EpochInfo) EndEpoch() { + e.CurrentEpoch++ + e.CurrentEpochStartTime = e.CurrentEpochStartTime.Add(e.Duration) } // Validate performs a stateless validation of the epoch info fields -func (ei EpochInfo) Validate() error { - if strings.TrimSpace(ei.Identifier) == "" { +func (e EpochInfo) Validate() error { + if strings.TrimSpace(e.Identifier) == "" { return ErrEpochIdentifierCannotBeEmpty } - if ei.Duration == 0 { + if e.Duration == 0 { return ErrEpochDurationCannotBeZero } - if ei.CurrentEpoch < 0 { - return errorsmod.Wrapf(errors.New(fmt.Sprintf("%d", ei.CurrentEpoch)), ErrCurrentEpochCannotBeNegative.Error()) + if e.CurrentEpoch < 0 { + return errorsmod.Wrapf(errors.New(fmt.Sprintf("%d", e.CurrentEpoch)), ErrCurrentEpochCannotBeNegative.Error()) } - if ei.CurrentEpochStartHeight < 0 { - return errorsmod.Wrapf(errors.New(fmt.Sprintf("%d", ei.CurrentEpoch)), ErrCurrentEpochStartHeightCannotBeNegative.Error()) + if e.CurrentEpochStartHeight < 0 { + return errorsmod.Wrapf(errors.New(fmt.Sprintf("%d", e.CurrentEpoch)), ErrCurrentEpochStartHeightCannotBeNegative.Error()) } return nil } diff --git a/x/epochs/types/epoch_info_test.go b/x/epochs/types/epoch_info_test.go index 70f3dbe6..fcd62c58 100644 --- a/x/epochs/types/epoch_info_test.go +++ b/x/epochs/types/epoch_info_test.go @@ -52,7 +52,7 @@ func (suite *EpochInfoTestSuite) TestValidateEpochInfo() { { ErrEpochDurationCannotBeZero, EpochInfo{ - IncentiveEpochId, + DailyEpochId, time.Now(), time.Hour * 0, 1, @@ -65,7 +65,7 @@ func (suite *EpochInfoTestSuite) TestValidateEpochInfo() { { ErrCurrentEpochCannotBeNegative, EpochInfo{ - IncentiveEpochId, + DailyEpochId, time.Now(), time.Hour * 24, -1, @@ -78,7 +78,7 @@ func (suite *EpochInfoTestSuite) TestValidateEpochInfo() { { ErrCurrentEpochStartHeightCannotBeNegative, EpochInfo{ - IncentiveEpochId, + DailyEpochId, time.Now(), time.Hour * 24, 1, @@ -91,7 +91,7 @@ func (suite *EpochInfoTestSuite) TestValidateEpochInfo() { { nil, EpochInfo{ - IncentiveEpochId, + DailyEpochId, time.Now(), time.Hour * 24, 1, diff --git a/x/epochs/types/errors.go b/x/epochs/types/errors.go index cd9b033d..cd5433a2 100644 --- a/x/epochs/types/errors.go +++ b/x/epochs/types/errors.go @@ -14,4 +14,6 @@ var ( ErrCurrentEpochCannotBeNegative = errorsmod.Register(ModuleName, 1103, "current epoch cannot be negative") ErrCurrentEpochStartHeightCannotBeNegative = errorsmod.Register(ModuleName, 1104, "current epoch start height cannot be negative") ErrDuplicatedEpochEntry = errorsmod.Register(ModuleName, 1105, "duplicated epoch entry") + ErrInvalidParameterType = errorsmod.Register(ModuleName, 1106, "invalid parameter type") + ErrEmptyDistributionEpochIdentifier = errorsmod.Register(ModuleName, 1107, "empty distribution epoch identifier") ) diff --git a/x/epochs/types/expected_keepers.go b/x/epochs/types/expected_keepers.go index dcab9f1a..6aa6e977 100644 --- a/x/epochs/types/expected_keepers.go +++ b/x/epochs/types/expected_keepers.go @@ -16,10 +16,3 @@ type BankKeeper interface { SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins // Methods imported from bank should be defined here } - -type EpochHooks interface { - // the first block whose timestamp is after the duration is counted as the end of the epoch - AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) - // new epoch is next block of epoch end block - BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) -} diff --git a/x/epochs/types/genesis.go b/x/epochs/types/genesis.go index 01347ce1..7c4c36b2 100644 --- a/x/epochs/types/genesis.go +++ b/x/epochs/types/genesis.go @@ -15,15 +15,25 @@ func NewGenesisState(epochs []EpochInfo) *GenesisState { // DefaultGenesis returns the default genesis state func DefaultGenesis() *GenesisState { + startTime := time.Time{} return &GenesisState{ Epochs: []EpochInfo{ { - Identifier: IncentiveEpochId, + Identifier: WeeklyEpochId, StartTime: time.Time{}, - Duration: time.Hour * 24 * 7 * 90, + Duration: time.Hour * 24 * 7, CurrentEpoch: 0, CurrentEpochStartHeight: 0, - CurrentEpochStartTime: time.Time{}, + CurrentEpochStartTime: startTime, + EpochCountingStarted: false, + }, + { + Identifier: DailyEpochId, + StartTime: time.Time{}, + Duration: time.Hour * 24, + CurrentEpoch: 0, + CurrentEpochStartHeight: 0, + CurrentEpochStartTime: startTime, EpochCountingStarted: false, }, }, diff --git a/x/epochs/types/genesis_test.go b/x/epochs/types/genesis_test.go index 99556b3c..be5074ae 100644 --- a/x/epochs/types/genesis_test.go +++ b/x/epochs/types/genesis_test.go @@ -38,7 +38,7 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { &GenesisState{ Epochs: []EpochInfo{ { - Identifier: IncentiveEpochId, + Identifier: DailyEpochId, StartTime: time.Time{}, Duration: time.Hour * 24 * 7, CurrentEpoch: 0, @@ -55,7 +55,7 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { &GenesisState{ Epochs: []EpochInfo{ { - Identifier: IncentiveEpochId, + Identifier: DailyEpochId, StartTime: time.Time{}, Duration: time.Hour * 24 * 7, CurrentEpoch: 0, @@ -64,7 +64,7 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { EpochCountingStarted: false, }, { - Identifier: IncentiveEpochId, + Identifier: DailyEpochId, StartTime: time.Time{}, Duration: time.Hour * 24 * 7, CurrentEpoch: 0, diff --git a/x/epochs/types/hooks.go b/x/epochs/types/hooks.go new file mode 100644 index 00000000..2288e663 --- /dev/null +++ b/x/epochs/types/hooks.go @@ -0,0 +1,37 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type EpochHooks interface { + // the first block whose timestamp is after the duration is counted as the end of the epoch + AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) + // new epoch is next block of epoch end block + BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) +} + +var _ EpochHooks = MultiEpochHooks{} + +// combine multiple gamm hooks, all hook functions are run in array sequence. +type MultiEpochHooks []EpochHooks + +func NewMultiEpochHooks(hooks ...EpochHooks) MultiEpochHooks { + return hooks +} + +// AfterEpochEnd is called when epoch is going to be ended, epochNumber is the +// number of epoch that is ending +func (h MultiEpochHooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) { + for i := range h { + h[i].AfterEpochEnd(ctx, epochIdentifier, epochNumber) + } +} + +// BeforeEpochStart is called when epoch is going to be started, epochNumber is +// the number of epoch that is starting +func (h MultiEpochHooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) { + for i := range h { + h[i].BeforeEpochStart(ctx, epochIdentifier, epochNumber) + } +} diff --git a/x/furnace/client/cli/query.go b/x/furnace/client/cli/query.go new file mode 100644 index 00000000..7fe413de --- /dev/null +++ b/x/furnace/client/cli/query.go @@ -0,0 +1,34 @@ +package cli + +import ( + "fmt" + // "strings" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + // "github.com/cosmos/cosmos-sdk/client/flags" + // sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/mycel-domain/mycel/x/furnace/types" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(queryRoute string) *cobra.Command { + // Group furnace queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(CmdQueryParams()) + cmd.AddCommand(CmdShowEpochBurnConfig()) + cmd.AddCommand(CmdListBurnAmount()) + cmd.AddCommand(CmdShowBurnAmount()) + // this line is used by starport scaffolding # 1 + + return cmd +} diff --git a/x/furnace/client/cli/query_burn_amount.go b/x/furnace/client/cli/query_burn_amount.go new file mode 100644 index 00000000..7931eb45 --- /dev/null +++ b/x/furnace/client/cli/query_burn_amount.go @@ -0,0 +1,82 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/mycel-domain/mycel/x/furnace/types" + "github.com/spf13/cast" +) + +func CmdListBurnAmount() *cobra.Command { + cmd := &cobra.Command{ + Use: "list-burn-amount", + Short: "list all burnAmount", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryAllBurnAmountRequest{ + Pagination: pageReq, + } + + res, err := queryClient.BurnAmountAll(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddPaginationFlagsToCmd(cmd, cmd.Use) + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdShowBurnAmount() *cobra.Command { + cmd := &cobra.Command{ + Use: "show-burn-amount [index]", + Short: "shows a burnAmount", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + argIndex, err := cast.ToUint64E(args[0]) + if err != nil { + return err + } + + params := &types.QueryGetBurnAmountRequest{ + Index: argIndex, + } + + res, err := queryClient.BurnAmount(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/furnace/client/cli/query_burn_amount_test.go b/x/furnace/client/cli/query_burn_amount_test.go new file mode 100644 index 00000000..2cd3dd87 --- /dev/null +++ b/x/furnace/client/cli/query_burn_amount_test.go @@ -0,0 +1,160 @@ +package cli_test + +import ( + "fmt" + "strconv" + "testing" + + tmcli "github.com/cometbft/cometbft/libs/cli" + "github.com/cosmos/cosmos-sdk/client/flags" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/mycel-domain/mycel/testutil/network" + "github.com/mycel-domain/mycel/testutil/nullify" + "github.com/mycel-domain/mycel/x/furnace/client/cli" + "github.com/mycel-domain/mycel/x/furnace/types" +) + +// Prevent strconv unused error +var _ = strconv.IntSize + +func networkWithBurnAmountObjects(t *testing.T, n int) (*network.Network, []types.BurnAmount) { + t.Helper() + cfg := network.DefaultConfig() + state := types.GenesisState{} + for i := 0; i < n; i++ { + burnAmount := types.BurnAmount{ + Index: uint64(i), + } + nullify.Fill(&burnAmount) + state.BurnAmounts = append(state.BurnAmounts, burnAmount) + } + buf, err := cfg.Codec.MarshalJSON(&state) + require.NoError(t, err) + cfg.GenesisState[types.ModuleName] = buf + return network.New(t, cfg), state.BurnAmounts +} + +func TestShowBurnAmount(t *testing.T) { + net, objs := networkWithBurnAmountObjects(t, 2) + + ctx := net.Validators[0].ClientCtx + common := []string{ + fmt.Sprintf("--%s=json", tmcli.OutputFlag), + } + tests := []struct { + desc string + idIndex uint64 + + args []string + err error + obj types.BurnAmount + }{ + { + desc: "found", + idIndex: objs[0].Index, + + args: common, + obj: objs[0], + }, + { + desc: "not found", + idIndex: 100000, + + args: common, + err: status.Error(codes.NotFound, "not found"), + }, + } + for _, tc := range tests { + t.Run(tc.desc, func(t *testing.T) { + args := []string{ + strconv.Itoa(int(tc.idIndex)), + } + args = append(args, tc.args...) + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowBurnAmount(), args) + if tc.err != nil { + stat, ok := status.FromError(tc.err) + require.True(t, ok) + require.ErrorIs(t, stat.Err(), tc.err) + } else { + require.NoError(t, err) + var resp types.QueryGetBurnAmountResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NotNil(t, resp.BurnAmount) + require.Equal(t, + nullify.Fill(&tc.obj), + nullify.Fill(&resp.BurnAmount), + ) + } + }) + } +} + +func TestListBurnAmount(t *testing.T) { + net, objs := networkWithBurnAmountObjects(t, 5) + + ctx := net.Validators[0].ClientCtx + request := func(next []byte, offset, limit uint64, total bool) []string { + args := []string{ + fmt.Sprintf("--%s=json", tmcli.OutputFlag), + } + if next == nil { + args = append(args, fmt.Sprintf("--%s=%d", flags.FlagOffset, offset)) + } else { + args = append(args, fmt.Sprintf("--%s=%s", flags.FlagPageKey, next)) + } + args = append(args, fmt.Sprintf("--%s=%d", flags.FlagLimit, limit)) + if total { + args = append(args, fmt.Sprintf("--%s", flags.FlagCountTotal)) + } + return args + } + t.Run("ByOffset", func(t *testing.T) { + step := 2 + for i := 0; i < len(objs); i += step { + args := request(nil, uint64(i), uint64(step), false) + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListBurnAmount(), args) + require.NoError(t, err) + var resp types.QueryAllBurnAmountResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.LessOrEqual(t, len(resp.BurnAmount), step) + require.Subset(t, + nullify.Fill(objs), + nullify.Fill(resp.BurnAmount), + ) + } + }) + t.Run("ByKey", func(t *testing.T) { + step := 2 + var next []byte + for i := 0; i < len(objs); i += step { + args := request(next, 0, uint64(step), false) + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListBurnAmount(), args) + require.NoError(t, err) + var resp types.QueryAllBurnAmountResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.LessOrEqual(t, len(resp.BurnAmount), step) + require.Subset(t, + nullify.Fill(objs), + nullify.Fill(resp.BurnAmount), + ) + next = resp.Pagination.NextKey + } + }) + t.Run("Total", func(t *testing.T) { + args := request(nil, 0, uint64(len(objs)), true) + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListBurnAmount(), args) + require.NoError(t, err) + var resp types.QueryAllBurnAmountResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NoError(t, err) + require.Equal(t, len(objs), int(resp.Pagination.Total)) + require.ElementsMatch(t, + nullify.Fill(objs), + nullify.Fill(resp.BurnAmount), + ) + }) +} diff --git a/x/furnace/client/cli/query_epoch_burn_config.go b/x/furnace/client/cli/query_epoch_burn_config.go new file mode 100644 index 00000000..061e0fa8 --- /dev/null +++ b/x/furnace/client/cli/query_epoch_burn_config.go @@ -0,0 +1,38 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/mycel-domain/mycel/x/furnace/types" +) + +func CmdShowEpochBurnConfig() *cobra.Command { + cmd := &cobra.Command{ + Use: "show-epoch-burn-config", + Short: "shows epochBurnConfig", + 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) + + params := &types.QueryGetEpochBurnConfigRequest{} + + res, err := queryClient.EpochBurnConfig(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/furnace/client/cli/query_epoch_burn_config_test.go b/x/furnace/client/cli/query_epoch_burn_config_test.go new file mode 100644 index 00000000..56c92940 --- /dev/null +++ b/x/furnace/client/cli/query_epoch_burn_config_test.go @@ -0,0 +1,67 @@ +package cli_test + +import ( + "fmt" + "testing" + + tmcli "github.com/cometbft/cometbft/libs/cli" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/status" + + "github.com/mycel-domain/mycel/testutil/network" + "github.com/mycel-domain/mycel/testutil/nullify" + "github.com/mycel-domain/mycel/x/furnace/client/cli" + "github.com/mycel-domain/mycel/x/furnace/types" +) + +func networkWithEpochBurnConfigObjects(t *testing.T) (*network.Network, types.EpochBurnConfig) { + t.Helper() + cfg := network.DefaultConfig() + state := types.GenesisState{} + epochBurnConfig := &types.EpochBurnConfig{} + nullify.Fill(&epochBurnConfig) + state.EpochBurnConfig = *epochBurnConfig + buf, err := cfg.Codec.MarshalJSON(&state) + require.NoError(t, err) + cfg.GenesisState[types.ModuleName] = buf + return network.New(t, cfg), state.EpochBurnConfig +} + +func TestShowEpochBurnConfig(t *testing.T) { + net, obj := networkWithEpochBurnConfigObjects(t) + + ctx := net.Validators[0].ClientCtx + common := []string{ + fmt.Sprintf("--%s=json", tmcli.OutputFlag), + } + tests := []struct { + desc string + args []string + err error + obj types.EpochBurnConfig + }{ + { + desc: "get", + args: common, + obj: obj, + }, + } + for _, tc := range tests { + t.Run(tc.desc, func(t *testing.T) { + var args []string + args = append(args, tc.args...) + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowEpochBurnConfig(), args) + if tc.err != nil { + stat, ok := status.FromError(tc.err) + require.True(t, ok) + require.ErrorIs(t, stat.Err(), tc.err) + } else { + require.NoError(t, err) + var resp types.QueryGetEpochBurnConfigResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NotNil(t, resp.EpochBurnConfig) + } + }) + } +} diff --git a/x/furnace/client/cli/query_params.go b/x/furnace/client/cli/query_params.go new file mode 100644 index 00000000..da6f62e8 --- /dev/null +++ b/x/furnace/client/cli/query_params.go @@ -0,0 +1,36 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/mycel-domain/mycel/x/furnace/types" +) + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "shows the parameters of the module", + 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) + + res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/furnace/client/cli/tx.go b/x/furnace/client/cli/tx.go new file mode 100644 index 00000000..0e1656f6 --- /dev/null +++ b/x/furnace/client/cli/tx.go @@ -0,0 +1,36 @@ +package cli + +import ( + "fmt" + "time" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + // "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/mycel-domain/mycel/x/furnace/types" +) + +var ( + DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds()) +) + +const ( + flagPacketTimeoutTimestamp = "packet-timeout-timestamp" + listSeparator = "," +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + // this line is used by starport scaffolding # 1 + + return cmd +} diff --git a/x/furnace/genesis.go b/x/furnace/genesis.go new file mode 100644 index 00000000..acf2561c --- /dev/null +++ b/x/furnace/genesis.go @@ -0,0 +1,36 @@ +package furnace + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/mycel-domain/mycel/x/furnace/keeper" + "github.com/mycel-domain/mycel/x/furnace/types" +) + +// InitGenesis initializes the module's state from a provided genesis state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + // Set genesis time + genState.EpochBurnConfig.StartTime = ctx.BlockTime() + k.SetEpochBurnConfig(ctx, genState.EpochBurnConfig) + // Set all the burnAmount + for _, elem := range genState.BurnAmounts { + k.SetBurnAmount(ctx, elem) + } + // this line is used by starport scaffolding # genesis/module/init + k.SetParams(ctx, genState.Params) +} + +// ExportGenesis returns the module's exported genesis +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + genesis := types.DefaultGenesis() + genesis.Params = k.GetParams(ctx) + + // Get all epochBurnConfig + epochBurnConfig, found := k.GetEpochBurnConfig(ctx) + if found { + genesis.EpochBurnConfig = epochBurnConfig + } + genesis.BurnAmounts = k.GetAllBurnAmount(ctx) + // this line is used by starport scaffolding # genesis/module/export + + return genesis +} diff --git a/x/furnace/genesis_test.go b/x/furnace/genesis_test.go new file mode 100644 index 00000000..3d12ef0a --- /dev/null +++ b/x/furnace/genesis_test.go @@ -0,0 +1,42 @@ +package furnace_test + +import ( + "testing" + + keepertest "github.com/mycel-domain/mycel/testutil/keeper" + "github.com/mycel-domain/mycel/testutil/nullify" + "github.com/mycel-domain/mycel/x/furnace" + "github.com/mycel-domain/mycel/x/furnace/types" + "github.com/stretchr/testify/require" +) + +func TestGenesis(t *testing.T) { + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + + EpochBurnConfig: types.EpochBurnConfig{ + EpochIdentifier: "11", + }, + BurnAmounts: []types.BurnAmount{ + { + Index: 0, + }, + { + Index: 1, + }, + }, + // this line is used by starport scaffolding # genesis/test/state + } + + k, ctx := keepertest.FurnaceKeeper(t) + furnace.InitGenesis(ctx, *k, genesisState) + got := furnace.ExportGenesis(ctx, *k) + require.NotNil(t, got) + + nullify.Fill(&genesisState) + nullify.Fill(got) + + require.Equal(t, genesisState.EpochBurnConfig, got.EpochBurnConfig) + require.ElementsMatch(t, genesisState.BurnAmounts, got.BurnAmounts) + // this line is used by starport scaffolding # genesis/test/assert +} diff --git a/x/furnace/keeper/burn_amount.go b/x/furnace/keeper/burn_amount.go new file mode 100644 index 00000000..a43f22de --- /dev/null +++ b/x/furnace/keeper/burn_amount.go @@ -0,0 +1,63 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/mycel-domain/mycel/x/furnace/types" +) + +// SetBurnAmount set a specific burnAmount in the store from its index +func (k Keeper) SetBurnAmount(ctx sdk.Context, burnAmount types.BurnAmount) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BurnAmountKeyPrefix)) + b := k.cdc.MustMarshal(&burnAmount) + store.Set(types.BurnAmountKey( + burnAmount.Index, + ), b) +} + +// GetBurnAmount returns a burnAmount from its index +func (k Keeper) GetBurnAmount( + ctx sdk.Context, + index uint64, + +) (val types.BurnAmount, found bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BurnAmountKeyPrefix)) + + b := store.Get(types.BurnAmountKey( + index, + )) + if b == nil { + return val, false + } + + k.cdc.MustUnmarshal(b, &val) + return val, true +} + +// RemoveBurnAmount removes a burnAmount from the store +func (k Keeper) RemoveBurnAmount( + ctx sdk.Context, + index uint64, + +) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BurnAmountKeyPrefix)) + store.Delete(types.BurnAmountKey( + index, + )) +} + +// GetAllBurnAmount returns all burnAmount +func (k Keeper) GetAllBurnAmount(ctx sdk.Context) (list []types.BurnAmount) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BurnAmountKeyPrefix)) + iterator := sdk.KVStorePrefixIterator(store, []byte{}) + + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var val types.BurnAmount + k.cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, val) + } + + return +} diff --git a/x/furnace/keeper/burn_amount_test.go b/x/furnace/keeper/burn_amount_test.go new file mode 100644 index 00000000..9c837e7c --- /dev/null +++ b/x/furnace/keeper/burn_amount_test.go @@ -0,0 +1,63 @@ +package keeper_test + +import ( + "strconv" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + keepertest "github.com/mycel-domain/mycel/testutil/keeper" + "github.com/mycel-domain/mycel/testutil/nullify" + "github.com/mycel-domain/mycel/x/furnace/keeper" + "github.com/mycel-domain/mycel/x/furnace/types" + "github.com/stretchr/testify/require" +) + +// Prevent strconv unused error +var _ = strconv.IntSize + +func createNBurnAmount(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.BurnAmount { + items := make([]types.BurnAmount, n) + for i := range items { + items[i].Index = uint64(i) + + keeper.SetBurnAmount(ctx, items[i]) + } + return items +} + +func TestBurnAmountGet(t *testing.T) { + keeper, ctx := keepertest.FurnaceKeeper(t) + items := createNBurnAmount(keeper, ctx, 10) + for _, item := range items { + rst, found := keeper.GetBurnAmount(ctx, + item.Index, + ) + require.True(t, found) + require.Equal(t, + nullify.Fill(&item), + nullify.Fill(&rst), + ) + } +} +func TestBurnAmountRemove(t *testing.T) { + keeper, ctx := keepertest.FurnaceKeeper(t) + items := createNBurnAmount(keeper, ctx, 10) + for _, item := range items { + keeper.RemoveBurnAmount(ctx, + item.Index, + ) + _, found := keeper.GetBurnAmount(ctx, + item.Index, + ) + require.False(t, found) + } +} + +func TestBurnAmountGetAll(t *testing.T) { + keeper, ctx := keepertest.FurnaceKeeper(t) + items := createNBurnAmount(keeper, ctx, 10) + require.ElementsMatch(t, + nullify.Fill(items), + nullify.Fill(keeper.GetAllBurnAmount(ctx)), + ) +} diff --git a/x/furnace/keeper/epoch_burn_config.go b/x/furnace/keeper/epoch_burn_config.go new file mode 100644 index 00000000..a3f7a8c7 --- /dev/null +++ b/x/furnace/keeper/epoch_burn_config.go @@ -0,0 +1,33 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/mycel-domain/mycel/x/furnace/types" +) + +// SetEpochBurnConfig set epochBurnConfig in the store +func (k Keeper) SetEpochBurnConfig(ctx sdk.Context, epochBurnConfig types.EpochBurnConfig) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.EpochBurnConfigKey)) + b := k.cdc.MustMarshal(&epochBurnConfig) + store.Set([]byte{0}, b) +} + +// GetEpochBurnConfig returns epochBurnConfig +func (k Keeper) GetEpochBurnConfig(ctx sdk.Context) (val types.EpochBurnConfig, found bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.EpochBurnConfigKey)) + + b := store.Get([]byte{0}) + if b == nil { + return val, false + } + + k.cdc.MustUnmarshal(b, &val) + return val, true +} + +// RemoveEpochBurnConfig removes epochBurnConfig from the store +func (k Keeper) RemoveEpochBurnConfig(ctx sdk.Context) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.EpochBurnConfigKey)) + store.Delete([]byte{0}) +} diff --git a/x/furnace/keeper/epoch_burn_config_test.go b/x/furnace/keeper/epoch_burn_config_test.go new file mode 100644 index 00000000..562f1a30 --- /dev/null +++ b/x/furnace/keeper/epoch_burn_config_test.go @@ -0,0 +1,38 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + keepertest "github.com/mycel-domain/mycel/testutil/keeper" + "github.com/mycel-domain/mycel/testutil/nullify" + "github.com/mycel-domain/mycel/x/furnace/keeper" + "github.com/mycel-domain/mycel/x/furnace/types" +) + +func createTestEpochBurnConfig(keeper *keeper.Keeper, ctx sdk.Context) types.EpochBurnConfig { + item := types.EpochBurnConfig{} + keeper.SetEpochBurnConfig(ctx, item) + return item +} + +func TestEpochBurnConfigGet(t *testing.T) { + keeper, ctx := keepertest.FurnaceKeeper(t) + item := createTestEpochBurnConfig(keeper, ctx) + rst, found := keeper.GetEpochBurnConfig(ctx) + require.True(t, found) + require.Equal(t, + nullify.Fill(&item), + nullify.Fill(&rst), + ) +} + +func TestEpochBurnConfigRemove(t *testing.T) { + keeper, ctx := keepertest.FurnaceKeeper(t) + createTestEpochBurnConfig(keeper, ctx) + keeper.RemoveEpochBurnConfig(ctx) + _, found := keeper.GetEpochBurnConfig(ctx) + require.False(t, found) +} diff --git a/x/furnace/keeper/event.go b/x/furnace/keeper/event.go new file mode 100644 index 00000000..ad195f76 --- /dev/null +++ b/x/furnace/keeper/event.go @@ -0,0 +1,31 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/mycel-domain/mycel/x/furnace/types" +) + +func EmitEpochBurnEvent(ctx sdk.Context, epochIdentifier string, epochNumber int64, burnAmount *types.BurnAmount, burnt sdk.Coin) { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeEpochBurn, + sdk.NewAttribute(types.AttributeKeyEpochIdentifier, epochIdentifier), + sdk.NewAttribute(types.AttributeKeyEpochNumber, sdk.NewInt(epochNumber).String()), + sdk.NewAttribute(types.AttributeKeyBurnIndex, sdk.NewInt(int64(burnAmount.Index)).String()), + sdk.NewAttribute(types.AttributeKeyBurnTotalEpochs, sdk.NewInt(int64(burnAmount.TotalEpochs)).String()), + sdk.NewAttribute(types.AttributeKeyBurnCurrentEpoch, sdk.NewInt(int64(burnAmount.CurrentEpoch)).String()), + sdk.NewAttribute(types.AttributeKeybBurnAmount, burnt.String()), + sdk.NewAttribute(types.AttributeKeyBurnCumulativeAmount, burnAmount.CumulativeBurntAmount.String()), + sdk.NewAttribute(types.AttributeKeyBurnTimestamp, ctx.BlockTime().String()), + ), + ) +} + +func EmitBurnAmountCreatedEvent(ctx sdk.Context, burnAmount *types.BurnAmount) { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeBurnAmountCreated, + sdk.NewAttribute(types.AttributeKeyBurnAmountIndex, sdk.NewInt(int64(burnAmount.Index)).String()), + ), + ) +} diff --git a/x/furnace/keeper/hooks.go b/x/furnace/keeper/hooks.go new file mode 100644 index 00000000..f55d25b2 --- /dev/null +++ b/x/furnace/keeper/hooks.go @@ -0,0 +1,120 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/mycel-domain/mycel/app/params" + epochstypes "github.com/mycel-domain/mycel/x/epochs/types" + "github.com/mycel-domain/mycel/x/furnace/types" +) + +func calculateBurntAmount(burnAmount *types.BurnAmount) sdk.Coin { + if burnAmount.TotalBurnAmount.Amount.GTE(sdk.NewInt(int64(burnAmount.TotalEpochs))) { + quotient := burnAmount.TotalBurnAmount.Amount.QuoRaw(int64(burnAmount.TotalEpochs)) + remander := burnAmount.TotalBurnAmount.Amount.ModRaw(int64(burnAmount.TotalEpochs)) + if remander.IsZero() || burnAmount.CurrentEpoch+1 != burnAmount.TotalEpochs { + return sdk.NewCoin(params.DefaultBondDenom, quotient) + } + return sdk.NewCoin(params.BaseCoinUnit, quotient.Add(remander)) + } else if burnAmount.CurrentEpoch == 0 { + return sdk.NewCoin(params.DefaultBondDenom, burnAmount.TotalBurnAmount.Amount) + } + return sdk.NewCoin(params.DefaultBondDenom, sdk.NewInt(0)) +} + +func createNextBurnAmount(ctx sdk.Context, k Keeper, config types.EpochBurnConfig) (burnAmount types.BurnAmount) { + // Create burn amount + burnAmount = types.BurnAmount{ + Index: uint64(config.CurrentBurnAmountIndex), + TotalEpochs: config.DefaultTotalEpochs, + CurrentEpoch: 0, + TotalBurnAmount: sdk.NewCoin(params.DefaultBondDenom, sdk.NewInt(0)), + CumulativeBurntAmount: sdk.NewCoin(params.DefaultBondDenom, sdk.NewInt(0)), + } + k.SetBurnAmount(ctx, burnAmount) + + // Emit event + EmitBurnAmountCreatedEvent(ctx, &burnAmount) + + return burnAmount +} + +// BeforeEpochStart is the epoch start hook. +func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) { +} + +// AfterEpochEnd is the epoch end hook. +func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) { + var burnt = sdk.NewCoin(params.DefaultBondDenom, sdk.NewInt(0)) + + config, found := k.GetEpochBurnConfig(ctx) + if !found { + panic("epoch burn config not found") + } + + // Check epoch identifier + if config.EpochIdentifier != epochIdentifier { + return + } + + // Get burn amount + burnAmount, found := k.GetBurnAmount(ctx, uint64(config.CurrentBurnAmountIndex)) + if !found { + burnAmount = createNextBurnAmount(ctx, k, config) + } + + // Check if CurrentEpoch is smaller than TotalEpochs + if burnAmount.CurrentEpoch > burnAmount.TotalEpochs { + panic("current epoch is greater than total epochs") + } + + // Check if CurrentEpoch is final epoch + if burnAmount.CurrentEpoch == burnAmount.TotalEpochs { + config.CurrentBurnAmountIndex++ + k.SetEpochBurnConfig(ctx, config) + + burnAmount, found = k.GetBurnAmount(ctx, uint64(config.CurrentBurnAmountIndex)) + if !found { + burnAmount = createNextBurnAmount(ctx, k, config) + } + } + + // Calculate burnt amount + if burnAmount.CumulativeBurntAmount.IsLT(burnAmount.TotalBurnAmount) { + burnt = calculateBurntAmount(&burnAmount) + } + + // TODO: Burn coins + + // Update burn amount + burnAmount.CumulativeBurntAmount = burnAmount.CumulativeBurntAmount.Add(burnt) + burnAmount.CurrentEpoch++ + k.SetBurnAmount(ctx, burnAmount) + + // Emit event + EmitEpochBurnEvent(ctx, epochIdentifier, epochNumber, &burnAmount, burnt) + +} + +// ___________________________________________________________________________________________________ + +// Hooks is the wrapper struct for the incentives keeper. +type Hooks struct { + k Keeper +} + +var _ epochstypes.EpochHooks = Hooks{} + +// Hooks returns the hook wrapper struct. +func (k Keeper) Hooks() Hooks { + return Hooks{k} +} + +// BeforeEpochStart is the epoch start hook. +func (h Hooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) { + h.k.BeforeEpochStart(ctx, epochIdentifier, epochNumber) +} + +// AfterEpochEnd is the epoch end hook. +func (h Hooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) { + h.k.AfterEpochEnd(ctx, epochIdentifier, epochNumber) +} diff --git a/x/furnace/keeper/hooks_test.go b/x/furnace/keeper/hooks_test.go new file mode 100644 index 00000000..c9dcfc59 --- /dev/null +++ b/x/furnace/keeper/hooks_test.go @@ -0,0 +1,263 @@ +package keeper_test + +import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/mycel-domain/mycel/app/params" + "github.com/mycel-domain/mycel/testutil" + epochstypes "github.com/mycel-domain/mycel/x/epochs/types" + "github.com/mycel-domain/mycel/x/furnace/types" + "time" +) + +type ExpBurnEvent struct { + EpochIndex string + EpochNumber string + BurnIndex string + BurnTotalEpochs string + BurnCurrentEpoch string + BurnAmount string + BurnCumulativeBurntAmount string +} + +type ExpCreateBurnAmountEvent struct { + BurnAmountIndex string +} + +var ( + now = time.Now() + oneDayDuration = time.Hour*24 + time.Second +) + +func (suite *KeeperTestSuite) TestAfterEpochEndCreateBurnAmount() { + testCases := []struct { + epochsCount int64 + expectedEvents []ExpCreateBurnAmountEvent + fn func() + }{ + { + epochsCount: 1, + expectedEvents: []ExpCreateBurnAmountEvent{ + { + BurnAmountIndex: "1", + }, + }, + }, + { + epochsCount: 31, + expectedEvents: []ExpCreateBurnAmountEvent{ + { + BurnAmountIndex: "1", + }, + { + BurnAmountIndex: "2", + }, + }, + }, + } + + for i, tc := range testCases { + suite.Run(fmt.Sprintf("Case %d", i), func() { + suite.SetupTest() + + for i := int64(1); i <= tc.epochsCount; i++ { + suite.ctx = suite.ctx.WithBlockHeight(i + 1).WithBlockTime(now.Add(oneDayDuration)) + suite.app.EpochsKeeper.BeginBlocker(suite.ctx) + // Check if curent epoch is expected + epochInfo, found := suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, epochstypes.DailyEpochId) + suite.Require().True(found) + suite.Require().Equal(i+1, epochInfo.CurrentEpoch) + + // Check if burn amount is expected + config, found := suite.app.FurnaceKeeper.GetEpochBurnConfig(suite.ctx) + suite.Require().True(found) + _, found = suite.app.FurnaceKeeper.GetBurnAmount(suite.ctx, uint64(config.CurrentBurnAmountIndex)) + suite.Require().True(found) + } + + // Check if event is emitted + events, found := testutil.FindEventsByType(suite.ctx.EventManager().Events(), types.EventTypeBurnAmountCreated) + suite.Require().True(found) + suite.Require().Equal(len(tc.expectedEvents), len(events)) + for i, event := range events { + suite.Require().Equal(tc.expectedEvents[i].BurnAmountIndex, event.Attributes[0].Value) + } + + }) + } + +} + +func (suite *KeeperTestSuite) TestAfterEpochEnd() { + + testCases := []struct { + totalBurnAmounts []int64 + expectedEvents []ExpBurnEvent + epochsCount int64 + fn func() + }{ + { + totalBurnAmounts: []int64{30, 31}, + epochsCount: 4, + expectedEvents: []ExpBurnEvent{ + { + EpochIndex: "daily", + EpochNumber: "1", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "1", + BurnAmount: "10umycel", + BurnCumulativeBurntAmount: "10umycel", + }, + { + EpochIndex: "daily", + EpochNumber: "2", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "2", + BurnAmount: "10umycel", + BurnCumulativeBurntAmount: "20umycel", + }, + { + EpochIndex: "daily", + EpochNumber: "3", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "3", + BurnAmount: "10umycel", + BurnCumulativeBurntAmount: "30umycel", + }, + { + EpochIndex: "daily", + EpochNumber: "4", + BurnIndex: "2", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "1", + BurnAmount: "10umycel", + BurnCumulativeBurntAmount: "10umycel", + }, + }, + }, + { + totalBurnAmounts: []int64{31}, + epochsCount: 3, + expectedEvents: []ExpBurnEvent{ + { + EpochIndex: "daily", + EpochNumber: "1", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "1", + BurnAmount: "10umycel", + BurnCumulativeBurntAmount: "10umycel", + }, + { + EpochIndex: "daily", + EpochNumber: "2", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "2", + BurnAmount: "10umycel", + BurnCumulativeBurntAmount: "20umycel", + }, + { + EpochIndex: "daily", + EpochNumber: "3", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "3", + BurnAmount: "11umycel", + BurnCumulativeBurntAmount: "31umycel", + }, + }, + }, + + { + totalBurnAmounts: []int64{1}, + epochsCount: 3, + expectedEvents: []ExpBurnEvent{ + { + EpochIndex: "daily", + EpochNumber: "1", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "1", + BurnAmount: "1umycel", + BurnCumulativeBurntAmount: "1umycel", + }, + { + EpochIndex: "daily", + EpochNumber: "2", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "2", + BurnAmount: "0umycel", + BurnCumulativeBurntAmount: "1umycel", + }, + { + EpochIndex: "daily", + EpochNumber: "3", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "3", + BurnAmount: "0umycel", + BurnCumulativeBurntAmount: "1umycel", + }, + }, + }, + } + + for i, tc := range testCases { + suite.Run(fmt.Sprintf("Case %d", i), func() { + suite.SetupTest() + + // Set burn totalBurnAmount + for i, _ := range tc.totalBurnAmounts { + suite.app.FurnaceKeeper.SetBurnAmount(suite.ctx, types.BurnAmount{ + Index: uint64(i + 1), + TotalEpochs: 3, + CurrentEpoch: 0, + TotalBurnAmount: sdk.NewCoin(params.DefaultBondDenom, sdk.NewInt(tc.totalBurnAmounts[i])), + CumulativeBurntAmount: sdk.NewCoin(params.DefaultBondDenom, sdk.NewInt(0)), + }) + } + + // Run fn + if tc.fn != nil { + tc.fn() + } + + for i := int64(1); i <= tc.epochsCount; i++ { + suite.ctx = suite.ctx.WithBlockHeight(i + 1).WithBlockTime(now.Add(oneDayDuration)) + suite.app.EpochsKeeper.BeginBlocker(suite.ctx) + // Check if curent epoch is expected + epochInfo, found := suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, epochstypes.DailyEpochId) + suite.Require().True(found) + suite.Require().Equal(i+1, epochInfo.CurrentEpoch) + + // Check if burn amount is expected + config, found := suite.app.FurnaceKeeper.GetEpochBurnConfig(suite.ctx) + suite.Require().True(found) + _, found = suite.app.FurnaceKeeper.GetBurnAmount(suite.ctx, uint64(config.CurrentBurnAmountIndex)) + suite.Require().True(found) + } + + // TODO: check if token is burnt + + // Check if event is emitted + events, found := testutil.FindEventsByType(suite.ctx.EventManager().Events(), types.EventTypeEpochBurn) + suite.Require().True(found) + suite.Require().Equal(len(tc.expectedEvents), len(events)) + for i, event := range events { + suite.Require().Equal(tc.expectedEvents[i].EpochIndex, event.Attributes[0].Value) + suite.Require().Equal(tc.expectedEvents[i].EpochNumber, event.Attributes[1].Value) + suite.Require().Equal(tc.expectedEvents[i].BurnIndex, event.Attributes[2].Value) + suite.Require().Equal(tc.expectedEvents[i].BurnTotalEpochs, event.Attributes[3].Value) + suite.Require().Equal(tc.expectedEvents[i].BurnCurrentEpoch, event.Attributes[4].Value) + suite.Require().Equal(tc.expectedEvents[i].BurnAmount, event.Attributes[5].Value) + suite.Require().Equal(tc.expectedEvents[i].BurnCumulativeBurntAmount, event.Attributes[6].Value) + } + }) + } + +} diff --git a/x/furnace/keeper/keeper.go b/x/furnace/keeper/keeper.go new file mode 100644 index 00000000..3ee1f4a0 --- /dev/null +++ b/x/furnace/keeper/keeper.go @@ -0,0 +1,54 @@ +package keeper + +import ( + "fmt" + + "github.com/cometbft/cometbft/libs/log" + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + + "github.com/mycel-domain/mycel/x/furnace/types" +) + +type ( + Keeper struct { + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + paramstore paramtypes.Subspace + + bankKeeper types.BankKeeper + epochsKeeper types.EpochsKeeper + } +) + +func NewKeeper( + cdc codec.BinaryCodec, + storeKey, + memKey storetypes.StoreKey, + ps paramtypes.Subspace, + + bankKeeper types.BankKeeper, + epochsKeeper types.EpochsKeeper, +) *Keeper { + // set KeyTable if it has not already been set + if !ps.HasKeyTable() { + ps = ps.WithKeyTable(types.ParamKeyTable()) + } + + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + paramstore: ps, + + bankKeeper: bankKeeper, + epochsKeeper: epochsKeeper, + } +} + +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} diff --git a/x/furnace/keeper/msg_server.go b/x/furnace/keeper/msg_server.go new file mode 100644 index 00000000..dc239a32 --- /dev/null +++ b/x/furnace/keeper/msg_server.go @@ -0,0 +1,17 @@ +package keeper + +import ( + "github.com/mycel-domain/mycel/x/furnace/types" +) + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} diff --git a/x/furnace/keeper/msg_server_test.go b/x/furnace/keeper/msg_server_test.go new file mode 100644 index 00000000..586745a2 --- /dev/null +++ b/x/furnace/keeper/msg_server_test.go @@ -0,0 +1,23 @@ +package keeper_test + +import ( + "context" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + keepertest "github.com/mycel-domain/mycel/testutil/keeper" + "github.com/mycel-domain/mycel/x/furnace/keeper" + "github.com/mycel-domain/mycel/x/furnace/types" + "github.com/stretchr/testify/require" +) + +func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) { + k, ctx := keepertest.FurnaceKeeper(t) + return keeper.NewMsgServerImpl(*k), sdk.WrapSDKContext(ctx) +} + +func TestMsgServer(t *testing.T) { + ms, ctx := setupMsgServer(t) + require.NotNil(t, ms) + require.NotNil(t, ctx) +} diff --git a/x/furnace/keeper/params.go b/x/furnace/keeper/params.go new file mode 100644 index 00000000..06b1ce27 --- /dev/null +++ b/x/furnace/keeper/params.go @@ -0,0 +1,16 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/mycel-domain/mycel/x/furnace/types" +) + +// GetParams get all parameters as types.Params +func (k Keeper) GetParams(ctx sdk.Context) types.Params { + return types.NewParams() +} + +// SetParams set the params +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + k.paramstore.SetParamSet(ctx, ¶ms) +} diff --git a/x/furnace/keeper/params_test.go b/x/furnace/keeper/params_test.go new file mode 100644 index 00000000..b5563a3a --- /dev/null +++ b/x/furnace/keeper/params_test.go @@ -0,0 +1,18 @@ +package keeper_test + +import ( + "testing" + + testkeeper "github.com/mycel-domain/mycel/testutil/keeper" + "github.com/mycel-domain/mycel/x/furnace/types" + "github.com/stretchr/testify/require" +) + +func TestGetParams(t *testing.T) { + k, ctx := testkeeper.FurnaceKeeper(t) + params := types.DefaultParams() + + k.SetParams(ctx, params) + + require.EqualValues(t, params, k.GetParams(ctx)) +} diff --git a/x/furnace/keeper/query.go b/x/furnace/keeper/query.go new file mode 100644 index 00000000..d6803270 --- /dev/null +++ b/x/furnace/keeper/query.go @@ -0,0 +1,7 @@ +package keeper + +import ( + "github.com/mycel-domain/mycel/x/furnace/types" +) + +var _ types.QueryServer = Keeper{} diff --git a/x/furnace/keeper/query_burn_amount.go b/x/furnace/keeper/query_burn_amount.go new file mode 100644 index 00000000..20d55145 --- /dev/null +++ b/x/furnace/keeper/query_burn_amount.go @@ -0,0 +1,57 @@ +package keeper + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/mycel-domain/mycel/x/furnace/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (k Keeper) BurnAmountAll(goCtx context.Context, req *types.QueryAllBurnAmountRequest) (*types.QueryAllBurnAmountResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + var burnAmounts []types.BurnAmount + ctx := sdk.UnwrapSDKContext(goCtx) + + store := ctx.KVStore(k.storeKey) + burnAmountStore := prefix.NewStore(store, types.KeyPrefix(types.BurnAmountKeyPrefix)) + + pageRes, err := query.Paginate(burnAmountStore, req.Pagination, func(key []byte, value []byte) error { + var burnAmount types.BurnAmount + if err := k.cdc.Unmarshal(value, &burnAmount); err != nil { + return err + } + + burnAmounts = append(burnAmounts, burnAmount) + return nil + }) + + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryAllBurnAmountResponse{BurnAmount: burnAmounts, Pagination: pageRes}, nil +} + +func (k Keeper) BurnAmount(goCtx context.Context, req *types.QueryGetBurnAmountRequest) (*types.QueryGetBurnAmountResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(goCtx) + + val, found := k.GetBurnAmount( + ctx, + req.Index, + ) + if !found { + return nil, status.Error(codes.NotFound, "not found") + } + + return &types.QueryGetBurnAmountResponse{BurnAmount: val}, nil +} diff --git a/x/furnace/keeper/query_burn_amount_test.go b/x/furnace/keeper/query_burn_amount_test.go new file mode 100644 index 00000000..2a422b4b --- /dev/null +++ b/x/furnace/keeper/query_burn_amount_test.go @@ -0,0 +1,127 @@ +package keeper_test + +import ( + "strconv" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + keepertest "github.com/mycel-domain/mycel/testutil/keeper" + "github.com/mycel-domain/mycel/testutil/nullify" + "github.com/mycel-domain/mycel/x/furnace/types" +) + +// Prevent strconv unused error +var _ = strconv.IntSize + +func TestBurnAmountQuerySingle(t *testing.T) { + keeper, ctx := keepertest.FurnaceKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + msgs := createNBurnAmount(keeper, ctx, 2) + tests := []struct { + desc string + request *types.QueryGetBurnAmountRequest + response *types.QueryGetBurnAmountResponse + err error + }{ + { + desc: "First", + request: &types.QueryGetBurnAmountRequest{ + Index: msgs[0].Index, + }, + response: &types.QueryGetBurnAmountResponse{BurnAmount: msgs[0]}, + }, + { + desc: "Second", + request: &types.QueryGetBurnAmountRequest{ + Index: msgs[1].Index, + }, + response: &types.QueryGetBurnAmountResponse{BurnAmount: msgs[1]}, + }, + { + desc: "KeyNotFound", + request: &types.QueryGetBurnAmountRequest{ + Index: 100000, + }, + err: status.Error(codes.NotFound, "not found"), + }, + { + desc: "InvalidRequest", + err: status.Error(codes.InvalidArgument, "invalid request"), + }, + } + for _, tc := range tests { + t.Run(tc.desc, func(t *testing.T) { + response, err := keeper.BurnAmount(wctx, tc.request) + if tc.err != nil { + require.ErrorIs(t, err, tc.err) + } else { + require.NoError(t, err) + require.Equal(t, + nullify.Fill(tc.response), + nullify.Fill(response), + ) + } + }) + } +} + +func TestBurnAmountQueryPaginated(t *testing.T) { + keeper, ctx := keepertest.FurnaceKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + msgs := createNBurnAmount(keeper, ctx, 5) + + request := func(next []byte, offset, limit uint64, total bool) *types.QueryAllBurnAmountRequest { + return &types.QueryAllBurnAmountRequest{ + Pagination: &query.PageRequest{ + Key: next, + Offset: offset, + Limit: limit, + CountTotal: total, + }, + } + } + t.Run("ByOffset", func(t *testing.T) { + step := 2 + for i := 0; i < len(msgs); i += step { + resp, err := keeper.BurnAmountAll(wctx, request(nil, uint64(i), uint64(step), false)) + require.NoError(t, err) + require.LessOrEqual(t, len(resp.BurnAmount), step) + require.Subset(t, + nullify.Fill(msgs), + nullify.Fill(resp.BurnAmount), + ) + } + }) + t.Run("ByKey", func(t *testing.T) { + step := 2 + var next []byte + for i := 0; i < len(msgs); i += step { + resp, err := keeper.BurnAmountAll(wctx, request(next, 0, uint64(step), false)) + require.NoError(t, err) + require.LessOrEqual(t, len(resp.BurnAmount), step) + require.Subset(t, + nullify.Fill(msgs), + nullify.Fill(resp.BurnAmount), + ) + next = resp.Pagination.NextKey + } + }) + t.Run("Total", func(t *testing.T) { + resp, err := keeper.BurnAmountAll(wctx, request(nil, 0, 0, true)) + require.NoError(t, err) + require.Equal(t, len(msgs), int(resp.Pagination.Total)) + require.ElementsMatch(t, + nullify.Fill(msgs), + nullify.Fill(resp.BurnAmount), + ) + }) + t.Run("InvalidRequest", func(t *testing.T) { + _, err := keeper.BurnAmountAll(wctx, nil) + require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + }) +} diff --git a/x/furnace/keeper/query_epoch_burn_config.go b/x/furnace/keeper/query_epoch_burn_config.go new file mode 100644 index 00000000..16ce9f3b --- /dev/null +++ b/x/furnace/keeper/query_epoch_burn_config.go @@ -0,0 +1,24 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/mycel-domain/mycel/x/furnace/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (k Keeper) EpochBurnConfig(goCtx context.Context, req *types.QueryGetEpochBurnConfigRequest) (*types.QueryGetEpochBurnConfigResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(goCtx) + + val, found := k.GetEpochBurnConfig(ctx) + if !found { + return nil, status.Error(codes.NotFound, "not found") + } + + return &types.QueryGetEpochBurnConfigResponse{EpochBurnConfig: val}, nil +} diff --git a/x/furnace/keeper/query_epoch_burn_config_test.go b/x/furnace/keeper/query_epoch_burn_config_test.go new file mode 100644 index 00000000..6a00bb5e --- /dev/null +++ b/x/furnace/keeper/query_epoch_burn_config_test.go @@ -0,0 +1,50 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + keepertest "github.com/mycel-domain/mycel/testutil/keeper" + "github.com/mycel-domain/mycel/testutil/nullify" + "github.com/mycel-domain/mycel/x/furnace/types" +) + +func TestEpochBurnConfigQuery(t *testing.T) { + keeper, ctx := keepertest.FurnaceKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + item := createTestEpochBurnConfig(keeper, ctx) + tests := []struct { + desc string + request *types.QueryGetEpochBurnConfigRequest + response *types.QueryGetEpochBurnConfigResponse + err error + }{ + { + desc: "First", + request: &types.QueryGetEpochBurnConfigRequest{}, + response: &types.QueryGetEpochBurnConfigResponse{EpochBurnConfig: item}, + }, + { + desc: "InvalidRequest", + err: status.Error(codes.InvalidArgument, "invalid request"), + }, + } + for _, tc := range tests { + t.Run(tc.desc, func(t *testing.T) { + response, err := keeper.EpochBurnConfig(wctx, tc.request) + if tc.err != nil { + require.ErrorIs(t, err, tc.err) + } else { + require.NoError(t, err) + require.Equal(t, + nullify.Fill(tc.response), + nullify.Fill(response), + ) + } + }) + } +} diff --git a/x/furnace/keeper/query_params.go b/x/furnace/keeper/query_params.go new file mode 100644 index 00000000..01d08cad --- /dev/null +++ b/x/furnace/keeper/query_params.go @@ -0,0 +1,19 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/mycel-domain/mycel/x/furnace/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(goCtx) + + return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil +} diff --git a/x/furnace/keeper/query_params_test.go b/x/furnace/keeper/query_params_test.go new file mode 100644 index 00000000..8b25b712 --- /dev/null +++ b/x/furnace/keeper/query_params_test.go @@ -0,0 +1,21 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + testkeeper "github.com/mycel-domain/mycel/testutil/keeper" + "github.com/mycel-domain/mycel/x/furnace/types" + "github.com/stretchr/testify/require" +) + +func TestParamsQuery(t *testing.T) { + keeper, ctx := testkeeper.FurnaceKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + params := types.DefaultParams() + keeper.SetParams(ctx, params) + + response, err := keeper.Params(wctx, &types.QueryParamsRequest{}) + require.NoError(t, err) + require.Equal(t, &types.QueryParamsResponse{Params: params}, response) +} diff --git a/x/furnace/keeper/setup_test.go b/x/furnace/keeper/setup_test.go new file mode 100644 index 00000000..b236b353 --- /dev/null +++ b/x/furnace/keeper/setup_test.go @@ -0,0 +1,41 @@ +package keeper_test + +import ( + mycelapp "github.com/mycel-domain/mycel/app" + "github.com/mycel-domain/mycel/x/epochs/types" + "testing" + "time" + + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/baseapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/suite" +) + +type KeeperTestSuite struct { + suite.Suite + + ctx sdk.Context + app *mycelapp.App + queryClient types.QueryClient + consAddress sdk.ConsAddress +} + +var s *KeeperTestSuite + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(KeeperTestSuite)) +} + +func (suite *KeeperTestSuite) SetupTest() { + // init app + app := mycelapp.Setup(suite.T(), false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{Time: time.Now().UTC()}) + + suite.app = app + suite.ctx = ctx + + queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) + types.RegisterQueryServer(queryHelper, suite.app.EpochsKeeper) + suite.queryClient = types.NewQueryClient(queryHelper) +} diff --git a/x/furnace/module.go b/x/furnace/module.go new file mode 100644 index 00000000..183f99e1 --- /dev/null +++ b/x/furnace/module.go @@ -0,0 +1,148 @@ +package furnace + +import ( + "context" + "encoding/json" + "fmt" + // this line is used by starport scaffolding # 1 + + "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/mycel-domain/mycel/x/furnace/client/cli" + "github.com/mycel-domain/mycel/x/furnace/keeper" + "github.com/mycel-domain/mycel/x/furnace/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface that defines the independent methods a Cosmos SDK module needs to implement. +type AppModuleBasic struct { + cdc codec.BinaryCodec +} + +func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the name of the module as a string +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the amino codec for the module, which is used to marshal and unmarshal structs to/from []byte in order to persist them in the module's KVStore +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns a default GenesisState for the module, marshalled to json.RawMessage. The default GenesisState need to be defined by the module developer and is primarily used for testing +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form +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) { + types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) +} + +// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, + accountKeeper types.AccountKeeper, + bankKeeper types.BankKeeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + } +} + +// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) +} + +// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the 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 + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + InitGenesis(ctx, am.keeper, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1 +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock contains the logic that is automatically triggered at the beginning of each block +func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock contains the logic that is automatically triggered at the end of each block +func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} diff --git a/x/furnace/module_simulation.go b/x/furnace/module_simulation.go new file mode 100644 index 00000000..787b556d --- /dev/null +++ b/x/furnace/module_simulation.go @@ -0,0 +1,64 @@ +package furnace + +import ( + "math/rand" + + "github.com/cosmos/cosmos-sdk/baseapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/mycel-domain/mycel/testutil/sample" + furnacesimulation "github.com/mycel-domain/mycel/x/furnace/simulation" + "github.com/mycel-domain/mycel/x/furnace/types" +) + +// avoid unused import issue +var ( + _ = sample.AccAddress + _ = furnacesimulation.FindAccount + _ = simulation.MsgEntryKind + _ = baseapp.Paramspace + _ = rand.Rand{} +) + +const ( +// this line is used by starport scaffolding # simapp/module/const +) + +// GenerateGenesisState creates a randomized GenState of the module. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + accs := make([]string, len(simState.Accounts)) + for i, acc := range simState.Accounts { + accs[i] = acc.Address.String() + } + furnaceGenesis := types.GenesisState{ + Params: types.DefaultParams(), + // this line is used by starport scaffolding # simapp/module/genesisState + } + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&furnaceGenesis) +} + +// RegisterStoreDecoder registers a decoder. +func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} + +// ProposalContents doesn't return any content functions for governance proposals. +func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { + return nil +} + +// WeightedOperations returns the all the gov module operations with their respective weights. +func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + operations := make([]simtypes.WeightedOperation, 0) + + // this line is used by starport scaffolding # simapp/module/operation + + return operations +} + +// ProposalMsgs returns msgs used for governance proposals for simulations. +func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + // this line is used by starport scaffolding # simapp/module/OpMsg + } +} diff --git a/x/furnace/simulation/helpers.go b/x/furnace/simulation/helpers.go new file mode 100644 index 00000000..92c437c0 --- /dev/null +++ b/x/furnace/simulation/helpers.go @@ -0,0 +1,15 @@ +package simulation + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" +) + +// FindAccount find a specific address from an account list +func FindAccount(accs []simtypes.Account, address string) (simtypes.Account, bool) { + creator, err := sdk.AccAddressFromBech32(address) + if err != nil { + panic(err) + } + return simtypes.FindAccount(accs, creator) +} diff --git a/x/furnace/types/burn_amount.pb.go b/x/furnace/types/burn_amount.pb.go new file mode 100644 index 00000000..18d0cf09 --- /dev/null +++ b/x/furnace/types/burn_amount.pb.go @@ -0,0 +1,527 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: mycel/furnace/burn_amount.proto + +package types + +import ( + fmt "fmt" + types "github.com/cosmos/cosmos-sdk/types" + _ "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 + +type BurnAmount struct { + Index uint64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"` + BurnStarted bool `protobuf:"varint,2,opt,name=burnStarted,proto3" json:"burnStarted,omitempty"` + TotalEpochs uint64 `protobuf:"varint,3,opt,name=totalEpochs,proto3" json:"totalEpochs,omitempty"` + CurrentEpoch uint64 `protobuf:"varint,4,opt,name=currentEpoch,proto3" json:"currentEpoch,omitempty"` + TotalBurnAmount types.Coin `protobuf:"bytes,5,opt,name=totalBurnAmount,proto3" json:"totalBurnAmount"` + CumulativeBurntAmount types.Coin `protobuf:"bytes,6,opt,name=cumulativeBurntAmount,proto3" json:"cumulativeBurntAmount"` +} + +func (m *BurnAmount) Reset() { *m = BurnAmount{} } +func (m *BurnAmount) String() string { return proto.CompactTextString(m) } +func (*BurnAmount) ProtoMessage() {} +func (*BurnAmount) Descriptor() ([]byte, []int) { + return fileDescriptor_c51e14c665b742e5, []int{0} +} +func (m *BurnAmount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BurnAmount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BurnAmount.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 *BurnAmount) XXX_Merge(src proto.Message) { + xxx_messageInfo_BurnAmount.Merge(m, src) +} +func (m *BurnAmount) XXX_Size() int { + return m.Size() +} +func (m *BurnAmount) XXX_DiscardUnknown() { + xxx_messageInfo_BurnAmount.DiscardUnknown(m) +} + +var xxx_messageInfo_BurnAmount proto.InternalMessageInfo + +func (m *BurnAmount) GetIndex() uint64 { + if m != nil { + return m.Index + } + return 0 +} + +func (m *BurnAmount) GetBurnStarted() bool { + if m != nil { + return m.BurnStarted + } + return false +} + +func (m *BurnAmount) GetTotalEpochs() uint64 { + if m != nil { + return m.TotalEpochs + } + return 0 +} + +func (m *BurnAmount) GetCurrentEpoch() uint64 { + if m != nil { + return m.CurrentEpoch + } + return 0 +} + +func (m *BurnAmount) GetTotalBurnAmount() types.Coin { + if m != nil { + return m.TotalBurnAmount + } + return types.Coin{} +} + +func (m *BurnAmount) GetCumulativeBurntAmount() types.Coin { + if m != nil { + return m.CumulativeBurntAmount + } + return types.Coin{} +} + +func init() { + proto.RegisterType((*BurnAmount)(nil), "mycel.furnace.BurnAmount") +} + +func init() { proto.RegisterFile("mycel/furnace/burn_amount.proto", fileDescriptor_c51e14c665b742e5) } + +var fileDescriptor_c51e14c665b742e5 = []byte{ + // 320 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xc1, 0x4e, 0x3a, 0x31, + 0x10, 0xc6, 0xb7, 0xfc, 0x81, 0xfc, 0x53, 0x34, 0x26, 0x1b, 0x4c, 0x56, 0x0e, 0x65, 0xc3, 0x89, + 0x0b, 0x6d, 0xd0, 0x27, 0x10, 0x63, 0x8c, 0x57, 0x8c, 0x17, 0x2f, 0xa6, 0x5b, 0x2a, 0x6c, 0xc2, + 0x76, 0x48, 0x77, 0x4a, 0xe0, 0x2d, 0x7c, 0x10, 0x1f, 0x84, 0x23, 0x47, 0x4f, 0xc6, 0xc0, 0x8b, + 0x98, 0xed, 0x6e, 0x14, 0x8d, 0x07, 0x6f, 0x9d, 0x6f, 0x7e, 0xdf, 0xb4, 0x5f, 0x87, 0x76, 0xb3, + 0xb5, 0xd2, 0x73, 0xf1, 0xe4, 0xac, 0x91, 0x4a, 0x8b, 0xc4, 0x59, 0xf3, 0x28, 0x33, 0x70, 0x06, + 0xf9, 0xc2, 0x02, 0x42, 0x78, 0xec, 0x01, 0x5e, 0x01, 0x9d, 0xf6, 0x14, 0xa6, 0xe0, 0x3b, 0xa2, + 0x38, 0x95, 0x50, 0x87, 0x29, 0xc8, 0x33, 0xc8, 0x45, 0x22, 0x73, 0x2d, 0x96, 0xc3, 0x44, 0xa3, + 0x1c, 0x0a, 0x05, 0xa9, 0x29, 0xfb, 0xbd, 0x97, 0x1a, 0xa5, 0x23, 0x67, 0xcd, 0xa5, 0x9f, 0x1c, + 0xb6, 0x69, 0x23, 0x35, 0x13, 0xbd, 0x8a, 0x48, 0x4c, 0xfa, 0xf5, 0x71, 0x59, 0x84, 0x31, 0x6d, + 0x15, 0xd7, 0xdf, 0xa1, 0xb4, 0xa8, 0x27, 0x51, 0x2d, 0x26, 0xfd, 0xff, 0xe3, 0x43, 0xa9, 0x20, + 0x10, 0x50, 0xce, 0xaf, 0x17, 0xa0, 0x66, 0x79, 0xf4, 0xcf, 0xbb, 0x0f, 0xa5, 0xb0, 0x47, 0x8f, + 0x94, 0xb3, 0x56, 0x1b, 0xf4, 0x42, 0x54, 0xf7, 0xc8, 0x37, 0x2d, 0xbc, 0xa5, 0x27, 0xde, 0xf2, + 0xf5, 0xa0, 0xa8, 0x11, 0x93, 0x7e, 0xeb, 0xfc, 0x8c, 0x97, 0x31, 0x78, 0x11, 0x83, 0x57, 0x31, + 0xf8, 0x15, 0xa4, 0x66, 0x54, 0xdf, 0xbc, 0x75, 0x83, 0xf1, 0x4f, 0x5f, 0x78, 0x4f, 0x4f, 0x95, + 0xcb, 0xdc, 0x5c, 0x62, 0xba, 0xd4, 0x85, 0x8e, 0xd5, 0xc0, 0xe6, 0xdf, 0x06, 0xfe, 0xee, 0x1e, + 0xdd, 0x6c, 0x76, 0x8c, 0x6c, 0x77, 0x8c, 0xbc, 0xef, 0x18, 0x79, 0xde, 0xb3, 0x60, 0xbb, 0x67, + 0xc1, 0xeb, 0x9e, 0x05, 0x0f, 0x83, 0x69, 0x8a, 0x33, 0x97, 0x70, 0x05, 0x99, 0xf0, 0x8b, 0x19, + 0x4c, 0x20, 0x93, 0xa9, 0x29, 0x0b, 0xb1, 0xfa, 0x5c, 0x24, 0xae, 0x17, 0x3a, 0x4f, 0x9a, 0xfe, + 0xfb, 0x2f, 0x3e, 0x02, 0x00, 0x00, 0xff, 0xff, 0x34, 0xf3, 0x88, 0x10, 0xe6, 0x01, 0x00, 0x00, +} + +func (m *BurnAmount) 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 *BurnAmount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BurnAmount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.CumulativeBurntAmount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintBurnAmount(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + { + size, err := m.TotalBurnAmount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintBurnAmount(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + if m.CurrentEpoch != 0 { + i = encodeVarintBurnAmount(dAtA, i, uint64(m.CurrentEpoch)) + i-- + dAtA[i] = 0x20 + } + if m.TotalEpochs != 0 { + i = encodeVarintBurnAmount(dAtA, i, uint64(m.TotalEpochs)) + i-- + dAtA[i] = 0x18 + } + if m.BurnStarted { + i-- + if m.BurnStarted { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if m.Index != 0 { + i = encodeVarintBurnAmount(dAtA, i, uint64(m.Index)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintBurnAmount(dAtA []byte, offset int, v uint64) int { + offset -= sovBurnAmount(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *BurnAmount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Index != 0 { + n += 1 + sovBurnAmount(uint64(m.Index)) + } + if m.BurnStarted { + n += 2 + } + if m.TotalEpochs != 0 { + n += 1 + sovBurnAmount(uint64(m.TotalEpochs)) + } + if m.CurrentEpoch != 0 { + n += 1 + sovBurnAmount(uint64(m.CurrentEpoch)) + } + l = m.TotalBurnAmount.Size() + n += 1 + l + sovBurnAmount(uint64(l)) + l = m.CumulativeBurntAmount.Size() + n += 1 + l + sovBurnAmount(uint64(l)) + return n +} + +func sovBurnAmount(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozBurnAmount(x uint64) (n int) { + return sovBurnAmount(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *BurnAmount) 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 ErrIntOverflowBurnAmount + } + 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: BurnAmount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BurnAmount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) + } + m.Index = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBurnAmount + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Index |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BurnStarted", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBurnAmount + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.BurnStarted = bool(v != 0) + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalEpochs", wireType) + } + m.TotalEpochs = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBurnAmount + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TotalEpochs |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentEpoch", wireType) + } + m.CurrentEpoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBurnAmount + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CurrentEpoch |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalBurnAmount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBurnAmount + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthBurnAmount + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthBurnAmount + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TotalBurnAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CumulativeBurntAmount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBurnAmount + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthBurnAmount + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthBurnAmount + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CumulativeBurntAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipBurnAmount(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthBurnAmount + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipBurnAmount(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, ErrIntOverflowBurnAmount + } + 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, ErrIntOverflowBurnAmount + } + 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, ErrIntOverflowBurnAmount + } + 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, ErrInvalidLengthBurnAmount + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupBurnAmount + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthBurnAmount + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthBurnAmount = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowBurnAmount = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupBurnAmount = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/furnace/types/codec.go b/x/furnace/types/codec.go new file mode 100644 index 00000000..844157a8 --- /dev/null +++ b/x/furnace/types/codec.go @@ -0,0 +1,23 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + // this line is used by starport scaffolding # 1 + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterCodec(cdc *codec.LegacyAmino) { + // this line is used by starport scaffolding # 2 +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + // this line is used by starport scaffolding # 3 + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) +) diff --git a/x/furnace/types/epoch_burn_config.pb.go b/x/furnace/types/epoch_burn_config.pb.go new file mode 100644 index 00000000..aea42631 --- /dev/null +++ b/x/furnace/types/epoch_burn_config.pb.go @@ -0,0 +1,454 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: mycel/furnace/epoch_burn_config.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + github_com_cosmos_gogoproto_types "github.com/cosmos/gogoproto/types" + _ "google.golang.org/protobuf/types/known/durationpb" + _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// 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 + +type EpochBurnConfig struct { + EpochIdentifier string `protobuf:"bytes,1,opt,name=epochIdentifier,proto3" json:"epochIdentifier,omitempty"` + CurrentBurnAmountIndex uint64 `protobuf:"varint,2,opt,name=currentBurnAmountIndex,proto3" json:"currentBurnAmountIndex,omitempty"` + DefaultTotalEpochs uint64 `protobuf:"varint,3,opt,name=defaultTotalEpochs,proto3" json:"defaultTotalEpochs,omitempty"` + StartTime time.Time `protobuf:"bytes,4,opt,name=startTime,proto3,stdtime" json:"startTime" yaml:"start_time"` +} + +func (m *EpochBurnConfig) Reset() { *m = EpochBurnConfig{} } +func (m *EpochBurnConfig) String() string { return proto.CompactTextString(m) } +func (*EpochBurnConfig) ProtoMessage() {} +func (*EpochBurnConfig) Descriptor() ([]byte, []int) { + return fileDescriptor_85095d78ef169197, []int{0} +} +func (m *EpochBurnConfig) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EpochBurnConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EpochBurnConfig.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 *EpochBurnConfig) XXX_Merge(src proto.Message) { + xxx_messageInfo_EpochBurnConfig.Merge(m, src) +} +func (m *EpochBurnConfig) XXX_Size() int { + return m.Size() +} +func (m *EpochBurnConfig) XXX_DiscardUnknown() { + xxx_messageInfo_EpochBurnConfig.DiscardUnknown(m) +} + +var xxx_messageInfo_EpochBurnConfig proto.InternalMessageInfo + +func (m *EpochBurnConfig) GetEpochIdentifier() string { + if m != nil { + return m.EpochIdentifier + } + return "" +} + +func (m *EpochBurnConfig) GetCurrentBurnAmountIndex() uint64 { + if m != nil { + return m.CurrentBurnAmountIndex + } + return 0 +} + +func (m *EpochBurnConfig) GetDefaultTotalEpochs() uint64 { + if m != nil { + return m.DefaultTotalEpochs + } + return 0 +} + +func (m *EpochBurnConfig) GetStartTime() time.Time { + if m != nil { + return m.StartTime + } + return time.Time{} +} + +func init() { + proto.RegisterType((*EpochBurnConfig)(nil), "mycel.furnace.EpochBurnConfig") +} + +func init() { + proto.RegisterFile("mycel/furnace/epoch_burn_config.proto", fileDescriptor_85095d78ef169197) +} + +var fileDescriptor_85095d78ef169197 = []byte{ + // 336 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0x41, 0x4b, 0xc3, 0x30, + 0x1c, 0xc5, 0x1b, 0x1d, 0xc2, 0x2a, 0x32, 0x2c, 0x22, 0x65, 0x60, 0x3a, 0x06, 0x42, 0x2f, 0x4b, + 0x40, 0xc1, 0x83, 0x37, 0x27, 0x22, 0xbb, 0x8e, 0x81, 0xe0, 0x65, 0xa4, 0x6d, 0xda, 0x05, 0x9a, + 0xa4, 0xa4, 0x09, 0x6c, 0xdf, 0x62, 0x1f, 0x6b, 0xc7, 0x1d, 0x3d, 0x4d, 0x59, 0xbf, 0x81, 0x67, + 0x0f, 0xd2, 0x74, 0x53, 0x18, 0x7a, 0xcb, 0x3f, 0xbf, 0xf7, 0x92, 0xf7, 0xf8, 0xbb, 0xd7, 0x7c, + 0x11, 0xd3, 0x1c, 0xa7, 0x46, 0x09, 0x12, 0x53, 0x4c, 0x0b, 0x19, 0xcf, 0xa6, 0x91, 0x51, 0x62, + 0x1a, 0x4b, 0x91, 0xb2, 0x0c, 0x15, 0x4a, 0x6a, 0xe9, 0x9d, 0x59, 0x19, 0xda, 0xc9, 0xba, 0x17, + 0x99, 0xcc, 0xa4, 0x25, 0xb8, 0x3e, 0x35, 0xa2, 0x2e, 0xcc, 0xa4, 0xcc, 0x72, 0x8a, 0xed, 0x14, + 0x99, 0x14, 0x27, 0x46, 0x11, 0xcd, 0xa4, 0xd8, 0xf1, 0xe0, 0x90, 0x6b, 0xc6, 0x69, 0xa9, 0x09, + 0x2f, 0x1a, 0x41, 0xff, 0x0b, 0xb8, 0x9d, 0xa7, 0x3a, 0xc1, 0xd0, 0x28, 0xf1, 0x68, 0xff, 0xf7, + 0x42, 0xb7, 0x63, 0x43, 0x8d, 0x12, 0x2a, 0x34, 0x4b, 0x19, 0x55, 0x3e, 0xe8, 0x81, 0xb0, 0x3d, + 0x3e, 0xbc, 0xf6, 0xee, 0xdc, 0xcb, 0xd8, 0x28, 0x45, 0x85, 0xae, 0xed, 0x0f, 0x5c, 0x1a, 0xa1, + 0x47, 0x22, 0xa1, 0x73, 0xff, 0xa8, 0x07, 0xc2, 0xd6, 0xf8, 0x1f, 0xea, 0x21, 0xd7, 0x4b, 0x68, + 0x4a, 0x4c, 0xae, 0x27, 0x52, 0x93, 0xdc, 0x06, 0x28, 0xfd, 0x63, 0xeb, 0xf9, 0x83, 0x78, 0x2f, + 0x6e, 0xbb, 0xd4, 0x44, 0xe9, 0x09, 0xe3, 0xd4, 0x6f, 0xf5, 0x40, 0x78, 0x7a, 0xd3, 0x45, 0x4d, + 0x35, 0xb4, 0xaf, 0x86, 0x26, 0xfb, 0x6a, 0xc3, 0xab, 0xd5, 0x26, 0x70, 0x3e, 0x37, 0xc1, 0xf9, + 0x82, 0xf0, 0xfc, 0xbe, 0x6f, 0xad, 0xd3, 0xba, 0x79, 0x7f, 0xf9, 0x1e, 0x80, 0xf1, 0xef, 0x5b, + 0xc3, 0xe7, 0xd5, 0x16, 0x82, 0xf5, 0x16, 0x82, 0x8f, 0x2d, 0x04, 0xcb, 0x0a, 0x3a, 0xeb, 0x0a, + 0x3a, 0x6f, 0x15, 0x74, 0x5e, 0x07, 0x19, 0xd3, 0x33, 0x13, 0xa1, 0x58, 0x72, 0x6c, 0x37, 0x31, + 0x48, 0x24, 0x27, 0x4c, 0x34, 0x03, 0x9e, 0xff, 0xec, 0x4f, 0x2f, 0x0a, 0x5a, 0x46, 0x27, 0x36, + 0xc6, 0xed, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x41, 0xb4, 0xd0, 0xb1, 0xdd, 0x01, 0x00, 0x00, +} + +func (m *EpochBurnConfig) 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 *EpochBurnConfig) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EpochBurnConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n1, err1 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.StartTime):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintEpochBurnConfig(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x22 + if m.DefaultTotalEpochs != 0 { + i = encodeVarintEpochBurnConfig(dAtA, i, uint64(m.DefaultTotalEpochs)) + i-- + dAtA[i] = 0x18 + } + if m.CurrentBurnAmountIndex != 0 { + i = encodeVarintEpochBurnConfig(dAtA, i, uint64(m.CurrentBurnAmountIndex)) + i-- + dAtA[i] = 0x10 + } + if len(m.EpochIdentifier) > 0 { + i -= len(m.EpochIdentifier) + copy(dAtA[i:], m.EpochIdentifier) + i = encodeVarintEpochBurnConfig(dAtA, i, uint64(len(m.EpochIdentifier))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintEpochBurnConfig(dAtA []byte, offset int, v uint64) int { + offset -= sovEpochBurnConfig(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *EpochBurnConfig) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.EpochIdentifier) + if l > 0 { + n += 1 + l + sovEpochBurnConfig(uint64(l)) + } + if m.CurrentBurnAmountIndex != 0 { + n += 1 + sovEpochBurnConfig(uint64(m.CurrentBurnAmountIndex)) + } + if m.DefaultTotalEpochs != 0 { + n += 1 + sovEpochBurnConfig(uint64(m.DefaultTotalEpochs)) + } + l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.StartTime) + n += 1 + l + sovEpochBurnConfig(uint64(l)) + return n +} + +func sovEpochBurnConfig(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozEpochBurnConfig(x uint64) (n int) { + return sovEpochBurnConfig(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *EpochBurnConfig) 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 ErrIntOverflowEpochBurnConfig + } + 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: EpochBurnConfig: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EpochBurnConfig: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochIdentifier", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEpochBurnConfig + } + 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 ErrInvalidLengthEpochBurnConfig + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEpochBurnConfig + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EpochIdentifier = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentBurnAmountIndex", wireType) + } + m.CurrentBurnAmountIndex = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEpochBurnConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CurrentBurnAmountIndex |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DefaultTotalEpochs", wireType) + } + m.DefaultTotalEpochs = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEpochBurnConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DefaultTotalEpochs |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEpochBurnConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEpochBurnConfig + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEpochBurnConfig + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.StartTime, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEpochBurnConfig(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEpochBurnConfig + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipEpochBurnConfig(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, ErrIntOverflowEpochBurnConfig + } + 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, ErrIntOverflowEpochBurnConfig + } + 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, ErrIntOverflowEpochBurnConfig + } + 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, ErrInvalidLengthEpochBurnConfig + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupEpochBurnConfig + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthEpochBurnConfig + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthEpochBurnConfig = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowEpochBurnConfig = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupEpochBurnConfig = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/furnace/types/errors.go b/x/furnace/types/errors.go new file mode 100644 index 00000000..bc86277c --- /dev/null +++ b/x/furnace/types/errors.go @@ -0,0 +1,12 @@ +package types + +// DONTCOVER + +import ( + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +// x/furnace module sentinel errors +var ( + ErrSample = sdkerrors.Register(ModuleName, 1100, "sample error") +) diff --git a/x/furnace/types/event.go b/x/furnace/types/event.go new file mode 100644 index 00000000..fccd92a4 --- /dev/null +++ b/x/furnace/types/event.go @@ -0,0 +1,20 @@ +package types + +const ( + EventTypeEpochBurn = "epoch-burn" + + AttributeKeyEpochIdentifier = "epoch-identifier" + AttributeKeyEpochNumber = "epoch-number" + AttributeKeyBurnIndex = "burn-index" + AttributeKeyBurnTotalEpochs = "burn-total-epochs" + AttributeKeyBurnCurrentEpoch = "burn-current-epoch" + AttributeKeybBurnAmount = "burn-amount" + AttributeKeyBurnCumulativeAmount = "burn-cumulative-amount" + AttributeKeyBurnTimestamp = "burn-timestamp" +) + +const ( + EventTypeBurnAmountCreated = "burn-amount-created" + + AttributeKeyBurnAmountIndex = "burn-amount-index" +) diff --git a/x/furnace/types/expected_keepers.go b/x/furnace/types/expected_keepers.go new file mode 100644 index 00000000..30d6c3a9 --- /dev/null +++ b/x/furnace/types/expected_keepers.go @@ -0,0 +1,24 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/types" + epochstypes "github.com/mycel-domain/mycel/x/epochs/types" +) + +type EpochsKeeper interface { + // Methods imported from epochs should be defined here + GetEpochInfo(ctx sdk.Context, identifier string) (val epochstypes.EpochInfo, found bool) +} + +// AccountKeeper defines the expected account keeper used for simulations (noalias) +type AccountKeeper interface { + GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI + // Methods imported from account should be defined here +} + +// BankKeeper defines the expected interface needed to retrieve account balances. +type BankKeeper interface { + SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins + // Methods imported from bank should be defined here +} diff --git a/x/furnace/types/genesis.go b/x/furnace/types/genesis.go new file mode 100644 index 00000000..f3500fb1 --- /dev/null +++ b/x/furnace/types/genesis.go @@ -0,0 +1,56 @@ +package types + +import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/mycel-domain/mycel/app/params" + epochstypes "github.com/mycel-domain/mycel/x/epochs/types" +) + +// DefaultIndex is the default global index +const DefaultIndex uint64 = 1 + +func GetDefaultEpochBurnConfig() EpochBurnConfig { + return EpochBurnConfig{ + EpochIdentifier: epochstypes.DailyEpochId, + CurrentBurnAmountIndex: 1, + DefaultTotalEpochs: 30, + } +} + +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + EpochBurnConfig: GetDefaultEpochBurnConfig(), + BurnAmounts: []BurnAmount{ + { + Index: 0, + BurnStarted: false, + TotalEpochs: 30, + CurrentEpoch: 0, + TotalBurnAmount: sdk.NewCoin(params.DefaultBondDenom, sdk.NewInt(0)), + CumulativeBurntAmount: sdk.NewCoin(params.DefaultBondDenom, sdk.NewInt(0)), + }, + }, + // this line is used by starport scaffolding # genesis/types/default + Params: DefaultParams(), + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + // Check for duplicated index in burnAmount + burnAmountIndexMap := make(map[string]struct{}) + + for _, elem := range gs.BurnAmounts { + index := string(BurnAmountKey(elem.Index)) + if _, ok := burnAmountIndexMap[index]; ok { + return fmt.Errorf("duplicated index for burnAmount") + } + burnAmountIndexMap[index] = struct{}{} + } + // this line is used by starport scaffolding # genesis/types/validate + + return gs.Params.Validate() +} diff --git a/x/furnace/types/genesis.pb.go b/x/furnace/types/genesis.pb.go new file mode 100644 index 00000000..24797199 --- /dev/null +++ b/x/furnace/types/genesis.pb.go @@ -0,0 +1,441 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: mycel/furnace/genesis.proto + +package types + +import ( + fmt "fmt" + _ "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 + +// GenesisState defines the furnace module's genesis state. +type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + EpochBurnConfig EpochBurnConfig `protobuf:"bytes,2,opt,name=epochBurnConfig,proto3" json:"epochBurnConfig"` + BurnAmounts []BurnAmount `protobuf:"bytes,3,rep,name=burnAmounts,proto3" json:"burnAmounts"` +} + +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_cb6ac84609cb49bc, []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) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func (m *GenesisState) GetEpochBurnConfig() EpochBurnConfig { + if m != nil { + return m.EpochBurnConfig + } + return EpochBurnConfig{} +} + +func (m *GenesisState) GetBurnAmounts() []BurnAmount { + if m != nil { + return m.BurnAmounts + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "mycel.furnace.GenesisState") +} + +func init() { proto.RegisterFile("mycel/furnace/genesis.proto", fileDescriptor_cb6ac84609cb49bc) } + +var fileDescriptor_cb6ac84609cb49bc = []byte{ + // 285 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x90, 0xc1, 0x4a, 0xc3, 0x30, + 0x1c, 0xc6, 0x1b, 0x27, 0x3b, 0xb4, 0x8a, 0x50, 0x14, 0x6a, 0x85, 0x6c, 0x08, 0xc2, 0x2e, 0x6b, + 0x61, 0x7b, 0x82, 0x55, 0x64, 0x37, 0x11, 0xbd, 0x79, 0x19, 0x69, 0xcd, 0xba, 0x82, 0x49, 0x4a, + 0x9a, 0x80, 0x7b, 0x0b, 0x1f, 0x6b, 0xc7, 0x9d, 0xc4, 0x93, 0x48, 0xfb, 0x22, 0xb2, 0x7f, 0xc2, + 0x30, 0xbd, 0xb5, 0x7c, 0xbf, 0xef, 0x97, 0x8f, 0xbf, 0x7f, 0xc3, 0xb6, 0x05, 0x7d, 0x4f, 0xd7, + 0x5a, 0x72, 0x52, 0xd0, 0xb4, 0xa4, 0x9c, 0x36, 0x55, 0x93, 0xd4, 0x52, 0x28, 0x11, 0x9e, 0x43, + 0x98, 0xd8, 0x30, 0xbe, 0x2c, 0x45, 0x29, 0x20, 0x49, 0x0f, 0x5f, 0x06, 0x8a, 0x63, 0xd7, 0x50, + 0x13, 0x49, 0x98, 0x15, 0xc4, 0x77, 0x6e, 0x46, 0x6b, 0x51, 0x6c, 0x56, 0xb9, 0x96, 0x7c, 0x55, + 0x08, 0xbe, 0xae, 0x4a, 0x8b, 0x8d, 0x5c, 0x0c, 0x00, 0xc2, 0x84, 0xe6, 0xca, 0x00, 0xb7, 0x5f, + 0xc8, 0x3f, 0x5b, 0x9a, 0x69, 0x2f, 0x8a, 0x28, 0x1a, 0xce, 0xfd, 0xa1, 0x79, 0x28, 0x42, 0x63, + 0x34, 0x09, 0x66, 0x57, 0x89, 0x33, 0x35, 0x79, 0x82, 0x30, 0x3b, 0xdd, 0xfd, 0x8c, 0xbc, 0x67, + 0x8b, 0x86, 0x8f, 0xfe, 0x05, 0x2c, 0xc8, 0xb4, 0xe4, 0xf7, 0xf0, 0x7e, 0x74, 0x02, 0x6d, 0xdc, + 0x6b, 0x3f, 0xb8, 0x94, 0xd5, 0xf4, 0xcb, 0xe1, 0xc2, 0x0f, 0x0e, 0x53, 0x17, 0xb0, 0xb4, 0x89, + 0x06, 0xe3, 0xc1, 0x24, 0x98, 0x5d, 0xf7, 0x5c, 0xd9, 0x91, 0xb0, 0x9a, 0xff, 0x9d, 0x6c, 0xb9, + 0x6b, 0x31, 0xda, 0xb7, 0x18, 0xfd, 0xb6, 0x18, 0x7d, 0x76, 0xd8, 0xdb, 0x77, 0xd8, 0xfb, 0xee, + 0xb0, 0xf7, 0x3a, 0x2d, 0x2b, 0xb5, 0xd1, 0x79, 0x52, 0x08, 0x96, 0x82, 0x71, 0xfa, 0x26, 0x18, + 0xa9, 0xb8, 0xf9, 0x49, 0x3f, 0x8e, 0xd7, 0x52, 0xdb, 0x9a, 0x36, 0xf9, 0x10, 0x0e, 0x35, 0xff, + 0x0b, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x20, 0x70, 0x72, 0xd0, 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.BurnAmounts) > 0 { + for iNdEx := len(m.BurnAmounts) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.BurnAmounts[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + { + size, err := m.EpochBurnConfig.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + 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 + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + l = m.EpochBurnConfig.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.BurnAmounts) > 0 { + for _, e := range m.BurnAmounts { + 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 != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", 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 + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochBurnConfig", 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 + } + if err := m.EpochBurnConfig.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BurnAmounts", 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.BurnAmounts = append(m.BurnAmounts, BurnAmount{}) + if err := m.BurnAmounts[len(m.BurnAmounts)-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/furnace/types/genesis_test.go b/x/furnace/types/genesis_test.go new file mode 100644 index 00000000..79ebcfa7 --- /dev/null +++ b/x/furnace/types/genesis_test.go @@ -0,0 +1,66 @@ +package types_test + +import ( + "testing" + + "github.com/mycel-domain/mycel/x/furnace/types" + "github.com/stretchr/testify/require" +) + +func TestGenesisState_Validate(t *testing.T) { + tests := []struct { + desc string + genState *types.GenesisState + valid bool + }{ + { + desc: "default is valid", + genState: types.DefaultGenesis(), + valid: true, + }, + { + desc: "valid genesis state", + genState: &types.GenesisState{ + + EpochBurnConfig: types.EpochBurnConfig{ + EpochIdentifier: "35", + }, + BurnAmounts: []types.BurnAmount{ + { + Index: 0, + }, + { + Index: 1, + }, + }, + // this line is used by starport scaffolding # types/genesis/validField + }, + valid: true, + }, + { + desc: "duplicated burnAmount", + genState: &types.GenesisState{ + BurnAmounts: []types.BurnAmount{ + { + Index: 0, + }, + { + Index: 0, + }, + }, + }, + valid: false, + }, + // this line is used by starport scaffolding # types/genesis/testcase + } + for _, tc := range tests { + t.Run(tc.desc, func(t *testing.T) { + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} diff --git a/x/furnace/types/key_burn_amount.go b/x/furnace/types/key_burn_amount.go new file mode 100644 index 00000000..1f6052bd --- /dev/null +++ b/x/furnace/types/key_burn_amount.go @@ -0,0 +1,24 @@ +package types + +import "encoding/binary" + +var _ binary.ByteOrder + +const ( + // BurnAmountKeyPrefix is the prefix to retrieve all BurnAmount + BurnAmountKeyPrefix = "BurnAmount/value/" +) + +// BurnAmountKey returns the store key to retrieve a BurnAmount from the index fields +func BurnAmountKey( + index uint64, +) []byte { + var key []byte + + indexBytes := make([]byte, 8) + binary.BigEndian.PutUint64(indexBytes, index) + key = append(key, indexBytes...) + key = append(key, []byte("/")...) + + return key +} diff --git a/x/furnace/types/keys.go b/x/furnace/types/keys.go new file mode 100644 index 00000000..688a05f1 --- /dev/null +++ b/x/furnace/types/keys.go @@ -0,0 +1,23 @@ +package types + +const ( + // ModuleName defines the module name + ModuleName = "furnace" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey defines the module's message routing key + RouterKey = ModuleName + + // MemStoreKey defines the in-memory store key + MemStoreKey = "mem_furnace" +) + +func KeyPrefix(p string) []byte { + return []byte(p) +} + +const ( + EpochBurnConfigKey = "EpochBurnConfig/value/" +) diff --git a/x/furnace/types/params.go b/x/furnace/types/params.go new file mode 100644 index 00000000..357196ad --- /dev/null +++ b/x/furnace/types/params.go @@ -0,0 +1,39 @@ +package types + +import ( + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "gopkg.in/yaml.v2" +) + +var _ paramtypes.ParamSet = (*Params)(nil) + +// ParamKeyTable the param key table for launch module +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// NewParams creates a new Params instance +func NewParams() Params { + return Params{} +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams() +} + +// ParamSetPairs get the params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{} +} + +// Validate validates the set of params +func (p Params) Validate() error { + return nil +} + +// String implements the Stringer interface. +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} diff --git a/x/furnace/types/params.pb.go b/x/furnace/types/params.pb.go new file mode 100644 index 00000000..e281b5d6 --- /dev/null +++ b/x/furnace/types/params.pb.go @@ -0,0 +1,264 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: mycel/furnace/params.proto + +package types + +import ( + fmt "fmt" + _ "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 + +// Params defines the parameters for the module. +type Params struct { +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_fa04402b6ce91d3e, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Params)(nil), "mycel.furnace.Params") +} + +func init() { proto.RegisterFile("mycel/furnace/params.proto", fileDescriptor_fa04402b6ce91d3e) } + +var fileDescriptor_fa04402b6ce91d3e = []byte{ + // 150 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xca, 0xad, 0x4c, 0x4e, + 0xcd, 0xd1, 0x4f, 0x2b, 0x2d, 0xca, 0x4b, 0x4c, 0x4e, 0xd5, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, + 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x05, 0xcb, 0xe9, 0x41, 0xe5, 0xa4, 0x44, 0xd2, + 0xf3, 0xd3, 0xf3, 0xc1, 0x32, 0xfa, 0x20, 0x16, 0x44, 0x91, 0x12, 0x1f, 0x17, 0x5b, 0x00, 0x58, + 0x93, 0x15, 0xcb, 0x8c, 0x05, 0xf2, 0x0c, 0x4e, 0xee, 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, 0x9b, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x0f, + 0x36, 0x59, 0x37, 0x25, 0x3f, 0x37, 0x31, 0x33, 0x0f, 0xc2, 0xd1, 0xaf, 0x80, 0x3b, 0xa2, 0xa4, + 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0x6c, 0xbe, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x3b, 0x5a, + 0xce, 0xf9, 0xa2, 0x00, 0x00, 0x00, +} + +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) 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 ErrIntOverflowParams + } + 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/furnace/types/query.pb.go b/x/furnace/types/query.pb.go new file mode 100644 index 00000000..94c39016 --- /dev/null +++ b/x/furnace/types/query.pb.go @@ -0,0 +1,1705 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: mycel/furnace/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/types" + 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 + +// QueryParamsRequest is request type for the Query/Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_12ab24936cee5a03, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.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 *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params holds all the parameters of this module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_12ab24936cee5a03, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.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 *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +type QueryGetEpochBurnConfigRequest struct { +} + +func (m *QueryGetEpochBurnConfigRequest) Reset() { *m = QueryGetEpochBurnConfigRequest{} } +func (m *QueryGetEpochBurnConfigRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetEpochBurnConfigRequest) ProtoMessage() {} +func (*QueryGetEpochBurnConfigRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_12ab24936cee5a03, []int{2} +} +func (m *QueryGetEpochBurnConfigRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetEpochBurnConfigRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetEpochBurnConfigRequest.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 *QueryGetEpochBurnConfigRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetEpochBurnConfigRequest.Merge(m, src) +} +func (m *QueryGetEpochBurnConfigRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetEpochBurnConfigRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetEpochBurnConfigRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetEpochBurnConfigRequest proto.InternalMessageInfo + +type QueryGetEpochBurnConfigResponse struct { + EpochBurnConfig EpochBurnConfig `protobuf:"bytes,1,opt,name=EpochBurnConfig,proto3" json:"EpochBurnConfig"` +} + +func (m *QueryGetEpochBurnConfigResponse) Reset() { *m = QueryGetEpochBurnConfigResponse{} } +func (m *QueryGetEpochBurnConfigResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetEpochBurnConfigResponse) ProtoMessage() {} +func (*QueryGetEpochBurnConfigResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_12ab24936cee5a03, []int{3} +} +func (m *QueryGetEpochBurnConfigResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetEpochBurnConfigResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetEpochBurnConfigResponse.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 *QueryGetEpochBurnConfigResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetEpochBurnConfigResponse.Merge(m, src) +} +func (m *QueryGetEpochBurnConfigResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetEpochBurnConfigResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetEpochBurnConfigResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetEpochBurnConfigResponse proto.InternalMessageInfo + +func (m *QueryGetEpochBurnConfigResponse) GetEpochBurnConfig() EpochBurnConfig { + if m != nil { + return m.EpochBurnConfig + } + return EpochBurnConfig{} +} + +type QueryGetBurnAmountRequest struct { + Index uint64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"` +} + +func (m *QueryGetBurnAmountRequest) Reset() { *m = QueryGetBurnAmountRequest{} } +func (m *QueryGetBurnAmountRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetBurnAmountRequest) ProtoMessage() {} +func (*QueryGetBurnAmountRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_12ab24936cee5a03, []int{4} +} +func (m *QueryGetBurnAmountRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetBurnAmountRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetBurnAmountRequest.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 *QueryGetBurnAmountRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetBurnAmountRequest.Merge(m, src) +} +func (m *QueryGetBurnAmountRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetBurnAmountRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetBurnAmountRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetBurnAmountRequest proto.InternalMessageInfo + +func (m *QueryGetBurnAmountRequest) GetIndex() uint64 { + if m != nil { + return m.Index + } + return 0 +} + +type QueryGetBurnAmountResponse struct { + BurnAmount BurnAmount `protobuf:"bytes,1,opt,name=burnAmount,proto3" json:"burnAmount"` +} + +func (m *QueryGetBurnAmountResponse) Reset() { *m = QueryGetBurnAmountResponse{} } +func (m *QueryGetBurnAmountResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetBurnAmountResponse) ProtoMessage() {} +func (*QueryGetBurnAmountResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_12ab24936cee5a03, []int{5} +} +func (m *QueryGetBurnAmountResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetBurnAmountResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetBurnAmountResponse.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 *QueryGetBurnAmountResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetBurnAmountResponse.Merge(m, src) +} +func (m *QueryGetBurnAmountResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetBurnAmountResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetBurnAmountResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetBurnAmountResponse proto.InternalMessageInfo + +func (m *QueryGetBurnAmountResponse) GetBurnAmount() BurnAmount { + if m != nil { + return m.BurnAmount + } + return BurnAmount{} +} + +type QueryAllBurnAmountRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllBurnAmountRequest) Reset() { *m = QueryAllBurnAmountRequest{} } +func (m *QueryAllBurnAmountRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAllBurnAmountRequest) ProtoMessage() {} +func (*QueryAllBurnAmountRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_12ab24936cee5a03, []int{6} +} +func (m *QueryAllBurnAmountRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllBurnAmountRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllBurnAmountRequest.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 *QueryAllBurnAmountRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllBurnAmountRequest.Merge(m, src) +} +func (m *QueryAllBurnAmountRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAllBurnAmountRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllBurnAmountRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllBurnAmountRequest proto.InternalMessageInfo + +func (m *QueryAllBurnAmountRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryAllBurnAmountResponse struct { + BurnAmount []BurnAmount `protobuf:"bytes,1,rep,name=burnAmount,proto3" json:"burnAmount"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllBurnAmountResponse) Reset() { *m = QueryAllBurnAmountResponse{} } +func (m *QueryAllBurnAmountResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAllBurnAmountResponse) ProtoMessage() {} +func (*QueryAllBurnAmountResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_12ab24936cee5a03, []int{7} +} +func (m *QueryAllBurnAmountResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllBurnAmountResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllBurnAmountResponse.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 *QueryAllBurnAmountResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllBurnAmountResponse.Merge(m, src) +} +func (m *QueryAllBurnAmountResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAllBurnAmountResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllBurnAmountResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllBurnAmountResponse proto.InternalMessageInfo + +func (m *QueryAllBurnAmountResponse) GetBurnAmount() []BurnAmount { + if m != nil { + return m.BurnAmount + } + return nil +} + +func (m *QueryAllBurnAmountResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "mycel.furnace.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "mycel.furnace.QueryParamsResponse") + proto.RegisterType((*QueryGetEpochBurnConfigRequest)(nil), "mycel.furnace.QueryGetEpochBurnConfigRequest") + proto.RegisterType((*QueryGetEpochBurnConfigResponse)(nil), "mycel.furnace.QueryGetEpochBurnConfigResponse") + proto.RegisterType((*QueryGetBurnAmountRequest)(nil), "mycel.furnace.QueryGetBurnAmountRequest") + proto.RegisterType((*QueryGetBurnAmountResponse)(nil), "mycel.furnace.QueryGetBurnAmountResponse") + proto.RegisterType((*QueryAllBurnAmountRequest)(nil), "mycel.furnace.QueryAllBurnAmountRequest") + proto.RegisterType((*QueryAllBurnAmountResponse)(nil), "mycel.furnace.QueryAllBurnAmountResponse") +} + +func init() { proto.RegisterFile("mycel/furnace/query.proto", fileDescriptor_12ab24936cee5a03) } + +var fileDescriptor_12ab24936cee5a03 = []byte{ + // 589 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0x4f, 0x6b, 0x13, 0x41, + 0x18, 0xc6, 0xb3, 0x35, 0xcd, 0x61, 0xa4, 0x08, 0x63, 0x04, 0xb3, 0xc8, 0xa6, 0x0e, 0x6a, 0xff, + 0x40, 0x66, 0x48, 0x8b, 0x78, 0x94, 0x44, 0x34, 0xe0, 0x41, 0x6a, 0x8e, 0x82, 0x94, 0xd9, 0xed, + 0x74, 0xbb, 0xb0, 0x3b, 0xb3, 0xd9, 0x3f, 0xd2, 0x50, 0xbc, 0xf8, 0x09, 0x04, 0xf1, 0xe2, 0x07, + 0xd0, 0xaf, 0xd2, 0x63, 0xc1, 0x8b, 0x27, 0x91, 0xc4, 0x0f, 0x22, 0x99, 0x7d, 0xd3, 0x64, 0x37, + 0x9b, 0x98, 0xde, 0x92, 0x7d, 0x9f, 0xf7, 0x7d, 0x7e, 0xef, 0xce, 0xb3, 0x83, 0x1a, 0xc1, 0xd0, + 0x11, 0x3e, 0x3b, 0x4d, 0x23, 0xc9, 0x1d, 0xc1, 0x06, 0xa9, 0x88, 0x86, 0x34, 0x8c, 0x54, 0xa2, + 0xf0, 0x96, 0x2e, 0x51, 0x28, 0x99, 0x75, 0x57, 0xb9, 0x4a, 0x57, 0xd8, 0xe4, 0x57, 0x26, 0x32, + 0x1f, 0xb8, 0x4a, 0xb9, 0xbe, 0x60, 0x3c, 0xf4, 0x18, 0x97, 0x52, 0x25, 0x3c, 0xf1, 0x94, 0x8c, + 0xa1, 0xba, 0xef, 0xa8, 0x38, 0x50, 0x31, 0xb3, 0x79, 0x0c, 0xb3, 0xd9, 0x87, 0xb6, 0x2d, 0x12, + 0xde, 0x66, 0x21, 0x77, 0x3d, 0xa9, 0xc5, 0xa0, 0x35, 0xf3, 0x24, 0x21, 0x8f, 0x78, 0x30, 0x9d, + 0xf3, 0x38, 0x5f, 0x13, 0xa1, 0x72, 0xce, 0x8e, 0xed, 0x34, 0x92, 0xc7, 0x8e, 0x92, 0xa7, 0x9e, + 0x0b, 0xb2, 0x66, 0x5e, 0xa6, 0x05, 0x3c, 0x50, 0xa9, 0x4c, 0x40, 0x60, 0xcd, 0xf3, 0x4c, 0x49, + 0x1c, 0xe5, 0x01, 0x03, 0xa9, 0x23, 0xfc, 0x76, 0x42, 0x79, 0xa4, 0xcd, 0xfb, 0x62, 0x90, 0x8a, + 0x38, 0x21, 0xaf, 0xd1, 0xdd, 0xdc, 0xd3, 0x38, 0x54, 0x32, 0x16, 0xf8, 0x10, 0xd5, 0x32, 0xc8, + 0xfb, 0xc6, 0xb6, 0xb1, 0x7b, 0xfb, 0xe0, 0x1e, 0xcd, 0xbd, 0x30, 0x9a, 0xc9, 0xbb, 0xd5, 0xcb, + 0xdf, 0xcd, 0x4a, 0x1f, 0xa4, 0x64, 0x1b, 0x59, 0x7a, 0x56, 0x4f, 0x24, 0x2f, 0x27, 0x5b, 0x74, + 0xd3, 0x48, 0xbe, 0xd0, 0x3b, 0x4c, 0xdd, 0x06, 0xa8, 0xb9, 0x54, 0x01, 0xce, 0x6f, 0xd0, 0x9d, + 0x42, 0x09, 0x10, 0xac, 0x02, 0x42, 0x41, 0x05, 0x2c, 0xc5, 0x66, 0xd2, 0x46, 0x8d, 0xa9, 0xe5, + 0xe4, 0x69, 0x47, 0xbf, 0x32, 0xe0, 0xc1, 0x75, 0xb4, 0xe9, 0xc9, 0x13, 0x71, 0xae, 0x2d, 0xaa, + 0xfd, 0xec, 0x0f, 0x79, 0x8f, 0xcc, 0xb2, 0x16, 0x00, 0x7c, 0x8e, 0x90, 0x7d, 0xfd, 0x14, 0xd8, + 0x1a, 0x05, 0xb6, 0x59, 0x1b, 0x60, 0xcd, 0xb5, 0x10, 0x07, 0x88, 0x3a, 0xbe, 0xbf, 0x48, 0xf4, + 0x0a, 0xa1, 0x59, 0x7a, 0x60, 0xfa, 0x13, 0x9a, 0x1d, 0x2d, 0x9d, 0x1c, 0x2d, 0xcd, 0x62, 0x0c, + 0x07, 0x4c, 0x8f, 0xb8, 0x2b, 0xa0, 0xb7, 0x3f, 0xd7, 0x49, 0xbe, 0x1b, 0xb0, 0x44, 0xc1, 0x65, + 0xc9, 0x12, 0xb7, 0x6e, 0xb8, 0x04, 0xee, 0xe5, 0x38, 0x37, 0x34, 0xe7, 0xce, 0x7f, 0x39, 0x33, + 0xf7, 0x79, 0xd0, 0x83, 0x71, 0x15, 0x6d, 0x6a, 0x50, 0x7c, 0x81, 0x6a, 0x59, 0xac, 0xf0, 0xc3, + 0x02, 0xc9, 0x62, 0x6e, 0x4d, 0xb2, 0x4a, 0x92, 0xd9, 0x90, 0xfd, 0x4f, 0x3f, 0xff, 0x7e, 0xd9, + 0x78, 0x84, 0x09, 0xd3, 0xda, 0xd6, 0x89, 0x0a, 0xb8, 0x27, 0x59, 0xd9, 0xb7, 0x88, 0x7f, 0x18, + 0x0b, 0xb9, 0xc3, 0xad, 0x32, 0x8f, 0xa5, 0xe1, 0x36, 0xe9, 0xba, 0x72, 0xc0, 0x7b, 0xaa, 0xf1, + 0x18, 0x6e, 0xad, 0xc2, 0x5b, 0xb8, 0x0e, 0xf0, 0x37, 0x03, 0xa1, 0xd9, 0xd1, 0xe0, 0xdd, 0x25, + 0xae, 0x0b, 0xd1, 0x32, 0xf7, 0xd6, 0x50, 0x02, 0xda, 0x33, 0x8d, 0xd6, 0xc6, 0x6c, 0x15, 0xda, + 0xdc, 0x15, 0xc4, 0x2e, 0xf4, 0x97, 0xf3, 0x11, 0x7f, 0x35, 0xd0, 0xd6, 0x6c, 0x5e, 0xc7, 0xf7, + 0xcb, 0xf9, 0xca, 0xa2, 0x5f, 0xce, 0x57, 0x1a, 0x5f, 0xc2, 0x34, 0xdf, 0x1e, 0xde, 0x59, 0x93, + 0xaf, 0xdb, 0xbb, 0x1c, 0x59, 0xc6, 0xd5, 0xc8, 0x32, 0xfe, 0x8c, 0x2c, 0xe3, 0xf3, 0xd8, 0xaa, + 0x5c, 0x8d, 0xad, 0xca, 0xaf, 0xb1, 0x55, 0x79, 0xd7, 0x72, 0xbd, 0xe4, 0x2c, 0xb5, 0xa9, 0xa3, + 0x82, 0xb2, 0x61, 0xe7, 0xd7, 0xe3, 0x92, 0x61, 0x28, 0x62, 0xbb, 0xa6, 0x2f, 0xd3, 0xc3, 0x7f, + 0x01, 0x00, 0x00, 0xff, 0xff, 0xd3, 0x3e, 0xdf, 0x90, 0x5c, 0x06, 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 { + // Parameters queries the parameters of the module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // Queries a EpochBurnConfig by index. + EpochBurnConfig(ctx context.Context, in *QueryGetEpochBurnConfigRequest, opts ...grpc.CallOption) (*QueryGetEpochBurnConfigResponse, error) + // Queries a list of BurnAmount items. + BurnAmount(ctx context.Context, in *QueryGetBurnAmountRequest, opts ...grpc.CallOption) (*QueryGetBurnAmountResponse, error) + BurnAmountAll(ctx context.Context, in *QueryAllBurnAmountRequest, opts ...grpc.CallOption) (*QueryAllBurnAmountResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/mycel.furnace.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) EpochBurnConfig(ctx context.Context, in *QueryGetEpochBurnConfigRequest, opts ...grpc.CallOption) (*QueryGetEpochBurnConfigResponse, error) { + out := new(QueryGetEpochBurnConfigResponse) + err := c.cc.Invoke(ctx, "/mycel.furnace.Query/EpochBurnConfig", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) BurnAmount(ctx context.Context, in *QueryGetBurnAmountRequest, opts ...grpc.CallOption) (*QueryGetBurnAmountResponse, error) { + out := new(QueryGetBurnAmountResponse) + err := c.cc.Invoke(ctx, "/mycel.furnace.Query/BurnAmount", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) BurnAmountAll(ctx context.Context, in *QueryAllBurnAmountRequest, opts ...grpc.CallOption) (*QueryAllBurnAmountResponse, error) { + out := new(QueryAllBurnAmountResponse) + err := c.cc.Invoke(ctx, "/mycel.furnace.Query/BurnAmountAll", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Parameters queries the parameters of the module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // Queries a EpochBurnConfig by index. + EpochBurnConfig(context.Context, *QueryGetEpochBurnConfigRequest) (*QueryGetEpochBurnConfigResponse, error) + // Queries a list of BurnAmount items. + BurnAmount(context.Context, *QueryGetBurnAmountRequest) (*QueryGetBurnAmountResponse, error) + BurnAmountAll(context.Context, *QueryAllBurnAmountRequest) (*QueryAllBurnAmountResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} +func (*UnimplementedQueryServer) EpochBurnConfig(ctx context.Context, req *QueryGetEpochBurnConfigRequest) (*QueryGetEpochBurnConfigResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method EpochBurnConfig not implemented") +} +func (*UnimplementedQueryServer) BurnAmount(ctx context.Context, req *QueryGetBurnAmountRequest) (*QueryGetBurnAmountResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BurnAmount not implemented") +} +func (*UnimplementedQueryServer) BurnAmountAll(ctx context.Context, req *QueryAllBurnAmountRequest) (*QueryAllBurnAmountResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BurnAmountAll not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/mycel.furnace.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_EpochBurnConfig_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetEpochBurnConfigRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).EpochBurnConfig(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/mycel.furnace.Query/EpochBurnConfig", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).EpochBurnConfig(ctx, req.(*QueryGetEpochBurnConfigRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_BurnAmount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetBurnAmountRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).BurnAmount(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/mycel.furnace.Query/BurnAmount", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).BurnAmount(ctx, req.(*QueryGetBurnAmountRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_BurnAmountAll_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAllBurnAmountRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).BurnAmountAll(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/mycel.furnace.Query/BurnAmountAll", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).BurnAmountAll(ctx, req.(*QueryAllBurnAmountRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "mycel.furnace.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "EpochBurnConfig", + Handler: _Query_EpochBurnConfig_Handler, + }, + { + MethodName: "BurnAmount", + Handler: _Query_BurnAmount_Handler, + }, + { + MethodName: "BurnAmountAll", + Handler: _Query_BurnAmountAll_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "mycel/furnace/query.proto", +} + +func (m *QueryParamsRequest) 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 *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) 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 *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.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 *QueryGetEpochBurnConfigRequest) 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 *QueryGetEpochBurnConfigRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetEpochBurnConfigRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryGetEpochBurnConfigResponse) 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 *QueryGetEpochBurnConfigResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetEpochBurnConfigResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.EpochBurnConfig.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 *QueryGetBurnAmountRequest) 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 *QueryGetBurnAmountRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetBurnAmountRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Index != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Index)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryGetBurnAmountResponse) 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 *QueryGetBurnAmountResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetBurnAmountResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.BurnAmount.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 *QueryAllBurnAmountRequest) 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 *QueryAllBurnAmountRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllBurnAmountRequest) 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 *QueryAllBurnAmountResponse) 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 *QueryAllBurnAmountResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllBurnAmountResponse) 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.BurnAmount) > 0 { + for iNdEx := len(m.BurnAmount) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.BurnAmount[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 *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryGetEpochBurnConfigRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryGetEpochBurnConfigResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.EpochBurnConfig.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryGetBurnAmountRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Index != 0 { + n += 1 + sovQuery(uint64(m.Index)) + } + return n +} + +func (m *QueryGetBurnAmountResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.BurnAmount.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryAllBurnAmountRequest) 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 *QueryAllBurnAmountResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.BurnAmount) > 0 { + for _, e := range m.BurnAmount { + 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 *QueryParamsRequest) 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: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) 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: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", 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.Params.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 *QueryGetEpochBurnConfigRequest) 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: QueryGetEpochBurnConfigRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetEpochBurnConfigRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetEpochBurnConfigResponse) 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: QueryGetEpochBurnConfigResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetEpochBurnConfigResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochBurnConfig", 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.EpochBurnConfig.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 *QueryGetBurnAmountRequest) 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: QueryGetBurnAmountRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetBurnAmountRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) + } + m.Index = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Index |= uint64(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 *QueryGetBurnAmountResponse) 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: QueryGetBurnAmountResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetBurnAmountResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BurnAmount", 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.BurnAmount.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 *QueryAllBurnAmountRequest) 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: QueryAllBurnAmountRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllBurnAmountRequest: 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 *QueryAllBurnAmountResponse) 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: QueryAllBurnAmountResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllBurnAmountResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BurnAmount", 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.BurnAmount = append(m.BurnAmount, BurnAmount{}) + if err := m.BurnAmount[len(m.BurnAmount)-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/furnace/types/query.pb.gw.go b/x/furnace/types/query.pb.gw.go new file mode 100644 index 00000000..8b2e5df6 --- /dev/null +++ b/x/furnace/types/query.pb.gw.go @@ -0,0 +1,402 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: mycel/furnace/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_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_EpochBurnConfig_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetEpochBurnConfigRequest + var metadata runtime.ServerMetadata + + msg, err := client.EpochBurnConfig(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_EpochBurnConfig_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetEpochBurnConfigRequest + var metadata runtime.ServerMetadata + + msg, err := server.EpochBurnConfig(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_BurnAmount_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetBurnAmountRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["index"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "index") + } + + protoReq.Index, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "index", err) + } + + msg, err := client.BurnAmount(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_BurnAmount_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetBurnAmountRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["index"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "index") + } + + protoReq.Index, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "index", err) + } + + msg, err := server.BurnAmount(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_BurnAmountAll_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_BurnAmountAll_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllBurnAmountRequest + 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_BurnAmountAll_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.BurnAmountAll(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_BurnAmountAll_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllBurnAmountRequest + 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_BurnAmountAll_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.BurnAmountAll(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_Params_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_Params_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_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_EpochBurnConfig_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_EpochBurnConfig_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_EpochBurnConfig_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_BurnAmount_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_BurnAmount_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_BurnAmount_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_BurnAmountAll_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_BurnAmountAll_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_BurnAmountAll_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_Params_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_Params_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_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_EpochBurnConfig_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_EpochBurnConfig_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_EpochBurnConfig_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_BurnAmount_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_BurnAmount_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_BurnAmount_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_BurnAmountAll_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_BurnAmountAll_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_BurnAmountAll_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"mycel-domain", "mycel", "furnace", "params"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_EpochBurnConfig_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"mycel-domain", "mycel", "furnace", "epoch_burn_config"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_BurnAmount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"mycel-domain", "mycel", "furnace", "burn_amount", "index"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_BurnAmountAll_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"mycel-domain", "mycel", "furnace", "burn_amount"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_EpochBurnConfig_0 = runtime.ForwardResponseMessage + + forward_Query_BurnAmount_0 = runtime.ForwardResponseMessage + + forward_Query_BurnAmountAll_0 = runtime.ForwardResponseMessage +) diff --git a/x/furnace/types/tx.pb.go b/x/furnace/types/tx.pb.go new file mode 100644 index 00000000..8686a628 --- /dev/null +++ b/x/furnace/types/tx.pb.go @@ -0,0 +1,80 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: mycel/furnace/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + math "math" +) + +// 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 + +func init() { proto.RegisterFile("mycel/furnace/tx.proto", fileDescriptor_1ffea38d7e61c9e2) } + +var fileDescriptor_1ffea38d7e61c9e2 = []byte{ + // 126 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcb, 0xad, 0x4c, 0x4e, + 0xcd, 0xd1, 0x4f, 0x2b, 0x2d, 0xca, 0x4b, 0x4c, 0x4e, 0xd5, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, + 0x2f, 0xc9, 0x17, 0xe2, 0x05, 0x8b, 0xeb, 0x41, 0xc5, 0x8d, 0x58, 0xb9, 0x98, 0x7d, 0x8b, 0xd3, + 0x9d, 0xdc, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, + 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x37, 0x3d, 0xb3, + 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0xac, 0x55, 0x37, 0x25, 0x3f, 0x37, 0x31, + 0x33, 0x0f, 0xc2, 0xd1, 0xaf, 0x40, 0xd8, 0x50, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0xb6, 0xc5, + 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xa1, 0x70, 0xfe, 0x2c, 0x7f, 0x00, 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 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "mycel.furnace.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{}, + Streams: []grpc.StreamDesc{}, + Metadata: "mycel/furnace/tx.proto", +} diff --git a/x/furnace/types/types.go b/x/furnace/types/types.go new file mode 100644 index 00000000..ab1254f4 --- /dev/null +++ b/x/furnace/types/types.go @@ -0,0 +1 @@ +package types diff --git a/x/registry/keeper/hooks.go b/x/registry/keeper/hooks.go new file mode 100644 index 00000000..241fb386 --- /dev/null +++ b/x/registry/keeper/hooks.go @@ -0,0 +1,38 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + epochstypes "github.com/mycel-domain/mycel/x/epochs/types" +) + +// BeforeEpochStart is the epoch start hook. +func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) { +} + +// AfterEpochEnd is the epoch end hook. +func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) { +} + +// ___________________________________________________________________________________________________ + +// Hooks is the wrapper struct for the incentives keeper. +type Hooks struct { + k Keeper +} + +var _ epochstypes.EpochHooks = Hooks{} + +// Hooks returns the hook wrapper struct. +func (k Keeper) Hooks() Hooks { + return Hooks{k} +} + +// BeforeEpochStart is the epoch start hook. +func (h Hooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) { + h.k.BeforeEpochStart(ctx, epochIdentifier, epochNumber) +} + +// AfterEpochEnd is the epoch end hook. +func (h Hooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) { + h.k.AfterEpochEnd(ctx, epochIdentifier, epochNumber) +} diff --git a/x/registry/keeper/setup_test.go b/x/registry/keeper/setup_test.go index b47e1877..42335286 100644 --- a/x/registry/keeper/setup_test.go +++ b/x/registry/keeper/setup_test.go @@ -8,7 +8,6 @@ import ( "time" "github.com/mycel-domain/mycel/testutil" - epochstypes "github.com/mycel-domain/mycel/x/epochs/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/baseapp" @@ -50,16 +49,6 @@ func (suite *KeeperTestSuite) SetupTest() { // Init bank keeper suite.app.BankKeeper.InitGenesis(suite.ctx, getBankGenesis()) - // Setup epochs - identifiers := []string{epochstypes.IncentiveEpochId} - for _, identifier := range identifiers { - epoch, found := suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, identifier) - suite.Require().True(found) - epoch.StartTime = suite.ctx.BlockTime() - epoch.CurrentEpochStartHeight = suite.ctx.BlockHeight() - suite.app.EpochsKeeper.SetEpochInfo(suite.ctx, epoch) - } - } func makeBalance(address string, balance int64) banktypes.Balance { diff --git a/x/registry/types/validate_second_level_domain.go b/x/registry/types/validate_second_level_domain.go index 21e23e2a..21f91a28 100644 --- a/x/registry/types/validate_second_level_domain.go +++ b/x/registry/types/validate_second_level_domain.go @@ -86,5 +86,3 @@ func (secondLevelDomain SecondLevelDomain) IsRecordEditable(sender string) (isEd isEditable = secondLevelDomain.AccessControl[sender] == DomainRole_EDITOR || secondLevelDomain.AccessControl[sender] == DomainRole_OWNER return isEditable, err } - - diff --git a/x/resolver/client/cli/query_dns_record.go b/x/resolver/client/cli/query_dns_record.go index e134ac2d..a0c291b2 100644 --- a/x/resolver/client/cli/query_dns_record.go +++ b/x/resolver/client/cli/query_dns_record.go @@ -30,8 +30,8 @@ func CmdDnsRecord() *cobra.Command { params := &types.QueryDnsRecordRequest{ - DomainName: reqDomainName, - DomainParent: reqDomainParent, + DomainName: reqDomainName, + DomainParent: reqDomainParent, DnsRecordType: reqDnsRecordType, } diff --git a/x/resolver/keeper/query.go b/x/resolver/keeper/query.go index c7bf1a90..ab3e10d7 100644 --- a/x/resolver/keeper/query.go +++ b/x/resolver/keeper/query.go @@ -4,4 +4,4 @@ import ( "github.com/mycel-domain/mycel/x/resolver/types" ) -var _ types.QueryServer= Keeper{} +var _ types.QueryServer = Keeper{} diff --git a/x/resolver/keeper/setup_test.go b/x/resolver/keeper/setup_test.go index b47e1877..72299998 100644 --- a/x/resolver/keeper/setup_test.go +++ b/x/resolver/keeper/setup_test.go @@ -8,7 +8,6 @@ import ( "time" "github.com/mycel-domain/mycel/testutil" - epochstypes "github.com/mycel-domain/mycel/x/epochs/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/baseapp" @@ -49,17 +48,6 @@ func (suite *KeeperTestSuite) SetupTest() { // Init bank keeper suite.app.BankKeeper.InitGenesis(suite.ctx, getBankGenesis()) - - // Setup epochs - identifiers := []string{epochstypes.IncentiveEpochId} - for _, identifier := range identifiers { - epoch, found := suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, identifier) - suite.Require().True(found) - epoch.StartTime = suite.ctx.BlockTime() - epoch.CurrentEpochStartHeight = suite.ctx.BlockHeight() - suite.app.EpochsKeeper.SetEpochInfo(suite.ctx, epoch) - } - } func makeBalance(address string, balance int64) banktypes.Balance {