From 92e075493f8954f2961dc43065ae7d97e8a42ff3 Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 20 Sep 2023 13:17:21 +0200 Subject: [PATCH 01/28] rename some variable --- app/app.go | 2 +- x/epochs/keeper/hooks.go | 27 --------------------------- x/epochs/types/epoch_info.go | 30 +++++++++++++++--------------- x/epochs/types/hooks.go | 31 +++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 43 deletions(-) create mode 100644 x/epochs/types/hooks.go diff --git a/app/app.go b/app/app.go index 36eec513..f8483ffa 100644 --- a/app/app.go +++ b/app/app.go @@ -727,7 +727,7 @@ func NewApp( ) app.EpochsKeeper.SetHooks( - epochsmodulekeeper.NewMultiEpochHooks( + epochsmoduletypes.NewMultiEpochHooks( // insert hooks here )) diff --git a/x/epochs/keeper/hooks.go b/x/epochs/keeper/hooks.go index a7387f68..8fcc7a2e 100644 --- a/x/epochs/keeper/hooks.go +++ b/x/epochs/keeper/hooks.go @@ -1,36 +1,9 @@ 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 func (k Keeper) AfterEpochEnd(ctx sdk.Context, identifier string, epochNumber int64) { k.hooks.AfterEpochEnd(ctx, identifier, epochNumber) 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/hooks.go b/x/epochs/types/hooks.go new file mode 100644 index 00000000..d8d36c3e --- /dev/null +++ b/x/epochs/types/hooks.go @@ -0,0 +1,31 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + + +var _ EpochHooks = MultiEpochHooks{} + +// combine multiple epoch 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) + } +} From 57fbbb624c58000a9ef1f653c0039f8cf2b07935 Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 20 Sep 2023 13:20:39 +0200 Subject: [PATCH 02/28] add DayEpochID --- x/epochs/types/epoch_identifier.go | 3 ++- x/epochs/types/genesis.go | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/x/epochs/types/epoch_identifier.go b/x/epochs/types/epoch_identifier.go index 3a4bec15..7a4ce0ab 100644 --- a/x/epochs/types/epoch_identifier.go +++ b/x/epochs/types/epoch_identifier.go @@ -1,5 +1,6 @@ package types const ( - IncentiveEpochId = "incentive" + WeekEpochId = "week" + DayEpochId = "day" ) diff --git a/x/epochs/types/genesis.go b/x/epochs/types/genesis.go index 01347ce1..48dd79ae 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: WeekEpochId, 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: DayEpochId, + StartTime: time.Time{}, + Duration: time.Hour * 24, + CurrentEpoch: 0, + CurrentEpochStartHeight: 0, + CurrentEpochStartTime: startTime, EpochCountingStarted: false, }, }, From 509fca7ff696cd8994594a9a663d1706a339ab25 Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 20 Sep 2023 13:36:54 +0200 Subject: [PATCH 03/28] fix tests --- x/epochs/keeper/setup_test.go | 9 --------- x/registry/keeper/setup_test.go | 11 ----------- x/resolver/keeper/setup_test.go | 12 ------------ 3 files changed, 32 deletions(-) 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/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/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 { From 8e7c5d08f16547a104ad946d43fc2dd6b98ad3f4 Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 20 Sep 2023 16:27:40 +0200 Subject: [PATCH 04/28] add hook test --- go.mod | 1 + x/epochs/keeper/hooks_test.go | 96 ++++++++++++++++++++++++++++++ x/epochs/keeper/keeper.go | 6 ++ x/epochs/types/expected_keepers.go | 7 --- x/epochs/types/hooks.go | 9 ++- 5 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 x/epochs/keeper/hooks_test.go diff --git a/go.mod b/go.mod index b6c0f5e9..10a0e381 100644 --- a/go.mod +++ b/go.mod @@ -150,6 +150,7 @@ require ( github.com/spf13/afero v1.9.5 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/viper v1.16.0 // indirect + github.com/stretchr/objx v0.5.0 // indirect github.com/subosito/gotenv v1.4.2 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tendermint/go-amino v0.16.0 // indirect diff --git a/x/epochs/keeper/hooks_test.go b/x/epochs/keeper/hooks_test.go new file mode 100644 index 00000000..71e76a95 --- /dev/null +++ b/x/epochs/keeper/hooks_test.go @@ -0,0 +1,96 @@ +package keeper_test + +import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/mycel-domain/mycel/x/epochs/types" + "strconv" + "time" +) + +type MockHooks struct{} + +const ( + EpochIdentifier = types.DayEpochId + 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)), + ), + ) + } +} + +func (suite *KeeperTestSuite) TestAfterEpochHooks() { + var ( + now = time.Now() + // oneDayDuration = time.Hour * 24 + ) + testCases := []struct { + expEpochNumber string + expEventIndex int + expEventType string + + fn func() + }{ + { + expEpochNumber: "1", + expEventIndex: 1, + expEventType: BeforeEpochStartEventType, + 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.DayEpochId) + suite.Require().True(found) + suite.Require().Equal(int64(1), epochInfo.CurrentEpoch) + }, + }, + } + + for i, tc := range testCases { + suite.Run(fmt.Sprintf("Case %d", i), func() { + suite.SetupTest() + + // Remove hooks + suite.app.EpochsKeeper.RemoveHooks() + + _ = tc + + // Register hooks + hook := new(MockHooks) + suite.app.EpochsKeeper.SetHooks(hook) + + // Run test Case + tc.fn() + + // Check events + event := suite.ctx.EventManager().Events()[tc.expEventIndex] + suite.Require().Equal(tc.expEventType, event.Type) + suite.Require().Equal(EpochIdentifier, event.Attributes[0].Value) + suite.Require().Equal(tc.expEpochNumber, event.Attributes[1].Value) + }) + } + +} 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/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/hooks.go b/x/epochs/types/hooks.go index d8d36c3e..48fe3229 100644 --- a/x/epochs/types/hooks.go +++ b/x/epochs/types/hooks.go @@ -4,10 +4,16 @@ 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 epoch hooks, all hook functions are run in array sequence +// combine multiple gamm hooks, all hook functions are run in array sequence. type MultiEpochHooks []EpochHooks func NewMultiEpochHooks(hooks ...EpochHooks) MultiEpochHooks { @@ -28,4 +34,5 @@ func (h MultiEpochHooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier strin for i := range h { h[i].BeforeEpochStart(ctx, epochIdentifier, epochNumber) } + } From d7f521235bb82d5607cc3ddf440b0fc1b61dd1a3 Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 20 Sep 2023 17:53:21 +0200 Subject: [PATCH 05/28] refactor test --- go.mod | 1 - testutil/events.go | 31 ++++++++++++++ x/epochs/keeper/hooks_test.go | 81 ++++++++++++++++++++++++++++------- x/epochs/module.go | 6 ++- 4 files changed, 101 insertions(+), 18 deletions(-) create mode 100644 testutil/events.go diff --git a/go.mod b/go.mod index 10a0e381..b6c0f5e9 100644 --- a/go.mod +++ b/go.mod @@ -150,7 +150,6 @@ require ( github.com/spf13/afero v1.9.5 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/viper v1.16.0 // indirect - github.com/stretchr/objx v0.5.0 // indirect github.com/subosito/gotenv v1.4.2 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tendermint/go-amino v0.16.0 // indirect diff --git a/testutil/events.go b/testutil/events.go new file mode 100644 index 00000000..6702183a --- /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/x/epochs/keeper/hooks_test.go b/x/epochs/keeper/hooks_test.go index 71e76a95..0050a05c 100644 --- a/x/epochs/keeper/hooks_test.go +++ b/x/epochs/keeper/hooks_test.go @@ -3,6 +3,7 @@ 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" @@ -40,22 +41,47 @@ func (h *MockHooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, ep } } +type ExpEvent struct { + EpochNumber string +} + func (suite *KeeperTestSuite) TestAfterEpochHooks() { var ( - now = time.Now() - // oneDayDuration = time.Hour * 24 + now = time.Now() + oneDayDuration = time.Hour*24 + time.Second ) testCases := []struct { - expEpochNumber string - expEventIndex int - expEventType string - - fn func() + expEpochNumber string + expBeforeEpochStartEvents []ExpEvent + expAfterEpochEndEvents []ExpEvent + fn func() }{ { - expEpochNumber: "1", - expEventIndex: 1, - expEventType: BeforeEpochStartEventType, + expBeforeEpochStartEvents: []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.DayEpochId) + suite.Require().True(found) + suite.Require().Equal(int64(1), epochInfo.CurrentEpoch) + }, + }, + { + expBeforeEpochStartEvents: []ExpEvent{ + { + EpochNumber: "1", + }, + { + EpochNumber: "2", + }, + }, fn: func() { // Begin first block suite.ctx = suite.ctx.WithBlockHeight(2).WithBlockTime(now.Add(time.Second)) @@ -65,6 +91,10 @@ func (suite *KeeperTestSuite) TestAfterEpochHooks() { epochInfo, found := suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, types.DayEpochId) suite.Require().True(found) suite.Require().Equal(int64(1), epochInfo.CurrentEpoch) + + // Begin second block + suite.ctx = suite.ctx.WithBlockHeight(3).WithBlockTime(now.Add(oneDayDuration)) + suite.app.EpochsKeeper.BeginBlocker(suite.ctx) }, }, } @@ -85,11 +115,32 @@ func (suite *KeeperTestSuite) TestAfterEpochHooks() { // Run test Case tc.fn() - // Check events - event := suite.ctx.EventManager().Events()[tc.expEventIndex] - suite.Require().Equal(tc.expEventType, event.Type) - suite.Require().Equal(EpochIdentifier, event.Attributes[0].Value) - suite.Require().Equal(tc.expEpochNumber, event.Attributes[1].Value) + // 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) + } + } + + if len(tc.expAfterEpochEndEvents) != 0 { + afterEpochEndEvents, found := testutil.FindEventsByType(suite.ctx.EventManager().Events(), AfterEpochEndEventType) + suite.Require().True(found) + for i, expEvent := range tc.expBeforeEpochStartEvents { + 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/module.go b/x/epochs/module.go index 318382e5..9d451a2e 100644 --- a/x/epochs/module.go +++ b/x/epochs/module.go @@ -140,9 +140,11 @@ 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(_ 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 { +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + // am.keeper.EndBlocker(ctx) return []abci.ValidatorUpdate{} } From 7e9b570a3e68af7cc8179314f921f768de80f0e5 Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 20 Sep 2023 18:28:42 +0200 Subject: [PATCH 06/28] add Registry hooks --- app/app.go | 1 + x/epochs/keeper/abci.go | 59 +++++++++++++++++++++----------------- x/epochs/module.go | 5 ++-- x/epochs/types/hooks.go | 1 - x/registry/keeper/hooks.go | 38 ++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 30 deletions(-) create mode 100644 x/registry/keeper/hooks.go diff --git a/app/app.go b/app/app.go index f8483ffa..ba484238 100644 --- a/app/app.go +++ b/app/app.go @@ -728,6 +728,7 @@ func NewApp( app.EpochsKeeper.SetHooks( epochsmoduletypes.NewMultiEpochHooks( + app.RegistryKeeper.Hooks(), // insert hooks here )) 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/module.go b/x/epochs/module.go index 9d451a2e..a7c10c26 100644 --- a/x/epochs/module.go +++ b/x/epochs/module.go @@ -140,11 +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(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - // am.keeper.EndBlocker(ctx) + am.keeper.EndBlocker(ctx) return []abci.ValidatorUpdate{} } diff --git a/x/epochs/types/hooks.go b/x/epochs/types/hooks.go index 48fe3229..2288e663 100644 --- a/x/epochs/types/hooks.go +++ b/x/epochs/types/hooks.go @@ -34,5 +34,4 @@ func (h MultiEpochHooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier strin for i := range h { h[i].BeforeEpochStart(ctx, epochIdentifier, epochNumber) } - } 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) +} From e3d62294ea282fcbf74c37d2bda10915730c1638 Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 20 Sep 2023 19:14:18 +0200 Subject: [PATCH 07/28] change set hooks --- app/app.go | 13 +++++++------ x/epochs/keeper/hooks.go | 10 ++++++++-- x/epochs/keeper/hooks_test.go | 26 ++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/app/app.go b/app/app.go index ba484238..548904b3 100644 --- a/app/app.go +++ b/app/app.go @@ -678,6 +678,13 @@ func NewApp( keys[epochsmoduletypes.MemStoreKey], app.GetSubspace(epochsmoduletypes.ModuleName), ) + + app.EpochsKeeper.SetHooks( + epochsmoduletypes.NewMultiEpochHooks( + app.RegistryKeeper.Hooks(), + // insert hooks here + )) + epochsModule := epochsmodule.NewAppModule(appCodec, app.EpochsKeeper, app.AccountKeeper, app.BankKeeper) app.RegistryKeeper = *registrymodulekeeper.NewKeeper( @@ -726,12 +733,6 @@ func NewApp( ), ) - app.EpochsKeeper.SetHooks( - epochsmoduletypes.NewMultiEpochHooks( - app.RegistryKeeper.Hooks(), - // insert hooks here - )) - /**** Module Options ****/ // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment diff --git a/x/epochs/keeper/hooks.go b/x/epochs/keeper/hooks.go index 8fcc7a2e..5200cbf6 100644 --- a/x/epochs/keeper/hooks.go +++ b/x/epochs/keeper/hooks.go @@ -4,12 +4,18 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// 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 index 0050a05c..156aad26 100644 --- a/x/epochs/keeper/hooks_test.go +++ b/x/epochs/keeper/hooks_test.go @@ -58,6 +58,11 @@ func (suite *KeeperTestSuite) TestAfterEpochHooks() { }{ { expBeforeEpochStartEvents: []ExpEvent{ + { + EpochNumber: "2", + }, + }, + expAfterEpochEndEvents: []ExpEvent{ { EpochNumber: "1", }, @@ -70,15 +75,23 @@ func (suite *KeeperTestSuite) TestAfterEpochHooks() { // Check if curent epoch is expected epochInfo, found := suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, types.DayEpochId) suite.Require().True(found) - suite.Require().Equal(int64(1), epochInfo.CurrentEpoch) + suite.Require().Equal(int64(2), epochInfo.CurrentEpoch) }, }, { expBeforeEpochStartEvents: []ExpEvent{ { - EpochNumber: "1", + EpochNumber: "2", }, { + EpochNumber: "3", + }, + }, + expAfterEpochEndEvents: []ExpEvent{ + { + EpochNumber: "1", + }, +{ EpochNumber: "2", }, }, @@ -90,11 +103,16 @@ func (suite *KeeperTestSuite) TestAfterEpochHooks() { // Check if curent epoch is expected epochInfo, found := suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, types.DayEpochId) suite.Require().True(found) - suite.Require().Equal(int64(1), epochInfo.CurrentEpoch) + 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.DayEpochId) + suite.Require().True(found) + suite.Require().Equal(int64(3), epochInfo.CurrentEpoch) }, }, } @@ -131,7 +149,7 @@ func (suite *KeeperTestSuite) TestAfterEpochHooks() { if len(tc.expAfterEpochEndEvents) != 0 { afterEpochEndEvents, found := testutil.FindEventsByType(suite.ctx.EventManager().Events(), AfterEpochEndEventType) suite.Require().True(found) - for i, expEvent := range tc.expBeforeEpochStartEvents { + for i, expEvent := range tc.expAfterEpochEndEvents { event := afterEpochEndEvents[i] suite.Require().Equal(AfterEpochEndEventType, event.Type) suite.Require().Equal(EpochIdentifier, event.Attributes[0].Value) From 0096e16c3aa9352dee2fd301bd9d09a1bfe258a0 Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 20 Sep 2023 19:17:32 +0200 Subject: [PATCH 08/28] change epoch id --- x/epochs/keeper/hooks_test.go | 8 ++++---- x/epochs/types/epoch_identifier.go | 4 ++-- x/epochs/types/epoch_info_test.go | 8 ++++---- x/epochs/types/genesis.go | 4 ++-- x/epochs/types/genesis_test.go | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/x/epochs/keeper/hooks_test.go b/x/epochs/keeper/hooks_test.go index 156aad26..d6aa5f84 100644 --- a/x/epochs/keeper/hooks_test.go +++ b/x/epochs/keeper/hooks_test.go @@ -12,7 +12,7 @@ import ( type MockHooks struct{} const ( - EpochIdentifier = types.DayEpochId + EpochIdentifier = types.DailyEpochId BeforeEpochStartEventType = "BeforeEpochStart" AfterEpochEndEventType = "AfterEpochEnd" ) @@ -73,7 +73,7 @@ func (suite *KeeperTestSuite) TestAfterEpochHooks() { suite.app.EpochsKeeper.BeginBlocker(suite.ctx) // Check if curent epoch is expected - epochInfo, found := suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, types.DayEpochId) + epochInfo, found := suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, types.DailyEpochId) suite.Require().True(found) suite.Require().Equal(int64(2), epochInfo.CurrentEpoch) }, @@ -101,7 +101,7 @@ func (suite *KeeperTestSuite) TestAfterEpochHooks() { suite.app.EpochsKeeper.BeginBlocker(suite.ctx) // Check if curent epoch is expected - epochInfo, found := suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, types.DayEpochId) + epochInfo, found := suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, types.DailyEpochId) suite.Require().True(found) suite.Require().Equal(int64(2), epochInfo.CurrentEpoch) @@ -110,7 +110,7 @@ func (suite *KeeperTestSuite) TestAfterEpochHooks() { suite.app.EpochsKeeper.BeginBlocker(suite.ctx) // Check if curent epoch is expected - epochInfo, found = suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, types.DayEpochId) + epochInfo, found = suite.app.EpochsKeeper.GetEpochInfo(suite.ctx, types.DailyEpochId) suite.Require().True(found) suite.Require().Equal(int64(3), epochInfo.CurrentEpoch) }, diff --git a/x/epochs/types/epoch_identifier.go b/x/epochs/types/epoch_identifier.go index 7a4ce0ab..80738b57 100644 --- a/x/epochs/types/epoch_identifier.go +++ b/x/epochs/types/epoch_identifier.go @@ -1,6 +1,6 @@ package types const ( - WeekEpochId = "week" - DayEpochId = "day" + WeeklyEpochId = "weekly" + DailyEpochId = "daily" ) 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/genesis.go b/x/epochs/types/genesis.go index 48dd79ae..7c4c36b2 100644 --- a/x/epochs/types/genesis.go +++ b/x/epochs/types/genesis.go @@ -19,7 +19,7 @@ func DefaultGenesis() *GenesisState { return &GenesisState{ Epochs: []EpochInfo{ { - Identifier: WeekEpochId, + Identifier: WeeklyEpochId, StartTime: time.Time{}, Duration: time.Hour * 24 * 7, CurrentEpoch: 0, @@ -28,7 +28,7 @@ func DefaultGenesis() *GenesisState { EpochCountingStarted: false, }, { - Identifier: DayEpochId, + Identifier: DailyEpochId, StartTime: time.Time{}, Duration: time.Hour * 24, CurrentEpoch: 0, 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, From 36ba1553959d1e0fd2809f1bca0ed4da2576d48a Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 20 Sep 2023 19:29:01 +0200 Subject: [PATCH 09/28] update readme --- x/epochs/README.md | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) 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] -``` From 9a218887e516cd29687946379835df6de38e9fc3 Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 20 Sep 2023 19:32:37 +0200 Subject: [PATCH 10/28] update readme --- x/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 From 2fb3a36eba493fb18ce487e86cbbcfa8016b3976 Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 20 Sep 2023 19:48:43 +0200 Subject: [PATCH 11/28] add comment --- x/epochs/keeper/hooks_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/epochs/keeper/hooks_test.go b/x/epochs/keeper/hooks_test.go index d6aa5f84..ade40497 100644 --- a/x/epochs/keeper/hooks_test.go +++ b/x/epochs/keeper/hooks_test.go @@ -124,8 +124,6 @@ func (suite *KeeperTestSuite) TestAfterEpochHooks() { // Remove hooks suite.app.EpochsKeeper.RemoveHooks() - _ = tc - // Register hooks hook := new(MockHooks) suite.app.EpochsKeeper.SetHooks(hook) @@ -146,6 +144,7 @@ func (suite *KeeperTestSuite) TestAfterEpochHooks() { } } + // Check after epoch end events if len(tc.expAfterEpochEndEvents) != 0 { afterEpochEndEvents, found := testutil.FindEventsByType(suite.ctx.EventManager().Events(), AfterEpochEndEventType) suite.Require().True(found) From e90ed10a4d57e1c6b5245d18ad5f38170bfd0f7d Mon Sep 17 00:00:00 2001 From: tarumi Date: Thu, 21 Sep 2023 14:49:42 +0200 Subject: [PATCH 12/28] scaffold furnace module --- app/app.go | 24 + cmd/myceld/cmd/root.go | 1 - cmd/myceld/main.go | 2 +- docs/static/openapi.yml | 46 ++ proto/mycel/furnace/genesis.proto | 12 + proto/mycel/furnace/params.proto | 12 + proto/mycel/furnace/query.proto | 26 + proto/mycel/furnace/tx.proto | 7 + testutil/events.go | 2 +- testutil/keeper/furnace.go | 54 ++ x/epochs/keeper/hooks_test.go | 2 +- x/epochs/types/epoch_identifier.go | 2 +- x/furnace/client/cli/query.go | 31 + x/furnace/client/cli/query_params.go | 36 ++ x/furnace/client/cli/tx.go | 36 ++ x/furnace/genesis.go | 23 + x/furnace/genesis_test.go | 29 + x/furnace/keeper/keeper.go | 54 ++ x/furnace/keeper/msg_server.go | 17 + x/furnace/keeper/msg_server_test.go | 23 + x/furnace/keeper/params.go | 16 + x/furnace/keeper/params_test.go | 18 + x/furnace/keeper/query.go | 7 + x/furnace/keeper/query_params.go | 19 + x/furnace/keeper/query_params_test.go | 21 + x/furnace/module.go | 148 +++++ x/furnace/module_simulation.go | 64 +++ x/furnace/simulation/helpers.go | 15 + x/furnace/types/codec.go | 23 + x/furnace/types/errors.go | 12 + x/furnace/types/expected_keepers.go | 22 + x/furnace/types/genesis.go | 24 + x/furnace/types/genesis.pb.go | 320 +++++++++++ x/furnace/types/genesis_test.go | 41 ++ x/furnace/types/keys.go | 19 + x/furnace/types/params.go | 39 ++ x/furnace/types/params.pb.go | 264 +++++++++ x/furnace/types/query.pb.go | 537 ++++++++++++++++++ x/furnace/types/query.pb.gw.go | 153 +++++ x/furnace/types/tx.pb.go | 80 +++ x/furnace/types/types.go | 1 + .../types/validate_second_level_domain.go | 2 - x/resolver/client/cli/query_dns_record.go | 4 +- x/resolver/keeper/query.go | 2 +- 44 files changed, 2280 insertions(+), 10 deletions(-) create mode 100644 proto/mycel/furnace/genesis.proto create mode 100644 proto/mycel/furnace/params.proto create mode 100644 proto/mycel/furnace/query.proto create mode 100644 proto/mycel/furnace/tx.proto create mode 100644 testutil/keeper/furnace.go create mode 100644 x/furnace/client/cli/query.go create mode 100644 x/furnace/client/cli/query_params.go create mode 100644 x/furnace/client/cli/tx.go create mode 100644 x/furnace/genesis.go create mode 100644 x/furnace/genesis_test.go create mode 100644 x/furnace/keeper/keeper.go create mode 100644 x/furnace/keeper/msg_server.go create mode 100644 x/furnace/keeper/msg_server_test.go create mode 100644 x/furnace/keeper/params.go create mode 100644 x/furnace/keeper/params_test.go create mode 100644 x/furnace/keeper/query.go create mode 100644 x/furnace/keeper/query_params.go create mode 100644 x/furnace/keeper/query_params_test.go create mode 100644 x/furnace/module.go create mode 100644 x/furnace/module_simulation.go create mode 100644 x/furnace/simulation/helpers.go create mode 100644 x/furnace/types/codec.go create mode 100644 x/furnace/types/errors.go create mode 100644 x/furnace/types/expected_keepers.go create mode 100644 x/furnace/types/genesis.go create mode 100644 x/furnace/types/genesis.pb.go create mode 100644 x/furnace/types/genesis_test.go create mode 100644 x/furnace/types/keys.go create mode 100644 x/furnace/types/params.go create mode 100644 x/furnace/types/params.pb.go create mode 100644 x/furnace/types/query.pb.go create mode 100644 x/furnace/types/query.pb.gw.go create mode 100644 x/furnace/types/tx.pb.go create mode 100644 x/furnace/types/types.go diff --git a/app/app.go b/app/app.go index 548904b3..a38df082 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) @@ -707,6 +715,17 @@ func NewApp( ) resolverModule := resolvermodule.NewAppModule(appCodec, app.ResolverKeeper, app.AccountKeeper, app.BankKeeper) + app.FurnaceKeeper = *furnacemodulekeeper.NewKeeper( + appCodec, + keys[furnacemoduletypes.StoreKey], + keys[furnacemoduletypes.MemStoreKey], + app.GetSubspace(furnacemoduletypes.ModuleName), + + app.BankKeeper, + app.EpochsKeeper, + ) + furnaceModule := furnacemodule.NewAppModule(appCodec, app.FurnaceKeeper, app.AccountKeeper, app.BankKeeper) + // this line is used by starport scaffolding # stargate/app/keeperDefinition /**** IBC Routing ****/ @@ -774,6 +793,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 @@ -812,6 +832,7 @@ func NewApp( registrymoduletypes.ModuleName, epochsmoduletypes.ModuleName, resolvermoduletypes.ModuleName, + furnacemoduletypes.ModuleName, // this line is used by starport scaffolding # stargate/app/beginBlockers ) @@ -843,6 +864,7 @@ func NewApp( registrymoduletypes.ModuleName, epochsmoduletypes.ModuleName, resolvermoduletypes.ModuleName, + furnacemoduletypes.ModuleName, // this line is used by starport scaffolding # stargate/app/endBlockers ) @@ -880,6 +902,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...) @@ -1143,6 +1166,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..6421814a 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -49691,6 +49691,42 @@ paths: 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 +80681,16 @@ 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.Params: + type: object + description: Params defines the parameters for the module. + 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/genesis.proto b/proto/mycel/furnace/genesis.proto new file mode 100644 index 00000000..b6bde79a --- /dev/null +++ b/proto/mycel/furnace/genesis.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package mycel.furnace; + +import "gogoproto/gogo.proto"; +import "mycel/furnace/params.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]; +} 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..89df4745 --- /dev/null +++ b/proto/mycel/furnace/query.proto @@ -0,0 +1,26 @@ +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"; + +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"; + } +} + +// 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]; +} \ No newline at end of file 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 index 6702183a..01f70de2 100644 --- a/testutil/events.go +++ b/testutil/events.go @@ -7,7 +7,7 @@ import ( func FindEventsByType(events []sdk.Event, eventType string) (foundEvents []sdk.Event, found bool) { for _, event := range events { if event.Type == eventType { - foundEvents = append(foundEvents, event) + foundEvents = append(foundEvents, event) } } found = len(foundEvents) > 0 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/epochs/keeper/hooks_test.go b/x/epochs/keeper/hooks_test.go index ade40497..d1c879b7 100644 --- a/x/epochs/keeper/hooks_test.go +++ b/x/epochs/keeper/hooks_test.go @@ -91,7 +91,7 @@ func (suite *KeeperTestSuite) TestAfterEpochHooks() { { EpochNumber: "1", }, -{ + { EpochNumber: "2", }, }, diff --git a/x/epochs/types/epoch_identifier.go b/x/epochs/types/epoch_identifier.go index 80738b57..bea49877 100644 --- a/x/epochs/types/epoch_identifier.go +++ b/x/epochs/types/epoch_identifier.go @@ -2,5 +2,5 @@ package types const ( WeeklyEpochId = "weekly" - DailyEpochId = "daily" + DailyEpochId = "daily" ) diff --git a/x/furnace/client/cli/query.go b/x/furnace/client/cli/query.go new file mode 100644 index 00000000..edbe5203 --- /dev/null +++ b/x/furnace/client/cli/query.go @@ -0,0 +1,31 @@ +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()) + // this line is used by starport scaffolding # 1 + + return cmd +} 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..7a915ec8 --- /dev/null +++ b/x/furnace/genesis.go @@ -0,0 +1,23 @@ +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) { + // 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) + + // 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..d372c265 --- /dev/null +++ b/x/furnace/genesis_test.go @@ -0,0 +1,29 @@ +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(), + + // 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) + + // this line is used by starport scaffolding # genesis/test/assert +} 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_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/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/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/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/expected_keepers.go b/x/furnace/types/expected_keepers.go new file mode 100644 index 00000000..e496643a --- /dev/null +++ b/x/furnace/types/expected_keepers.go @@ -0,0 +1,22 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +type EpochsKeeper interface { + // Methods imported from epochs should be defined here +} + +// 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..0af9b441 --- /dev/null +++ b/x/furnace/types/genesis.go @@ -0,0 +1,24 @@ +package types + +import ( +// this line is used by starport scaffolding # genesis/types/import +) + +// DefaultIndex is the default global index +const DefaultIndex uint64 = 1 + +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + // 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 { + // 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..e9d84319 --- /dev/null +++ b/x/furnace/types/genesis.pb.go @@ -0,0 +1,320 @@ +// 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"` +} + +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 init() { + proto.RegisterType((*GenesisState)(nil), "mycel.furnace.GenesisState") +} + +func init() { proto.RegisterFile("mycel/furnace/genesis.proto", fileDescriptor_cb6ac84609cb49bc) } + +var fileDescriptor_cb6ac84609cb49bc = []byte{ + // 192 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xce, 0xad, 0x4c, 0x4e, + 0xcd, 0xd1, 0x4f, 0x2b, 0x2d, 0xca, 0x4b, 0x4c, 0x4e, 0xd5, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, + 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x05, 0x4b, 0xea, 0x41, 0x25, 0xa5, 0x44, + 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x32, 0xfa, 0x20, 0x16, 0x44, 0x91, 0x94, 0x14, 0xaa, 0x09, 0x05, + 0x89, 0x45, 0x89, 0xb9, 0x50, 0x03, 0x94, 0x9c, 0xb9, 0x78, 0xdc, 0x21, 0x26, 0x06, 0x97, 0x24, + 0x96, 0xa4, 0x0a, 0x19, 0x73, 0xb1, 0x41, 0xe4, 0x25, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0x44, + 0xf5, 0x50, 0x6c, 0xd0, 0x0b, 0x00, 0x4b, 0x3a, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x04, 0x55, + 0xea, 0xe4, 0x7e, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, + 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xba, 0xe9, 0x99, + 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x60, 0x83, 0x74, 0x53, 0xf2, 0x73, 0x13, + 0x33, 0xf3, 0x20, 0x1c, 0xfd, 0x0a, 0xb8, 0xa3, 0x4a, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, + 0x8e, 0x32, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x6f, 0x03, 0xf6, 0xa3, 0xf4, 0x00, 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 + { + 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)) + 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 + 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..d1d7b59c --- /dev/null +++ b/x/furnace/types/genesis_test.go @@ -0,0 +1,41 @@ +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{ + + // this line is used by starport scaffolding # types/genesis/validField + }, + valid: true, + }, + // 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/keys.go b/x/furnace/types/keys.go new file mode 100644 index 00000000..180b8b21 --- /dev/null +++ b/x/furnace/types/keys.go @@ -0,0 +1,19 @@ +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) +} 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..dba6c93c --- /dev/null +++ b/x/furnace/types/query.pb.go @@ -0,0 +1,537 @@ +// 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/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{} +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "mycel.furnace.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "mycel.furnace.QueryParamsResponse") +} + +func init() { proto.RegisterFile("mycel/furnace/query.proto", fileDescriptor_12ab24936cee5a03) } + +var fileDescriptor_12ab24936cee5a03 = []byte{ + // 299 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x90, 0xc1, 0x4a, 0xc3, 0x30, + 0x18, 0xc7, 0x1b, 0xd1, 0x1d, 0x22, 0x5e, 0xe2, 0x04, 0x2d, 0x12, 0xb5, 0x78, 0x90, 0xc1, 0x1a, + 0xb6, 0xbd, 0xc1, 0x2e, 0x82, 0x27, 0xdd, 0xd1, 0x5b, 0x5a, 0x63, 0x2c, 0xac, 0xf9, 0xb2, 0x26, + 0x15, 0x87, 0x37, 0xf1, 0x01, 0x04, 0x5f, 0x6a, 0xc7, 0x81, 0x17, 0x4f, 0x22, 0xad, 0x0f, 0x22, + 0x4b, 0x83, 0x50, 0x1d, 0xde, 0xc2, 0xf7, 0xff, 0x7d, 0x3f, 0xfe, 0x5f, 0xf0, 0x41, 0x3e, 0x4f, + 0xc5, 0x94, 0xdd, 0x96, 0x85, 0xe2, 0xa9, 0x60, 0xb3, 0x52, 0x14, 0xf3, 0x58, 0x17, 0x60, 0x81, + 0xec, 0xb8, 0x28, 0xf6, 0x51, 0xd8, 0x95, 0x20, 0xc1, 0x25, 0x6c, 0xf5, 0x6a, 0xa0, 0xf0, 0x50, + 0x02, 0xc8, 0xa9, 0x60, 0x5c, 0x67, 0x8c, 0x2b, 0x05, 0x96, 0xdb, 0x0c, 0x94, 0xf1, 0x69, 0x2f, + 0x05, 0x93, 0x83, 0x61, 0x09, 0x37, 0xde, 0xcd, 0xee, 0x07, 0x89, 0xb0, 0x7c, 0xc0, 0x34, 0x97, + 0x99, 0x72, 0xb0, 0x67, 0xc3, 0x76, 0x13, 0xcd, 0x0b, 0x9e, 0x7b, 0x4f, 0xd4, 0xc5, 0xe4, 0x6a, + 0xb5, 0x7d, 0xe9, 0x86, 0x13, 0x31, 0x2b, 0x85, 0xb1, 0xd1, 0x05, 0xde, 0x6d, 0x4d, 0x8d, 0x06, + 0x65, 0x04, 0x19, 0xe1, 0x4e, 0xb3, 0xbc, 0x8f, 0x8e, 0xd1, 0xd9, 0xf6, 0x70, 0x2f, 0x6e, 0x1d, + 0x12, 0x37, 0xf8, 0x78, 0x73, 0xf1, 0x71, 0x14, 0x4c, 0x3c, 0x3a, 0x7c, 0x46, 0x78, 0xcb, 0xc9, + 0xc8, 0x23, 0xee, 0x34, 0x04, 0x39, 0xf9, 0xb5, 0xf8, 0xb7, 0x42, 0x18, 0xfd, 0x87, 0x34, 0x7d, + 0xa2, 0xde, 0xd3, 0xdb, 0xd7, 0xeb, 0xc6, 0x29, 0x89, 0x98, 0x63, 0xfb, 0x37, 0x90, 0xf3, 0x4c, + 0xb1, 0x75, 0xe7, 0x8e, 0xcf, 0x17, 0x15, 0x45, 0xcb, 0x8a, 0xa2, 0xcf, 0x8a, 0xa2, 0x97, 0x9a, + 0x06, 0xcb, 0x9a, 0x06, 0xef, 0x35, 0x0d, 0xae, 0xfb, 0x32, 0xb3, 0x77, 0x65, 0x12, 0xa7, 0x90, + 0xaf, 0xf3, 0x3c, 0xfc, 0x98, 0xec, 0x5c, 0x0b, 0x93, 0x74, 0xdc, 0xc7, 0x8d, 0xbe, 0x03, 0x00, + 0x00, 0xff, 0xff, 0xa0, 0x12, 0x7a, 0x15, 0xe0, 0x01, 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) +} + +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 +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Parameters queries the parameters of the module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, 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 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) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "mycel.furnace.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_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 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 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 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..02c78981 --- /dev/null +++ b/x/furnace/types/query.pb.gw.go @@ -0,0 +1,153 @@ +// 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 + +} + +// 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()...) + + }) + + 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()...) + + }) + + 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))) +) + +var ( + forward_Query_Params_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/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{} From 7af44756f233bc2b4399b1c3702207b487dd88ca Mon Sep 17 00:00:00 2001 From: tarumi Date: Thu, 21 Sep 2023 15:49:10 +0200 Subject: [PATCH 13/28] scaffold EpochBurnConfig --- docs/static/openapi.yml | 48 ++ proto/mycel/furnace/epoch_burn_config.proto | 25 + proto/mycel/furnace/genesis.proto | 6 +- proto/mycel/furnace/query.proto | 23 +- x/furnace/client/cli/query.go | 1 + .../client/cli/query_epoch_burn_config.go | 38 ++ .../cli/query_epoch_burn_config_test.go | 71 +++ x/furnace/genesis.go | 9 + x/furnace/genesis_test.go | 4 + x/furnace/keeper/epoch_burn_config.go | 33 ++ x/furnace/keeper/epoch_burn_config_test.go | 38 ++ x/furnace/keeper/query_epoch_burn_config.go | 24 + .../keeper/query_epoch_burn_config_test.go | 50 ++ x/furnace/types/epoch_burn_config.pb.go | 472 ++++++++++++++++++ x/furnace/types/genesis.go | 1 + x/furnace/types/genesis.pb.go | 84 +++- x/furnace/types/genesis_test.go | 5 +- x/furnace/types/keys.go | 4 + x/furnace/types/query.pb.go | 375 +++++++++++++- x/furnace/types/query.pb.gw.go | 65 +++ 20 files changed, 1341 insertions(+), 35 deletions(-) create mode 100644 proto/mycel/furnace/epoch_burn_config.proto create mode 100644 x/furnace/client/cli/query_epoch_burn_config.go create mode 100644 x/furnace/client/cli/query_epoch_burn_config_test.go create mode 100644 x/furnace/keeper/epoch_burn_config.go create mode 100644 x/furnace/keeper/epoch_burn_config_test.go create mode 100644 x/furnace/keeper/query_epoch_burn_config.go create mode 100644 x/furnace/keeper/query_epoch_burn_config_test.go create mode 100644 x/furnace/types/epoch_burn_config.pb.go diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index 6421814a..7fd4bc05 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -49691,6 +49691,41 @@ paths: additionalProperties: {} 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 + 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. @@ -80681,9 +80716,22 @@ 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.EpochBurnConfig: + type: object + properties: + epochIdentifier: + type: string mycel.furnace.Params: type: object description: Params defines the parameters for the module. + mycel.furnace.QueryGetEpochBurnConfigResponse: + type: object + properties: + EpochBurnConfig: + type: object + properties: + epochIdentifier: + type: string mycel.furnace.QueryParamsResponse: type: object properties: diff --git a/proto/mycel/furnace/epoch_burn_config.proto b/proto/mycel/furnace/epoch_burn_config.proto new file mode 100644 index 00000000..76642e41 --- /dev/null +++ b/proto/mycel/furnace/epoch_burn_config.proto @@ -0,0 +1,25 @@ +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 currentBurnAmountIdentifier = 2; + google.protobuf.Timestamp startTime = 3 [ + (gogoproto.stdtime) = true, + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"start_time\"" + ]; + google.protobuf.Duration duration = 4[ + (gogoproto.nullable) = false, + (gogoproto.stdduration) = true, + (gogoproto.jsontag) = "duration,omitempty", + (gogoproto.moretags) = "yaml:\"duration\"" + ]; +} diff --git a/proto/mycel/furnace/genesis.proto b/proto/mycel/furnace/genesis.proto index b6bde79a..75ad49e1 100644 --- a/proto/mycel/furnace/genesis.proto +++ b/proto/mycel/furnace/genesis.proto @@ -1,12 +1,16 @@ syntax = "proto3"; + package mycel.furnace; import "gogoproto/gogo.proto"; import "mycel/furnace/params.proto"; +import "mycel/furnace/epoch_burn_config.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]; + Params params = 1 [(gogoproto.nullable) = false]; + EpochBurnConfig epochBurnConfig = 2; } + diff --git a/proto/mycel/furnace/query.proto b/proto/mycel/furnace/query.proto index 89df4745..ec6594ca 100644 --- a/proto/mycel/furnace/query.proto +++ b/proto/mycel/furnace/query.proto @@ -1,26 +1,43 @@ 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"; 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) { + 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"; + } } - // 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]; -} \ No newline at end of file +} + +message QueryGetEpochBurnConfigRequest {} + +message QueryGetEpochBurnConfigResponse { + EpochBurnConfig EpochBurnConfig = 1 [(gogoproto.nullable) = false]; +} + diff --git a/x/furnace/client/cli/query.go b/x/furnace/client/cli/query.go index edbe5203..ea584e42 100644 --- a/x/furnace/client/cli/query.go +++ b/x/furnace/client/cli/query.go @@ -25,6 +25,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command { } cmd.AddCommand(CmdQueryParams()) + cmd.AddCommand(CmdShowEpochBurnConfig()) // this line is used by starport scaffolding # 1 return cmd 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..1b5e198c --- /dev/null +++ b/x/furnace/client/cli/query_epoch_burn_config_test.go @@ -0,0 +1,71 @@ +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) + require.Equal(t, + nullify.Fill(&tc.obj), + nullify.Fill(&resp.EpochBurnConfig), + ) + } + }) + } +} diff --git a/x/furnace/genesis.go b/x/furnace/genesis.go index 7a915ec8..5fe26b03 100644 --- a/x/furnace/genesis.go +++ b/x/furnace/genesis.go @@ -8,6 +8,10 @@ import ( // InitGenesis initializes the module's state from a provided genesis state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + // Set if defined + if genState.EpochBurnConfig != nil { + k.SetEpochBurnConfig(ctx, *genState.EpochBurnConfig) + } // this line is used by starport scaffolding # genesis/module/init k.SetParams(ctx, genState.Params) } @@ -17,6 +21,11 @@ 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 + } // 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 index d372c265..38eec21e 100644 --- a/x/furnace/genesis_test.go +++ b/x/furnace/genesis_test.go @@ -14,6 +14,9 @@ func TestGenesis(t *testing.T) { genesisState := types.GenesisState{ Params: types.DefaultParams(), + EpochBurnConfig: &types.EpochBurnConfig{ + EpochIdentifier: "11", + }, // this line is used by starport scaffolding # genesis/test/state } @@ -25,5 +28,6 @@ func TestGenesis(t *testing.T) { nullify.Fill(&genesisState) nullify.Fill(got) + require.Equal(t, genesisState.EpochBurnConfig, got.EpochBurnConfig) // this line is used by starport scaffolding # genesis/test/assert } 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/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/types/epoch_burn_config.pb.go b/x/furnace/types/epoch_burn_config.pb.go new file mode 100644 index 00000000..152a07fb --- /dev/null +++ b/x/furnace/types/epoch_burn_config.pb.go @@ -0,0 +1,472 @@ +// 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"` + CurrentBurnAmountIdentifier uint64 `protobuf:"varint,2,opt,name=currentBurnAmountIdentifier,proto3" json:"currentBurnAmountIdentifier,omitempty"` + StartTime time.Time `protobuf:"bytes,3,opt,name=startTime,proto3,stdtime" json:"startTime" yaml:"start_time"` + Duration time.Duration `protobuf:"bytes,4,opt,name=duration,proto3,stdduration" json:"duration,omitempty" yaml:"duration"` +} + +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) GetCurrentBurnAmountIdentifier() uint64 { + if m != nil { + return m.CurrentBurnAmountIdentifier + } + return 0 +} + +func (m *EpochBurnConfig) GetStartTime() time.Time { + if m != nil { + return m.StartTime + } + return time.Time{} +} + +func (m *EpochBurnConfig) GetDuration() time.Duration { + if m != nil { + return m.Duration + } + return 0 +} + +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{ + // 360 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x52, 0x4d, 0x4b, 0xf3, 0x30, + 0x1c, 0x6f, 0xf6, 0x8c, 0x07, 0x57, 0x91, 0x61, 0xf1, 0x30, 0x27, 0xa6, 0xa3, 0x20, 0xf4, 0xe0, + 0x1a, 0xd4, 0x9b, 0x27, 0xad, 0x8a, 0x78, 0x1d, 0x03, 0xc1, 0xcb, 0x68, 0xbb, 0xb4, 0x0b, 0x2c, + 0x49, 0xc9, 0x12, 0xb0, 0xdf, 0x62, 0x47, 0x3f, 0x8e, 0xc7, 0x1d, 0x77, 0xf4, 0x54, 0x65, 0xbb, + 0x79, 0xdc, 0x27, 0x90, 0xa6, 0xeb, 0x94, 0x09, 0xde, 0xf2, 0xcf, 0xef, 0x35, 0x2f, 0xe6, 0x09, + 0xcd, 0x22, 0x3c, 0x46, 0xb1, 0x12, 0x2c, 0x88, 0x30, 0xc2, 0x29, 0x8f, 0x46, 0x83, 0x50, 0x09, + 0x36, 0x88, 0x38, 0x8b, 0x49, 0xe2, 0xa5, 0x82, 0x4b, 0x6e, 0xed, 0x69, 0x9a, 0xb7, 0xa6, 0xb5, + 0x0f, 0x12, 0x9e, 0x70, 0x8d, 0xa0, 0x62, 0x55, 0x92, 0xda, 0x30, 0xe1, 0x3c, 0x19, 0x63, 0xa4, + 0xa7, 0x50, 0xc5, 0x68, 0xa8, 0x44, 0x20, 0x09, 0x67, 0x6b, 0xdc, 0xde, 0xc6, 0x25, 0xa1, 0x78, + 0x22, 0x03, 0x9a, 0x96, 0x04, 0xe7, 0xb5, 0x66, 0x36, 0xef, 0x8a, 0x06, 0xbe, 0x12, 0xec, 0x46, + 0xe7, 0x5b, 0xae, 0xd9, 0xd4, 0xa5, 0x1e, 0x86, 0x98, 0x49, 0x12, 0x13, 0x2c, 0x5a, 0xa0, 0x03, + 0xdc, 0x46, 0x6f, 0x7b, 0xdb, 0xba, 0x32, 0x8f, 0x22, 0x25, 0x04, 0x66, 0xb2, 0x90, 0x5f, 0x53, + 0xae, 0x98, 0xfc, 0xa1, 0xaa, 0x75, 0x80, 0x5b, 0xef, 0xfd, 0x45, 0xb1, 0x1e, 0xcd, 0xc6, 0x44, + 0x06, 0x42, 0xf6, 0x09, 0xc5, 0xad, 0x7f, 0x1d, 0xe0, 0xee, 0x9e, 0xb7, 0xbd, 0xb2, 0xb4, 0x57, + 0x95, 0xf6, 0xfa, 0x55, 0x69, 0xff, 0x78, 0x96, 0xdb, 0xc6, 0x2a, 0xb7, 0xf7, 0xb3, 0x80, 0x8e, + 0x2f, 0x1d, 0x2d, 0x1d, 0x14, 0x67, 0x72, 0xa6, 0xef, 0x36, 0xe8, 0x7d, 0x7b, 0x59, 0x23, 0x73, + 0xa7, 0xba, 0x8b, 0x56, 0x5d, 0xfb, 0x1e, 0xfe, 0xf2, 0xbd, 0x5d, 0x13, 0xfc, 0xb3, 0xc2, 0xf6, + 0x33, 0xb7, 0xad, 0x4a, 0x72, 0xca, 0x29, 0x91, 0x98, 0xa6, 0x32, 0x5b, 0xe5, 0x76, 0xb3, 0x0c, + 0xab, 0x30, 0xe7, 0xa5, 0x88, 0xda, 0xb8, 0xfb, 0xf7, 0xb3, 0x05, 0x04, 0xf3, 0x05, 0x04, 0x1f, + 0x0b, 0x08, 0xa6, 0x4b, 0x68, 0xcc, 0x97, 0xd0, 0x78, 0x5b, 0x42, 0xe3, 0xa9, 0x9b, 0x10, 0x39, + 0x52, 0xa1, 0x17, 0x71, 0x8a, 0xf4, 0x6b, 0x76, 0x87, 0x9c, 0x06, 0x84, 0x95, 0x03, 0x7a, 0xde, + 0xfc, 0x01, 0x99, 0xa5, 0x78, 0x12, 0xfe, 0xd7, 0xc5, 0x2e, 0xbe, 0x02, 0x00, 0x00, 0xff, 0xff, + 0x91, 0xcc, 0x10, 0x39, 0x21, 0x02, 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.StdDurationMarshalTo(m.Duration, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.Duration):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintEpochBurnConfig(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x22 + n2, err2 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.StartTime):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintEpochBurnConfig(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x1a + if m.CurrentBurnAmountIdentifier != 0 { + i = encodeVarintEpochBurnConfig(dAtA, i, uint64(m.CurrentBurnAmountIdentifier)) + 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.CurrentBurnAmountIdentifier != 0 { + n += 1 + sovEpochBurnConfig(uint64(m.CurrentBurnAmountIdentifier)) + } + l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.StartTime) + n += 1 + l + sovEpochBurnConfig(uint64(l)) + l = github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.Duration) + 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 CurrentBurnAmountIdentifier", wireType) + } + m.CurrentBurnAmountIdentifier = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEpochBurnConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CurrentBurnAmountIdentifier |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + 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 + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Duration", 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.StdDurationUnmarshal(&m.Duration, 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/genesis.go b/x/furnace/types/genesis.go index 0af9b441..efd10f6f 100644 --- a/x/furnace/types/genesis.go +++ b/x/furnace/types/genesis.go @@ -10,6 +10,7 @@ const DefaultIndex uint64 = 1 // DefaultGenesis returns the default genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ + EpochBurnConfig: nil, // this line is used by starport scaffolding # genesis/types/default Params: DefaultParams(), } diff --git a/x/furnace/types/genesis.pb.go b/x/furnace/types/genesis.pb.go index e9d84319..950853fb 100644 --- a/x/furnace/types/genesis.pb.go +++ b/x/furnace/types/genesis.pb.go @@ -25,7 +25,8 @@ 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"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + EpochBurnConfig *EpochBurnConfig `protobuf:"bytes,2,opt,name=epochBurnConfig,proto3" json:"epochBurnConfig,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -68,6 +69,13 @@ func (m *GenesisState) GetParams() Params { return Params{} } +func (m *GenesisState) GetEpochBurnConfig() *EpochBurnConfig { + if m != nil { + return m.EpochBurnConfig + } + return nil +} + func init() { proto.RegisterType((*GenesisState)(nil), "mycel.furnace.GenesisState") } @@ -75,19 +83,23 @@ func init() { func init() { proto.RegisterFile("mycel/furnace/genesis.proto", fileDescriptor_cb6ac84609cb49bc) } var fileDescriptor_cb6ac84609cb49bc = []byte{ - // 192 bytes of a gzipped FileDescriptorProto + // 243 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xce, 0xad, 0x4c, 0x4e, 0xcd, 0xd1, 0x4f, 0x2b, 0x2d, 0xca, 0x4b, 0x4c, 0x4e, 0xd5, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x05, 0x4b, 0xea, 0x41, 0x25, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x32, 0xfa, 0x20, 0x16, 0x44, 0x91, 0x94, 0x14, 0xaa, 0x09, 0x05, - 0x89, 0x45, 0x89, 0xb9, 0x50, 0x03, 0x94, 0x9c, 0xb9, 0x78, 0xdc, 0x21, 0x26, 0x06, 0x97, 0x24, - 0x96, 0xa4, 0x0a, 0x19, 0x73, 0xb1, 0x41, 0xe4, 0x25, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0x44, - 0xf5, 0x50, 0x6c, 0xd0, 0x0b, 0x00, 0x4b, 0x3a, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x04, 0x55, - 0xea, 0xe4, 0x7e, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, - 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xba, 0xe9, 0x99, - 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x60, 0x83, 0x74, 0x53, 0xf2, 0x73, 0x13, - 0x33, 0xf3, 0x20, 0x1c, 0xfd, 0x0a, 0xb8, 0xa3, 0x4a, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, - 0x8e, 0x32, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x6f, 0x03, 0xf6, 0xa3, 0xf4, 0x00, 0x00, 0x00, + 0x89, 0x45, 0x89, 0xb9, 0x50, 0x03, 0xa4, 0x54, 0x51, 0xe5, 0x52, 0x0b, 0xf2, 0x93, 0x33, 0xe2, + 0x93, 0x4a, 0x8b, 0xf2, 0xe2, 0x93, 0xf3, 0xf3, 0xd2, 0x32, 0xd3, 0x21, 0xca, 0x94, 0x7a, 0x19, + 0xb9, 0x78, 0xdc, 0x21, 0x36, 0x07, 0x97, 0x24, 0x96, 0xa4, 0x0a, 0x19, 0x73, 0xb1, 0x41, 0xcc, + 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x36, 0x12, 0xd5, 0x43, 0x71, 0x89, 0x5e, 0x00, 0x58, 0xd2, + 0x89, 0xe5, 0xc4, 0x3d, 0x79, 0x86, 0x20, 0xa8, 0x52, 0x21, 0x0f, 0x2e, 0x7e, 0xb0, 0x05, 0x4e, + 0xa5, 0x45, 0x79, 0xce, 0x60, 0xe3, 0x25, 0x98, 0xc0, 0xba, 0xe5, 0xd0, 0x74, 0xbb, 0xa2, 0xaa, + 0x0a, 0x42, 0xd7, 0xe6, 0xe4, 0x7e, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, + 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, + 0xba, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x60, 0x43, 0x75, 0x53, + 0xf2, 0x73, 0x13, 0x33, 0xf3, 0x20, 0x1c, 0xfd, 0x0a, 0xb8, 0x57, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, + 0x93, 0xd8, 0xc0, 0xfe, 0x33, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xb1, 0xed, 0x0a, 0x81, 0x66, + 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -110,6 +122,18 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.EpochBurnConfig != nil { + { + 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 { @@ -142,6 +166,10 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) + if m.EpochBurnConfig != nil { + l = m.EpochBurnConfig.Size() + n += 1 + l + sovGenesis(uint64(l)) + } return n } @@ -213,6 +241,42 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { 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 m.EpochBurnConfig == nil { + m.EpochBurnConfig = &EpochBurnConfig{} + } + if err := m.EpochBurnConfig.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/furnace/types/genesis_test.go b/x/furnace/types/genesis_test.go index d1d7b59c..a34f9427 100644 --- a/x/furnace/types/genesis_test.go +++ b/x/furnace/types/genesis_test.go @@ -19,9 +19,12 @@ func TestGenesisState_Validate(t *testing.T) { valid: true, }, { - desc: "valid genesis state", + desc: "valid genesis state", genState: &types.GenesisState{ + EpochBurnConfig: &types.EpochBurnConfig{ + EpochIdentifier: "35", + }, // this line is used by starport scaffolding # types/genesis/validField }, valid: true, diff --git a/x/furnace/types/keys.go b/x/furnace/types/keys.go index 180b8b21..688a05f1 100644 --- a/x/furnace/types/keys.go +++ b/x/furnace/types/keys.go @@ -17,3 +17,7 @@ const ( func KeyPrefix(p string) []byte { return []byte(p) } + +const ( + EpochBurnConfigKey = "EpochBurnConfig/value/" +) diff --git a/x/furnace/types/query.pb.go b/x/furnace/types/query.pb.go index dba6c93c..5780cbe8 100644 --- a/x/furnace/types/query.pb.go +++ b/x/furnace/types/query.pb.go @@ -113,34 +113,122 @@ func (m *QueryParamsResponse) GetParams() 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{} +} + 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") } func init() { proto.RegisterFile("mycel/furnace/query.proto", fileDescriptor_12ab24936cee5a03) } var fileDescriptor_12ab24936cee5a03 = []byte{ - // 299 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x90, 0xc1, 0x4a, 0xc3, 0x30, - 0x18, 0xc7, 0x1b, 0xd1, 0x1d, 0x22, 0x5e, 0xe2, 0x04, 0x2d, 0x12, 0xb5, 0x78, 0x90, 0xc1, 0x1a, - 0xb6, 0xbd, 0xc1, 0x2e, 0x82, 0x27, 0xdd, 0xd1, 0x5b, 0x5a, 0x63, 0x2c, 0xac, 0xf9, 0xb2, 0x26, - 0x15, 0x87, 0x37, 0xf1, 0x01, 0x04, 0x5f, 0x6a, 0xc7, 0x81, 0x17, 0x4f, 0x22, 0xad, 0x0f, 0x22, - 0x4b, 0x83, 0x50, 0x1d, 0xde, 0xc2, 0xf7, 0xff, 0x7d, 0x3f, 0xfe, 0x5f, 0xf0, 0x41, 0x3e, 0x4f, - 0xc5, 0x94, 0xdd, 0x96, 0x85, 0xe2, 0xa9, 0x60, 0xb3, 0x52, 0x14, 0xf3, 0x58, 0x17, 0x60, 0x81, - 0xec, 0xb8, 0x28, 0xf6, 0x51, 0xd8, 0x95, 0x20, 0xc1, 0x25, 0x6c, 0xf5, 0x6a, 0xa0, 0xf0, 0x50, - 0x02, 0xc8, 0xa9, 0x60, 0x5c, 0x67, 0x8c, 0x2b, 0x05, 0x96, 0xdb, 0x0c, 0x94, 0xf1, 0x69, 0x2f, - 0x05, 0x93, 0x83, 0x61, 0x09, 0x37, 0xde, 0xcd, 0xee, 0x07, 0x89, 0xb0, 0x7c, 0xc0, 0x34, 0x97, - 0x99, 0x72, 0xb0, 0x67, 0xc3, 0x76, 0x13, 0xcd, 0x0b, 0x9e, 0x7b, 0x4f, 0xd4, 0xc5, 0xe4, 0x6a, - 0xb5, 0x7d, 0xe9, 0x86, 0x13, 0x31, 0x2b, 0x85, 0xb1, 0xd1, 0x05, 0xde, 0x6d, 0x4d, 0x8d, 0x06, - 0x65, 0x04, 0x19, 0xe1, 0x4e, 0xb3, 0xbc, 0x8f, 0x8e, 0xd1, 0xd9, 0xf6, 0x70, 0x2f, 0x6e, 0x1d, - 0x12, 0x37, 0xf8, 0x78, 0x73, 0xf1, 0x71, 0x14, 0x4c, 0x3c, 0x3a, 0x7c, 0x46, 0x78, 0xcb, 0xc9, - 0xc8, 0x23, 0xee, 0x34, 0x04, 0x39, 0xf9, 0xb5, 0xf8, 0xb7, 0x42, 0x18, 0xfd, 0x87, 0x34, 0x7d, - 0xa2, 0xde, 0xd3, 0xdb, 0xd7, 0xeb, 0xc6, 0x29, 0x89, 0x98, 0x63, 0xfb, 0x37, 0x90, 0xf3, 0x4c, - 0xb1, 0x75, 0xe7, 0x8e, 0xcf, 0x17, 0x15, 0x45, 0xcb, 0x8a, 0xa2, 0xcf, 0x8a, 0xa2, 0x97, 0x9a, - 0x06, 0xcb, 0x9a, 0x06, 0xef, 0x35, 0x0d, 0xae, 0xfb, 0x32, 0xb3, 0x77, 0x65, 0x12, 0xa7, 0x90, - 0xaf, 0xf3, 0x3c, 0xfc, 0x98, 0xec, 0x5c, 0x0b, 0x93, 0x74, 0xdc, 0xc7, 0x8d, 0xbe, 0x03, 0x00, - 0x00, 0xff, 0xff, 0xa0, 0x12, 0x7a, 0x15, 0xe0, 0x01, 0x00, 0x00, + // 394 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcd, 0x4a, 0xeb, 0x40, + 0x18, 0x86, 0x93, 0x72, 0x4e, 0x17, 0x73, 0x38, 0x1c, 0x98, 0x53, 0x41, 0x83, 0x4c, 0x6b, 0x50, + 0x90, 0x42, 0x32, 0xb4, 0xc5, 0x1b, 0xa8, 0x48, 0xc1, 0x85, 0x68, 0x97, 0x6e, 0xca, 0x24, 0x4e, + 0xd3, 0x40, 0x33, 0x93, 0x66, 0x26, 0x62, 0x71, 0xe7, 0x15, 0x08, 0x5e, 0x84, 0x3b, 0xaf, 0xa3, + 0xcb, 0x82, 0x1b, 0x57, 0x22, 0xad, 0x17, 0x22, 0x9d, 0x4c, 0x85, 0xa4, 0x3f, 0xb8, 0x0b, 0xf9, + 0x9e, 0x79, 0xdf, 0x67, 0x7e, 0xc0, 0x5e, 0x34, 0xf6, 0xe9, 0x10, 0xf7, 0xd3, 0x84, 0x11, 0x9f, + 0xe2, 0x51, 0x4a, 0x93, 0xb1, 0x1b, 0x27, 0x5c, 0x72, 0xf8, 0x57, 0x8d, 0x5c, 0x3d, 0xb2, 0x2a, + 0x01, 0x0f, 0xb8, 0x9a, 0xe0, 0xc5, 0x57, 0x06, 0x59, 0xfb, 0x01, 0xe7, 0xc1, 0x90, 0x62, 0x12, + 0x87, 0x98, 0x30, 0xc6, 0x25, 0x91, 0x21, 0x67, 0x42, 0x4f, 0xeb, 0x3e, 0x17, 0x11, 0x17, 0xd8, + 0x23, 0x42, 0x67, 0xe3, 0xdb, 0x86, 0x47, 0x25, 0x69, 0xe0, 0x98, 0x04, 0x21, 0x53, 0xb0, 0x66, + 0xad, 0xbc, 0x49, 0x4c, 0x12, 0x12, 0x2d, 0x73, 0x8e, 0xf2, 0x33, 0x1a, 0x73, 0x7f, 0xd0, 0xf3, + 0xd2, 0x84, 0xf5, 0x7c, 0xce, 0xfa, 0x61, 0x90, 0x61, 0x76, 0x05, 0xc0, 0xab, 0x45, 0xc9, 0xa5, + 0x5a, 0xdb, 0xa5, 0xa3, 0x94, 0x0a, 0x69, 0x9f, 0x83, 0xff, 0xb9, 0xbf, 0x22, 0xe6, 0x4c, 0x50, + 0xd8, 0x02, 0xe5, 0xac, 0x63, 0xd7, 0xac, 0x99, 0xc7, 0x7f, 0x9a, 0x3b, 0x6e, 0x6e, 0xbf, 0x6e, + 0x86, 0xb7, 0x7f, 0x4d, 0xde, 0xab, 0x46, 0x57, 0xa3, 0x76, 0x0d, 0x20, 0x95, 0xd5, 0xa1, 0xf2, + 0x6c, 0x21, 0xd1, 0x4e, 0x13, 0x76, 0xaa, 0x14, 0x96, 0x6d, 0x23, 0x50, 0xdd, 0x48, 0xe8, 0xe6, + 0x0b, 0xf0, 0xaf, 0x30, 0xd2, 0x0a, 0xa8, 0xa0, 0x50, 0xa0, 0xb4, 0x4b, 0x71, 0x71, 0xf3, 0xa5, + 0x04, 0x7e, 0xab, 0x4e, 0x78, 0x0f, 0xca, 0x99, 0x36, 0x3c, 0x28, 0x44, 0xad, 0x9e, 0x8b, 0x65, + 0x6f, 0x43, 0x32, 0x55, 0xbb, 0xfe, 0xf0, 0xfa, 0xf9, 0x54, 0x3a, 0x84, 0x36, 0x56, 0xac, 0x73, + 0xc3, 0x23, 0x12, 0x32, 0xbc, 0xee, 0xaa, 0xe0, 0xb3, 0xb9, 0xb2, 0x2f, 0xe8, 0xac, 0xeb, 0xd8, + 0x78, 0x78, 0x96, 0xfb, 0x53, 0x5c, 0xeb, 0x9d, 0x28, 0x3d, 0x0c, 0x9d, 0x6d, 0x7a, 0x2b, 0xaf, + 0xa5, 0xdd, 0x99, 0xcc, 0x90, 0x39, 0x9d, 0x21, 0xf3, 0x63, 0x86, 0xcc, 0xc7, 0x39, 0x32, 0xa6, + 0x73, 0x64, 0xbc, 0xcd, 0x91, 0x71, 0xed, 0x04, 0xa1, 0x1c, 0xa4, 0x9e, 0xeb, 0xf3, 0x68, 0x5d, + 0xe4, 0xdd, 0x77, 0xa8, 0x1c, 0xc7, 0x54, 0x78, 0x65, 0xf5, 0xee, 0x5a, 0x5f, 0x01, 0x00, 0x00, + 0xff, 0xff, 0x3f, 0x88, 0x3f, 0xe5, 0x46, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -157,6 +245,8 @@ const _ = grpc.SupportPackageIsVersion4 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) } type queryClient struct { @@ -176,10 +266,21 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . 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 +} + // 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) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -189,6 +290,9 @@ 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 RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -212,6 +316,24 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf 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) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "mycel.furnace.Query", HandlerType: (*QueryServer)(nil), @@ -220,6 +342,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "Params", Handler: _Query_Params_Handler, }, + { + MethodName: "EpochBurnConfig", + Handler: _Query_EpochBurnConfig_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "mycel/furnace/query.proto", @@ -281,6 +407,62 @@ func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { 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 encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -312,6 +494,26 @@ func (m *QueryParamsResponse) Size() (n int) { 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 sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -451,6 +653,139 @@ func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { } 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 skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/furnace/types/query.pb.gw.go b/x/furnace/types/query.pb.gw.go index 02c78981..56e36253 100644 --- a/x/furnace/types/query.pb.gw.go +++ b/x/furnace/types/query.pb.gw.go @@ -51,6 +51,24 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal } +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 + +} + // 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. @@ -80,6 +98,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + 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()...) + + }) + return nil } @@ -141,13 +182,37 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + 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()...) + + }) + 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))) ) var ( forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_EpochBurnConfig_0 = runtime.ForwardResponseMessage ) From abeac9277ed2e12185600a551885809c8885a612 Mon Sep 17 00:00:00 2001 From: tarumi Date: Thu, 21 Sep 2023 16:07:49 +0200 Subject: [PATCH 14/28] add genesis --- docs/static/openapi.yml | 24 +++++++++++++ proto/mycel/furnace/genesis.proto | 2 +- x/furnace/genesis.go | 9 +++-- x/furnace/types/genesis.go | 13 +++++-- x/furnace/types/genesis.pb.go | 59 ++++++++++++++----------------- x/furnace/types/genesis_test.go | 2 +- 6 files changed, 67 insertions(+), 42 deletions(-) diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index 7fd4bc05..eb6df80c 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -49706,6 +49706,14 @@ paths: properties: epochIdentifier: type: string + currentBurnAmountIdentifier: + type: string + format: uint64 + startTime: + type: string + format: date-time + duration: + type: string default: description: An unexpected error response. schema: @@ -80721,6 +80729,14 @@ definitions: properties: epochIdentifier: type: string + currentBurnAmountIdentifier: + type: string + format: uint64 + startTime: + type: string + format: date-time + duration: + type: string mycel.furnace.Params: type: object description: Params defines the parameters for the module. @@ -80732,6 +80748,14 @@ definitions: properties: epochIdentifier: type: string + currentBurnAmountIdentifier: + type: string + format: uint64 + startTime: + type: string + format: date-time + duration: + type: string mycel.furnace.QueryParamsResponse: type: object properties: diff --git a/proto/mycel/furnace/genesis.proto b/proto/mycel/furnace/genesis.proto index 75ad49e1..bdd94b49 100644 --- a/proto/mycel/furnace/genesis.proto +++ b/proto/mycel/furnace/genesis.proto @@ -11,6 +11,6 @@ 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; + EpochBurnConfig epochBurnConfig = 2 [(gogoproto.nullable) = false]; } diff --git a/x/furnace/genesis.go b/x/furnace/genesis.go index 5fe26b03..7b0bae76 100644 --- a/x/furnace/genesis.go +++ b/x/furnace/genesis.go @@ -8,10 +8,9 @@ import ( // InitGenesis initializes the module's state from a provided genesis state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { - // Set if defined - if genState.EpochBurnConfig != nil { - k.SetEpochBurnConfig(ctx, *genState.EpochBurnConfig) - } + // Set genesis time + genState.EpochBurnConfig.StartTime = ctx.BlockTime() + k.SetEpochBurnConfig(ctx, genState.EpochBurnConfig) // this line is used by starport scaffolding # genesis/module/init k.SetParams(ctx, genState.Params) } @@ -24,7 +23,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { // Get all epochBurnConfig epochBurnConfig, found := k.GetEpochBurnConfig(ctx) if found { - genesis.EpochBurnConfig = &epochBurnConfig + genesis.EpochBurnConfig = epochBurnConfig } // this line is used by starport scaffolding # genesis/module/export diff --git a/x/furnace/types/genesis.go b/x/furnace/types/genesis.go index efd10f6f..763f92c8 100644 --- a/x/furnace/types/genesis.go +++ b/x/furnace/types/genesis.go @@ -1,16 +1,25 @@ package types import ( -// this line is used by starport scaffolding # genesis/types/import + epochstypes "github.com/mycel-domain/mycel/x/epochs/types" + "time" ) // DefaultIndex is the default global index const DefaultIndex uint64 = 1 +func GetDefaultEpochBurnConfig() EpochBurnConfig { + return EpochBurnConfig{ + EpochIdentifier: epochstypes.DailyEpochId, + CurrentBurnAmountIdentifier: 1, + Duration: time.Hour * 24 * 30 * 4, + } +} + // DefaultGenesis returns the default genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ - EpochBurnConfig: nil, + EpochBurnConfig: GetDefaultEpochBurnConfig(), // this line is used by starport scaffolding # genesis/types/default Params: DefaultParams(), } diff --git a/x/furnace/types/genesis.pb.go b/x/furnace/types/genesis.pb.go index 950853fb..9b11957a 100644 --- a/x/furnace/types/genesis.pb.go +++ b/x/furnace/types/genesis.pb.go @@ -25,8 +25,8 @@ 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,omitempty"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + EpochBurnConfig EpochBurnConfig `protobuf:"bytes,2,opt,name=epochBurnConfig,proto3" json:"epochBurnConfig"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -69,11 +69,11 @@ func (m *GenesisState) GetParams() Params { return Params{} } -func (m *GenesisState) GetEpochBurnConfig() *EpochBurnConfig { +func (m *GenesisState) GetEpochBurnConfig() EpochBurnConfig { if m != nil { return m.EpochBurnConfig } - return nil + return EpochBurnConfig{} } func init() { @@ -83,23 +83,23 @@ func init() { func init() { proto.RegisterFile("mycel/furnace/genesis.proto", fileDescriptor_cb6ac84609cb49bc) } var fileDescriptor_cb6ac84609cb49bc = []byte{ - // 243 bytes of a gzipped FileDescriptorProto + // 244 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xce, 0xad, 0x4c, 0x4e, 0xcd, 0xd1, 0x4f, 0x2b, 0x2d, 0xca, 0x4b, 0x4c, 0x4e, 0xd5, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x05, 0x4b, 0xea, 0x41, 0x25, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x32, 0xfa, 0x20, 0x16, 0x44, 0x91, 0x94, 0x14, 0xaa, 0x09, 0x05, 0x89, 0x45, 0x89, 0xb9, 0x50, 0x03, 0xa4, 0x54, 0x51, 0xe5, 0x52, 0x0b, 0xf2, 0x93, 0x33, 0xe2, - 0x93, 0x4a, 0x8b, 0xf2, 0xe2, 0x93, 0xf3, 0xf3, 0xd2, 0x32, 0xd3, 0x21, 0xca, 0x94, 0x7a, 0x19, - 0xb9, 0x78, 0xdc, 0x21, 0x36, 0x07, 0x97, 0x24, 0x96, 0xa4, 0x0a, 0x19, 0x73, 0xb1, 0x41, 0xcc, - 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x36, 0x12, 0xd5, 0x43, 0x71, 0x89, 0x5e, 0x00, 0x58, 0xd2, - 0x89, 0xe5, 0xc4, 0x3d, 0x79, 0x86, 0x20, 0xa8, 0x52, 0x21, 0x0f, 0x2e, 0x7e, 0xb0, 0x05, 0x4e, - 0xa5, 0x45, 0x79, 0xce, 0x60, 0xe3, 0x25, 0x98, 0xc0, 0xba, 0xe5, 0xd0, 0x74, 0xbb, 0xa2, 0xaa, - 0x0a, 0x42, 0xd7, 0xe6, 0xe4, 0x7e, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, - 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, - 0xba, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x60, 0x43, 0x75, 0x53, - 0xf2, 0x73, 0x13, 0x33, 0xf3, 0x20, 0x1c, 0xfd, 0x0a, 0xb8, 0x57, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, - 0x93, 0xd8, 0xc0, 0xfe, 0x33, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xb1, 0xed, 0x0a, 0x81, 0x66, - 0x01, 0x00, 0x00, + 0x93, 0x4a, 0x8b, 0xf2, 0xe2, 0x93, 0xf3, 0xf3, 0xd2, 0x32, 0xd3, 0x21, 0xca, 0x94, 0x26, 0x33, + 0x72, 0xf1, 0xb8, 0x43, 0x6c, 0x0e, 0x2e, 0x49, 0x2c, 0x49, 0x15, 0x32, 0xe6, 0x62, 0x83, 0x98, + 0x23, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x6d, 0x24, 0xaa, 0x87, 0xe2, 0x12, 0xbd, 0x00, 0xb0, 0xa4, + 0x13, 0xcb, 0x89, 0x7b, 0xf2, 0x0c, 0x41, 0x50, 0xa5, 0x42, 0x7e, 0x5c, 0xfc, 0x60, 0x0b, 0x9c, + 0x4a, 0x8b, 0xf2, 0x9c, 0xc1, 0xc6, 0x4b, 0x30, 0x81, 0x75, 0xcb, 0xa1, 0xe9, 0x76, 0x45, 0x55, + 0x05, 0x35, 0x06, 0x5d, 0xb3, 0x93, 0xfb, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, + 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, + 0x44, 0xe9, 0xa6, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x83, 0x8d, 0xd6, + 0x4d, 0xc9, 0xcf, 0x4d, 0xcc, 0xcc, 0x83, 0x70, 0xf4, 0x2b, 0xe0, 0x1e, 0x2e, 0xa9, 0x2c, 0x48, + 0x2d, 0x4e, 0x62, 0x03, 0xfb, 0xd2, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xfa, 0xd2, 0x13, 0xcc, + 0x6c, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -122,18 +122,16 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.EpochBurnConfig != nil { - { - size, err := m.EpochBurnConfig.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) + { + size, err := m.EpochBurnConfig.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x12 + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x12 { size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -166,10 +164,8 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) - if m.EpochBurnConfig != nil { - l = m.EpochBurnConfig.Size() - n += 1 + l + sovGenesis(uint64(l)) - } + l = m.EpochBurnConfig.Size() + n += 1 + l + sovGenesis(uint64(l)) return n } @@ -270,9 +266,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.EpochBurnConfig == nil { - m.EpochBurnConfig = &EpochBurnConfig{} - } if err := m.EpochBurnConfig.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/x/furnace/types/genesis_test.go b/x/furnace/types/genesis_test.go index a34f9427..5e56a995 100644 --- a/x/furnace/types/genesis_test.go +++ b/x/furnace/types/genesis_test.go @@ -22,7 +22,7 @@ func TestGenesisState_Validate(t *testing.T) { desc: "valid genesis state", genState: &types.GenesisState{ - EpochBurnConfig: &types.EpochBurnConfig{ + EpochBurnConfig: types.EpochBurnConfig{ EpochIdentifier: "35", }, // this line is used by starport scaffolding # types/genesis/validField From 381d6b48c79b4b75a1c4caf5e8c14b05419241cf Mon Sep 17 00:00:00 2001 From: tarumi Date: Thu, 21 Sep 2023 16:19:35 +0200 Subject: [PATCH 15/28] scaffold burn amount --- docs/static/openapi.yml | 370 ++++++++ proto/mycel/furnace/burn_amount.proto | 15 + proto/mycel/furnace/genesis.proto | 6 +- proto/mycel/furnace/query.proto | 29 + x/furnace/client/cli/query.go | 2 + x/furnace/client/cli/query_burn_amount.go | 82 ++ .../client/cli/query_burn_amount_test.go | 160 ++++ x/furnace/genesis.go | 5 + x/furnace/genesis_test.go | 9 + x/furnace/keeper/burn_amount.go | 63 ++ x/furnace/keeper/burn_amount_test.go | 63 ++ x/furnace/keeper/query_burn_amount.go | 57 ++ x/furnace/keeper/query_burn_amount_test.go | 127 +++ x/furnace/types/burn_amount.pb.go | 455 +++++++++ x/furnace/types/genesis.go | 12 + x/furnace/types/genesis.pb.go | 99 +- x/furnace/types/genesis_test.go | 22 + x/furnace/types/key_burn_amount.go | 24 + x/furnace/types/query.pb.go | 890 +++++++++++++++++- x/furnace/types/query.pb.gw.go | 184 ++++ 20 files changed, 2627 insertions(+), 47 deletions(-) create mode 100644 proto/mycel/furnace/burn_amount.proto create mode 100644 x/furnace/client/cli/query_burn_amount.go create mode 100644 x/furnace/client/cli/query_burn_amount_test.go create mode 100644 x/furnace/keeper/burn_amount.go create mode 100644 x/furnace/keeper/burn_amount_test.go create mode 100644 x/furnace/keeper/query_burn_amount.go create mode 100644 x/furnace/keeper/query_burn_amount_test.go create mode 100644 x/furnace/types/burn_amount.pb.go create mode 100644 x/furnace/types/key_burn_amount.go diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index eb6df80c..df0d6fbb 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -49691,6 +49691,234 @@ 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: + identifier: + type: string + format: uint64 + burnStarted: + type: boolean + 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. + burntAmount: + 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/{identifier}: + get: + summary: Queries a list of BurnAmount items. + operationId: MycelFurnaceBurnAmount + responses: + '200': + description: A successful response. + schema: + type: object + properties: + burnAmount: + type: object + properties: + identifier: + type: string + format: uint64 + burnStarted: + type: boolean + 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. + burntAmount: + 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: identifier + in: path + required: true + type: string + format: uint64 + tags: + - Query /mycel-domain/mycel/furnace/epoch_burn_config: get: summary: Queries a EpochBurnConfig by index. @@ -80724,6 +80952,38 @@ 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: + identifier: + type: string + format: uint64 + burnStarted: + type: boolean + 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. + burntAmount: + 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: @@ -80740,6 +81000,116 @@ definitions: 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: + identifier: + type: string + format: uint64 + burnStarted: + type: boolean + 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. + burntAmount: + 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: + identifier: + type: string + format: uint64 + burnStarted: + type: boolean + 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. + burntAmount: + 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: diff --git a/proto/mycel/furnace/burn_amount.proto b/proto/mycel/furnace/burn_amount.proto new file mode 100644 index 00000000..271baed0 --- /dev/null +++ b/proto/mycel/furnace/burn_amount.proto @@ -0,0 +1,15 @@ +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 identifier = 1; + bool burnStarted = 2; + cosmos.base.v1beta1.Coin totalBurnAmount = 3 [(gogoproto.nullable) = false]; + cosmos.base.v1beta1.Coin burntAmount = 4 [(gogoproto.nullable) = false]; + +} + diff --git a/proto/mycel/furnace/genesis.proto b/proto/mycel/furnace/genesis.proto index bdd94b49..37c1dbda 100644 --- a/proto/mycel/furnace/genesis.proto +++ b/proto/mycel/furnace/genesis.proto @@ -5,12 +5,14 @@ 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]; + Params params = 1 [(gogoproto.nullable) = false]; + EpochBurnConfig epochBurnConfig = 2 [(gogoproto.nullable) = false]; + repeated BurnAmount burnAmountList = 3 [(gogoproto.nullable) = false]; } diff --git a/proto/mycel/furnace/query.proto b/proto/mycel/furnace/query.proto index ec6594ca..4bb09041 100644 --- a/proto/mycel/furnace/query.proto +++ b/proto/mycel/furnace/query.proto @@ -7,6 +7,8 @@ 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"; @@ -24,6 +26,16 @@ service Query { 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/{identifier}"; + + } + 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 {} @@ -41,3 +53,20 @@ message QueryGetEpochBurnConfigResponse { EpochBurnConfig EpochBurnConfig = 1 [(gogoproto.nullable) = false]; } +message QueryGetBurnAmountRequest { + uint64 identifier = 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/x/furnace/client/cli/query.go b/x/furnace/client/cli/query.go index ea584e42..7fe413de 100644 --- a/x/furnace/client/cli/query.go +++ b/x/furnace/client/cli/query.go @@ -26,6 +26,8 @@ func GetQueryCmd(queryRoute string) *cobra.Command { 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..23e20e01 --- /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 [identifier]", + 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) + + argIdentifier, err := cast.ToUint64E(args[0]) + if err != nil { + return err + } + + params := &types.QueryGetBurnAmountRequest{ + Identifier: argIdentifier, + } + + 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..4b1f404e --- /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{ + Identifier: uint64(i), + } + nullify.Fill(&burnAmount) + state.BurnAmountList = append(state.BurnAmountList, burnAmount) + } + buf, err := cfg.Codec.MarshalJSON(&state) + require.NoError(t, err) + cfg.GenesisState[types.ModuleName] = buf + return network.New(t, cfg), state.BurnAmountList +} + +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 + idIdentifier uint64 + + args []string + err error + obj types.BurnAmount + }{ + { + desc: "found", + idIdentifier: objs[0].Identifier, + + args: common, + obj: objs[0], + }, + { + desc: "not found", + idIdentifier: 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.idIdentifier)), + } + 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/genesis.go b/x/furnace/genesis.go index 7b0bae76..32d16aa4 100644 --- a/x/furnace/genesis.go +++ b/x/furnace/genesis.go @@ -11,6 +11,10 @@ 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.BurnAmountList { + k.SetBurnAmount(ctx, elem) + } // this line is used by starport scaffolding # genesis/module/init k.SetParams(ctx, genState.Params) } @@ -25,6 +29,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { if found { genesis.EpochBurnConfig = epochBurnConfig } + genesis.BurnAmountList = 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 index 38eec21e..7cb0ad40 100644 --- a/x/furnace/genesis_test.go +++ b/x/furnace/genesis_test.go @@ -17,6 +17,14 @@ func TestGenesis(t *testing.T) { EpochBurnConfig: &types.EpochBurnConfig{ EpochIdentifier: "11", }, + BurnAmountList: []types.BurnAmount{ + { + Identifier: 0, + }, + { + Identifier: 1, + }, + }, // this line is used by starport scaffolding # genesis/test/state } @@ -29,5 +37,6 @@ func TestGenesis(t *testing.T) { nullify.Fill(got) require.Equal(t, genesisState.EpochBurnConfig, got.EpochBurnConfig) + require.ElementsMatch(t, genesisState.BurnAmountList, got.BurnAmountList) // 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..35dc62f3 --- /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.Identifier, + ), b) +} + +// GetBurnAmount returns a burnAmount from its index +func (k Keeper) GetBurnAmount( + ctx sdk.Context, + identifier uint64, + +) (val types.BurnAmount, found bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BurnAmountKeyPrefix)) + + b := store.Get(types.BurnAmountKey( + identifier, + )) + 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, + identifier uint64, + +) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BurnAmountKeyPrefix)) + store.Delete(types.BurnAmountKey( + identifier, + )) +} + +// 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..53955e3e --- /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].Identifier = 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.Identifier, + ) + 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.Identifier, + ) + _, found := keeper.GetBurnAmount(ctx, + item.Identifier, + ) + 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/query_burn_amount.go b/x/furnace/keeper/query_burn_amount.go new file mode 100644 index 00000000..15d33e2e --- /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.Identifier, + ) + 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..41d8fe48 --- /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{ + Identifier: msgs[0].Identifier, + }, + response: &types.QueryGetBurnAmountResponse{BurnAmount: msgs[0]}, + }, + { + desc: "Second", + request: &types.QueryGetBurnAmountRequest{ + Identifier: msgs[1].Identifier, + }, + response: &types.QueryGetBurnAmountResponse{BurnAmount: msgs[1]}, + }, + { + desc: "KeyNotFound", + request: &types.QueryGetBurnAmountRequest{ + Identifier: 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/types/burn_amount.pb.go b/x/furnace/types/burn_amount.pb.go new file mode 100644 index 00000000..a2c7e7a3 --- /dev/null +++ b/x/furnace/types/burn_amount.pb.go @@ -0,0 +1,455 @@ +// 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 { + Identifier uint64 `protobuf:"varint,1,opt,name=identifier,proto3" json:"identifier,omitempty"` + BurnStarted bool `protobuf:"varint,2,opt,name=burnStarted,proto3" json:"burnStarted,omitempty"` + TotalBurnAmount types.Coin `protobuf:"bytes,3,opt,name=totalBurnAmount,proto3" json:"totalBurnAmount"` + BurntAmount types.Coin `protobuf:"bytes,4,opt,name=burntAmount,proto3" json:"burntAmount"` +} + +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) GetIdentifier() uint64 { + if m != nil { + return m.Identifier + } + return 0 +} + +func (m *BurnAmount) GetBurnStarted() bool { + if m != nil { + return m.BurnStarted + } + return false +} + +func (m *BurnAmount) GetTotalBurnAmount() types.Coin { + if m != nil { + return m.TotalBurnAmount + } + return types.Coin{} +} + +func (m *BurnAmount) GetBurntAmount() types.Coin { + if m != nil { + return m.BurntAmount + } + 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{ + // 280 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x90, 0xb1, 0x4e, 0xc3, 0x30, + 0x10, 0x86, 0x63, 0xa8, 0x10, 0x72, 0x85, 0x90, 0x22, 0x86, 0xd0, 0xc1, 0x8d, 0x98, 0xb2, 0xd4, + 0x56, 0xe1, 0x09, 0x1a, 0x06, 0xc4, 0x1a, 0x36, 0x16, 0xe4, 0x24, 0x6e, 0xb0, 0xd4, 0xf8, 0x2a, + 0xe7, 0x82, 0xe8, 0x5b, 0xf0, 0x58, 0x1d, 0x3b, 0x32, 0x20, 0x84, 0x92, 0x17, 0x41, 0x89, 0x23, + 0x88, 0x98, 0xd8, 0xec, 0xbb, 0xff, 0xff, 0xef, 0xd3, 0x4f, 0xe7, 0xe5, 0x2e, 0x53, 0x1b, 0xb1, + 0xae, 0xad, 0x91, 0x99, 0x12, 0x69, 0x6d, 0xcd, 0x93, 0x2c, 0xa1, 0x36, 0xc8, 0xb7, 0x16, 0x10, + 0xfc, 0xb3, 0x5e, 0xc0, 0x07, 0xc1, 0xec, 0xa2, 0x80, 0x02, 0xfa, 0x8d, 0xe8, 0x5e, 0x4e, 0x34, + 0x63, 0x19, 0x54, 0x25, 0x54, 0x22, 0x95, 0x95, 0x12, 0x2f, 0xcb, 0x54, 0xa1, 0x5c, 0x8a, 0x0c, + 0xb4, 0x71, 0xfb, 0xab, 0x0f, 0x42, 0x69, 0x5c, 0x5b, 0xb3, 0xea, 0x93, 0x7d, 0x46, 0xa9, 0xce, + 0x95, 0x41, 0xbd, 0xd6, 0xca, 0x06, 0x24, 0x24, 0xd1, 0x24, 0x19, 0x4d, 0xfc, 0x90, 0x4e, 0x3b, + 0x90, 0x07, 0x94, 0x16, 0x55, 0x1e, 0x1c, 0x85, 0x24, 0x3a, 0x4d, 0xc6, 0x23, 0xff, 0x9e, 0x9e, + 0x23, 0xa0, 0xdc, 0xfc, 0x86, 0x06, 0xc7, 0x21, 0x89, 0xa6, 0xd7, 0x97, 0xdc, 0xa1, 0xf0, 0x0e, + 0x85, 0x0f, 0x28, 0xfc, 0x16, 0xb4, 0x89, 0x27, 0xfb, 0xcf, 0xb9, 0x97, 0xfc, 0xf5, 0xf9, 0x2b, + 0x77, 0x0c, 0x87, 0x98, 0xc9, 0xff, 0x62, 0xc6, 0x9e, 0xf8, 0x6e, 0xdf, 0x30, 0x72, 0x68, 0x18, + 0xf9, 0x6a, 0x18, 0x79, 0x6b, 0x99, 0x77, 0x68, 0x99, 0xf7, 0xde, 0x32, 0xef, 0x71, 0x51, 0x68, + 0x7c, 0xae, 0x53, 0x9e, 0x41, 0x29, 0xfa, 0x22, 0x17, 0x39, 0x94, 0x52, 0x1b, 0xf7, 0x11, 0xaf, + 0x3f, 0xc5, 0xe3, 0x6e, 0xab, 0xaa, 0xf4, 0xa4, 0xaf, 0xeb, 0xe6, 0x3b, 0x00, 0x00, 0xff, 0xff, + 0xd4, 0x70, 0x42, 0x68, 0x96, 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.BurntAmount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintBurnAmount(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + { + size, err := m.TotalBurnAmount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintBurnAmount(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if m.BurnStarted { + i-- + if m.BurnStarted { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if m.Identifier != 0 { + i = encodeVarintBurnAmount(dAtA, i, uint64(m.Identifier)) + 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.Identifier != 0 { + n += 1 + sovBurnAmount(uint64(m.Identifier)) + } + if m.BurnStarted { + n += 2 + } + l = m.TotalBurnAmount.Size() + n += 1 + l + sovBurnAmount(uint64(l)) + l = m.BurntAmount.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 Identifier", wireType) + } + m.Identifier = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBurnAmount + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Identifier |= 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 != 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 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BurntAmount", 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.BurntAmount.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/genesis.go b/x/furnace/types/genesis.go index 763f92c8..ad99b214 100644 --- a/x/furnace/types/genesis.go +++ b/x/furnace/types/genesis.go @@ -1,6 +1,7 @@ package types import ( + "fmt" epochstypes "github.com/mycel-domain/mycel/x/epochs/types" "time" ) @@ -20,6 +21,7 @@ func GetDefaultEpochBurnConfig() EpochBurnConfig { func DefaultGenesis() *GenesisState { return &GenesisState{ EpochBurnConfig: GetDefaultEpochBurnConfig(), + BurnAmountList: []BurnAmount{}, // this line is used by starport scaffolding # genesis/types/default Params: DefaultParams(), } @@ -28,6 +30,16 @@ func DefaultGenesis() *GenesisState { // 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.BurnAmountList { + index := string(BurnAmountKey(elem.Identifier)) + 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 index 9b11957a..9227f44c 100644 --- a/x/furnace/types/genesis.pb.go +++ b/x/furnace/types/genesis.pb.go @@ -27,6 +27,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package 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"` + BurnAmountList []BurnAmount `protobuf:"bytes,3,rep,name=burnAmountList,proto3" json:"burnAmountList"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -76,6 +77,13 @@ func (m *GenesisState) GetEpochBurnConfig() EpochBurnConfig { return EpochBurnConfig{} } +func (m *GenesisState) GetBurnAmountList() []BurnAmount { + if m != nil { + return m.BurnAmountList + } + return nil +} + func init() { proto.RegisterType((*GenesisState)(nil), "mycel.furnace.GenesisState") } @@ -83,23 +91,26 @@ func init() { func init() { proto.RegisterFile("mycel/furnace/genesis.proto", fileDescriptor_cb6ac84609cb49bc) } var fileDescriptor_cb6ac84609cb49bc = []byte{ - // 244 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xce, 0xad, 0x4c, 0x4e, - 0xcd, 0xd1, 0x4f, 0x2b, 0x2d, 0xca, 0x4b, 0x4c, 0x4e, 0xd5, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, - 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x05, 0x4b, 0xea, 0x41, 0x25, 0xa5, 0x44, - 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x32, 0xfa, 0x20, 0x16, 0x44, 0x91, 0x94, 0x14, 0xaa, 0x09, 0x05, - 0x89, 0x45, 0x89, 0xb9, 0x50, 0x03, 0xa4, 0x54, 0x51, 0xe5, 0x52, 0x0b, 0xf2, 0x93, 0x33, 0xe2, - 0x93, 0x4a, 0x8b, 0xf2, 0xe2, 0x93, 0xf3, 0xf3, 0xd2, 0x32, 0xd3, 0x21, 0xca, 0x94, 0x26, 0x33, - 0x72, 0xf1, 0xb8, 0x43, 0x6c, 0x0e, 0x2e, 0x49, 0x2c, 0x49, 0x15, 0x32, 0xe6, 0x62, 0x83, 0x98, - 0x23, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x6d, 0x24, 0xaa, 0x87, 0xe2, 0x12, 0xbd, 0x00, 0xb0, 0xa4, - 0x13, 0xcb, 0x89, 0x7b, 0xf2, 0x0c, 0x41, 0x50, 0xa5, 0x42, 0x7e, 0x5c, 0xfc, 0x60, 0x0b, 0x9c, - 0x4a, 0x8b, 0xf2, 0x9c, 0xc1, 0xc6, 0x4b, 0x30, 0x81, 0x75, 0xcb, 0xa1, 0xe9, 0x76, 0x45, 0x55, - 0x05, 0x35, 0x06, 0x5d, 0xb3, 0x93, 0xfb, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, - 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, - 0x44, 0xe9, 0xa6, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x83, 0x8d, 0xd6, - 0x4d, 0xc9, 0xcf, 0x4d, 0xcc, 0xcc, 0x83, 0x70, 0xf4, 0x2b, 0xe0, 0x1e, 0x2e, 0xa9, 0x2c, 0x48, - 0x2d, 0x4e, 0x62, 0x03, 0xfb, 0xd2, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xfa, 0xd2, 0x13, 0xcc, - 0x6c, 0x01, 0x00, 0x00, + // 289 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x90, 0x4f, 0x4b, 0xc3, 0x30, + 0x18, 0xc6, 0x1b, 0x27, 0x3b, 0x74, 0xfe, 0x81, 0xa2, 0x50, 0x2b, 0x64, 0x43, 0x10, 0x76, 0x59, + 0x0b, 0xdb, 0x27, 0xb0, 0x22, 0xbd, 0x88, 0x88, 0xde, 0xbc, 0x8c, 0xb4, 0x66, 0x5d, 0xc1, 0x24, + 0x25, 0x4d, 0xc0, 0x7d, 0x0b, 0x3f, 0xd6, 0x8e, 0x3b, 0x7a, 0x10, 0x91, 0xf6, 0x8b, 0xc8, 0xde, + 0x84, 0x41, 0x7a, 0x6b, 0x79, 0x7e, 0xcf, 0x2f, 0x0f, 0xaf, 0x7f, 0xcd, 0x36, 0x05, 0xfd, 0x48, + 0x56, 0x5a, 0x72, 0x52, 0xd0, 0xa4, 0xa4, 0x9c, 0x36, 0x55, 0x13, 0xd7, 0x52, 0x28, 0x11, 0x9c, + 0x42, 0x18, 0xdb, 0x30, 0xba, 0x28, 0x45, 0x29, 0x20, 0x49, 0xf6, 0x5f, 0x06, 0x8a, 0x22, 0xd7, + 0x50, 0x13, 0x49, 0x98, 0x15, 0x44, 0xb7, 0x6e, 0x46, 0x6b, 0x51, 0xac, 0x97, 0xb9, 0x96, 0x7c, + 0x59, 0x08, 0xbe, 0xaa, 0x4a, 0x8b, 0x8d, 0x5d, 0x0c, 0x00, 0xc2, 0x84, 0xe6, 0xca, 0x00, 0x37, + 0x3f, 0xc8, 0x3f, 0xc9, 0xcc, 0xb4, 0x57, 0x45, 0x14, 0x0d, 0x16, 0xfe, 0xd0, 0x3c, 0x14, 0xa2, + 0x09, 0x9a, 0x8e, 0xe6, 0x97, 0xb1, 0x33, 0x35, 0x7e, 0x86, 0x30, 0x3d, 0xde, 0xfe, 0x8e, 0xbd, + 0x17, 0x8b, 0x06, 0x4f, 0xfe, 0x39, 0x2c, 0x48, 0xb5, 0xe4, 0xf7, 0xf0, 0x7e, 0x78, 0x04, 0x6d, + 0xdc, 0x6b, 0x3f, 0xb8, 0x94, 0xd5, 0xf4, 0xcb, 0x41, 0xe6, 0x9f, 0xed, 0xa7, 0xde, 0xc1, 0xd2, + 0xc7, 0xaa, 0x51, 0xe1, 0x60, 0x32, 0x98, 0x8e, 0xe6, 0x57, 0x3d, 0x5d, 0x7a, 0x80, 0xac, 0xa9, + 0x57, 0x4b, 0xb3, 0x6d, 0x8b, 0xd1, 0xae, 0xc5, 0xe8, 0xaf, 0xc5, 0xe8, 0xab, 0xc3, 0xde, 0xae, + 0xc3, 0xde, 0x77, 0x87, 0xbd, 0xb7, 0x59, 0x59, 0xa9, 0xb5, 0xce, 0xe3, 0x42, 0xb0, 0x04, 0xa4, + 0xb3, 0x77, 0xc1, 0x48, 0xc5, 0xcd, 0x4f, 0xf2, 0x79, 0xb8, 0x99, 0xda, 0xd4, 0xb4, 0xc9, 0x87, + 0x70, 0xae, 0xc5, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x8b, 0x9e, 0x52, 0x71, 0xd6, 0x01, 0x00, + 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -122,6 +133,20 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.BurnAmountList) > 0 { + for iNdEx := len(m.BurnAmountList) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.BurnAmountList[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 { @@ -166,6 +191,12 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) l = m.EpochBurnConfig.Size() n += 1 + l + sovGenesis(uint64(l)) + if len(m.BurnAmountList) > 0 { + for _, e := range m.BurnAmountList { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } return n } @@ -270,6 +301,40 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BurnAmountList", 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.BurnAmountList = append(m.BurnAmountList, BurnAmount{}) + if err := m.BurnAmountList[len(m.BurnAmountList)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/furnace/types/genesis_test.go b/x/furnace/types/genesis_test.go index 5e56a995..72e4dd4a 100644 --- a/x/furnace/types/genesis_test.go +++ b/x/furnace/types/genesis_test.go @@ -25,10 +25,32 @@ func TestGenesisState_Validate(t *testing.T) { EpochBurnConfig: types.EpochBurnConfig{ EpochIdentifier: "35", }, + BurnAmountList: []types.BurnAmount{ + { + Identifier: 0, + }, + { + Identifier: 1, + }, + }, // this line is used by starport scaffolding # types/genesis/validField }, valid: true, }, + { + desc: "duplicated burnAmount", + genState: &types.GenesisState{ + BurnAmountList: []types.BurnAmount{ + { + Identifier: 0, + }, + { + Identifier: 0, + }, + }, + }, + valid: false, + }, // this line is used by starport scaffolding # types/genesis/testcase } for _, tc := range tests { diff --git a/x/furnace/types/key_burn_amount.go b/x/furnace/types/key_burn_amount.go new file mode 100644 index 00000000..7782eb19 --- /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( + identifier uint64, +) []byte { + var key []byte + + identifierBytes := make([]byte, 8) + binary.BigEndian.PutUint64(identifierBytes, identifier) + key = append(key, identifierBytes...) + key = append(key, []byte("/")...) + + return key +} diff --git a/x/furnace/types/query.pb.go b/x/furnace/types/query.pb.go index 5780cbe8..24b23088 100644 --- a/x/furnace/types/query.pb.go +++ b/x/furnace/types/query.pb.go @@ -6,7 +6,8 @@ package types import ( context "context" fmt "fmt" - _ "github.com/cosmos/cosmos-sdk/types/query" + _ "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" @@ -193,42 +194,243 @@ func (m *QueryGetEpochBurnConfigResponse) GetEpochBurnConfig() EpochBurnConfig { return EpochBurnConfig{} } +type QueryGetBurnAmountRequest struct { + Identifier uint64 `protobuf:"varint,1,opt,name=identifier,proto3" json:"identifier,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) GetIdentifier() uint64 { + if m != nil { + return m.Identifier + } + 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{ - // 394 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcd, 0x4a, 0xeb, 0x40, - 0x18, 0x86, 0x93, 0x72, 0x4e, 0x17, 0x73, 0x38, 0x1c, 0x98, 0x53, 0x41, 0x83, 0x4c, 0x6b, 0x50, - 0x90, 0x42, 0x32, 0xb4, 0xc5, 0x1b, 0xa8, 0x48, 0xc1, 0x85, 0x68, 0x97, 0x6e, 0xca, 0x24, 0x4e, - 0xd3, 0x40, 0x33, 0x93, 0x66, 0x26, 0x62, 0x71, 0xe7, 0x15, 0x08, 0x5e, 0x84, 0x3b, 0xaf, 0xa3, - 0xcb, 0x82, 0x1b, 0x57, 0x22, 0xad, 0x17, 0x22, 0x9d, 0x4c, 0x85, 0xa4, 0x3f, 0xb8, 0x0b, 0xf9, - 0x9e, 0x79, 0xdf, 0x67, 0x7e, 0xc0, 0x5e, 0x34, 0xf6, 0xe9, 0x10, 0xf7, 0xd3, 0x84, 0x11, 0x9f, - 0xe2, 0x51, 0x4a, 0x93, 0xb1, 0x1b, 0x27, 0x5c, 0x72, 0xf8, 0x57, 0x8d, 0x5c, 0x3d, 0xb2, 0x2a, - 0x01, 0x0f, 0xb8, 0x9a, 0xe0, 0xc5, 0x57, 0x06, 0x59, 0xfb, 0x01, 0xe7, 0xc1, 0x90, 0x62, 0x12, - 0x87, 0x98, 0x30, 0xc6, 0x25, 0x91, 0x21, 0x67, 0x42, 0x4f, 0xeb, 0x3e, 0x17, 0x11, 0x17, 0xd8, - 0x23, 0x42, 0x67, 0xe3, 0xdb, 0x86, 0x47, 0x25, 0x69, 0xe0, 0x98, 0x04, 0x21, 0x53, 0xb0, 0x66, - 0xad, 0xbc, 0x49, 0x4c, 0x12, 0x12, 0x2d, 0x73, 0x8e, 0xf2, 0x33, 0x1a, 0x73, 0x7f, 0xd0, 0xf3, - 0xd2, 0x84, 0xf5, 0x7c, 0xce, 0xfa, 0x61, 0x90, 0x61, 0x76, 0x05, 0xc0, 0xab, 0x45, 0xc9, 0xa5, - 0x5a, 0xdb, 0xa5, 0xa3, 0x94, 0x0a, 0x69, 0x9f, 0x83, 0xff, 0xb9, 0xbf, 0x22, 0xe6, 0x4c, 0x50, - 0xd8, 0x02, 0xe5, 0xac, 0x63, 0xd7, 0xac, 0x99, 0xc7, 0x7f, 0x9a, 0x3b, 0x6e, 0x6e, 0xbf, 0x6e, - 0x86, 0xb7, 0x7f, 0x4d, 0xde, 0xab, 0x46, 0x57, 0xa3, 0x76, 0x0d, 0x20, 0x95, 0xd5, 0xa1, 0xf2, - 0x6c, 0x21, 0xd1, 0x4e, 0x13, 0x76, 0xaa, 0x14, 0x96, 0x6d, 0x23, 0x50, 0xdd, 0x48, 0xe8, 0xe6, - 0x0b, 0xf0, 0xaf, 0x30, 0xd2, 0x0a, 0xa8, 0xa0, 0x50, 0xa0, 0xb4, 0x4b, 0x71, 0x71, 0xf3, 0xa5, - 0x04, 0x7e, 0xab, 0x4e, 0x78, 0x0f, 0xca, 0x99, 0x36, 0x3c, 0x28, 0x44, 0xad, 0x9e, 0x8b, 0x65, - 0x6f, 0x43, 0x32, 0x55, 0xbb, 0xfe, 0xf0, 0xfa, 0xf9, 0x54, 0x3a, 0x84, 0x36, 0x56, 0xac, 0x73, - 0xc3, 0x23, 0x12, 0x32, 0xbc, 0xee, 0xaa, 0xe0, 0xb3, 0xb9, 0xb2, 0x2f, 0xe8, 0xac, 0xeb, 0xd8, - 0x78, 0x78, 0x96, 0xfb, 0x53, 0x5c, 0xeb, 0x9d, 0x28, 0x3d, 0x0c, 0x9d, 0x6d, 0x7a, 0x2b, 0xaf, - 0xa5, 0xdd, 0x99, 0xcc, 0x90, 0x39, 0x9d, 0x21, 0xf3, 0x63, 0x86, 0xcc, 0xc7, 0x39, 0x32, 0xa6, - 0x73, 0x64, 0xbc, 0xcd, 0x91, 0x71, 0xed, 0x04, 0xa1, 0x1c, 0xa4, 0x9e, 0xeb, 0xf3, 0x68, 0x5d, - 0xe4, 0xdd, 0x77, 0xa8, 0x1c, 0xc7, 0x54, 0x78, 0x65, 0xf5, 0xee, 0x5a, 0x5f, 0x01, 0x00, 0x00, - 0xff, 0xff, 0x3f, 0x88, 0x3f, 0xe5, 0x46, 0x03, 0x00, 0x00, + // 594 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0x4d, 0x6b, 0x13, 0x41, + 0x18, 0xc7, 0xb3, 0x35, 0xe6, 0x30, 0x52, 0x84, 0xb1, 0x82, 0x59, 0x64, 0x53, 0x07, 0xb5, 0x2f, + 0x90, 0x1d, 0xda, 0xaa, 0x17, 0x05, 0x49, 0x44, 0x03, 0x1e, 0xa4, 0xe6, 0x28, 0x48, 0x99, 0xdd, + 0x4e, 0xb6, 0x0b, 0xbb, 0x33, 0x9b, 0x7d, 0x11, 0x43, 0xf1, 0xe2, 0x27, 0x10, 0xc4, 0xb3, 0x37, + 0xfd, 0x2a, 0x3d, 0x16, 0xbc, 0x78, 0x12, 0x49, 0x3c, 0xf8, 0x31, 0x24, 0xb3, 0x4f, 0x9a, 0x7d, + 0x4b, 0x4c, 0x6f, 0x61, 0x9e, 0xff, 0xf3, 0xfc, 0x7f, 0x4f, 0xe6, 0xbf, 0x83, 0x9a, 0xfe, 0xc8, + 0xe6, 0x1e, 0x1d, 0x24, 0xa1, 0x60, 0x36, 0xa7, 0xc3, 0x84, 0x87, 0x23, 0x33, 0x08, 0x65, 0x2c, + 0xf1, 0xba, 0x2a, 0x99, 0x50, 0xd2, 0x37, 0x1c, 0xe9, 0x48, 0x55, 0xa1, 0xd3, 0x5f, 0xa9, 0x48, + 0xbf, 0xed, 0x48, 0xe9, 0x78, 0x9c, 0xb2, 0xc0, 0xa5, 0x4c, 0x08, 0x19, 0xb3, 0xd8, 0x95, 0x22, + 0x82, 0xea, 0xae, 0x2d, 0x23, 0x5f, 0x46, 0xd4, 0x62, 0x11, 0xcc, 0xa6, 0xef, 0xf6, 0x2c, 0x1e, + 0xb3, 0x3d, 0x1a, 0x30, 0xc7, 0x15, 0x4a, 0x0c, 0x5a, 0x3d, 0x4f, 0x12, 0xb0, 0x90, 0xf9, 0xb3, + 0x39, 0xf7, 0xf2, 0x35, 0x1e, 0x48, 0xfb, 0xe4, 0xc8, 0x4a, 0x42, 0x71, 0x64, 0x4b, 0x31, 0x70, + 0x1d, 0x90, 0xb5, 0xf2, 0x32, 0x25, 0x60, 0xbe, 0x4c, 0x44, 0x0c, 0x02, 0x23, 0xcb, 0x33, 0x23, + 0xb1, 0xa5, 0x0b, 0x0c, 0x64, 0x03, 0xe1, 0xd7, 0x53, 0xca, 0x43, 0x65, 0xde, 0xe7, 0xc3, 0x84, + 0x47, 0x31, 0x79, 0x89, 0x6e, 0xe4, 0x4e, 0xa3, 0x40, 0x8a, 0x88, 0xe3, 0x03, 0xd4, 0x48, 0x21, + 0x6f, 0x69, 0x9b, 0xda, 0xf6, 0xb5, 0xfd, 0x9b, 0x66, 0xee, 0x0f, 0x33, 0x53, 0x79, 0xb7, 0x7e, + 0xf6, 0xab, 0x55, 0xeb, 0x83, 0x94, 0x6c, 0x22, 0x43, 0xcd, 0xea, 0xf1, 0xf8, 0xf9, 0x74, 0x8b, + 0x6e, 0x12, 0x8a, 0x67, 0x6a, 0x87, 0x99, 0xdb, 0x10, 0xb5, 0x16, 0x2a, 0xc0, 0xf9, 0x15, 0xba, + 0x5e, 0x28, 0x01, 0x82, 0x51, 0x40, 0x28, 0xa8, 0x80, 0xa5, 0xd8, 0x4c, 0x1e, 0xa3, 0xe6, 0xcc, + 0x72, 0x7a, 0xda, 0x51, 0x7f, 0x19, 0xf0, 0x60, 0x03, 0x21, 0xf7, 0x98, 0x8b, 0xd8, 0x1d, 0xb8, + 0x3c, 0x54, 0x3e, 0xf5, 0x7e, 0xe6, 0x84, 0xbc, 0x45, 0x7a, 0x55, 0x33, 0xa0, 0x3e, 0x45, 0xc8, + 0xba, 0x38, 0x05, 0xca, 0x66, 0x81, 0x72, 0xde, 0x06, 0x80, 0x99, 0x16, 0x62, 0x03, 0x5b, 0xc7, + 0xf3, 0xca, 0x6c, 0x2f, 0x10, 0x9a, 0xe7, 0x08, 0xa6, 0xdf, 0x37, 0xd3, 0x4b, 0x36, 0xa7, 0x97, + 0x6c, 0xa6, 0x81, 0x86, 0xab, 0x36, 0x0f, 0x99, 0xc3, 0xa1, 0xb7, 0x9f, 0xe9, 0x24, 0xdf, 0x34, + 0x58, 0xa2, 0xe0, 0xb2, 0x60, 0x89, 0x2b, 0x97, 0x5c, 0x02, 0xf7, 0x72, 0x9c, 0x6b, 0x8a, 0x73, + 0xeb, 0xbf, 0x9c, 0xa9, 0x7b, 0x16, 0x74, 0xff, 0x6f, 0x1d, 0x5d, 0x55, 0xa0, 0xf8, 0x14, 0x35, + 0xd2, 0x80, 0xe1, 0x3b, 0x05, 0x92, 0x72, 0x82, 0x75, 0xb2, 0x4c, 0x92, 0xda, 0x90, 0xdd, 0x8f, + 0x3f, 0xfe, 0x7c, 0x5e, 0xbb, 0x8b, 0x09, 0x55, 0xda, 0xf6, 0xb1, 0xf4, 0x99, 0x2b, 0x68, 0xd5, + 0x57, 0x89, 0xbf, 0x6b, 0xa5, 0x04, 0xe2, 0x76, 0x95, 0xc7, 0xc2, 0x98, 0xeb, 0xe6, 0xaa, 0x72, + 0xc0, 0x7b, 0xa8, 0xf0, 0x28, 0x6e, 0x2f, 0xc3, 0x2b, 0x3d, 0x0c, 0xf8, 0xab, 0x86, 0xd0, 0xfc, + 0x6a, 0xf0, 0xf6, 0x02, 0xd7, 0x52, 0xb4, 0xf4, 0x9d, 0x15, 0x94, 0x80, 0xf6, 0x44, 0xa1, 0x3d, + 0xc2, 0x0f, 0x96, 0xa1, 0x65, 0x1e, 0x23, 0x7a, 0x3a, 0xff, 0x7c, 0x3e, 0xe0, 0x2f, 0x1a, 0x5a, + 0x9f, 0x0f, 0xed, 0x78, 0x5e, 0x35, 0x64, 0x55, 0xfe, 0xab, 0x21, 0x2b, 0x33, 0x4c, 0xa8, 0x82, + 0xdc, 0xc1, 0x5b, 0x2b, 0x42, 0x76, 0x7b, 0x67, 0x63, 0x43, 0x3b, 0x1f, 0x1b, 0xda, 0xef, 0xb1, + 0xa1, 0x7d, 0x9a, 0x18, 0xb5, 0xf3, 0x89, 0x51, 0xfb, 0x39, 0x31, 0x6a, 0x6f, 0xda, 0x8e, 0x1b, + 0x9f, 0x24, 0x96, 0x69, 0x4b, 0xbf, 0x6a, 0xd8, 0xfb, 0x8b, 0x71, 0xf1, 0x28, 0xe0, 0x91, 0xd5, + 0x50, 0x6f, 0xeb, 0xc1, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf9, 0x0c, 0x8e, 0x69, 0x6b, 0x06, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -247,6 +449,9 @@ type QueryClient interface { 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 { @@ -275,12 +480,33 @@ func (c *queryClient) EpochBurnConfig(ctx context.Context, in *QueryGetEpochBurn 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. @@ -293,6 +519,12 @@ func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsReq 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) @@ -334,6 +566,42 @@ func _Query_EpochBurnConfig_Handler(srv interface{}, ctx context.Context, dec fu 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), @@ -346,6 +614,14 @@ var _Query_serviceDesc = grpc.ServiceDesc{ 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", @@ -463,6 +739,151 @@ func (m *QueryGetEpochBurnConfigResponse) MarshalToSizedBuffer(dAtA []byte) (int 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.Identifier != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Identifier)) + 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 @@ -514,7 +935,62 @@ func (m *QueryGetEpochBurnConfigResponse) Size() (n int) { return n } -func sovQuery(x uint64) (n int) { +func (m *QueryGetBurnAmountRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Identifier != 0 { + n += 1 + sovQuery(uint64(m.Identifier)) + } + 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) { @@ -786,6 +1262,364 @@ func (m *QueryGetEpochBurnConfigResponse) Unmarshal(dAtA []byte) error { } 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 Identifier", wireType) + } + m.Identifier = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Identifier |= 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 diff --git a/x/furnace/types/query.pb.gw.go b/x/furnace/types/query.pb.gw.go index 56e36253..d64a24ab 100644 --- a/x/furnace/types/query.pb.gw.go +++ b/x/furnace/types/query.pb.gw.go @@ -69,6 +69,96 @@ func local_request_Query_EpochBurnConfig_0(ctx context.Context, marshaler runtim } +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["identifier"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "identifier") + } + + protoReq.Identifier, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "identifier", 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["identifier"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "identifier") + } + + protoReq.Identifier, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "identifier", 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. @@ -121,6 +211,52 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + 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 } @@ -202,6 +338,46 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + 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 } @@ -209,10 +385,18 @@ 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", "identifier"}, "", 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 ) From 17e285483b1515eec18e73f41062d02316f4a672 Mon Sep 17 00:00:00 2001 From: tarumi Date: Thu, 21 Sep 2023 16:23:36 +0200 Subject: [PATCH 16/28] rename burnamountlist --- proto/mycel/furnace/genesis.proto | 2 +- .../client/cli/query_burn_amount_test.go | 4 +- .../cli/query_epoch_burn_config_test.go | 4 +- x/furnace/genesis.go | 4 +- x/furnace/genesis_test.go | 4 +- x/furnace/types/genesis.go | 4 +- x/furnace/types/genesis.pb.go | 61 +++++++++---------- 7 files changed, 41 insertions(+), 42 deletions(-) diff --git a/proto/mycel/furnace/genesis.proto b/proto/mycel/furnace/genesis.proto index 37c1dbda..3b247ec6 100644 --- a/proto/mycel/furnace/genesis.proto +++ b/proto/mycel/furnace/genesis.proto @@ -13,6 +13,6 @@ option go_package = "github.com/mycel-domain/mycel/x/furnace/types"; message GenesisState { Params params = 1 [(gogoproto.nullable) = false]; EpochBurnConfig epochBurnConfig = 2 [(gogoproto.nullable) = false]; - repeated BurnAmount burnAmountList = 3 [(gogoproto.nullable) = false]; + repeated BurnAmount burnAmounts = 3 [(gogoproto.nullable) = false]; } diff --git a/x/furnace/client/cli/query_burn_amount_test.go b/x/furnace/client/cli/query_burn_amount_test.go index 4b1f404e..58dcbb12 100644 --- a/x/furnace/client/cli/query_burn_amount_test.go +++ b/x/furnace/client/cli/query_burn_amount_test.go @@ -30,12 +30,12 @@ func networkWithBurnAmountObjects(t *testing.T, n int) (*network.Network, []type Identifier: uint64(i), } nullify.Fill(&burnAmount) - state.BurnAmountList = append(state.BurnAmountList, 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.BurnAmountList + return network.New(t, cfg), state.BurnAmounts } func TestShowBurnAmount(t *testing.T) { diff --git a/x/furnace/client/cli/query_epoch_burn_config_test.go b/x/furnace/client/cli/query_epoch_burn_config_test.go index 1b5e198c..f3356656 100644 --- a/x/furnace/client/cli/query_epoch_burn_config_test.go +++ b/x/furnace/client/cli/query_epoch_burn_config_test.go @@ -21,11 +21,11 @@ func networkWithEpochBurnConfigObjects(t *testing.T) (*network.Network, types.Ep state := types.GenesisState{} epochBurnConfig := &types.EpochBurnConfig{} nullify.Fill(&epochBurnConfig) - state.EpochBurnConfig = 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 + return network.New(t, cfg), state.EpochBurnConfig } func TestShowEpochBurnConfig(t *testing.T) { diff --git a/x/furnace/genesis.go b/x/furnace/genesis.go index 32d16aa4..acf2561c 100644 --- a/x/furnace/genesis.go +++ b/x/furnace/genesis.go @@ -12,7 +12,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) genState.EpochBurnConfig.StartTime = ctx.BlockTime() k.SetEpochBurnConfig(ctx, genState.EpochBurnConfig) // Set all the burnAmount - for _, elem := range genState.BurnAmountList { + for _, elem := range genState.BurnAmounts { k.SetBurnAmount(ctx, elem) } // this line is used by starport scaffolding # genesis/module/init @@ -29,7 +29,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { if found { genesis.EpochBurnConfig = epochBurnConfig } - genesis.BurnAmountList = k.GetAllBurnAmount(ctx) + 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 index 7cb0ad40..cd2fa5e1 100644 --- a/x/furnace/genesis_test.go +++ b/x/furnace/genesis_test.go @@ -17,7 +17,7 @@ func TestGenesis(t *testing.T) { EpochBurnConfig: &types.EpochBurnConfig{ EpochIdentifier: "11", }, - BurnAmountList: []types.BurnAmount{ + BurnAmounts: []types.BurnAmount{ { Identifier: 0, }, @@ -37,6 +37,6 @@ func TestGenesis(t *testing.T) { nullify.Fill(got) require.Equal(t, genesisState.EpochBurnConfig, got.EpochBurnConfig) - require.ElementsMatch(t, genesisState.BurnAmountList, got.BurnAmountList) + require.ElementsMatch(t, genesisState.BurnAmounts, got.BurnAmountList) // this line is used by starport scaffolding # genesis/test/assert } diff --git a/x/furnace/types/genesis.go b/x/furnace/types/genesis.go index ad99b214..9722e255 100644 --- a/x/furnace/types/genesis.go +++ b/x/furnace/types/genesis.go @@ -21,7 +21,7 @@ func GetDefaultEpochBurnConfig() EpochBurnConfig { func DefaultGenesis() *GenesisState { return &GenesisState{ EpochBurnConfig: GetDefaultEpochBurnConfig(), - BurnAmountList: []BurnAmount{}, + BurnAmounts: []BurnAmount{}, // this line is used by starport scaffolding # genesis/types/default Params: DefaultParams(), } @@ -33,7 +33,7 @@ func (gs GenesisState) Validate() error { // Check for duplicated index in burnAmount burnAmountIndexMap := make(map[string]struct{}) - for _, elem := range gs.BurnAmountList { + for _, elem := range gs.BurnAmounts { index := string(BurnAmountKey(elem.Identifier)) if _, ok := burnAmountIndexMap[index]; ok { return fmt.Errorf("duplicated index for burnAmount") diff --git a/x/furnace/types/genesis.pb.go b/x/furnace/types/genesis.pb.go index 9227f44c..24797199 100644 --- a/x/furnace/types/genesis.pb.go +++ b/x/furnace/types/genesis.pb.go @@ -27,7 +27,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package 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"` - BurnAmountList []BurnAmount `protobuf:"bytes,3,rep,name=burnAmountList,proto3" json:"burnAmountList"` + BurnAmounts []BurnAmount `protobuf:"bytes,3,rep,name=burnAmounts,proto3" json:"burnAmounts"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -77,9 +77,9 @@ func (m *GenesisState) GetEpochBurnConfig() EpochBurnConfig { return EpochBurnConfig{} } -func (m *GenesisState) GetBurnAmountList() []BurnAmount { +func (m *GenesisState) GetBurnAmounts() []BurnAmount { if m != nil { - return m.BurnAmountList + return m.BurnAmounts } return nil } @@ -91,26 +91,25 @@ func init() { func init() { proto.RegisterFile("mycel/furnace/genesis.proto", fileDescriptor_cb6ac84609cb49bc) } var fileDescriptor_cb6ac84609cb49bc = []byte{ - // 289 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x90, 0x4f, 0x4b, 0xc3, 0x30, - 0x18, 0xc6, 0x1b, 0x27, 0x3b, 0x74, 0xfe, 0x81, 0xa2, 0x50, 0x2b, 0x64, 0x43, 0x10, 0x76, 0x59, - 0x0b, 0xdb, 0x27, 0xb0, 0x22, 0xbd, 0x88, 0x88, 0xde, 0xbc, 0x8c, 0xb4, 0x66, 0x5d, 0xc1, 0x24, - 0x25, 0x4d, 0xc0, 0x7d, 0x0b, 0x3f, 0xd6, 0x8e, 0x3b, 0x7a, 0x10, 0x91, 0xf6, 0x8b, 0xc8, 0xde, - 0x84, 0x41, 0x7a, 0x6b, 0x79, 0x7e, 0xcf, 0x2f, 0x0f, 0xaf, 0x7f, 0xcd, 0x36, 0x05, 0xfd, 0x48, - 0x56, 0x5a, 0x72, 0x52, 0xd0, 0xa4, 0xa4, 0x9c, 0x36, 0x55, 0x13, 0xd7, 0x52, 0x28, 0x11, 0x9c, - 0x42, 0x18, 0xdb, 0x30, 0xba, 0x28, 0x45, 0x29, 0x20, 0x49, 0xf6, 0x5f, 0x06, 0x8a, 0x22, 0xd7, - 0x50, 0x13, 0x49, 0x98, 0x15, 0x44, 0xb7, 0x6e, 0x46, 0x6b, 0x51, 0xac, 0x97, 0xb9, 0x96, 0x7c, - 0x59, 0x08, 0xbe, 0xaa, 0x4a, 0x8b, 0x8d, 0x5d, 0x0c, 0x00, 0xc2, 0x84, 0xe6, 0xca, 0x00, 0x37, - 0x3f, 0xc8, 0x3f, 0xc9, 0xcc, 0xb4, 0x57, 0x45, 0x14, 0x0d, 0x16, 0xfe, 0xd0, 0x3c, 0x14, 0xa2, - 0x09, 0x9a, 0x8e, 0xe6, 0x97, 0xb1, 0x33, 0x35, 0x7e, 0x86, 0x30, 0x3d, 0xde, 0xfe, 0x8e, 0xbd, - 0x17, 0x8b, 0x06, 0x4f, 0xfe, 0x39, 0x2c, 0x48, 0xb5, 0xe4, 0xf7, 0xf0, 0x7e, 0x78, 0x04, 0x6d, - 0xdc, 0x6b, 0x3f, 0xb8, 0x94, 0xd5, 0xf4, 0xcb, 0x41, 0xe6, 0x9f, 0xed, 0xa7, 0xde, 0xc1, 0xd2, - 0xc7, 0xaa, 0x51, 0xe1, 0x60, 0x32, 0x98, 0x8e, 0xe6, 0x57, 0x3d, 0x5d, 0x7a, 0x80, 0xac, 0xa9, - 0x57, 0x4b, 0xb3, 0x6d, 0x8b, 0xd1, 0xae, 0xc5, 0xe8, 0xaf, 0xc5, 0xe8, 0xab, 0xc3, 0xde, 0xae, - 0xc3, 0xde, 0x77, 0x87, 0xbd, 0xb7, 0x59, 0x59, 0xa9, 0xb5, 0xce, 0xe3, 0x42, 0xb0, 0x04, 0xa4, - 0xb3, 0x77, 0xc1, 0x48, 0xc5, 0xcd, 0x4f, 0xf2, 0x79, 0xb8, 0x99, 0xda, 0xd4, 0xb4, 0xc9, 0x87, - 0x70, 0xae, 0xc5, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x8b, 0x9e, 0x52, 0x71, 0xd6, 0x01, 0x00, - 0x00, + // 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) { @@ -133,10 +132,10 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.BurnAmountList) > 0 { - for iNdEx := len(m.BurnAmountList) - 1; iNdEx >= 0; iNdEx-- { + if len(m.BurnAmounts) > 0 { + for iNdEx := len(m.BurnAmounts) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.BurnAmountList[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.BurnAmounts[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -191,8 +190,8 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) l = m.EpochBurnConfig.Size() n += 1 + l + sovGenesis(uint64(l)) - if len(m.BurnAmountList) > 0 { - for _, e := range m.BurnAmountList { + if len(m.BurnAmounts) > 0 { + for _, e := range m.BurnAmounts { l = e.Size() n += 1 + l + sovGenesis(uint64(l)) } @@ -303,7 +302,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BurnAmountList", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field BurnAmounts", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -330,8 +329,8 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.BurnAmountList = append(m.BurnAmountList, BurnAmount{}) - if err := m.BurnAmountList[len(m.BurnAmountList)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.BurnAmounts = append(m.BurnAmounts, BurnAmount{}) + if err := m.BurnAmounts[len(m.BurnAmounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex From eb34a4543ea26ea42d46adcaefbb1eb449d56941 Mon Sep 17 00:00:00 2001 From: tarumi Date: Thu, 21 Sep 2023 17:35:18 +0200 Subject: [PATCH 17/28] fix compilation err --- x/furnace/client/cli/query_epoch_burn_config_test.go | 4 ---- x/furnace/genesis_test.go | 4 ++-- x/furnace/types/genesis_test.go | 4 ++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/x/furnace/client/cli/query_epoch_burn_config_test.go b/x/furnace/client/cli/query_epoch_burn_config_test.go index f3356656..56c92940 100644 --- a/x/furnace/client/cli/query_epoch_burn_config_test.go +++ b/x/furnace/client/cli/query_epoch_burn_config_test.go @@ -61,10 +61,6 @@ func TestShowEpochBurnConfig(t *testing.T) { var resp types.QueryGetEpochBurnConfigResponse require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) require.NotNil(t, resp.EpochBurnConfig) - require.Equal(t, - nullify.Fill(&tc.obj), - nullify.Fill(&resp.EpochBurnConfig), - ) } }) } diff --git a/x/furnace/genesis_test.go b/x/furnace/genesis_test.go index cd2fa5e1..d6e9b1b7 100644 --- a/x/furnace/genesis_test.go +++ b/x/furnace/genesis_test.go @@ -14,7 +14,7 @@ func TestGenesis(t *testing.T) { genesisState := types.GenesisState{ Params: types.DefaultParams(), - EpochBurnConfig: &types.EpochBurnConfig{ + EpochBurnConfig: types.EpochBurnConfig{ EpochIdentifier: "11", }, BurnAmounts: []types.BurnAmount{ @@ -37,6 +37,6 @@ func TestGenesis(t *testing.T) { nullify.Fill(got) require.Equal(t, genesisState.EpochBurnConfig, got.EpochBurnConfig) - require.ElementsMatch(t, genesisState.BurnAmounts, got.BurnAmountList) + require.ElementsMatch(t, genesisState.BurnAmounts, got.BurnAmounts) // this line is used by starport scaffolding # genesis/test/assert } diff --git a/x/furnace/types/genesis_test.go b/x/furnace/types/genesis_test.go index 72e4dd4a..9de4522e 100644 --- a/x/furnace/types/genesis_test.go +++ b/x/furnace/types/genesis_test.go @@ -25,7 +25,7 @@ func TestGenesisState_Validate(t *testing.T) { EpochBurnConfig: types.EpochBurnConfig{ EpochIdentifier: "35", }, - BurnAmountList: []types.BurnAmount{ + BurnAmounts: []types.BurnAmount{ { Identifier: 0, }, @@ -40,7 +40,7 @@ func TestGenesisState_Validate(t *testing.T) { { desc: "duplicated burnAmount", genState: &types.GenesisState{ - BurnAmountList: []types.BurnAmount{ + BurnAmounts: []types.BurnAmount{ { Identifier: 0, }, From 8dd1a7e05d76f1c8d936a430817f5aa727eaa3c4 Mon Sep 17 00:00:00 2001 From: tarumi Date: Mon, 25 Sep 2023 13:21:41 +0200 Subject: [PATCH 18/28] add validate epoch identifier --- x/epochs/types/epoch_identifier.go | 23 +++++++++++++++++ x/epochs/types/errors.go | 2 ++ x/furnace/keeper/hooks.go | 40 ++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 x/furnace/keeper/hooks.go diff --git a/x/epochs/types/epoch_identifier.go b/x/epochs/types/epoch_identifier.go index bea49877..791951dc 100644 --- a/x/epochs/types/epoch_identifier.go +++ b/x/epochs/types/epoch_identifier.go @@ -1,6 +1,29 @@ package types +import ( + errorsmod "cosmossdk.io/errors" +) + const ( 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/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/furnace/keeper/hooks.go b/x/furnace/keeper/hooks.go new file mode 100644 index 00000000..debf050d --- /dev/null +++ b/x/furnace/keeper/hooks.go @@ -0,0 +1,40 @@ +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) { + params := k.GetParams(ctx) + _ = params +} + +// ___________________________________________________________________________________________________ + +// 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) +} From 5bb8360eb8be443c2d9ae0f7172f2b74bb71abad Mon Sep 17 00:00:00 2001 From: tarumi Date: Mon, 25 Sep 2023 14:14:09 +0200 Subject: [PATCH 19/28] add burn logic --- x/furnace/keeper/hooks.go | 41 +++++++++++++++++++++++++++-- x/furnace/types/event.go | 10 +++++++ x/furnace/types/expected_keepers.go | 2 ++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 x/furnace/types/event.go diff --git a/x/furnace/keeper/hooks.go b/x/furnace/keeper/hooks.go index debf050d..68c9981a 100644 --- a/x/furnace/keeper/hooks.go +++ b/x/furnace/keeper/hooks.go @@ -3,6 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" epochstypes "github.com/mycel-domain/mycel/x/epochs/types" + "github.com/mycel-domain/mycel/x/furnace/types" ) // BeforeEpochStart is the epoch start hook. @@ -11,8 +12,44 @@ func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochN // AfterEpochEnd is the epoch end hook. func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) { - params := k.GetParams(ctx) - _ = params + // Get the epoch burn config. + config, found := k.GetEpochBurnConfig(ctx) + if !found { + panic("epoch burn config not found") + } + + if config.EpochIdentifier == epochIdentifier { + burnAmount, found := k.GetBurnAmount(ctx, config.CurrentBurnAmountIdentifier) + if !found { + panic("burn amount not found") + } + + // Calc burn amount for this epoch. + epochInfo, found := k.epochsKeeper.GetEpochInfo(ctx, epochIdentifier) + if !found { + panic("epoch info not found") + } + burntAmount := burnAmount.TotalBurnAmount.Amount.Mul(sdk.NewInt(int64(epochInfo.Duration) / int64(config.Duration))) + burnt := sdk.NewCoin(burnAmount.TotalBurnAmount.Denom, burntAmount) + + // TODO: Burn coins + + // Add the burn amount to burntAmount + burnAmount.BurntAmount = burnAmount.BurntAmount.Add(burnt) + k.SetBurnAmount(ctx, burnAmount) + + // Emit Events + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeEpochBurn, + sdk.NewAttribute(types.AttributeKeyEpochIdentifier, epochIdentifier), + sdk.NewAttribute(types.AttributeKeyEpochNumber, sdk.NewInt(epochNumber).String()), + sdk.NewAttribute(types.AtributeKeyEpochBurnAmount, burntAmount.String()), + sdk.NewAttribute(types.AtributeKeyEpochBurnTimestamp, ctx.BlockTime().String()), + ), + ) + + } } // ___________________________________________________________________________________________________ diff --git a/x/furnace/types/event.go b/x/furnace/types/event.go new file mode 100644 index 00000000..3bbcdab4 --- /dev/null +++ b/x/furnace/types/event.go @@ -0,0 +1,10 @@ +package types + +const ( + EventTypeEpochBurn = "epoch-burn" + + AttributeKeyEpochIdentifier = "epoch-identifier" + AttributeKeyEpochNumber = "epoch-number" + AtributeKeyEpochBurnAmount = "epoch-burn-amount" + AtributeKeyEpochBurnTimestamp = "epoch-burn-timestamp" +) diff --git a/x/furnace/types/expected_keepers.go b/x/furnace/types/expected_keepers.go index e496643a..30d6c3a9 100644 --- a/x/furnace/types/expected_keepers.go +++ b/x/furnace/types/expected_keepers.go @@ -3,10 +3,12 @@ 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) From 02e2aae6459d543e95d8afdfff348aa7a081fddf Mon Sep 17 00:00:00 2001 From: tarumi Date: Mon, 25 Sep 2023 17:04:13 +0200 Subject: [PATCH 20/28] [wip] add test --- app/app.go | 27 +++++++++----- x/furnace/keeper/hooks_test.go | 67 ++++++++++++++++++++++++++++++++++ x/furnace/keeper/setup_test.go | 41 +++++++++++++++++++++ 3 files changed, 126 insertions(+), 9 deletions(-) create mode 100644 x/furnace/keeper/hooks_test.go create mode 100644 x/furnace/keeper/setup_test.go diff --git a/app/app.go b/app/app.go index a38df082..f8351deb 100644 --- a/app/app.go +++ b/app/app.go @@ -679,7 +679,7 @@ func NewApp( ), ) - // my modules + // My module's keepers app.EpochsKeeper = *epochsmodulekeeper.NewKeeper( appCodec, keys[epochsmoduletypes.StoreKey], @@ -687,13 +687,14 @@ func NewApp( app.GetSubspace(epochsmoduletypes.ModuleName), ) - app.EpochsKeeper.SetHooks( - epochsmoduletypes.NewMultiEpochHooks( - app.RegistryKeeper.Hooks(), - // insert hooks here - )) + app.ResolverKeeper = *resolvermodulekeeper.NewKeeper( + appCodec, + keys[resolvermoduletypes.StoreKey], + keys[resolvermoduletypes.MemStoreKey], + app.GetSubspace(resolvermoduletypes.ModuleName), - epochsModule := epochsmodule.NewAppModule(appCodec, app.EpochsKeeper, app.AccountKeeper, app.BankKeeper) + app.RegistryKeeper, + ) app.RegistryKeeper = *registrymodulekeeper.NewKeeper( appCodec, @@ -703,7 +704,6 @@ func NewApp( app.BankKeeper, ) - registryModule := registrymodule.NewAppModule(appCodec, app.RegistryKeeper, app.AccountKeeper, app.BankKeeper) app.ResolverKeeper = *resolvermodulekeeper.NewKeeper( appCodec, @@ -713,7 +713,6 @@ func NewApp( app.RegistryKeeper, ) - resolverModule := resolvermodule.NewAppModule(appCodec, app.ResolverKeeper, app.AccountKeeper, app.BankKeeper) app.FurnaceKeeper = *furnacemodulekeeper.NewKeeper( appCodec, @@ -724,6 +723,16 @@ func NewApp( 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 diff --git a/x/furnace/keeper/hooks_test.go b/x/furnace/keeper/hooks_test.go new file mode 100644 index 00000000..17185a59 --- /dev/null +++ b/x/furnace/keeper/hooks_test.go @@ -0,0 +1,67 @@ +package keeper_test + +import ( + "fmt" + "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 ExpEvent struct { + EpochIdentifier string + EpochNumber string + BurntAmount string +} + +func (suite *KeeperTestSuite) TestAfterEpochEnd() { + var ( + now = time.Now() + ) + testCases := []struct { + totalBurnAmount int64 + identifier uint64 + expectedEvent ExpEvent + fn func() + }{ + { + totalBurnAmount: 100, + identifier: 1, + expectedEvent: ExpEvent{ + EpochIdentifier: "1", + EpochNumber: "1", + BurntAmount: "100", + }, + 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, epochstypes.DailyEpochId) + suite.Require().True(found) + suite.Require().Equal(int64(2), epochInfo.CurrentEpoch) + + }, + }, + } + + for i, tc := range testCases { + suite.Run(fmt.Sprintf("Case %d", i), func() { + suite.SetupTest() + + tc.fn() + + // 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) + event := events[0] + suite.Require().Equal(tc.expectedEvent.EpochIdentifier, event.Attributes[0].Value) + suite.Require().Equal(tc.expectedEvent.EpochNumber, event.Attributes[1].Value) + suite.Require().Equal(tc.expectedEvent.BurntAmount, event.Attributes[2].Value) + }) + } + +} 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) +} From bcfc042b5374b674ecc4b570ab9fd51a32da213f Mon Sep 17 00:00:00 2001 From: tarumi Date: Tue, 26 Sep 2023 11:19:18 +0200 Subject: [PATCH 21/28] refactor burnamount store --- docs/static/openapi.yml | 71 ++++++--- proto/mycel/furnace/burn_amount.proto | 9 +- proto/mycel/furnace/epoch_burn_config.proto | 11 +- x/furnace/client/cli/query_burn_amount.go | 2 +- x/furnace/keeper/burn_amount.go | 10 +- x/furnace/keeper/hooks.go | 10 +- x/furnace/keeper/hooks_test.go | 51 ++++--- x/furnace/types/burn_amount.pb.go | 154 ++++++++++++++------ x/furnace/types/epoch_burn_config.pb.go | 128 +++++++--------- x/furnace/types/genesis.go | 19 ++- x/furnace/types/genesis_test.go | 8 +- x/furnace/types/key_burn_amount.go | 8 +- 12 files changed, 292 insertions(+), 189 deletions(-) diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index df0d6fbb..65ae024c 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -49705,11 +49705,17 @@ paths: items: type: object properties: - identifier: + index: type: string format: uint64 burnStarted: type: boolean + totalEpochs: + type: string + format: uint64 + currentEpoch: + type: string + format: uint64 totalBurnAmount: type: object properties: @@ -49725,7 +49731,7 @@ paths: custom method signatures required by gogoproto. - burntAmount: + cumulativeBurntAmount: type: object properties: denom: @@ -49858,11 +49864,17 @@ paths: burnAmount: type: object properties: - identifier: + index: type: string format: uint64 burnStarted: type: boolean + totalEpochs: + type: string + format: uint64 + currentEpoch: + type: string + format: uint64 totalBurnAmount: type: object properties: @@ -49878,7 +49890,7 @@ paths: custom method signatures required by gogoproto. - burntAmount: + cumulativeBurntAmount: type: object properties: denom: @@ -49934,14 +49946,15 @@ paths: properties: epochIdentifier: type: string - currentBurnAmountIdentifier: + currentBurnAmountIndex: + type: string + format: uint64 + defaultTotalEpochs: type: string format: uint64 startTime: type: string format: date-time - duration: - type: string default: description: An unexpected error response. schema: @@ -80955,11 +80968,17 @@ definitions: mycel.furnace.BurnAmount: type: object properties: - identifier: + index: type: string format: uint64 burnStarted: type: boolean + totalEpochs: + type: string + format: uint64 + currentEpoch: + type: string + format: uint64 totalBurnAmount: type: object properties: @@ -80972,7 +80991,7 @@ definitions: NOTE: The amount field is an Int which implements the custom method signatures required by gogoproto. - burntAmount: + cumulativeBurntAmount: type: object properties: denom: @@ -80989,14 +81008,15 @@ definitions: properties: epochIdentifier: type: string - currentBurnAmountIdentifier: + currentBurnAmountIndex: + type: string + format: uint64 + defaultTotalEpochs: type: string format: uint64 startTime: type: string format: date-time - duration: - type: string mycel.furnace.Params: type: object description: Params defines the parameters for the module. @@ -81008,11 +81028,17 @@ definitions: items: type: object properties: - identifier: + index: type: string format: uint64 burnStarted: type: boolean + totalEpochs: + type: string + format: uint64 + currentEpoch: + type: string + format: uint64 totalBurnAmount: type: object properties: @@ -81028,7 +81054,7 @@ definitions: method signatures required by gogoproto. - burntAmount: + cumulativeBurntAmount: type: object properties: denom: @@ -81075,11 +81101,17 @@ definitions: burnAmount: type: object properties: - identifier: + index: type: string format: uint64 burnStarted: type: boolean + totalEpochs: + type: string + format: uint64 + currentEpoch: + type: string + format: uint64 totalBurnAmount: type: object properties: @@ -81095,7 +81127,7 @@ definitions: method signatures required by gogoproto. - burntAmount: + cumulativeBurntAmount: type: object properties: denom: @@ -81118,14 +81150,15 @@ definitions: properties: epochIdentifier: type: string - currentBurnAmountIdentifier: + currentBurnAmountIndex: + type: string + format: uint64 + defaultTotalEpochs: type: string format: uint64 startTime: type: string format: date-time - duration: - type: string mycel.furnace.QueryParamsResponse: type: object properties: diff --git a/proto/mycel/furnace/burn_amount.proto b/proto/mycel/furnace/burn_amount.proto index 271baed0..67b14d55 100644 --- a/proto/mycel/furnace/burn_amount.proto +++ b/proto/mycel/furnace/burn_amount.proto @@ -6,10 +6,11 @@ import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; message BurnAmount { - uint64 identifier = 1; + uint64 index = 1; bool burnStarted = 2; - cosmos.base.v1beta1.Coin totalBurnAmount = 3 [(gogoproto.nullable) = false]; - cosmos.base.v1beta1.Coin burntAmount = 4 [(gogoproto.nullable) = false]; - + 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 index 76642e41..3bbcfb43 100644 --- a/proto/mycel/furnace/epoch_burn_config.proto +++ b/proto/mycel/furnace/epoch_burn_config.proto @@ -10,16 +10,11 @@ option go_package = "github.com/mycel-domain/mycel/x/furnace/types"; message EpochBurnConfig { string epochIdentifier = 1; - uint64 currentBurnAmountIdentifier = 2; - google.protobuf.Timestamp startTime = 3 [ + uint64 currentBurnAmountIndex = 2; + uint64 defaultTotalEpochs = 3; + google.protobuf.Timestamp startTime = 4 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"start_time\"" ]; - google.protobuf.Duration duration = 4[ - (gogoproto.nullable) = false, - (gogoproto.stdduration) = true, - (gogoproto.jsontag) = "duration,omitempty", - (gogoproto.moretags) = "yaml:\"duration\"" - ]; } diff --git a/x/furnace/client/cli/query_burn_amount.go b/x/furnace/client/cli/query_burn_amount.go index 23e20e01..9320714f 100644 --- a/x/furnace/client/cli/query_burn_amount.go +++ b/x/furnace/client/cli/query_burn_amount.go @@ -47,7 +47,7 @@ func CmdListBurnAmount() *cobra.Command { func CmdShowBurnAmount() *cobra.Command { cmd := &cobra.Command{ - Use: "show-burn-amount [identifier]", + Use: "show-burn-amount [index]", Short: "shows a burnAmount", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/x/furnace/keeper/burn_amount.go b/x/furnace/keeper/burn_amount.go index 35dc62f3..a43f22de 100644 --- a/x/furnace/keeper/burn_amount.go +++ b/x/furnace/keeper/burn_amount.go @@ -11,20 +11,20 @@ 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.Identifier, + burnAmount.Index, ), b) } // GetBurnAmount returns a burnAmount from its index func (k Keeper) GetBurnAmount( ctx sdk.Context, - identifier uint64, + index uint64, ) (val types.BurnAmount, found bool) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BurnAmountKeyPrefix)) b := store.Get(types.BurnAmountKey( - identifier, + index, )) if b == nil { return val, false @@ -37,12 +37,12 @@ func (k Keeper) GetBurnAmount( // RemoveBurnAmount removes a burnAmount from the store func (k Keeper) RemoveBurnAmount( ctx sdk.Context, - identifier uint64, + index uint64, ) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BurnAmountKeyPrefix)) store.Delete(types.BurnAmountKey( - identifier, + index, )) } diff --git a/x/furnace/keeper/hooks.go b/x/furnace/keeper/hooks.go index 68c9981a..7e3a79e1 100644 --- a/x/furnace/keeper/hooks.go +++ b/x/furnace/keeper/hooks.go @@ -19,7 +19,7 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumb } if config.EpochIdentifier == epochIdentifier { - burnAmount, found := k.GetBurnAmount(ctx, config.CurrentBurnAmountIdentifier) + burnAmount, found := k.GetBurnAmount(ctx, config.CurrentBurnAmountIndex) if !found { panic("burn amount not found") } @@ -29,14 +29,12 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumb if !found { panic("epoch info not found") } - burntAmount := burnAmount.TotalBurnAmount.Amount.Mul(sdk.NewInt(int64(epochInfo.Duration) / int64(config.Duration))) - burnt := sdk.NewCoin(burnAmount.TotalBurnAmount.Denom, burntAmount) // TODO: Burn coins + _ = epochInfo + _ = burnAmount // Add the burn amount to burntAmount - burnAmount.BurntAmount = burnAmount.BurntAmount.Add(burnt) - k.SetBurnAmount(ctx, burnAmount) // Emit Events ctx.EventManager().EmitEvent( @@ -44,7 +42,7 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumb types.EventTypeEpochBurn, sdk.NewAttribute(types.AttributeKeyEpochIdentifier, epochIdentifier), sdk.NewAttribute(types.AttributeKeyEpochNumber, sdk.NewInt(epochNumber).String()), - sdk.NewAttribute(types.AtributeKeyEpochBurnAmount, burntAmount.String()), + sdk.NewAttribute(types.AtributeKeyEpochBurnAmount, burnAmount.String()), sdk.NewAttribute(types.AtributeKeyEpochBurnTimestamp, ctx.BlockTime().String()), ), ) diff --git a/x/furnace/keeper/hooks_test.go b/x/furnace/keeper/hooks_test.go index 17185a59..ff4c310a 100644 --- a/x/furnace/keeper/hooks_test.go +++ b/x/furnace/keeper/hooks_test.go @@ -2,16 +2,16 @@ package keeper_test import ( "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" "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 ExpEvent struct { - EpochIdentifier string + EpochIndex string EpochNumber string - BurntAmount string + CumulativeBurntAmount string } func (suite *KeeperTestSuite) TestAfterEpochEnd() { @@ -20,27 +20,32 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { ) testCases := []struct { totalBurnAmount int64 - identifier uint64 - expectedEvent ExpEvent + index uint64 + expectedEvents []ExpEvent fn func() }{ { totalBurnAmount: 100, - identifier: 1, - expectedEvent: ExpEvent{ - EpochIdentifier: "1", - EpochNumber: "1", - BurntAmount: "100", + index: 1, + expectedEvents: []ExpEvent{ + { + EpochIndex: "daily", + EpochNumber: "1", + CumulativeBurntAmount: "0stake", + }, + { + EpochIndex: "daily", + EpochNumber: "2", + CumulativeBurntAmount: "30stake", + }, }, 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, epochstypes.DailyEpochId) - suite.Require().True(found) - suite.Require().Equal(int64(2), epochInfo.CurrentEpoch) + // Begin first block + suite.ctx = suite.ctx.WithBlockHeight(3).WithBlockTime(now.Add(time.Hour * 24)) + suite.app.EpochsKeeper.BeginBlocker(suite.ctx) }, }, @@ -50,6 +55,13 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { suite.Run(fmt.Sprintf("Case %d", i), func() { suite.SetupTest() + // Set burn totalBurnAmount + suite.app.FurnaceKeeper.SetBurnAmount(suite.ctx, types.BurnAmount{ + Index: tc.index, + TotalBurnAmount: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(tc.totalBurnAmount)), + CumulativeBurntAmount: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)), + }) + tc.fn() // TODO: check if token is burnt @@ -57,10 +69,11 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { // Check if event is emitted events, found := testutil.FindEventsByType(suite.ctx.EventManager().Events(), types.EventTypeEpochBurn) suite.Require().True(found) - event := events[0] - suite.Require().Equal(tc.expectedEvent.EpochIdentifier, event.Attributes[0].Value) - suite.Require().Equal(tc.expectedEvent.EpochNumber, event.Attributes[1].Value) - suite.Require().Equal(tc.expectedEvent.BurntAmount, event.Attributes[2].Value) + 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].CumulativeBurntAmount, event.Attributes[2].Value) + } }) } diff --git a/x/furnace/types/burn_amount.pb.go b/x/furnace/types/burn_amount.pb.go index a2c7e7a3..18d0cf09 100644 --- a/x/furnace/types/burn_amount.pb.go +++ b/x/furnace/types/burn_amount.pb.go @@ -25,10 +25,12 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type BurnAmount struct { - Identifier uint64 `protobuf:"varint,1,opt,name=identifier,proto3" json:"identifier,omitempty"` - BurnStarted bool `protobuf:"varint,2,opt,name=burnStarted,proto3" json:"burnStarted,omitempty"` - TotalBurnAmount types.Coin `protobuf:"bytes,3,opt,name=totalBurnAmount,proto3" json:"totalBurnAmount"` - BurntAmount types.Coin `protobuf:"bytes,4,opt,name=burntAmount,proto3" json:"burntAmount"` + 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{} } @@ -64,9 +66,9 @@ func (m *BurnAmount) XXX_DiscardUnknown() { var xxx_messageInfo_BurnAmount proto.InternalMessageInfo -func (m *BurnAmount) GetIdentifier() uint64 { +func (m *BurnAmount) GetIndex() uint64 { if m != nil { - return m.Identifier + return m.Index } return 0 } @@ -78,6 +80,20 @@ func (m *BurnAmount) GetBurnStarted() bool { 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 @@ -85,9 +101,9 @@ func (m *BurnAmount) GetTotalBurnAmount() types.Coin { return types.Coin{} } -func (m *BurnAmount) GetBurntAmount() types.Coin { +func (m *BurnAmount) GetCumulativeBurntAmount() types.Coin { if m != nil { - return m.BurntAmount + return m.CumulativeBurntAmount } return types.Coin{} } @@ -99,25 +115,27 @@ func init() { func init() { proto.RegisterFile("mycel/furnace/burn_amount.proto", fileDescriptor_c51e14c665b742e5) } var fileDescriptor_c51e14c665b742e5 = []byte{ - // 280 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x90, 0xb1, 0x4e, 0xc3, 0x30, - 0x10, 0x86, 0x63, 0xa8, 0x10, 0x72, 0x85, 0x90, 0x22, 0x86, 0xd0, 0xc1, 0x8d, 0x98, 0xb2, 0xd4, - 0x56, 0xe1, 0x09, 0x1a, 0x06, 0xc4, 0x1a, 0x36, 0x16, 0xe4, 0x24, 0x6e, 0xb0, 0xd4, 0xf8, 0x2a, - 0xe7, 0x82, 0xe8, 0x5b, 0xf0, 0x58, 0x1d, 0x3b, 0x32, 0x20, 0x84, 0x92, 0x17, 0x41, 0x89, 0x23, - 0x88, 0x98, 0xd8, 0xec, 0xbb, 0xff, 0xff, 0xef, 0xd3, 0x4f, 0xe7, 0xe5, 0x2e, 0x53, 0x1b, 0xb1, - 0xae, 0xad, 0x91, 0x99, 0x12, 0x69, 0x6d, 0xcd, 0x93, 0x2c, 0xa1, 0x36, 0xc8, 0xb7, 0x16, 0x10, - 0xfc, 0xb3, 0x5e, 0xc0, 0x07, 0xc1, 0xec, 0xa2, 0x80, 0x02, 0xfa, 0x8d, 0xe8, 0x5e, 0x4e, 0x34, - 0x63, 0x19, 0x54, 0x25, 0x54, 0x22, 0x95, 0x95, 0x12, 0x2f, 0xcb, 0x54, 0xa1, 0x5c, 0x8a, 0x0c, - 0xb4, 0x71, 0xfb, 0xab, 0x0f, 0x42, 0x69, 0x5c, 0x5b, 0xb3, 0xea, 0x93, 0x7d, 0x46, 0xa9, 0xce, - 0x95, 0x41, 0xbd, 0xd6, 0xca, 0x06, 0x24, 0x24, 0xd1, 0x24, 0x19, 0x4d, 0xfc, 0x90, 0x4e, 0x3b, - 0x90, 0x07, 0x94, 0x16, 0x55, 0x1e, 0x1c, 0x85, 0x24, 0x3a, 0x4d, 0xc6, 0x23, 0xff, 0x9e, 0x9e, - 0x23, 0xa0, 0xdc, 0xfc, 0x86, 0x06, 0xc7, 0x21, 0x89, 0xa6, 0xd7, 0x97, 0xdc, 0xa1, 0xf0, 0x0e, - 0x85, 0x0f, 0x28, 0xfc, 0x16, 0xb4, 0x89, 0x27, 0xfb, 0xcf, 0xb9, 0x97, 0xfc, 0xf5, 0xf9, 0x2b, - 0x77, 0x0c, 0x87, 0x98, 0xc9, 0xff, 0x62, 0xc6, 0x9e, 0xf8, 0x6e, 0xdf, 0x30, 0x72, 0x68, 0x18, - 0xf9, 0x6a, 0x18, 0x79, 0x6b, 0x99, 0x77, 0x68, 0x99, 0xf7, 0xde, 0x32, 0xef, 0x71, 0x51, 0x68, - 0x7c, 0xae, 0x53, 0x9e, 0x41, 0x29, 0xfa, 0x22, 0x17, 0x39, 0x94, 0x52, 0x1b, 0xf7, 0x11, 0xaf, - 0x3f, 0xc5, 0xe3, 0x6e, 0xab, 0xaa, 0xf4, 0xa4, 0xaf, 0xeb, 0xe6, 0x3b, 0x00, 0x00, 0xff, 0xff, - 0xd4, 0x70, 0x42, 0x68, 0x96, 0x01, 0x00, 0x00, + // 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) { @@ -141,7 +159,7 @@ func (m *BurnAmount) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size, err := m.BurntAmount.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.CumulativeBurntAmount.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -149,7 +167,7 @@ func (m *BurnAmount) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintBurnAmount(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x22 + dAtA[i] = 0x32 { size, err := m.TotalBurnAmount.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -159,7 +177,17 @@ func (m *BurnAmount) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintBurnAmount(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x1a + 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 { @@ -170,8 +198,8 @@ func (m *BurnAmount) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x10 } - if m.Identifier != 0 { - i = encodeVarintBurnAmount(dAtA, i, uint64(m.Identifier)) + if m.Index != 0 { + i = encodeVarintBurnAmount(dAtA, i, uint64(m.Index)) i-- dAtA[i] = 0x8 } @@ -195,15 +223,21 @@ func (m *BurnAmount) Size() (n int) { } var l int _ = l - if m.Identifier != 0 { - n += 1 + sovBurnAmount(uint64(m.Identifier)) + 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.BurntAmount.Size() + l = m.CumulativeBurntAmount.Size() n += 1 + l + sovBurnAmount(uint64(l)) return n } @@ -245,9 +279,9 @@ func (m *BurnAmount) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Identifier", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) } - m.Identifier = 0 + m.Index = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowBurnAmount @@ -257,7 +291,7 @@ func (m *BurnAmount) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Identifier |= uint64(b&0x7F) << shift + m.Index |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -283,6 +317,44 @@ func (m *BurnAmount) Unmarshal(dAtA []byte) error { } 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) } @@ -315,9 +387,9 @@ func (m *BurnAmount) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 4: + case 6: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BurntAmount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field CumulativeBurntAmount", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -344,7 +416,7 @@ func (m *BurnAmount) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.BurntAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.CumulativeBurntAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/furnace/types/epoch_burn_config.pb.go b/x/furnace/types/epoch_burn_config.pb.go index 152a07fb..aea42631 100644 --- a/x/furnace/types/epoch_burn_config.pb.go +++ b/x/furnace/types/epoch_burn_config.pb.go @@ -29,10 +29,10 @@ var _ = time.Kitchen const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type EpochBurnConfig struct { - EpochIdentifier string `protobuf:"bytes,1,opt,name=epochIdentifier,proto3" json:"epochIdentifier,omitempty"` - CurrentBurnAmountIdentifier uint64 `protobuf:"varint,2,opt,name=currentBurnAmountIdentifier,proto3" json:"currentBurnAmountIdentifier,omitempty"` - StartTime time.Time `protobuf:"bytes,3,opt,name=startTime,proto3,stdtime" json:"startTime" yaml:"start_time"` - Duration time.Duration `protobuf:"bytes,4,opt,name=duration,proto3,stdduration" json:"duration,omitempty" yaml:"duration"` + 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{} } @@ -75,25 +75,25 @@ func (m *EpochBurnConfig) GetEpochIdentifier() string { return "" } -func (m *EpochBurnConfig) GetCurrentBurnAmountIdentifier() uint64 { +func (m *EpochBurnConfig) GetCurrentBurnAmountIndex() uint64 { if m != nil { - return m.CurrentBurnAmountIdentifier + return m.CurrentBurnAmountIndex } return 0 } -func (m *EpochBurnConfig) GetStartTime() time.Time { +func (m *EpochBurnConfig) GetDefaultTotalEpochs() uint64 { if m != nil { - return m.StartTime + return m.DefaultTotalEpochs } - return time.Time{} + return 0 } -func (m *EpochBurnConfig) GetDuration() time.Duration { +func (m *EpochBurnConfig) GetStartTime() time.Time { if m != nil { - return m.Duration + return m.StartTime } - return 0 + return time.Time{} } func init() { @@ -105,30 +105,28 @@ func init() { } var fileDescriptor_85095d78ef169197 = []byte{ - // 360 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x52, 0x4d, 0x4b, 0xf3, 0x30, - 0x1c, 0x6f, 0xf6, 0x8c, 0x07, 0x57, 0x91, 0x61, 0xf1, 0x30, 0x27, 0xa6, 0xa3, 0x20, 0xf4, 0xe0, - 0x1a, 0xd4, 0x9b, 0x27, 0xad, 0x8a, 0x78, 0x1d, 0x03, 0xc1, 0xcb, 0x68, 0xbb, 0xb4, 0x0b, 0x2c, - 0x49, 0xc9, 0x12, 0xb0, 0xdf, 0x62, 0x47, 0x3f, 0x8e, 0xc7, 0x1d, 0x77, 0xf4, 0x54, 0x65, 0xbb, - 0x79, 0xdc, 0x27, 0x90, 0xa6, 0xeb, 0x94, 0x09, 0xde, 0xf2, 0xcf, 0xef, 0x35, 0x2f, 0xe6, 0x09, - 0xcd, 0x22, 0x3c, 0x46, 0xb1, 0x12, 0x2c, 0x88, 0x30, 0xc2, 0x29, 0x8f, 0x46, 0x83, 0x50, 0x09, - 0x36, 0x88, 0x38, 0x8b, 0x49, 0xe2, 0xa5, 0x82, 0x4b, 0x6e, 0xed, 0x69, 0x9a, 0xb7, 0xa6, 0xb5, - 0x0f, 0x12, 0x9e, 0x70, 0x8d, 0xa0, 0x62, 0x55, 0x92, 0xda, 0x30, 0xe1, 0x3c, 0x19, 0x63, 0xa4, - 0xa7, 0x50, 0xc5, 0x68, 0xa8, 0x44, 0x20, 0x09, 0x67, 0x6b, 0xdc, 0xde, 0xc6, 0x25, 0xa1, 0x78, - 0x22, 0x03, 0x9a, 0x96, 0x04, 0xe7, 0xb5, 0x66, 0x36, 0xef, 0x8a, 0x06, 0xbe, 0x12, 0xec, 0x46, - 0xe7, 0x5b, 0xae, 0xd9, 0xd4, 0xa5, 0x1e, 0x86, 0x98, 0x49, 0x12, 0x13, 0x2c, 0x5a, 0xa0, 0x03, - 0xdc, 0x46, 0x6f, 0x7b, 0xdb, 0xba, 0x32, 0x8f, 0x22, 0x25, 0x04, 0x66, 0xb2, 0x90, 0x5f, 0x53, - 0xae, 0x98, 0xfc, 0xa1, 0xaa, 0x75, 0x80, 0x5b, 0xef, 0xfd, 0x45, 0xb1, 0x1e, 0xcd, 0xc6, 0x44, - 0x06, 0x42, 0xf6, 0x09, 0xc5, 0xad, 0x7f, 0x1d, 0xe0, 0xee, 0x9e, 0xb7, 0xbd, 0xb2, 0xb4, 0x57, - 0x95, 0xf6, 0xfa, 0x55, 0x69, 0xff, 0x78, 0x96, 0xdb, 0xc6, 0x2a, 0xb7, 0xf7, 0xb3, 0x80, 0x8e, - 0x2f, 0x1d, 0x2d, 0x1d, 0x14, 0x67, 0x72, 0xa6, 0xef, 0x36, 0xe8, 0x7d, 0x7b, 0x59, 0x23, 0x73, - 0xa7, 0xba, 0x8b, 0x56, 0x5d, 0xfb, 0x1e, 0xfe, 0xf2, 0xbd, 0x5d, 0x13, 0xfc, 0xb3, 0xc2, 0xf6, - 0x33, 0xb7, 0xad, 0x4a, 0x72, 0xca, 0x29, 0x91, 0x98, 0xa6, 0x32, 0x5b, 0xe5, 0x76, 0xb3, 0x0c, - 0xab, 0x30, 0xe7, 0xa5, 0x88, 0xda, 0xb8, 0xfb, 0xf7, 0xb3, 0x05, 0x04, 0xf3, 0x05, 0x04, 0x1f, - 0x0b, 0x08, 0xa6, 0x4b, 0x68, 0xcc, 0x97, 0xd0, 0x78, 0x5b, 0x42, 0xe3, 0xa9, 0x9b, 0x10, 0x39, - 0x52, 0xa1, 0x17, 0x71, 0x8a, 0xf4, 0x6b, 0x76, 0x87, 0x9c, 0x06, 0x84, 0x95, 0x03, 0x7a, 0xde, - 0xfc, 0x01, 0x99, 0xa5, 0x78, 0x12, 0xfe, 0xd7, 0xc5, 0x2e, 0xbe, 0x02, 0x00, 0x00, 0xff, 0xff, - 0x91, 0xcc, 0x10, 0x39, 0x21, 0x02, 0x00, 0x00, + // 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) { @@ -151,7 +149,7 @@ func (m *EpochBurnConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - n1, err1 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(m.Duration, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.Duration):]) + 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 } @@ -159,16 +157,13 @@ func (m *EpochBurnConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintEpochBurnConfig(dAtA, i, uint64(n1)) i-- dAtA[i] = 0x22 - n2, err2 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.StartTime):]) - if err2 != nil { - return 0, err2 + if m.DefaultTotalEpochs != 0 { + i = encodeVarintEpochBurnConfig(dAtA, i, uint64(m.DefaultTotalEpochs)) + i-- + dAtA[i] = 0x18 } - i -= n2 - i = encodeVarintEpochBurnConfig(dAtA, i, uint64(n2)) - i-- - dAtA[i] = 0x1a - if m.CurrentBurnAmountIdentifier != 0 { - i = encodeVarintEpochBurnConfig(dAtA, i, uint64(m.CurrentBurnAmountIdentifier)) + if m.CurrentBurnAmountIndex != 0 { + i = encodeVarintEpochBurnConfig(dAtA, i, uint64(m.CurrentBurnAmountIndex)) i-- dAtA[i] = 0x10 } @@ -203,13 +198,14 @@ func (m *EpochBurnConfig) Size() (n int) { if l > 0 { n += 1 + l + sovEpochBurnConfig(uint64(l)) } - if m.CurrentBurnAmountIdentifier != 0 { - n += 1 + sovEpochBurnConfig(uint64(m.CurrentBurnAmountIdentifier)) + 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)) - l = github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.Duration) - n += 1 + l + sovEpochBurnConfig(uint64(l)) return n } @@ -282,9 +278,9 @@ func (m *EpochBurnConfig) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CurrentBurnAmountIdentifier", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field CurrentBurnAmountIndex", wireType) } - m.CurrentBurnAmountIdentifier = 0 + m.CurrentBurnAmountIndex = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEpochBurnConfig @@ -294,16 +290,16 @@ func (m *EpochBurnConfig) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.CurrentBurnAmountIdentifier |= uint64(b&0x7F) << shift + m.CurrentBurnAmountIndex |= uint64(b&0x7F) << shift if b < 0x80 { break } } case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DefaultTotalEpochs", wireType) } - var msglen int + m.DefaultTotalEpochs = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEpochBurnConfig @@ -313,28 +309,14 @@ func (m *EpochBurnConfig) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + m.DefaultTotalEpochs |= uint64(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 case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Duration", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -361,7 +343,7 @@ func (m *EpochBurnConfig) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := github_com_cosmos_gogoproto_types.StdDurationUnmarshal(&m.Duration, dAtA[iNdEx:postIndex]); err != nil { + if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.StartTime, dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/furnace/types/genesis.go b/x/furnace/types/genesis.go index 9722e255..c7c3dfe2 100644 --- a/x/furnace/types/genesis.go +++ b/x/furnace/types/genesis.go @@ -2,8 +2,8 @@ package types import ( "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" epochstypes "github.com/mycel-domain/mycel/x/epochs/types" - "time" ) // DefaultIndex is the default global index @@ -12,8 +12,8 @@ const DefaultIndex uint64 = 1 func GetDefaultEpochBurnConfig() EpochBurnConfig { return EpochBurnConfig{ EpochIdentifier: epochstypes.DailyEpochId, - CurrentBurnAmountIdentifier: 1, - Duration: time.Hour * 24 * 30 * 4, + CurrentBurnAmountIndex: 0, + DefaultTotalEpochs: 30, } } @@ -21,7 +21,16 @@ func GetDefaultEpochBurnConfig() EpochBurnConfig { func DefaultGenesis() *GenesisState { return &GenesisState{ EpochBurnConfig: GetDefaultEpochBurnConfig(), - BurnAmounts: []BurnAmount{}, + BurnAmounts: []BurnAmount{ + { + Index: 0, + BurnStarted: false, + TotalEpochs: 30, + CurrentEpoch: 0, + TotalBurnAmount: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)), + CumulativeBurntAmount: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)), + }, + }, // this line is used by starport scaffolding # genesis/types/default Params: DefaultParams(), } @@ -34,7 +43,7 @@ func (gs GenesisState) Validate() error { burnAmountIndexMap := make(map[string]struct{}) for _, elem := range gs.BurnAmounts { - index := string(BurnAmountKey(elem.Identifier)) + index := string(BurnAmountKey(elem.Index)) if _, ok := burnAmountIndexMap[index]; ok { return fmt.Errorf("duplicated index for burnAmount") } diff --git a/x/furnace/types/genesis_test.go b/x/furnace/types/genesis_test.go index 9de4522e..79ebcfa7 100644 --- a/x/furnace/types/genesis_test.go +++ b/x/furnace/types/genesis_test.go @@ -27,10 +27,10 @@ func TestGenesisState_Validate(t *testing.T) { }, BurnAmounts: []types.BurnAmount{ { - Identifier: 0, + Index: 0, }, { - Identifier: 1, + Index: 1, }, }, // this line is used by starport scaffolding # types/genesis/validField @@ -42,10 +42,10 @@ func TestGenesisState_Validate(t *testing.T) { genState: &types.GenesisState{ BurnAmounts: []types.BurnAmount{ { - Identifier: 0, + Index: 0, }, { - Identifier: 0, + Index: 0, }, }, }, diff --git a/x/furnace/types/key_burn_amount.go b/x/furnace/types/key_burn_amount.go index 7782eb19..1f6052bd 100644 --- a/x/furnace/types/key_burn_amount.go +++ b/x/furnace/types/key_burn_amount.go @@ -11,13 +11,13 @@ const ( // BurnAmountKey returns the store key to retrieve a BurnAmount from the index fields func BurnAmountKey( - identifier uint64, + index uint64, ) []byte { var key []byte - identifierBytes := make([]byte, 8) - binary.BigEndian.PutUint64(identifierBytes, identifier) - key = append(key, identifierBytes...) + indexBytes := make([]byte, 8) + binary.BigEndian.PutUint64(indexBytes, index) + key = append(key, indexBytes...) key = append(key, []byte("/")...) return key From ab9df6fd6d32f60faf23e1ade7a8aafd093a4e2c Mon Sep 17 00:00:00 2001 From: tarumi Date: Tue, 26 Sep 2023 11:57:58 +0200 Subject: [PATCH 22/28] fix compilation err --- proto/mycel/furnace/query.proto | 4 +- x/furnace/client/cli/query_burn_amount.go | 4 +- .../client/cli/query_burn_amount_test.go | 10 +- x/furnace/keeper/burn_amount_test.go | 8 +- x/furnace/keeper/query_burn_amount.go | 2 +- x/furnace/keeper/query_burn_amount_test.go | 6 +- x/furnace/types/query.pb.go | 97 +++++++++---------- x/furnace/types/query.pb.gw.go | 18 ++-- 8 files changed, 74 insertions(+), 75 deletions(-) diff --git a/proto/mycel/furnace/query.proto b/proto/mycel/furnace/query.proto index 4bb09041..05f8fa3d 100644 --- a/proto/mycel/furnace/query.proto +++ b/proto/mycel/furnace/query.proto @@ -29,7 +29,7 @@ service Query { // Queries a list of BurnAmount items. rpc BurnAmount (QueryGetBurnAmountRequest) returns (QueryGetBurnAmountResponse) { - option (google.api.http).get = "/mycel-domain/mycel/furnace/burn_amount/{identifier}"; + option (google.api.http).get = "/mycel-domain/mycel/furnace/burn_amount/{index}"; } rpc BurnAmountAll (QueryAllBurnAmountRequest) returns (QueryAllBurnAmountResponse) { @@ -54,7 +54,7 @@ message QueryGetEpochBurnConfigResponse { } message QueryGetBurnAmountRequest { - uint64 identifier = 1; + uint64 index = 1; } message QueryGetBurnAmountResponse { diff --git a/x/furnace/client/cli/query_burn_amount.go b/x/furnace/client/cli/query_burn_amount.go index 9320714f..7931eb45 100644 --- a/x/furnace/client/cli/query_burn_amount.go +++ b/x/furnace/client/cli/query_burn_amount.go @@ -58,13 +58,13 @@ func CmdShowBurnAmount() *cobra.Command { queryClient := types.NewQueryClient(clientCtx) - argIdentifier, err := cast.ToUint64E(args[0]) + argIndex, err := cast.ToUint64E(args[0]) if err != nil { return err } params := &types.QueryGetBurnAmountRequest{ - Identifier: argIdentifier, + Index: argIndex, } res, err := queryClient.BurnAmount(cmd.Context(), params) diff --git a/x/furnace/client/cli/query_burn_amount_test.go b/x/furnace/client/cli/query_burn_amount_test.go index 58dcbb12..2cd3dd87 100644 --- a/x/furnace/client/cli/query_burn_amount_test.go +++ b/x/furnace/client/cli/query_burn_amount_test.go @@ -27,7 +27,7 @@ func networkWithBurnAmountObjects(t *testing.T, n int) (*network.Network, []type state := types.GenesisState{} for i := 0; i < n; i++ { burnAmount := types.BurnAmount{ - Identifier: uint64(i), + Index: uint64(i), } nullify.Fill(&burnAmount) state.BurnAmounts = append(state.BurnAmounts, burnAmount) @@ -47,7 +47,7 @@ func TestShowBurnAmount(t *testing.T) { } tests := []struct { desc string - idIdentifier uint64 + idIndex uint64 args []string err error @@ -55,14 +55,14 @@ func TestShowBurnAmount(t *testing.T) { }{ { desc: "found", - idIdentifier: objs[0].Identifier, + idIndex: objs[0].Index, args: common, obj: objs[0], }, { desc: "not found", - idIdentifier: 100000, + idIndex: 100000, args: common, err: status.Error(codes.NotFound, "not found"), @@ -71,7 +71,7 @@ func TestShowBurnAmount(t *testing.T) { for _, tc := range tests { t.Run(tc.desc, func(t *testing.T) { args := []string{ - strconv.Itoa(int(tc.idIdentifier)), + strconv.Itoa(int(tc.idIndex)), } args = append(args, tc.args...) out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowBurnAmount(), args) diff --git a/x/furnace/keeper/burn_amount_test.go b/x/furnace/keeper/burn_amount_test.go index 53955e3e..9c837e7c 100644 --- a/x/furnace/keeper/burn_amount_test.go +++ b/x/furnace/keeper/burn_amount_test.go @@ -18,7 +18,7 @@ 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].Identifier = uint64(i) + items[i].Index = uint64(i) keeper.SetBurnAmount(ctx, items[i]) } @@ -30,7 +30,7 @@ func TestBurnAmountGet(t *testing.T) { items := createNBurnAmount(keeper, ctx, 10) for _, item := range items { rst, found := keeper.GetBurnAmount(ctx, - item.Identifier, + item.Index, ) require.True(t, found) require.Equal(t, @@ -44,10 +44,10 @@ func TestBurnAmountRemove(t *testing.T) { items := createNBurnAmount(keeper, ctx, 10) for _, item := range items { keeper.RemoveBurnAmount(ctx, - item.Identifier, + item.Index, ) _, found := keeper.GetBurnAmount(ctx, - item.Identifier, + item.Index, ) require.False(t, found) } diff --git a/x/furnace/keeper/query_burn_amount.go b/x/furnace/keeper/query_burn_amount.go index 15d33e2e..20d55145 100644 --- a/x/furnace/keeper/query_burn_amount.go +++ b/x/furnace/keeper/query_burn_amount.go @@ -47,7 +47,7 @@ func (k Keeper) BurnAmount(goCtx context.Context, req *types.QueryGetBurnAmountR val, found := k.GetBurnAmount( ctx, - req.Identifier, + req.Index, ) if !found { return nil, status.Error(codes.NotFound, "not found") diff --git a/x/furnace/keeper/query_burn_amount_test.go b/x/furnace/keeper/query_burn_amount_test.go index 41d8fe48..2a422b4b 100644 --- a/x/furnace/keeper/query_burn_amount_test.go +++ b/x/furnace/keeper/query_burn_amount_test.go @@ -31,21 +31,21 @@ func TestBurnAmountQuerySingle(t *testing.T) { { desc: "First", request: &types.QueryGetBurnAmountRequest{ - Identifier: msgs[0].Identifier, + Index: msgs[0].Index, }, response: &types.QueryGetBurnAmountResponse{BurnAmount: msgs[0]}, }, { desc: "Second", request: &types.QueryGetBurnAmountRequest{ - Identifier: msgs[1].Identifier, + Index: msgs[1].Index, }, response: &types.QueryGetBurnAmountResponse{BurnAmount: msgs[1]}, }, { desc: "KeyNotFound", request: &types.QueryGetBurnAmountRequest{ - Identifier: 100000, + Index: 100000, }, err: status.Error(codes.NotFound, "not found"), }, diff --git a/x/furnace/types/query.pb.go b/x/furnace/types/query.pb.go index 24b23088..94c39016 100644 --- a/x/furnace/types/query.pb.go +++ b/x/furnace/types/query.pb.go @@ -195,7 +195,7 @@ func (m *QueryGetEpochBurnConfigResponse) GetEpochBurnConfig() EpochBurnConfig { } type QueryGetBurnAmountRequest struct { - Identifier uint64 `protobuf:"varint,1,opt,name=identifier,proto3" json:"identifier,omitempty"` + Index uint64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"` } func (m *QueryGetBurnAmountRequest) Reset() { *m = QueryGetBurnAmountRequest{} } @@ -231,9 +231,9 @@ func (m *QueryGetBurnAmountRequest) XXX_DiscardUnknown() { var xxx_messageInfo_QueryGetBurnAmountRequest proto.InternalMessageInfo -func (m *QueryGetBurnAmountRequest) GetIdentifier() uint64 { +func (m *QueryGetBurnAmountRequest) GetIndex() uint64 { if m != nil { - return m.Identifier + return m.Index } return 0 } @@ -392,45 +392,44 @@ func init() { func init() { proto.RegisterFile("mycel/furnace/query.proto", fileDescriptor_12ab24936cee5a03) } var fileDescriptor_12ab24936cee5a03 = []byte{ - // 594 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0x4d, 0x6b, 0x13, 0x41, - 0x18, 0xc7, 0xb3, 0x35, 0xe6, 0x30, 0x52, 0x84, 0xb1, 0x82, 0x59, 0x64, 0x53, 0x07, 0xb5, 0x2f, - 0x90, 0x1d, 0xda, 0xaa, 0x17, 0x05, 0x49, 0x44, 0x03, 0x1e, 0xa4, 0xe6, 0x28, 0x48, 0x99, 0xdd, - 0x4e, 0xb6, 0x0b, 0xbb, 0x33, 0x9b, 0x7d, 0x11, 0x43, 0xf1, 0xe2, 0x27, 0x10, 0xc4, 0xb3, 0x37, - 0xfd, 0x2a, 0x3d, 0x16, 0xbc, 0x78, 0x12, 0x49, 0x3c, 0xf8, 0x31, 0x24, 0xb3, 0x4f, 0x9a, 0x7d, - 0x4b, 0x4c, 0x6f, 0x61, 0x9e, 0xff, 0xf3, 0xfc, 0x7f, 0x4f, 0xe6, 0xbf, 0x83, 0x9a, 0xfe, 0xc8, - 0xe6, 0x1e, 0x1d, 0x24, 0xa1, 0x60, 0x36, 0xa7, 0xc3, 0x84, 0x87, 0x23, 0x33, 0x08, 0x65, 0x2c, - 0xf1, 0xba, 0x2a, 0x99, 0x50, 0xd2, 0x37, 0x1c, 0xe9, 0x48, 0x55, 0xa1, 0xd3, 0x5f, 0xa9, 0x48, - 0xbf, 0xed, 0x48, 0xe9, 0x78, 0x9c, 0xb2, 0xc0, 0xa5, 0x4c, 0x08, 0x19, 0xb3, 0xd8, 0x95, 0x22, - 0x82, 0xea, 0xae, 0x2d, 0x23, 0x5f, 0x46, 0xd4, 0x62, 0x11, 0xcc, 0xa6, 0xef, 0xf6, 0x2c, 0x1e, - 0xb3, 0x3d, 0x1a, 0x30, 0xc7, 0x15, 0x4a, 0x0c, 0x5a, 0x3d, 0x4f, 0x12, 0xb0, 0x90, 0xf9, 0xb3, - 0x39, 0xf7, 0xf2, 0x35, 0x1e, 0x48, 0xfb, 0xe4, 0xc8, 0x4a, 0x42, 0x71, 0x64, 0x4b, 0x31, 0x70, - 0x1d, 0x90, 0xb5, 0xf2, 0x32, 0x25, 0x60, 0xbe, 0x4c, 0x44, 0x0c, 0x02, 0x23, 0xcb, 0x33, 0x23, - 0xb1, 0xa5, 0x0b, 0x0c, 0x64, 0x03, 0xe1, 0xd7, 0x53, 0xca, 0x43, 0x65, 0xde, 0xe7, 0xc3, 0x84, - 0x47, 0x31, 0x79, 0x89, 0x6e, 0xe4, 0x4e, 0xa3, 0x40, 0x8a, 0x88, 0xe3, 0x03, 0xd4, 0x48, 0x21, - 0x6f, 0x69, 0x9b, 0xda, 0xf6, 0xb5, 0xfd, 0x9b, 0x66, 0xee, 0x0f, 0x33, 0x53, 0x79, 0xb7, 0x7e, - 0xf6, 0xab, 0x55, 0xeb, 0x83, 0x94, 0x6c, 0x22, 0x43, 0xcd, 0xea, 0xf1, 0xf8, 0xf9, 0x74, 0x8b, - 0x6e, 0x12, 0x8a, 0x67, 0x6a, 0x87, 0x99, 0xdb, 0x10, 0xb5, 0x16, 0x2a, 0xc0, 0xf9, 0x15, 0xba, - 0x5e, 0x28, 0x01, 0x82, 0x51, 0x40, 0x28, 0xa8, 0x80, 0xa5, 0xd8, 0x4c, 0x1e, 0xa3, 0xe6, 0xcc, - 0x72, 0x7a, 0xda, 0x51, 0x7f, 0x19, 0xf0, 0x60, 0x03, 0x21, 0xf7, 0x98, 0x8b, 0xd8, 0x1d, 0xb8, - 0x3c, 0x54, 0x3e, 0xf5, 0x7e, 0xe6, 0x84, 0xbc, 0x45, 0x7a, 0x55, 0x33, 0xa0, 0x3e, 0x45, 0xc8, - 0xba, 0x38, 0x05, 0xca, 0x66, 0x81, 0x72, 0xde, 0x06, 0x80, 0x99, 0x16, 0x62, 0x03, 0x5b, 0xc7, - 0xf3, 0xca, 0x6c, 0x2f, 0x10, 0x9a, 0xe7, 0x08, 0xa6, 0xdf, 0x37, 0xd3, 0x4b, 0x36, 0xa7, 0x97, - 0x6c, 0xa6, 0x81, 0x86, 0xab, 0x36, 0x0f, 0x99, 0xc3, 0xa1, 0xb7, 0x9f, 0xe9, 0x24, 0xdf, 0x34, - 0x58, 0xa2, 0xe0, 0xb2, 0x60, 0x89, 0x2b, 0x97, 0x5c, 0x02, 0xf7, 0x72, 0x9c, 0x6b, 0x8a, 0x73, - 0xeb, 0xbf, 0x9c, 0xa9, 0x7b, 0x16, 0x74, 0xff, 0x6f, 0x1d, 0x5d, 0x55, 0xa0, 0xf8, 0x14, 0x35, - 0xd2, 0x80, 0xe1, 0x3b, 0x05, 0x92, 0x72, 0x82, 0x75, 0xb2, 0x4c, 0x92, 0xda, 0x90, 0xdd, 0x8f, - 0x3f, 0xfe, 0x7c, 0x5e, 0xbb, 0x8b, 0x09, 0x55, 0xda, 0xf6, 0xb1, 0xf4, 0x99, 0x2b, 0x68, 0xd5, - 0x57, 0x89, 0xbf, 0x6b, 0xa5, 0x04, 0xe2, 0x76, 0x95, 0xc7, 0xc2, 0x98, 0xeb, 0xe6, 0xaa, 0x72, - 0xc0, 0x7b, 0xa8, 0xf0, 0x28, 0x6e, 0x2f, 0xc3, 0x2b, 0x3d, 0x0c, 0xf8, 0xab, 0x86, 0xd0, 0xfc, - 0x6a, 0xf0, 0xf6, 0x02, 0xd7, 0x52, 0xb4, 0xf4, 0x9d, 0x15, 0x94, 0x80, 0xf6, 0x44, 0xa1, 0x3d, - 0xc2, 0x0f, 0x96, 0xa1, 0x65, 0x1e, 0x23, 0x7a, 0x3a, 0xff, 0x7c, 0x3e, 0xe0, 0x2f, 0x1a, 0x5a, - 0x9f, 0x0f, 0xed, 0x78, 0x5e, 0x35, 0x64, 0x55, 0xfe, 0xab, 0x21, 0x2b, 0x33, 0x4c, 0xa8, 0x82, - 0xdc, 0xc1, 0x5b, 0x2b, 0x42, 0x76, 0x7b, 0x67, 0x63, 0x43, 0x3b, 0x1f, 0x1b, 0xda, 0xef, 0xb1, - 0xa1, 0x7d, 0x9a, 0x18, 0xb5, 0xf3, 0x89, 0x51, 0xfb, 0x39, 0x31, 0x6a, 0x6f, 0xda, 0x8e, 0x1b, - 0x9f, 0x24, 0x96, 0x69, 0x4b, 0xbf, 0x6a, 0xd8, 0xfb, 0x8b, 0x71, 0xf1, 0x28, 0xe0, 0x91, 0xd5, - 0x50, 0x6f, 0xeb, 0xc1, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf9, 0x0c, 0x8e, 0x69, 0x6b, 0x06, - 0x00, 0x00, + // 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. @@ -759,8 +758,8 @@ func (m *QueryGetBurnAmountRequest) MarshalToSizedBuffer(dAtA []byte) (int, erro _ = i var l int _ = l - if m.Identifier != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.Identifier)) + if m.Index != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Index)) i-- dAtA[i] = 0x8 } @@ -941,8 +940,8 @@ func (m *QueryGetBurnAmountRequest) Size() (n int) { } var l int _ = l - if m.Identifier != 0 { - n += 1 + sovQuery(uint64(m.Identifier)) + if m.Index != 0 { + n += 1 + sovQuery(uint64(m.Index)) } return n } @@ -1293,9 +1292,9 @@ func (m *QueryGetBurnAmountRequest) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Identifier", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) } - m.Identifier = 0 + m.Index = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -1305,7 +1304,7 @@ func (m *QueryGetBurnAmountRequest) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Identifier |= uint64(b&0x7F) << shift + m.Index |= uint64(b&0x7F) << shift if b < 0x80 { break } diff --git a/x/furnace/types/query.pb.gw.go b/x/furnace/types/query.pb.gw.go index d64a24ab..8b2e5df6 100644 --- a/x/furnace/types/query.pb.gw.go +++ b/x/furnace/types/query.pb.gw.go @@ -80,15 +80,15 @@ func request_Query_BurnAmount_0(ctx context.Context, marshaler runtime.Marshaler _ = err ) - val, ok = pathParams["identifier"] + val, ok = pathParams["index"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "identifier") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "index") } - protoReq.Identifier, err = runtime.Uint64(val) + protoReq.Index, err = runtime.Uint64(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "identifier", err) + 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)) @@ -107,15 +107,15 @@ func local_request_Query_BurnAmount_0(ctx context.Context, marshaler runtime.Mar _ = err ) - val, ok = pathParams["identifier"] + val, ok = pathParams["index"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "identifier") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "index") } - protoReq.Identifier, err = runtime.Uint64(val) + protoReq.Index, err = runtime.Uint64(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "identifier", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "index", err) } msg, err := server.BurnAmount(ctx, &protoReq) @@ -386,7 +386,7 @@ var ( 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", "identifier"}, "", 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))) ) From 772863505f3ad976baeb17e374073d1611120dec Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 27 Sep 2023 15:22:44 +0200 Subject: [PATCH 23/28] impl hooks --- x/furnace/keeper/hooks.go | 57 +++++++++-- x/furnace/keeper/hooks_test.go | 169 +++++++++++++++++++++++++++------ x/furnace/types/event.go | 12 ++- x/furnace/types/genesis.go | 8 +- 4 files changed, 198 insertions(+), 48 deletions(-) diff --git a/x/furnace/keeper/hooks.go b/x/furnace/keeper/hooks.go index 7e3a79e1..d80ea87c 100644 --- a/x/furnace/keeper/hooks.go +++ b/x/furnace/keeper/hooks.go @@ -12,6 +12,8 @@ func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochN // AfterEpochEnd is the epoch end hook. func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) { + var burnt = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)) + // Get the epoch burn config. config, found := k.GetEpochBurnConfig(ctx) if !found { @@ -19,22 +21,54 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumb } if config.EpochIdentifier == epochIdentifier { - burnAmount, found := k.GetBurnAmount(ctx, config.CurrentBurnAmountIndex) + burnAmount, found := k.GetBurnAmount(ctx, uint64(config.CurrentBurnAmountIndex)) if !found { panic("burn amount not found") } - // Calc burn amount for this epoch. - epochInfo, found := k.epochsKeeper.GetEpochInfo(ctx, epochIdentifier) - if !found { - panic("epoch info not found") + if burnAmount.CurrentEpoch < burnAmount.TotalEpochs { + // Check if the current epoch is the last epoch. + if burnAmount.CurrentEpoch == burnAmount.TotalEpochs { + config.CurrentBurnAmountIndex++ + k.SetEpochBurnConfig(ctx, config) + } + + // Check if the current epoch is less than the total epochs. + if burnAmount.CumulativeBurntAmount.IsLT(burnAmount.TotalBurnAmount) { + // Check if the total burn amount is greater than the total epochs. + 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)) + // Check if the remander is zero. + if remander.IsZero() { + // Set the burnt amount to the quotient. + burnt = sdk.NewCoin(sdk.DefaultBondDenom, quotient) + } else { + // Check if the current epoch is the last epoch. + if burnAmount.CurrentEpoch+1 == burnAmount.TotalEpochs { + // Set the burnt amount to the quotient plus the remander. + burnt = sdk.NewCoin(sdk.DefaultBondDenom, quotient.Add(remander)) + } else { + // Set the burnt amount to the quotient. + burnt = sdk.NewCoin(sdk.DefaultBondDenom, quotient) + } + } + } else { + if burnAmount.CurrentEpoch == 0 { + burnt = sdk.NewCoin(sdk.DefaultBondDenom, burnAmount.TotalBurnAmount.Amount) + } + } + } + } else { + panic("current epoch is greater than total epochs") } // TODO: Burn coins - _ = epochInfo - _ = burnAmount // Add the burn amount to burntAmount + burnAmount.CumulativeBurntAmount = burnAmount.CumulativeBurntAmount.Add(burnt) + burnAmount.CurrentEpoch++ + k.SetBurnAmount(ctx, burnAmount) // Emit Events ctx.EventManager().EmitEvent( @@ -42,11 +76,14 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumb types.EventTypeEpochBurn, sdk.NewAttribute(types.AttributeKeyEpochIdentifier, epochIdentifier), sdk.NewAttribute(types.AttributeKeyEpochNumber, sdk.NewInt(epochNumber).String()), - sdk.NewAttribute(types.AtributeKeyEpochBurnAmount, burnAmount.String()), - sdk.NewAttribute(types.AtributeKeyEpochBurnTimestamp, ctx.BlockTime().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()), ), ) - } } diff --git a/x/furnace/keeper/hooks_test.go b/x/furnace/keeper/hooks_test.go index ff4c310a..6c07476a 100644 --- a/x/furnace/keeper/hooks_test.go +++ b/x/furnace/keeper/hooks_test.go @@ -4,49 +4,130 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" "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 ExpEvent struct { - EpochIndex string - EpochNumber string - CumulativeBurntAmount string + EpochIndex string + EpochNumber string + BurnIndex string + BurnTotalEpochs string + BurnCurrentEpoch string + BurnAmount string + BurnCumulativeBurntAmount string } func (suite *KeeperTestSuite) TestAfterEpochEnd() { var ( - now = time.Now() + now = time.Now() + oneDayDuration = time.Hour*24 + time.Second ) testCases := []struct { - totalBurnAmount int64 - index uint64 - expectedEvents []ExpEvent - fn func() + totalBurnAmounts []int64 + expectedEvents []ExpEvent + epochsCount int64 + fn func() }{ { - totalBurnAmount: 100, - index: 1, + totalBurnAmounts: []int64{30}, + epochsCount: 3, expectedEvents: []ExpEvent{ { - EpochIndex: "daily", - EpochNumber: "1", - CumulativeBurntAmount: "0stake", + EpochIndex: "daily", + EpochNumber: "1", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "1", + BurnAmount: "10stake", + BurnCumulativeBurntAmount: "10stake", }, { - EpochIndex: "daily", - EpochNumber: "2", - CumulativeBurntAmount: "30stake", + EpochIndex: "daily", + EpochNumber: "2", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "2", + BurnAmount: "10stake", + BurnCumulativeBurntAmount: "20stake", + }, + { + EpochIndex: "daily", + EpochNumber: "3", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "3", + BurnAmount: "10stake", + BurnCumulativeBurntAmount: "30stake", }, }, - fn: func() { - // Begin first block - suite.ctx = suite.ctx.WithBlockHeight(2).WithBlockTime(now.Add(time.Second)) - suite.app.EpochsKeeper.BeginBlocker(suite.ctx) - // Begin first block - suite.ctx = suite.ctx.WithBlockHeight(3).WithBlockTime(now.Add(time.Hour * 24)) - suite.app.EpochsKeeper.BeginBlocker(suite.ctx) + }, + { + totalBurnAmounts: []int64{31}, + epochsCount: 3, + expectedEvents: []ExpEvent{ + { + EpochIndex: "daily", + EpochNumber: "1", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "1", + BurnAmount: "10stake", + BurnCumulativeBurntAmount: "10stake", + }, + { + EpochIndex: "daily", + EpochNumber: "2", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "2", + BurnAmount: "10stake", + BurnCumulativeBurntAmount: "20stake", + }, + { + EpochIndex: "daily", + EpochNumber: "3", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "3", + BurnAmount: "11stake", + BurnCumulativeBurntAmount: "31stake", + }, + }, + }, + { + totalBurnAmounts: []int64{1}, + epochsCount: 3, + expectedEvents: []ExpEvent{ + { + EpochIndex: "daily", + EpochNumber: "1", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "1", + BurnAmount: "1stake", + BurnCumulativeBurntAmount: "1stake", + }, + { + EpochIndex: "daily", + EpochNumber: "2", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "2", + BurnAmount: "0stake", + BurnCumulativeBurntAmount: "1stake", + }, + { + EpochIndex: "daily", + EpochNumber: "3", + BurnIndex: "1", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "3", + BurnAmount: "0stake", + BurnCumulativeBurntAmount: "1stake", + }, }, }, } @@ -56,23 +137,51 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { suite.SetupTest() // Set burn totalBurnAmount - suite.app.FurnaceKeeper.SetBurnAmount(suite.ctx, types.BurnAmount{ - Index: tc.index, - TotalBurnAmount: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(tc.totalBurnAmount)), - CumulativeBurntAmount: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)), - }) + for i, _ := range tc.totalBurnAmounts { + suite.app.FurnaceKeeper.SetBurnAmount(suite.ctx, types.BurnAmount{ + Index: uint64(i + 1), + TotalEpochs: 3, + CurrentEpoch: 0, + TotalBurnAmount: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(tc.totalBurnAmounts[i])), + CumulativeBurntAmount: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)), + }) + } + + // Run fn + if tc.fn != nil { + tc.fn() + } - 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) + burnAmount, found := suite.app.FurnaceKeeper.GetBurnAmount(suite.ctx, uint64(config.CurrentBurnAmountIndex)) + suite.Require().True(found) + suite.Require().Equal(i, int64(burnAmount.CurrentEpoch)) + } // 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].CumulativeBurntAmount, event.Attributes[2].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/types/event.go b/x/furnace/types/event.go index 3bbcdab4..300bf1aa 100644 --- a/x/furnace/types/event.go +++ b/x/furnace/types/event.go @@ -3,8 +3,12 @@ package types const ( EventTypeEpochBurn = "epoch-burn" - AttributeKeyEpochIdentifier = "epoch-identifier" - AttributeKeyEpochNumber = "epoch-number" - AtributeKeyEpochBurnAmount = "epoch-burn-amount" - AtributeKeyEpochBurnTimestamp = "epoch-burn-timestamp" + 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" ) diff --git a/x/furnace/types/genesis.go b/x/furnace/types/genesis.go index c7c3dfe2..b202d5f4 100644 --- a/x/furnace/types/genesis.go +++ b/x/furnace/types/genesis.go @@ -11,9 +11,9 @@ const DefaultIndex uint64 = 1 func GetDefaultEpochBurnConfig() EpochBurnConfig { return EpochBurnConfig{ - EpochIdentifier: epochstypes.DailyEpochId, - CurrentBurnAmountIndex: 0, - DefaultTotalEpochs: 30, + EpochIdentifier: epochstypes.DailyEpochId, + CurrentBurnAmountIndex: 1, + DefaultTotalEpochs: 30, } } @@ -23,7 +23,7 @@ func DefaultGenesis() *GenesisState { EpochBurnConfig: GetDefaultEpochBurnConfig(), BurnAmounts: []BurnAmount{ { - Index: 0, + Index: 0, BurnStarted: false, TotalEpochs: 30, CurrentEpoch: 0, From 3ba17efedc8e0ca586dbb9ea6f19a469edd68eae Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 27 Sep 2023 15:30:06 +0200 Subject: [PATCH 24/28] impl refer next burn amount when index incremented --- x/furnace/keeper/hooks.go | 6 +++++- x/furnace/keeper/hooks_test.go | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/x/furnace/keeper/hooks.go b/x/furnace/keeper/hooks.go index d80ea87c..2b35f6f8 100644 --- a/x/furnace/keeper/hooks.go +++ b/x/furnace/keeper/hooks.go @@ -26,11 +26,15 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumb panic("burn amount not found") } - if burnAmount.CurrentEpoch < burnAmount.TotalEpochs { + if burnAmount.CurrentEpoch <= burnAmount.TotalEpochs { // Check if the current epoch is the last epoch. if burnAmount.CurrentEpoch == burnAmount.TotalEpochs { config.CurrentBurnAmountIndex++ k.SetEpochBurnConfig(ctx, config) + burnAmount, found = k.GetBurnAmount(ctx, uint64(config.CurrentBurnAmountIndex)) + if !found { + panic("burn amount not found") + } } // Check if the current epoch is less than the total epochs. diff --git a/x/furnace/keeper/hooks_test.go b/x/furnace/keeper/hooks_test.go index 6c07476a..21e19673 100644 --- a/x/furnace/keeper/hooks_test.go +++ b/x/furnace/keeper/hooks_test.go @@ -31,8 +31,8 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { fn func() }{ { - totalBurnAmounts: []int64{30}, - epochsCount: 3, + totalBurnAmounts: []int64{30, 31}, + epochsCount: 4, expectedEvents: []ExpEvent{ { EpochIndex: "daily", @@ -61,6 +61,15 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { BurnAmount: "10stake", BurnCumulativeBurntAmount: "30stake", }, + { + EpochIndex: "daily", + EpochNumber: "4", + BurnIndex: "2", + BurnTotalEpochs: "3", + BurnCurrentEpoch: "1", + BurnAmount: "10stake", + BurnCumulativeBurntAmount: "10stake", + }, }, }, { @@ -163,9 +172,8 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { // Check if burn amount is expected config, found := suite.app.FurnaceKeeper.GetEpochBurnConfig(suite.ctx) suite.Require().True(found) - burnAmount, found := suite.app.FurnaceKeeper.GetBurnAmount(suite.ctx, uint64(config.CurrentBurnAmountIndex)) + _, found = suite.app.FurnaceKeeper.GetBurnAmount(suite.ctx, uint64(config.CurrentBurnAmountIndex)) suite.Require().True(found) - suite.Require().Equal(i, int64(burnAmount.CurrentEpoch)) } // TODO: check if token is burnt From 49478c30a9dbf467b8fab70d854e955f138ed9a4 Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 27 Sep 2023 15:44:18 +0200 Subject: [PATCH 25/28] refactor func --- docs/static/openapi.yml | 4 +- x/furnace/keeper/hooks.go | 132 +++++++++++++++++++------------------- 2 files changed, 69 insertions(+), 67 deletions(-) diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index 65ae024c..51ffa319 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -49851,7 +49851,7 @@ paths: type: boolean tags: - Query - /mycel-domain/mycel/furnace/burn_amount/{identifier}: + /mycel-domain/mycel/furnace/burn_amount/{index}: get: summary: Queries a list of BurnAmount items. operationId: MycelFurnaceBurnAmount @@ -49924,7 +49924,7 @@ paths: type: string additionalProperties: {} parameters: - - name: identifier + - name: index in: path required: true type: string diff --git a/x/furnace/keeper/hooks.go b/x/furnace/keeper/hooks.go index 2b35f6f8..b47bf2d8 100644 --- a/x/furnace/keeper/hooks.go +++ b/x/furnace/keeper/hooks.go @@ -6,6 +6,36 @@ import ( "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 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(sdk.DefaultBondDenom, quotient) + } + return sdk.NewCoin(sdk.DefaultBondDenom, quotient.Add(remander)) + } else if burnAmount.CurrentEpoch == 0 { + return sdk.NewCoin(sdk.DefaultBondDenom, burnAmount.TotalBurnAmount.Amount) + } + return sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)) +} + // BeforeEpochStart is the epoch start hook. func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) { } @@ -14,81 +44,53 @@ func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochN func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) { var burnt = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)) - // Get the epoch burn config. config, found := k.GetEpochBurnConfig(ctx) if !found { panic("epoch burn config not found") } - if config.EpochIdentifier == epochIdentifier { - burnAmount, found := k.GetBurnAmount(ctx, uint64(config.CurrentBurnAmountIndex)) + // Check epoch identifier + if config.EpochIdentifier != epochIdentifier { + return + } + + // Get burn amount + burnAmount, found := k.GetBurnAmount(ctx, uint64(config.CurrentBurnAmountIndex)) + if !found { + panic("burn amount not found") + } + + // 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 { panic("burn amount not found") } + } - if burnAmount.CurrentEpoch <= burnAmount.TotalEpochs { - // Check if the current epoch is the last epoch. - if burnAmount.CurrentEpoch == burnAmount.TotalEpochs { - config.CurrentBurnAmountIndex++ - k.SetEpochBurnConfig(ctx, config) - burnAmount, found = k.GetBurnAmount(ctx, uint64(config.CurrentBurnAmountIndex)) - if !found { - panic("burn amount not found") - } - } - - // Check if the current epoch is less than the total epochs. - if burnAmount.CumulativeBurntAmount.IsLT(burnAmount.TotalBurnAmount) { - // Check if the total burn amount is greater than the total epochs. - 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)) - // Check if the remander is zero. - if remander.IsZero() { - // Set the burnt amount to the quotient. - burnt = sdk.NewCoin(sdk.DefaultBondDenom, quotient) - } else { - // Check if the current epoch is the last epoch. - if burnAmount.CurrentEpoch+1 == burnAmount.TotalEpochs { - // Set the burnt amount to the quotient plus the remander. - burnt = sdk.NewCoin(sdk.DefaultBondDenom, quotient.Add(remander)) - } else { - // Set the burnt amount to the quotient. - burnt = sdk.NewCoin(sdk.DefaultBondDenom, quotient) - } - } - } else { - if burnAmount.CurrentEpoch == 0 { - burnt = sdk.NewCoin(sdk.DefaultBondDenom, burnAmount.TotalBurnAmount.Amount) - } - } - } - } else { - panic("current epoch is greater than total epochs") - } - - // TODO: Burn coins - - // Add the burn amount to burntAmount - burnAmount.CumulativeBurntAmount = burnAmount.CumulativeBurntAmount.Add(burnt) - burnAmount.CurrentEpoch++ - k.SetBurnAmount(ctx, burnAmount) - - // Emit Events - 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()), - ), - ) + // 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) + } // ___________________________________________________________________________________________________ From a24749d7702d26d126e23a52bed0dc222e48c395 Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 27 Sep 2023 15:57:44 +0200 Subject: [PATCH 26/28] rename denom --- x/furnace/keeper/hooks.go | 11 +++++---- x/furnace/keeper/hooks_test.go | 45 +++++++++++++++++----------------- x/furnace/types/genesis.go | 5 ++-- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/x/furnace/keeper/hooks.go b/x/furnace/keeper/hooks.go index b47bf2d8..54e18c8f 100644 --- a/x/furnace/keeper/hooks.go +++ b/x/furnace/keeper/hooks.go @@ -2,6 +2,7 @@ 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" ) @@ -27,13 +28,13 @@ func calculateBurntAmount(burnAmount *types.BurnAmount) sdk.Coin { 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(sdk.DefaultBondDenom, quotient) + return sdk.NewCoin(params.DefaultBondDenom, quotient) } - return sdk.NewCoin(sdk.DefaultBondDenom, quotient.Add(remander)) + return sdk.NewCoin(params.BaseCoinUnit, quotient.Add(remander)) } else if burnAmount.CurrentEpoch == 0 { - return sdk.NewCoin(sdk.DefaultBondDenom, burnAmount.TotalBurnAmount.Amount) + return sdk.NewCoin(params.DefaultBondDenom, burnAmount.TotalBurnAmount.Amount) } - return sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)) + return sdk.NewCoin(params.DefaultBondDenom, sdk.NewInt(0)) } // BeforeEpochStart is the epoch start hook. @@ -42,7 +43,7 @@ func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochN // AfterEpochEnd is the epoch end hook. func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) { - var burnt = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)) + var burnt = sdk.NewCoin(params.DefaultBondDenom, sdk.NewInt(0)) config, found := k.GetEpochBurnConfig(ctx) if !found { diff --git a/x/furnace/keeper/hooks_test.go b/x/furnace/keeper/hooks_test.go index 21e19673..74126651 100644 --- a/x/furnace/keeper/hooks_test.go +++ b/x/furnace/keeper/hooks_test.go @@ -3,6 +3,7 @@ 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" @@ -40,8 +41,8 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { BurnIndex: "1", BurnTotalEpochs: "3", BurnCurrentEpoch: "1", - BurnAmount: "10stake", - BurnCumulativeBurntAmount: "10stake", + BurnAmount: "10umycel", + BurnCumulativeBurntAmount: "10umycel", }, { EpochIndex: "daily", @@ -49,8 +50,8 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { BurnIndex: "1", BurnTotalEpochs: "3", BurnCurrentEpoch: "2", - BurnAmount: "10stake", - BurnCumulativeBurntAmount: "20stake", + BurnAmount: "10umycel", + BurnCumulativeBurntAmount: "20umycel", }, { EpochIndex: "daily", @@ -58,8 +59,8 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { BurnIndex: "1", BurnTotalEpochs: "3", BurnCurrentEpoch: "3", - BurnAmount: "10stake", - BurnCumulativeBurntAmount: "30stake", + BurnAmount: "10umycel", + BurnCumulativeBurntAmount: "30umycel", }, { EpochIndex: "daily", @@ -67,8 +68,8 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { BurnIndex: "2", BurnTotalEpochs: "3", BurnCurrentEpoch: "1", - BurnAmount: "10stake", - BurnCumulativeBurntAmount: "10stake", + BurnAmount: "10umycel", + BurnCumulativeBurntAmount: "10umycel", }, }, }, @@ -82,8 +83,8 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { BurnIndex: "1", BurnTotalEpochs: "3", BurnCurrentEpoch: "1", - BurnAmount: "10stake", - BurnCumulativeBurntAmount: "10stake", + BurnAmount: "10umycel", + BurnCumulativeBurntAmount: "10umycel", }, { EpochIndex: "daily", @@ -91,8 +92,8 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { BurnIndex: "1", BurnTotalEpochs: "3", BurnCurrentEpoch: "2", - BurnAmount: "10stake", - BurnCumulativeBurntAmount: "20stake", + BurnAmount: "10umycel", + BurnCumulativeBurntAmount: "20umycel", }, { EpochIndex: "daily", @@ -100,8 +101,8 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { BurnIndex: "1", BurnTotalEpochs: "3", BurnCurrentEpoch: "3", - BurnAmount: "11stake", - BurnCumulativeBurntAmount: "31stake", + BurnAmount: "11umycel", + BurnCumulativeBurntAmount: "31umycel", }, }, }, @@ -116,8 +117,8 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { BurnIndex: "1", BurnTotalEpochs: "3", BurnCurrentEpoch: "1", - BurnAmount: "1stake", - BurnCumulativeBurntAmount: "1stake", + BurnAmount: "1umycel", + BurnCumulativeBurntAmount: "1umycel", }, { EpochIndex: "daily", @@ -125,8 +126,8 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { BurnIndex: "1", BurnTotalEpochs: "3", BurnCurrentEpoch: "2", - BurnAmount: "0stake", - BurnCumulativeBurntAmount: "1stake", + BurnAmount: "0umycel", + BurnCumulativeBurntAmount: "1umycel", }, { EpochIndex: "daily", @@ -134,8 +135,8 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { BurnIndex: "1", BurnTotalEpochs: "3", BurnCurrentEpoch: "3", - BurnAmount: "0stake", - BurnCumulativeBurntAmount: "1stake", + BurnAmount: "0umycel", + BurnCumulativeBurntAmount: "1umycel", }, }, }, @@ -151,8 +152,8 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { Index: uint64(i + 1), TotalEpochs: 3, CurrentEpoch: 0, - TotalBurnAmount: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(tc.totalBurnAmounts[i])), - CumulativeBurntAmount: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)), + TotalBurnAmount: sdk.NewCoin(params.DefaultBondDenom, sdk.NewInt(tc.totalBurnAmounts[i])), + CumulativeBurntAmount: sdk.NewCoin(params.DefaultBondDenom, sdk.NewInt(0)), }) } diff --git a/x/furnace/types/genesis.go b/x/furnace/types/genesis.go index b202d5f4..f3500fb1 100644 --- a/x/furnace/types/genesis.go +++ b/x/furnace/types/genesis.go @@ -3,6 +3,7 @@ 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" ) @@ -27,8 +28,8 @@ func DefaultGenesis() *GenesisState { BurnStarted: false, TotalEpochs: 30, CurrentEpoch: 0, - TotalBurnAmount: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)), - CumulativeBurntAmount: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(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 From 262a18d4a2465fef8595efda9df842b6f3f46dab Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 27 Sep 2023 16:03:40 +0200 Subject: [PATCH 27/28] fix compilation err --- x/furnace/genesis_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/furnace/genesis_test.go b/x/furnace/genesis_test.go index d6e9b1b7..3d12ef0a 100644 --- a/x/furnace/genesis_test.go +++ b/x/furnace/genesis_test.go @@ -19,10 +19,10 @@ func TestGenesis(t *testing.T) { }, BurnAmounts: []types.BurnAmount{ { - Identifier: 0, + Index: 0, }, { - Identifier: 1, + Index: 1, }, }, // this line is used by starport scaffolding # genesis/test/state From d1552f7774bc48d6cf76ec969bf8c44656bb6456 Mon Sep 17 00:00:00 2001 From: tarumi Date: Fri, 29 Sep 2023 13:58:50 +0200 Subject: [PATCH 28/28] create burnAmount if next burnAmount is nil --- x/furnace/keeper/event.go | 31 +++++++++++++ x/furnace/keeper/hooks.go | 39 ++++++++-------- x/furnace/keeper/hooks_test.go | 83 ++++++++++++++++++++++++++++++---- x/furnace/types/event.go | 6 +++ 4 files changed, 131 insertions(+), 28 deletions(-) create mode 100644 x/furnace/keeper/event.go 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 index 54e18c8f..f55d25b2 100644 --- a/x/furnace/keeper/hooks.go +++ b/x/furnace/keeper/hooks.go @@ -7,22 +7,6 @@ import ( "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 calculateBurntAmount(burnAmount *types.BurnAmount) sdk.Coin { if burnAmount.TotalBurnAmount.Amount.GTE(sdk.NewInt(int64(burnAmount.TotalEpochs))) { quotient := burnAmount.TotalBurnAmount.Amount.QuoRaw(int64(burnAmount.TotalEpochs)) @@ -37,6 +21,23 @@ func calculateBurntAmount(burnAmount *types.BurnAmount) sdk.Coin { 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) { } @@ -58,7 +59,7 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumb // Get burn amount burnAmount, found := k.GetBurnAmount(ctx, uint64(config.CurrentBurnAmountIndex)) if !found { - panic("burn amount not found") + burnAmount = createNextBurnAmount(ctx, k, config) } // Check if CurrentEpoch is smaller than TotalEpochs @@ -73,7 +74,7 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumb burnAmount, found = k.GetBurnAmount(ctx, uint64(config.CurrentBurnAmountIndex)) if !found { - panic("burn amount not found") + burnAmount = createNextBurnAmount(ctx, k, config) } } @@ -90,7 +91,7 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumb k.SetBurnAmount(ctx, burnAmount) // Emit event - emitEpochBurnEvent(ctx, epochIdentifier, epochNumber, &burnAmount, burnt) + EmitEpochBurnEvent(ctx, epochIdentifier, epochNumber, &burnAmount, burnt) } diff --git a/x/furnace/keeper/hooks_test.go b/x/furnace/keeper/hooks_test.go index 74126651..c9dcfc59 100644 --- a/x/furnace/keeper/hooks_test.go +++ b/x/furnace/keeper/hooks_test.go @@ -10,7 +10,7 @@ import ( "time" ) -type ExpEvent struct { +type ExpBurnEvent struct { EpochIndex string EpochNumber string BurnIndex string @@ -20,21 +20,86 @@ type ExpEvent struct { 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() { - var ( - now = time.Now() - oneDayDuration = time.Hour*24 + time.Second - ) + testCases := []struct { totalBurnAmounts []int64 - expectedEvents []ExpEvent + expectedEvents []ExpBurnEvent epochsCount int64 fn func() }{ { totalBurnAmounts: []int64{30, 31}, epochsCount: 4, - expectedEvents: []ExpEvent{ + expectedEvents: []ExpBurnEvent{ { EpochIndex: "daily", EpochNumber: "1", @@ -76,7 +141,7 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { { totalBurnAmounts: []int64{31}, epochsCount: 3, - expectedEvents: []ExpEvent{ + expectedEvents: []ExpBurnEvent{ { EpochIndex: "daily", EpochNumber: "1", @@ -110,7 +175,7 @@ func (suite *KeeperTestSuite) TestAfterEpochEnd() { { totalBurnAmounts: []int64{1}, epochsCount: 3, - expectedEvents: []ExpEvent{ + expectedEvents: []ExpBurnEvent{ { EpochIndex: "daily", EpochNumber: "1", diff --git a/x/furnace/types/event.go b/x/furnace/types/event.go index 300bf1aa..fccd92a4 100644 --- a/x/furnace/types/event.go +++ b/x/furnace/types/event.go @@ -12,3 +12,9 @@ const ( AttributeKeyBurnCumulativeAmount = "burn-cumulative-amount" AttributeKeyBurnTimestamp = "burn-timestamp" ) + +const ( + EventTypeBurnAmountCreated = "burn-amount-created" + + AttributeKeyBurnAmountIndex = "burn-amount-index" +)