diff --git a/app/proposals_allowlisting.go b/app/proposals_allowlisting.go index f2cba406d..9b360b0ea 100644 --- a/app/proposals_allowlisting.go +++ b/app/proposals_allowlisting.go @@ -75,6 +75,8 @@ func isSdkMessageWhitelisted(msg sdk.Msg) bool { *feeburnertypes.MsgUpdateParams, *feerefundertypes.MsgUpdateParams, *crontypes.MsgUpdateParams, + *crontypes.MsgAddSchedule, + *crontypes.MsgRemoveSchedule, *contractmanagertypes.MsgUpdateParams, *dextypes.MsgUpdateParams, *banktypes.MsgUpdateParams, diff --git a/proto/neutron/cron/genesis.proto b/proto/neutron/cron/genesis.proto index 61b27069a..eba407f97 100644 --- a/proto/neutron/cron/genesis.proto +++ b/proto/neutron/cron/genesis.proto @@ -8,7 +8,7 @@ import "neutron/cron/schedule.proto"; option go_package = "github.com/neutron-org/neutron/v4/x/cron/types"; -// GenesisState defines the cron module's genesis state. +// Defines the cron module's genesis state. message GenesisState { repeated Schedule scheduleList = 2 [(gogoproto.nullable) = false]; Params params = 1 [(gogoproto.nullable) = false]; diff --git a/proto/neutron/cron/params.proto b/proto/neutron/cron/params.proto index 9bea16a5b..c3c5cf452 100644 --- a/proto/neutron/cron/params.proto +++ b/proto/neutron/cron/params.proto @@ -5,7 +5,7 @@ import "gogoproto/gogo.proto"; option go_package = "github.com/neutron-org/neutron/v4/x/cron/types"; -// Params defines the parameters for the module. +// Defines the parameters for the module. message Params { option (gogoproto.goproto_stringer) = false; // Security address that can remove schedules diff --git a/proto/neutron/cron/query.proto b/proto/neutron/cron/query.proto index 401e9ce9d..60ee505e0 100644 --- a/proto/neutron/cron/query.proto +++ b/proto/neutron/cron/query.proto @@ -10,7 +10,7 @@ import "neutron/cron/schedule.proto"; option go_package = "github.com/neutron-org/neutron/v4/x/cron/types"; -// Query defines the gRPC querier service. +// Defines the gRPC querier service. service Query { // Queries the parameters of the module. rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { @@ -30,25 +30,31 @@ service Query { // this line is used by starport scaffolding # 2 } +// The request type for the Query/Params RPC method. message QueryParamsRequest {} +// The response type for the Query/Params RPC method. message QueryParamsResponse { // params holds all the parameters of this module. Params params = 1 [(gogoproto.nullable) = false]; } +// The request type for the Query/Schedule RPC method. message QueryGetScheduleRequest { string name = 1; } +// The response type for the Query/Params RPC method. message QueryGetScheduleResponse { Schedule schedule = 1 [(gogoproto.nullable) = false]; } +// The request type for the Query/Schedules RPC method. message QuerySchedulesRequest { cosmos.base.query.v1beta1.PageRequest pagination = 1; } +// The response type for the Query/Params RPC method. message QuerySchedulesResponse { repeated Schedule schedules = 1 [(gogoproto.nullable) = false]; cosmos.base.query.v1beta1.PageResponse pagination = 2; diff --git a/proto/neutron/cron/schedule.proto b/proto/neutron/cron/schedule.proto index 5df38de34..b6147aed4 100644 --- a/proto/neutron/cron/schedule.proto +++ b/proto/neutron/cron/schedule.proto @@ -5,25 +5,38 @@ import "gogoproto/gogo.proto"; option go_package = "github.com/neutron-org/neutron/v4/x/cron/types"; +// Defines when messages will be executed in the block +enum ExecutionStage { + // Execution at the end of the block + EXECUTION_STAGE_END_BLOCKER = 0; + // Execution at the beginning of the block + EXECUTION_STAGE_BEGIN_BLOCKER = 1; +} + +// Defines the schedule for execution message Schedule { // Name of schedule string name = 1; // Period in blocks uint64 period = 2; - // Msgs that will be executed every period amount of time + // Msgs that will be executed every certain number of blocks, specified in the `period` field repeated MsgExecuteContract msgs = 3 [(gogoproto.nullable) = false]; // Last execution's block height uint64 last_execute_height = 4; + // Stage when messages will be executed + ExecutionStage execution_stage = 5; } +// Defines the contract and the message to pass message MsgExecuteContract { - // Contract is the address of the smart contract + // The address of the smart contract string contract = 1; - // Msg is json encoded message to be passed to the contract + // JSON encoded message to be passed to the contract string msg = 2; } +// Defines the number of current schedules message ScheduleCount { - // Count is the number of current schedules + // The number of current schedules int32 count = 1; } diff --git a/proto/neutron/cron/tx.proto b/proto/neutron/cron/tx.proto index 6bb9d3bf7..fcb9b383a 100644 --- a/proto/neutron/cron/tx.proto +++ b/proto/neutron/cron/tx.proto @@ -6,32 +6,72 @@ import "cosmos/msg/v1/msg.proto"; import "cosmos_proto/cosmos.proto"; import "gogoproto/gogo.proto"; import "neutron/cron/params.proto"; +import "neutron/cron/schedule.proto"; // this line is used by starport scaffolding # proto/tx/import option go_package = "github.com/neutron-org/neutron/v4/x/cron/types"; -// Msg defines the Msg service. +// Defines the Msg service. service Msg { option (cosmos.msg.v1.service) = true; + // Adds new schedule. + rpc AddSchedule(MsgAddSchedule) returns (MsgAddScheduleResponse); + // Removes schedule. + rpc RemoveSchedule(MsgRemoveSchedule) returns (MsgRemoveScheduleResponse); + // Updates the module parameters. rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); // this line is used by starport scaffolding # proto/tx/rpc } +// The MsgAddSchedule request type. +message MsgAddSchedule { + option (amino.name) = "cron/MsgAddSchedule"; + option (cosmos.msg.v1.signer) = "authority"; + + // The address of the governance account. + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + // Name of the schedule + string name = 2; + // Period in blocks + uint64 period = 3; + // Msgs that will be executed every certain number of blocks, specified in the `period` field + repeated MsgExecuteContract msgs = 4 [(gogoproto.nullable) = false]; + // Stage when messages will be executed + ExecutionStage execution_stage = 5; +} + +// Defines the response structure for executing a MsgAddSchedule message. +message MsgAddScheduleResponse {} + +// The MsgRemoveSchedule request type. +message MsgRemoveSchedule { + option (amino.name) = "cron/MsgRemoveSchedule"; + option (cosmos.msg.v1.signer) = "authority"; + + // The address of the governance account. + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + // Name of the schedule + string name = 2; +} + +// Defines the response structure for executing a MsgRemoveSchedule message. +message MsgRemoveScheduleResponse {} + // this line is used by starport scaffolding # proto/tx/message -// MsgUpdateParams is the MsgUpdateParams request type. +// The MsgUpdateParams request type. // // Since: 0.47 message MsgUpdateParams { option (amino.name) = "cron/MsgUpdateParams"; option (cosmos.msg.v1.signer) = "authority"; - // Authority is the address of the governance account. + // The address of the governance account. string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; - // params defines the x/cron parameters to update. + // Defines the x/cron parameters to update. // // NOTE: All parameters must be supplied. Params params = 2 [ @@ -40,8 +80,7 @@ message MsgUpdateParams { ]; } -// MsgUpdateParamsResponse defines the response structure for executing a -// MsgUpdateParams message. +// Defines the response structure for executing a MsgUpdateParams message. // // Since: 0.47 message MsgUpdateParamsResponse {} diff --git a/proto/neutron/cron/v1/schedule.proto b/proto/neutron/cron/v1/schedule.proto new file mode 100644 index 000000000..8995431fe --- /dev/null +++ b/proto/neutron/cron/v1/schedule.proto @@ -0,0 +1,32 @@ +syntax = "proto3"; +package neutron.cron.v1; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/neutron-org/neutron/v4/x/cron/types/v1"; + +// Defines the schedule for execution +message Schedule { + // Name of schedule + string name = 1; + // Period in blocks + uint64 period = 2; + // Msgs that will be executed every certain number of blocks, specified in the `period` field + repeated MsgExecuteContract msgs = 3 [(gogoproto.nullable) = false]; + // Last execution's block height + uint64 last_execute_height = 4; +} + +// Defines the contract and the message to pass +message MsgExecuteContract { + // The address of the smart contract + string contract = 1; + // JSON encoded message to be passed to the contract + string msg = 2; +} + +// Defines the number of current schedules +message ScheduleCount { + // The number of current schedules + int32 count = 1; +} diff --git a/wasmbinding/bindings/msg.go b/wasmbinding/bindings/msg.go index 2aee5622a..8c57b202a 100644 --- a/wasmbinding/bindings/msg.go +++ b/wasmbinding/bindings/msg.go @@ -196,9 +196,10 @@ type ForceTransfer struct { // AddSchedule adds new schedule to the cron module type AddSchedule struct { - Name string `json:"name"` - Period uint64 `json:"period"` - Msgs []MsgExecuteContract `json:"msgs"` + Name string `json:"name"` + Period uint64 `json:"period"` + Msgs []MsgExecuteContract `json:"msgs"` + ExecutionStage string `json:"execution_stage"` } // AddScheduleResponse holds response AddSchedule diff --git a/wasmbinding/message_plugin.go b/wasmbinding/message_plugin.go index 30d53717d..8e00248d9 100644 --- a/wasmbinding/message_plugin.go +++ b/wasmbinding/message_plugin.go @@ -73,7 +73,8 @@ func CustomMessageDecorator( Adminserver: adminmodulekeeper.NewMsgServerImpl(*adminKeeper), Bank: bankKeeper, TokenFactory: tokenFactoryKeeper, - CronKeeper: cronKeeper, + CronMsgServer: cronkeeper.NewMsgServerImpl(*cronKeeper), + CronQueryServer: cronKeeper, AdminKeeper: adminKeeper, ContractmanagerKeeper: contractmanagerKeeper, DexMsgServer: dexkeeper.NewMsgServerImpl(*dexKeeper), @@ -90,7 +91,8 @@ type CustomMessenger struct { Adminserver admintypes.MsgServer Bank *bankkeeper.BaseKeeper TokenFactory *tokenfactorykeeper.Keeper - CronKeeper *cronkeeper.Keeper + CronMsgServer crontypes.MsgServer + CronQueryServer crontypes.QueryServer AdminKeeper *adminmodulekeeper.Keeper ContractmanagerKeeper *contractmanagerkeeper.Keeper DexMsgServer dextypes.MsgServer @@ -989,6 +991,8 @@ func (m *CustomMessenger) addSchedule(ctx sdk.Context, contractAddr sdk.AccAddre return nil, nil, nil, errors.Wrap(sdkerrors.ErrUnauthorized, "only admin can add schedule") } + authority := authtypes.NewModuleAddress(admintypes.ModuleName) + msgs := make([]crontypes.MsgExecuteContract, 0, len(addSchedule.Msgs)) for _, msg := range addSchedule.Msgs { msgs = append(msgs, crontypes.MsgExecuteContract{ @@ -997,13 +1001,20 @@ func (m *CustomMessenger) addSchedule(ctx sdk.Context, contractAddr sdk.AccAddre }) } - err := m.CronKeeper.AddSchedule(ctx, addSchedule.Name, addSchedule.Period, msgs) + _, err := m.CronMsgServer.AddSchedule(ctx, &crontypes.MsgAddSchedule{ + Authority: authority.String(), + Name: addSchedule.Name, + Period: addSchedule.Period, + Msgs: msgs, + ExecutionStage: crontypes.ExecutionStage(crontypes.ExecutionStage_value[addSchedule.ExecutionStage]), + }) if err != nil { ctx.Logger().Error("failed to addSchedule", "from_address", contractAddr.String(), + "name", addSchedule.Name, "error", err, ) - return nil, nil, nil, errors.Wrap(err, "marshal json failed") + return nil, nil, nil, errors.Wrapf(err, "failed to add %s schedule", addSchedule.Name) } ctx.Logger().Debug("schedule added", @@ -1016,12 +1027,30 @@ func (m *CustomMessenger) addSchedule(ctx sdk.Context, contractAddr sdk.AccAddre } func (m *CustomMessenger) removeSchedule(ctx sdk.Context, contractAddr sdk.AccAddress, removeSchedule *bindings.RemoveSchedule) ([]sdk.Event, [][]byte, [][]*types.Any, error) { - params := m.CronKeeper.GetParams(ctx) - if !m.isAdmin(ctx, contractAddr) && contractAddr.String() != params.SecurityAddress { + params, err := m.CronQueryServer.Params(ctx, &crontypes.QueryParamsRequest{}) + if err != nil { + ctx.Logger().Error("failed to removeSchedule", "error", err) + return nil, nil, nil, errors.Wrap(err, "failed to removeSchedule") + } + + if !m.isAdmin(ctx, contractAddr) && contractAddr.String() != params.Params.SecurityAddress { return nil, nil, nil, errors.Wrap(sdkerrors.ErrUnauthorized, "only admin or security dao can remove schedule") } - m.CronKeeper.RemoveSchedule(ctx, removeSchedule.Name) + authority := authtypes.NewModuleAddress(admintypes.ModuleName) + + _, err = m.CronMsgServer.RemoveSchedule(ctx, &crontypes.MsgRemoveSchedule{ + Authority: authority.String(), + Name: removeSchedule.Name, + }) + if err != nil { + ctx.Logger().Error("failed to removeSchedule", + "from_address", contractAddr.String(), + "name", removeSchedule.Name, + "error", err, + ) + return nil, nil, nil, errors.Wrapf(err, "failed to remove %s schedule", removeSchedule.Name) + } ctx.Logger().Debug("schedule removed", "from_address", contractAddr.String(), diff --git a/wasmbinding/test/custom_message_test.go b/wasmbinding/test/custom_message_test.go index 446c7159f..fe15d1d10 100644 --- a/wasmbinding/test/custom_message_test.go +++ b/wasmbinding/test/custom_message_test.go @@ -6,6 +6,7 @@ import ( "testing" contractmanagertypes "github.com/neutron-org/neutron/v4/x/contractmanager/types" + types2 "github.com/neutron-org/neutron/v4/x/cron/types" "cosmossdk.io/math" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" @@ -23,6 +24,8 @@ import ( adminkeeper "github.com/cosmos/admin-module/v2/x/adminmodule/keeper" + cronkeeper "github.com/neutron-org/neutron/v4/x/cron/keeper" + "github.com/neutron-org/neutron/v4/app/params" "github.com/CosmWasm/wasmd/x/wasm/keeper" @@ -67,7 +70,8 @@ func (suite *CustomMessengerTestSuite) SetupTest() { suite.messenger.Adminserver = adminkeeper.NewMsgServerImpl(suite.neutron.AdminmoduleKeeper) suite.messenger.Bank = &suite.neutron.BankKeeper suite.messenger.TokenFactory = suite.neutron.TokenFactoryKeeper - suite.messenger.CronKeeper = &suite.neutron.CronKeeper + suite.messenger.CronMsgServer = cronkeeper.NewMsgServerImpl(suite.neutron.CronKeeper) + suite.messenger.CronQueryServer = suite.neutron.CronKeeper suite.messenger.AdminKeeper = &suite.neutron.AdminmoduleKeeper suite.messenger.ContractmanagerKeeper = &suite.neutron.ContractManagerKeeper suite.contractOwner = keeper.RandomAccountAddress(suite.T()) @@ -718,6 +722,10 @@ func (suite *CustomMessengerTestSuite) TestAddRemoveSchedule() { }, } + schedule, ok := suite.neutron.CronKeeper.GetSchedule(suite.ctx, "schedule1") + suite.True(ok) + suite.Equal(types2.ExecutionStage_EXECUTION_STAGE_END_BLOCKER, schedule.ExecutionStage) + // Dispatch AddSchedule message _, err = suite.executeNeutronMsg(suite.contractAddress, msg) suite.NoError(err) diff --git a/x/cron/genesis.go b/x/cron/genesis.go index 974790399..525840e26 100644 --- a/x/cron/genesis.go +++ b/x/cron/genesis.go @@ -11,7 +11,7 @@ import ( func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { // Set all the schedules for _, elem := range genState.ScheduleList { - err := k.AddSchedule(ctx, elem.Name, elem.Period, elem.Msgs) + err := k.AddSchedule(ctx, elem.Name, elem.Period, elem.Msgs, elem.ExecutionStage) if err != nil { panic(err) } diff --git a/x/cron/keeper/grpc_query_schedule_test.go b/x/cron/keeper/grpc_query_schedule_test.go index b778f8fba..a132fc8d4 100644 --- a/x/cron/keeper/grpc_query_schedule_test.go +++ b/x/cron/keeper/grpc_query_schedule_test.go @@ -133,8 +133,9 @@ func createNSchedule(t *testing.T, ctx sdk.Context, k *cronkeeper.Keeper, n int3 item.Period = 1000 item.Msgs = nil item.LastExecuteHeight = uint64(ctx.BlockHeight()) + item.ExecutionStage = types.ExecutionStage_EXECUTION_STAGE_END_BLOCKER - err := k.AddSchedule(ctx, item.Name, item.Period, item.Msgs) + err := k.AddSchedule(ctx, item.Name, item.Period, item.Msgs, item.ExecutionStage) require.NoError(t, err) res[idx] = item diff --git a/x/cron/keeper/keeper.go b/x/cron/keeper/keeper.go index 2be2f49ee..070f18b2d 100644 --- a/x/cron/keeper/keeper.go +++ b/x/cron/keeper/keeper.go @@ -66,10 +66,9 @@ func (k *Keeper) Logger(ctx sdk.Context) log.Logger { // ExecuteReadySchedules gets all schedules that are due for execution (with limit that is equal to Params.Limit) // and executes messages in each one -// NOTE that errors in contract calls rollback all already executed messages -func (k *Keeper) ExecuteReadySchedules(ctx sdk.Context) { +func (k *Keeper) ExecuteReadySchedules(ctx sdk.Context, executionStage types.ExecutionStage) { telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), LabelExecuteReadySchedules) - schedules := k.getSchedulesReadyForExecution(ctx) + schedules := k.getSchedulesReadyForExecution(ctx, executionStage) for _, schedule := range schedules { err := k.executeSchedule(ctx, schedule) @@ -77,9 +76,15 @@ func (k *Keeper) ExecuteReadySchedules(ctx sdk.Context) { } } -// AddSchedule adds new schedule to execution for every block `period`. +// AddSchedule adds a new schedule to be executed every certain number of blocks, specified in the `period`. // First schedule execution is supposed to be on `now + period` block. -func (k *Keeper) AddSchedule(ctx sdk.Context, name string, period uint64, msgs []types.MsgExecuteContract) error { +func (k *Keeper) AddSchedule( + ctx sdk.Context, + name string, + period uint64, + msgs []types.MsgExecuteContract, + executionStage types.ExecutionStage, +) error { if k.scheduleExists(ctx, name) { return fmt.Errorf("schedule already exists with name=%v", name) } @@ -89,7 +94,9 @@ func (k *Keeper) AddSchedule(ctx sdk.Context, name string, period uint64, msgs [ Period: period, Msgs: msgs, LastExecuteHeight: uint64(ctx.BlockHeight()), // let's execute newly added schedule on `now + period` block + ExecutionStage: executionStage, } + k.storeSchedule(ctx, schedule) k.changeTotalCount(ctx, 1) @@ -141,7 +148,7 @@ func (k *Keeper) GetScheduleCount(ctx sdk.Context) int32 { return k.getScheduleCount(ctx) } -func (k *Keeper) getSchedulesReadyForExecution(ctx sdk.Context) []types.Schedule { +func (k *Keeper) getSchedulesReadyForExecution(ctx sdk.Context, executionStage types.ExecutionStage) []types.Schedule { params := k.GetParams(ctx) store := prefix.NewStore(ctx.KVStore(k.storeKey), types.ScheduleKey) count := uint64(0) @@ -155,7 +162,7 @@ func (k *Keeper) getSchedulesReadyForExecution(ctx sdk.Context) []types.Schedule var schedule types.Schedule k.cdc.MustUnmarshal(iterator.Value(), &schedule) - if k.intervalPassed(ctx, schedule) { + if k.intervalPassed(ctx, schedule) && schedule.ExecutionStage == executionStage { res = append(res, schedule) count++ diff --git a/x/cron/keeper/keeper_test.go b/x/cron/keeper/keeper_test.go index 8abe2060c..d58553c56 100644 --- a/x/cron/keeper/keeper_test.go +++ b/x/cron/keeper/keeper_test.go @@ -44,7 +44,7 @@ func TestKeeperExecuteReadySchedules(t *testing.T) { schedules := []types.Schedule{ { Name: "1_unready1", - Period: 3, + Period: 10, Msgs: []types.MsgExecuteContract{ { Contract: "1_neutron", @@ -52,10 +52,11 @@ func TestKeeperExecuteReadySchedules(t *testing.T) { }, }, LastExecuteHeight: 4, + ExecutionStage: types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER, }, { Name: "2_ready1", - Period: 3, + Period: 4, Msgs: []types.MsgExecuteContract{ { Contract: "2_neutron", @@ -63,10 +64,11 @@ func TestKeeperExecuteReadySchedules(t *testing.T) { }, }, LastExecuteHeight: 0, + ExecutionStage: types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER, }, { Name: "3_ready2", - Period: 3, + Period: 4, Msgs: []types.MsgExecuteContract{ { Contract: "3_neutron", @@ -74,12 +76,14 @@ func TestKeeperExecuteReadySchedules(t *testing.T) { }, }, LastExecuteHeight: 0, + ExecutionStage: types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER, }, { Name: "4_unready2", - Period: 3, + Period: 10, Msgs: []types.MsgExecuteContract{}, LastExecuteHeight: 4, + ExecutionStage: types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER, }, { Name: "5_ready3", @@ -91,22 +95,34 @@ func TestKeeperExecuteReadySchedules(t *testing.T) { }, }, LastExecuteHeight: 0, + ExecutionStage: types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER, + }, + { + Name: "6_ready4", + Period: 3, + Msgs: []types.MsgExecuteContract{ + { + Contract: "6_neutron", + Msg: "6_msg", + }, + }, + LastExecuteHeight: 0, + ExecutionStage: types.ExecutionStage_EXECUTION_STAGE_END_BLOCKER, }, } for _, item := range schedules { ctx = ctx.WithBlockHeight(int64(item.LastExecuteHeight)) - err := k.AddSchedule(ctx, item.Name, item.Period, item.Msgs) + err := k.AddSchedule(ctx, item.Name, item.Period, item.Msgs, item.ExecutionStage) require.NoError(t, err) } count := k.GetScheduleCount(ctx) - require.Equal(t, count, int32(5)) + require.Equal(t, count, int32(6)) ctx = ctx.WithBlockHeight(5) - accountKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(addr) - accountKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(addr) + accountKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(addr).AnyTimes() wasmMsgServer.EXPECT().ExecuteContract(gomock.Any(), &wasmtypes.MsgExecuteContract{ Sender: testutil.TestOwnerAddress, Contract: "2_neutron", @@ -120,25 +136,26 @@ func TestKeeperExecuteReadySchedules(t *testing.T) { Funds: sdk.NewCoins(), }).Return(&wasmtypes.MsgExecuteContractResponse{}, nil) - k.ExecuteReadySchedules(ctx) + k.ExecuteReadySchedules(ctx, types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER) unready1, _ := k.GetSchedule(ctx, "1_unready1") ready1, _ := k.GetSchedule(ctx, "2_ready1") ready2, _ := k.GetSchedule(ctx, "3_ready2") unready2, _ := k.GetSchedule(ctx, "4_unready2") ready3, _ := k.GetSchedule(ctx, "5_ready3") + ready4, _ := k.GetSchedule(ctx, "6_ready4") require.Equal(t, uint64(4), unready1.LastExecuteHeight) require.Equal(t, uint64(5), ready1.LastExecuteHeight) require.Equal(t, uint64(5), ready2.LastExecuteHeight) require.Equal(t, uint64(4), unready2.LastExecuteHeight) require.Equal(t, uint64(0), ready3.LastExecuteHeight) + require.Equal(t, uint64(0), ready4.LastExecuteHeight) // let's make another call at the next height // Notice that now only one ready schedule left because we got limit of 2 at once ctx = ctx.WithBlockHeight(6) - accountKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(addr) wasmMsgServer.EXPECT().ExecuteContract(gomock.Any(), &wasmtypes.MsgExecuteContract{ Sender: testutil.TestOwnerAddress, Contract: "5_neutron", @@ -146,19 +163,46 @@ func TestKeeperExecuteReadySchedules(t *testing.T) { Funds: sdk.NewCoins(), }).Return(&wasmtypes.MsgExecuteContractResponse{}, nil) - k.ExecuteReadySchedules(ctx) + k.ExecuteReadySchedules(ctx, types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER) unready1, _ = k.GetSchedule(ctx, "1_unready1") ready1, _ = k.GetSchedule(ctx, "2_ready1") ready2, _ = k.GetSchedule(ctx, "3_ready2") unready2, _ = k.GetSchedule(ctx, "4_unready2") ready3, _ = k.GetSchedule(ctx, "5_ready3") + ready4, _ = k.GetSchedule(ctx, "6_ready4") require.Equal(t, uint64(4), unready1.LastExecuteHeight) require.Equal(t, uint64(5), ready1.LastExecuteHeight) require.Equal(t, uint64(5), ready2.LastExecuteHeight) require.Equal(t, uint64(4), unready2.LastExecuteHeight) require.Equal(t, uint64(6), ready3.LastExecuteHeight) + require.Equal(t, uint64(0), ready4.LastExecuteHeight) + + ctx = ctx.WithBlockHeight(7) + + wasmMsgServer.EXPECT().ExecuteContract(gomock.Any(), &wasmtypes.MsgExecuteContract{ + Sender: testutil.TestOwnerAddress, + Contract: "6_neutron", + Msg: []byte("6_msg"), + Funds: sdk.NewCoins(), + }).Return(&wasmtypes.MsgExecuteContractResponse{}, nil) + + k.ExecuteReadySchedules(ctx, types.ExecutionStage_EXECUTION_STAGE_END_BLOCKER) + + unready1, _ = k.GetSchedule(ctx, "1_unready1") + ready1, _ = k.GetSchedule(ctx, "2_ready1") + ready2, _ = k.GetSchedule(ctx, "3_ready2") + unready2, _ = k.GetSchedule(ctx, "4_unready2") + ready3, _ = k.GetSchedule(ctx, "5_ready3") + ready4, _ = k.GetSchedule(ctx, "6_ready4") + + require.Equal(t, uint64(4), unready1.LastExecuteHeight) + require.Equal(t, uint64(5), ready1.LastExecuteHeight) + require.Equal(t, uint64(5), ready2.LastExecuteHeight) + require.Equal(t, uint64(4), unready2.LastExecuteHeight) + require.Equal(t, uint64(6), ready3.LastExecuteHeight) + require.Equal(t, uint64(7), ready4.LastExecuteHeight) } func TestAddSchedule(t *testing.T) { @@ -183,11 +227,19 @@ func TestAddSchedule(t *testing.T) { Contract: "c", Msg: "m", }, - }) + }, types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER) + require.NoError(t, err) + + err = k.AddSchedule(ctx, "b", 7, []types.MsgExecuteContract{ + { + Contract: "c", + Msg: "m", + }, + }, types.ExecutionStage_EXECUTION_STAGE_END_BLOCKER) require.NoError(t, err) // second time with same name returns error - err = k.AddSchedule(ctx, "a", 5, []types.MsgExecuteContract{}) + err = k.AddSchedule(ctx, "a", 5, []types.MsgExecuteContract{}, types.ExecutionStage_EXECUTION_STAGE_END_BLOCKER) require.Error(t, err) scheduleA, found := k.GetSchedule(ctx, "a") @@ -197,6 +249,12 @@ func TestAddSchedule(t *testing.T) { require.Equal(t, scheduleA.Msgs, []types.MsgExecuteContract{ {Contract: "c", Msg: "m"}, }) + require.Equal(t, scheduleA.ExecutionStage, types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER) + + schedules := k.GetAllSchedules(ctx) + require.Len(t, schedules, 2) + require.Equal(t, schedules[0].ExecutionStage, types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER) + require.Equal(t, schedules[1].ExecutionStage, types.ExecutionStage_EXECUTION_STAGE_END_BLOCKER) // remove schedule works k.RemoveSchedule(ctx, "a") @@ -223,9 +281,10 @@ func TestGetAllSchedules(t *testing.T) { Period: 5, Msgs: nil, LastExecuteHeight: uint64(ctx.BlockHeight()), + ExecutionStage: types.ExecutionStage_EXECUTION_STAGE_END_BLOCKER, } expectedSchedules = append(expectedSchedules, s) - err := k.AddSchedule(ctx, s.Name, s.Period, s.Msgs) + err := k.AddSchedule(ctx, s.Name, s.Period, s.Msgs, s.ExecutionStage) require.NoError(t, err) } diff --git a/x/cron/keeper/migrations.go b/x/cron/keeper/migrations.go new file mode 100644 index 000000000..0166a8da9 --- /dev/null +++ b/x/cron/keeper/migrations.go @@ -0,0 +1,22 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + v2 "github.com/neutron-org/neutron/v4/x/cron/migrations/v2" +) + +// Migrator is a struct for handling in-place store migrations. +type Migrator struct { + keeper Keeper +} + +// NewMigrator returns a new Migrator. +func NewMigrator(keeper Keeper) Migrator { + return Migrator{keeper: keeper} +} + +// Migrate1to2 migrates from version 1 to 2. +func (m Migrator) Migrate1to2(ctx sdk.Context) error { + return v2.MigrateStore(ctx, m.keeper.cdc, m.keeper.storeKey) +} diff --git a/x/cron/keeper/msg_server.go b/x/cron/keeper/msg_server.go index e49e578ab..c42a0d1c4 100644 --- a/x/cron/keeper/msg_server.go +++ b/x/cron/keeper/msg_server.go @@ -11,30 +11,66 @@ import ( ) type msgServer struct { - Keeper + keeper Keeper } // NewMsgServerImpl returns an implementation of the MsgServer interface // for the provided Keeper. func NewMsgServerImpl(keeper Keeper) types.MsgServer { - return &msgServer{Keeper: keeper} + return &msgServer{keeper: keeper} } var _ types.MsgServer = msgServer{} +// AddSchedule adds new schedule +func (k msgServer) AddSchedule(goCtx context.Context, req *types.MsgAddSchedule) (*types.MsgAddScheduleResponse, error) { + if err := req.Validate(); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgAddSchedule") + } + + authority := k.keeper.GetAuthority() + if authority != req.Authority { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid authority; expected %s, got %s", authority, req.Authority) + } + + ctx := sdk.UnwrapSDKContext(goCtx) + if err := k.keeper.AddSchedule(ctx, req.Name, req.Period, req.Msgs, req.ExecutionStage); err != nil { + return nil, errors.Wrap(err, "failed to add schedule") + } + + return &types.MsgAddScheduleResponse{}, nil +} + +// RemoveSchedule removes schedule +func (k msgServer) RemoveSchedule(goCtx context.Context, req *types.MsgRemoveSchedule) (*types.MsgRemoveScheduleResponse, error) { + if err := req.Validate(); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgRemoveSchedule") + } + + authority := k.keeper.GetAuthority() + if authority != req.Authority { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid authority; expected %s, got %s", authority, req.Authority) + } + + ctx := sdk.UnwrapSDKContext(goCtx) + k.keeper.RemoveSchedule(ctx, req.Name) + + return &types.MsgRemoveScheduleResponse{}, nil +} + // UpdateParams updates the module parameters -func (k Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { +func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { if err := req.Validate(); err != nil { return nil, errors.Wrap(err, "failed to validate MsgUpdateParams") } - authority := k.GetAuthority() + authority := k.keeper.GetAuthority() if authority != req.Authority { return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid authority; expected %s, got %s", authority, req.Authority) } ctx := sdk.UnwrapSDKContext(goCtx) - if err := k.SetParams(ctx, req.Params); err != nil { + if err := k.keeper.SetParams(ctx, req.Params); err != nil { return nil, err } diff --git a/x/cron/keeper/msg_server_test.go b/x/cron/keeper/msg_server_test.go index 17a3655ac..ef10b1ffc 100644 --- a/x/cron/keeper/msg_server_test.go +++ b/x/cron/keeper/msg_server_test.go @@ -6,12 +6,171 @@ import ( "github.com/stretchr/testify/require" "github.com/neutron-org/neutron/v4/testutil" - "github.com/neutron-org/neutron/v4/testutil/cron/keeper" + testkeeper "github.com/neutron-org/neutron/v4/testutil/cron/keeper" + cronkeeper "github.com/neutron-org/neutron/v4/x/cron/keeper" "github.com/neutron-org/neutron/v4/x/cron/types" ) +func TestMsgAddScheduleValidate(t *testing.T) { + k, ctx := testkeeper.CronKeeper(t, nil, nil) + msgServer := cronkeeper.NewMsgServerImpl(*k) + + tests := []struct { + name string + msg types.MsgAddSchedule + expectedErr string + }{ + { + "empty authority", + types.MsgAddSchedule{ + Authority: "", + Name: "name", + Period: 3, + Msgs: []types.MsgExecuteContract{ + { + Contract: "contract", + Msg: "msg", + }, + }, + ExecutionStage: types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER, + }, + "authority is invalid", + }, + { + "invalid authority", + types.MsgAddSchedule{ + Authority: "invalid authority", + Name: "name", + Period: 3, + Msgs: []types.MsgExecuteContract{ + { + Contract: "contract", + Msg: "msg", + }, + }, + ExecutionStage: types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER, + }, + "authority is invalid", + }, + { + "invalid name", + types.MsgAddSchedule{ + Authority: testutil.TestOwnerAddress, + Name: "", + Period: 3, + Msgs: []types.MsgExecuteContract{ + { + Contract: "contract", + Msg: "msg", + }, + }, + ExecutionStage: types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER, + }, + "name is invalid", + }, + { + "invalid period", + types.MsgAddSchedule{ + Authority: testutil.TestOwnerAddress, + Name: "name", + Period: 0, + Msgs: []types.MsgExecuteContract{ + { + Contract: "contract", + Msg: "msg", + }, + }, + ExecutionStage: types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER, + }, + "period is invalid", + }, + { + "empty msgs", + types.MsgAddSchedule{ + Authority: testutil.TestOwnerAddress, + Name: "name", + Period: 3, + Msgs: []types.MsgExecuteContract{}, + ExecutionStage: types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER, + }, + "msgs should not be empty", + }, + { + "invalid execution stage", + types.MsgAddSchedule{ + Authority: testutil.TestOwnerAddress, + Name: "name", + Period: 3, + Msgs: []types.MsgExecuteContract{ + { + Contract: "contract", + Msg: "msg", + }, + }, + ExecutionStage: 7, + }, + "execution stage is invalid", + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + resp, err := msgServer.AddSchedule(ctx, &tt.msg) + require.ErrorContains(t, err, tt.expectedErr) + require.Nil(t, resp) + }) + } +} + +func TestMsgRemoveScheduleValidate(t *testing.T) { + k, ctx := testkeeper.CronKeeper(t, nil, nil) + msgServer := cronkeeper.NewMsgServerImpl(*k) + + tests := []struct { + name string + msg types.MsgRemoveSchedule + expectedErr string + }{ + { + "empty authority", + types.MsgRemoveSchedule{ + Authority: "", + Name: "name", + }, + "authority is invalid", + }, + { + "invalid authority", + types.MsgRemoveSchedule{ + Authority: "invalid authority", + Name: "name", + }, + "authority is invalid", + }, + { + "invalid name", + types.MsgRemoveSchedule{ + Authority: testutil.TestOwnerAddress, + Name: "", + }, + "name is invalid", + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + resp, err := msgServer.RemoveSchedule(ctx, &tt.msg) + require.ErrorContains(t, err, tt.expectedErr) + require.Nil(t, resp) + }) + } +} + func TestMsgUpdateParamsValidate(t *testing.T) { - k, ctx := keeper.CronKeeper(t, nil, nil) + k, ctx := testkeeper.CronKeeper(t, nil, nil) + msgServer := cronkeeper.NewMsgServerImpl(*k) tests := []struct { name string @@ -57,7 +216,7 @@ func TestMsgUpdateParamsValidate(t *testing.T) { for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { - resp, err := k.UpdateParams(ctx, &tt.msg) + resp, err := msgServer.UpdateParams(ctx, &tt.msg) require.ErrorContains(t, err, tt.expectedErr) require.Nil(t, resp) }) diff --git a/x/cron/migrations/v2/store.go b/x/cron/migrations/v2/store.go new file mode 100644 index 000000000..f3311aba0 --- /dev/null +++ b/x/cron/migrations/v2/store.go @@ -0,0 +1,56 @@ +package v2 + +import ( + "cosmossdk.io/errors" + "cosmossdk.io/store/prefix" + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/neutron-org/neutron/v4/x/cron/types" +) + +// MigrateStore performs in-place store migrations. +// The migration adds execution stage for schedules. +func MigrateStore(ctx sdk.Context, cdc codec.BinaryCodec, storeKey storetypes.StoreKey) error { + return migrateSchedules(ctx, cdc, storeKey) +} + +type migrationUpdate struct { + key []byte + val []byte +} + +func migrateSchedules(ctx sdk.Context, cdc codec.BinaryCodec, storeKey storetypes.StoreKey) error { + ctx.Logger().Info("Migrating cron Schedules...") + + store := prefix.NewStore(ctx.KVStore(storeKey), types.ScheduleKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{}) + schedulesToUpdate := make([]migrationUpdate, 0) + + for ; iterator.Valid(); iterator.Next() { + var schedule types.Schedule + cdc.MustUnmarshal(iterator.Value(), &schedule) + // Set execution in EndBlocker + schedule.ExecutionStage = types.ExecutionStage_EXECUTION_STAGE_END_BLOCKER + + schedulesToUpdate = append(schedulesToUpdate, migrationUpdate{ + key: iterator.Key(), + val: cdc.MustMarshal(&schedule), + }) + } + + err := iterator.Close() + if err != nil { + return errors.Wrap(err, "iterator failed to close during migration") + } + + // Store the updated Schedules + for _, v := range schedulesToUpdate { + store.Set(v.key, v.val) + } + + ctx.Logger().Info("Finished migrating cron Schedules...") + + return nil +} diff --git a/x/cron/migrations/v2/store_test.go b/x/cron/migrations/v2/store_test.go new file mode 100644 index 000000000..6b6f46355 --- /dev/null +++ b/x/cron/migrations/v2/store_test.go @@ -0,0 +1,60 @@ +package v2_test + +import ( + "testing" + + "cosmossdk.io/store/prefix" + "github.com/stretchr/testify/suite" + + "github.com/neutron-org/neutron/v4/testutil" + v2 "github.com/neutron-org/neutron/v4/x/cron/migrations/v2" + "github.com/neutron-org/neutron/v4/x/cron/types" + v1types "github.com/neutron-org/neutron/v4/x/cron/types/v1" +) + +type V2CronMigrationTestSuite struct { + testutil.IBCConnectionTestSuite +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(V2CronMigrationTestSuite)) +} + +func (suite *V2CronMigrationTestSuite) TestScheduleUpgrade() { + var ( + app = suite.GetNeutronZoneApp(suite.ChainA) + storeKey = app.GetKey(types.StoreKey) + ctx = suite.ChainA.GetContext() + cdc = app.AppCodec() + ) + + schedule := v1types.Schedule{ + Name: "name", + Period: 3, + Msgs: []v1types.MsgExecuteContract{ + { + Contract: "contract", + Msg: "msg", + }, + }, + LastExecuteHeight: 1, + } + + store := prefix.NewStore(ctx.KVStore(storeKey), types.ScheduleKey) + bz := cdc.MustMarshal(&schedule) + store.Set(types.GetScheduleKey(schedule.Name), bz) + + // Run migration + suite.NoError(v2.MigrateStore(ctx, cdc, storeKey)) + + // Check Schedule has correct ExecutionStage + newSchedule, _ := app.CronKeeper.GetSchedule(ctx, schedule.Name) + suite.Equal(newSchedule.Name, schedule.Name) + suite.Equal(newSchedule.Period, schedule.Period) + for i, msg := range newSchedule.Msgs { + suite.Equal(msg.Contract, schedule.Msgs[i].Contract) + suite.Equal(msg.Msg, schedule.Msgs[i].Msg) + } + suite.Equal(newSchedule.LastExecuteHeight, schedule.LastExecuteHeight) + suite.Equal(newSchedule.ExecutionStage, types.ExecutionStage_EXECUTION_STAGE_END_BLOCKER) +} diff --git a/x/cron/module.go b/x/cron/module.go index 60dc09b91..3471b0379 100644 --- a/x/cron/module.go +++ b/x/cron/module.go @@ -155,10 +155,12 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw func (AppModule) ConsensusVersion() uint64 { return types.ConsensusVersion } // BeginBlock contains the logic that is automatically triggered at the beginning of each block -func (am AppModule) BeginBlock(_ sdk.Context) {} +func (am AppModule) BeginBlock(ctx sdk.Context) { + am.keeper.ExecuteReadySchedules(ctx, types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER) +} // EndBlock contains the logic that is automatically triggered at the end of each block func (am AppModule) EndBlock(ctx context.Context) ([]abci.ValidatorUpdate, error) { - am.keeper.ExecuteReadySchedules(sdk.UnwrapSDKContext(ctx)) + am.keeper.ExecuteReadySchedules(sdk.UnwrapSDKContext(ctx), types.ExecutionStage_EXECUTION_STAGE_END_BLOCKER) return []abci.ValidatorUpdate{}, nil } diff --git a/x/cron/types/codec.go b/x/cron/types/codec.go index a52eff2c6..6772e97b9 100644 --- a/x/cron/types/codec.go +++ b/x/cron/types/codec.go @@ -15,6 +15,8 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations( (*sdk.Msg)(nil), &MsgUpdateParams{}, + &MsgAddSchedule{}, + &MsgRemoveSchedule{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } diff --git a/x/cron/types/genesis.pb.go b/x/cron/types/genesis.pb.go index 2d3546994..274598ad7 100644 --- a/x/cron/types/genesis.pb.go +++ b/x/cron/types/genesis.pb.go @@ -23,7 +23,7 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// GenesisState defines the cron module's genesis state. +// Defines the cron module's genesis state. type GenesisState struct { ScheduleList []Schedule `protobuf:"bytes,2,rep,name=scheduleList,proto3" json:"scheduleList"` Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` diff --git a/x/cron/types/params.pb.go b/x/cron/types/params.pb.go index c71904ce8..e927ec42a 100644 --- a/x/cron/types/params.pb.go +++ b/x/cron/types/params.pb.go @@ -23,7 +23,7 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// Params defines the parameters for the module. +// Defines the parameters for the module. type Params struct { // Security address that can remove schedules SecurityAddress string `protobuf:"bytes,1,opt,name=security_address,json=securityAddress,proto3" json:"security_address,omitempty"` diff --git a/x/cron/types/query.pb.go b/x/cron/types/query.pb.go index c34c6c3f9..912a44eaa 100644 --- a/x/cron/types/query.pb.go +++ b/x/cron/types/query.pb.go @@ -30,6 +30,7 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// The request type for the Query/Params RPC method. type QueryParamsRequest struct { } @@ -66,6 +67,7 @@ func (m *QueryParamsRequest) XXX_DiscardUnknown() { var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo +// The 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"` @@ -111,6 +113,7 @@ func (m *QueryParamsResponse) GetParams() Params { return Params{} } +// The request type for the Query/Schedule RPC method. type QueryGetScheduleRequest struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` } @@ -155,6 +158,7 @@ func (m *QueryGetScheduleRequest) GetName() string { return "" } +// The response type for the Query/Params RPC method. type QueryGetScheduleResponse struct { Schedule Schedule `protobuf:"bytes,1,opt,name=schedule,proto3" json:"schedule"` } @@ -199,6 +203,7 @@ func (m *QueryGetScheduleResponse) GetSchedule() Schedule { return Schedule{} } +// The request type for the Query/Schedules RPC method. type QuerySchedulesRequest struct { Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` } @@ -243,6 +248,7 @@ func (m *QuerySchedulesRequest) GetPagination() *query.PageRequest { return nil } +// The response type for the Query/Params RPC method. type QuerySchedulesResponse struct { Schedules []Schedule `protobuf:"bytes,1,rep,name=schedules,proto3" json:"schedules"` Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` diff --git a/x/cron/types/schedule.pb.go b/x/cron/types/schedule.pb.go index cda29cf72..845a1059a 100644 --- a/x/cron/types/schedule.pb.go +++ b/x/cron/types/schedule.pb.go @@ -23,15 +23,46 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// Defines when messages will be executed in the block +type ExecutionStage int32 + +const ( + // Execution at the end of the block + ExecutionStage_EXECUTION_STAGE_END_BLOCKER ExecutionStage = 0 + // Execution at the beginning of the block + ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER ExecutionStage = 1 +) + +var ExecutionStage_name = map[int32]string{ + 0: "EXECUTION_STAGE_END_BLOCKER", + 1: "EXECUTION_STAGE_BEGIN_BLOCKER", +} + +var ExecutionStage_value = map[string]int32{ + "EXECUTION_STAGE_END_BLOCKER": 0, + "EXECUTION_STAGE_BEGIN_BLOCKER": 1, +} + +func (x ExecutionStage) String() string { + return proto.EnumName(ExecutionStage_name, int32(x)) +} + +func (ExecutionStage) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_49ace1b59de613ef, []int{0} +} + +// Defines the schedule for execution type Schedule struct { // Name of schedule Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` // Period in blocks Period uint64 `protobuf:"varint,2,opt,name=period,proto3" json:"period,omitempty"` - // Msgs that will be executed every period amount of time + // Msgs that will be executed every certain number of blocks, specified in the `period` field Msgs []MsgExecuteContract `protobuf:"bytes,3,rep,name=msgs,proto3" json:"msgs"` // Last execution's block height LastExecuteHeight uint64 `protobuf:"varint,4,opt,name=last_execute_height,json=lastExecuteHeight,proto3" json:"last_execute_height,omitempty"` + // Stage when messages will be executed + ExecutionStage ExecutionStage `protobuf:"varint,5,opt,name=execution_stage,json=executionStage,proto3,enum=neutron.cron.ExecutionStage" json:"execution_stage,omitempty"` } func (m *Schedule) Reset() { *m = Schedule{} } @@ -95,10 +126,18 @@ func (m *Schedule) GetLastExecuteHeight() uint64 { return 0 } +func (m *Schedule) GetExecutionStage() ExecutionStage { + if m != nil { + return m.ExecutionStage + } + return ExecutionStage_EXECUTION_STAGE_END_BLOCKER +} + +// Defines the contract and the message to pass type MsgExecuteContract struct { - // Contract is the address of the smart contract + // The address of the smart contract Contract string `protobuf:"bytes,1,opt,name=contract,proto3" json:"contract,omitempty"` - // Msg is json encoded message to be passed to the contract + // JSON encoded message to be passed to the contract Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` } @@ -149,8 +188,9 @@ func (m *MsgExecuteContract) GetMsg() string { return "" } +// Defines the number of current schedules type ScheduleCount struct { - // Count is the number of current schedules + // The number of current schedules Count int32 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` } @@ -195,6 +235,7 @@ func (m *ScheduleCount) GetCount() int32 { } func init() { + proto.RegisterEnum("neutron.cron.ExecutionStage", ExecutionStage_name, ExecutionStage_value) proto.RegisterType((*Schedule)(nil), "neutron.cron.Schedule") proto.RegisterType((*MsgExecuteContract)(nil), "neutron.cron.MsgExecuteContract") proto.RegisterType((*ScheduleCount)(nil), "neutron.cron.ScheduleCount") @@ -203,27 +244,32 @@ func init() { func init() { proto.RegisterFile("neutron/cron/schedule.proto", fileDescriptor_49ace1b59de613ef) } var fileDescriptor_49ace1b59de613ef = []byte{ - // 309 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x91, 0x41, 0x4b, 0xfb, 0x30, - 0x18, 0xc6, 0x9b, 0xff, 0xba, 0xb1, 0xe5, 0xaf, 0xa0, 0x71, 0x48, 0x99, 0x10, 0x4b, 0x41, 0xe8, - 0xc5, 0x14, 0xd4, 0x93, 0xc7, 0x0e, 0x61, 0x17, 0x2f, 0xf5, 0xe6, 0x65, 0x74, 0x59, 0x48, 0x0b, - 0x6b, 0x53, 0x9a, 0x54, 0xe6, 0xb7, 0xf0, 0x33, 0xf8, 0x69, 0x76, 0xdc, 0xd1, 0x93, 0x48, 0xfb, - 0x45, 0x24, 0x69, 0x26, 0x82, 0x97, 0xf0, 0x7b, 0x78, 0xde, 0x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x75, 0xd8, 0xd9, 0x77, 0xd8, 0xf9, 0xe8, 0xb0, 0xf3, 0x4c, 0x78, 0xae, 0xb2, 0x66, 0x45, 0xa8, - 0x28, 0x22, 0xbb, 0xec, 0xb5, 0xa8, 0xf9, 0x81, 0xa3, 0x97, 0xbb, 0x68, 0xdb, 0x7f, 0x83, 0x7a, - 0xad, 0x98, 0x5c, 0x8d, 0xcc, 0x03, 0xdf, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0x4e, 0x19, 0x38, - 0x8d, 0xa3, 0x01, 0x00, 0x00, + // 393 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x92, 0xc1, 0xaa, 0xd3, 0x40, + 0x18, 0x85, 0x33, 0x36, 0x2d, 0xed, 0xa8, 0xb5, 0x8e, 0x45, 0x42, 0xab, 0x69, 0x2c, 0x08, 0x41, + 0x30, 0x81, 0xea, 0xca, 0x9d, 0x89, 0x43, 0x5b, 0xd4, 0x16, 0xd2, 0x0a, 0xe2, 0x26, 0xa4, 0xe9, + 0x30, 0x09, 0x34, 0x99, 0x92, 0x99, 0x48, 0x7d, 0x0b, 0x1f, 0xab, 0xcb, 0x2e, 0x5d, 0x89, 0xb4, + 0x2b, 0xdf, 0xe2, 0x92, 0x49, 0x5a, 0x6e, 0xef, 0xdd, 0x84, 0x73, 0x38, 0xdf, 0xe1, 0x9f, 0xf9, + 0x33, 0xb0, 0x9f, 0x92, 0x5c, 0x64, 0x2c, 0xb5, 0xc3, 0xe2, 0xc3, 0xc3, 0x88, 0xac, 0xf3, 0x0d, + 0xb1, 0xb6, 0x19, 0x13, 0x0c, 0x3d, 0xaa, 0x42, 0xab, 0x08, 0x7b, 0x5d, 0xca, 0x28, 0x93, 0x81, + 0x5d, 0xa8, 0x92, 0x19, 0xfe, 0x07, 0xb0, 0xb9, 0xa8, 0x6a, 0x08, 0x41, 0x35, 0x0d, 0x12, 0xa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0x9f, 0xb1, 0xd7, 0x51, 0xd0, 0x2b, 0xf8, 0xf2, 0x2e, 0xe0, 0xe0, + 0xf1, 0x74, 0x76, 0x41, 0x80, 0x33, 0xd9, 0x1f, 0x75, 0x70, 0x38, 0xea, 0xe0, 0xdf, 0x51, 0x07, + 0xbf, 0x4f, 0xba, 0x72, 0x38, 0xe9, 0xca, 0x9f, 0x93, 0xae, 0xfc, 0xb0, 0x68, 0x2c, 0xa2, 0x7c, + 0x65, 0x85, 0x2c, 0xb1, 0xab, 0x95, 0xbc, 0x65, 0x19, 0x3d, 0x6b, 0xfb, 0xe7, 0x7b, 0x7b, 0x57, + 0xbe, 0x11, 0xf1, 0x6b, 0x4b, 0xf8, 0xaa, 0x21, 0xff, 0xfe, 0xbb, 0x9b, 0x00, 0x00, 0x00, 0xff, + 0xff, 0x2e, 0xa9, 0x20, 0xa0, 0x40, 0x02, 0x00, 0x00, } func (m *Schedule) Marshal() (dAtA []byte, err error) { @@ -246,6 +292,11 @@ func (m *Schedule) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.ExecutionStage != 0 { + i = encodeVarintSchedule(dAtA, i, uint64(m.ExecutionStage)) + i-- + dAtA[i] = 0x28 + } if m.LastExecuteHeight != 0 { i = encodeVarintSchedule(dAtA, i, uint64(m.LastExecuteHeight)) i-- @@ -378,6 +429,9 @@ func (m *Schedule) Size() (n int) { if m.LastExecuteHeight != 0 { n += 1 + sovSchedule(uint64(m.LastExecuteHeight)) } + if m.ExecutionStage != 0 { + n += 1 + sovSchedule(uint64(m.ExecutionStage)) + } return n } @@ -549,6 +603,25 @@ func (m *Schedule) Unmarshal(dAtA []byte) error { break } } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExecutionStage", wireType) + } + m.ExecutionStage = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ExecutionStage |= ExecutionStage(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipSchedule(dAtA[iNdEx:]) diff --git a/x/cron/types/tx.go b/x/cron/types/tx.go index eb48677cb..27b4ceec4 100644 --- a/x/cron/types/tx.go +++ b/x/cron/types/tx.go @@ -1,10 +1,95 @@ package types import ( - errorsmod "cosmossdk.io/errors" + "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) +var _ sdk.Msg = &MsgAddSchedule{} + +func (msg *MsgAddSchedule) Route() string { + return RouterKey +} + +func (msg *MsgAddSchedule) Type() string { + return "add-schedule" +} + +func (msg *MsgAddSchedule) GetSigners() []sdk.AccAddress { + authority, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{authority} +} + +func (msg *MsgAddSchedule) GetSignBytes() []byte { + return ModuleCdc.MustMarshalJSON(msg) +} + +func (msg *MsgAddSchedule) Validate() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return errors.Wrap(err, "authority is invalid") + } + + if msg.Name == "" { + return errors.Wrap(sdkerrors.ErrInvalidRequest, "name is invalid") + } + + if msg.Period == 0 { + return errors.Wrap(sdkerrors.ErrInvalidRequest, "period is invalid") + } + + if len(msg.Msgs) == 0 { + return errors.Wrap(sdkerrors.ErrInvalidRequest, "msgs should not be empty") + } + + if _, ok := ExecutionStage_name[int32(msg.ExecutionStage)]; !ok { + return errors.Wrap(sdkerrors.ErrInvalidRequest, "execution stage is invalid") + } + + return nil +} + +//---------------------------------------------------------------- + +var _ sdk.Msg = &MsgRemoveSchedule{} + +func (msg *MsgRemoveSchedule) Route() string { + return RouterKey +} + +func (msg *MsgRemoveSchedule) Type() string { + return "remove-schedule" +} + +func (msg *MsgRemoveSchedule) GetSigners() []sdk.AccAddress { + authority, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{authority} +} + +func (msg *MsgRemoveSchedule) GetSignBytes() []byte { + return ModuleCdc.MustMarshalJSON(msg) +} + +func (msg *MsgRemoveSchedule) Validate() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return errors.Wrap(err, "authority is invalid") + } + + if msg.Name == "" { + return errors.Wrap(sdkerrors.ErrInvalidRequest, "name is invalid") + } + + return nil +} + +//---------------------------------------------------------------- + var _ sdk.Msg = &MsgUpdateParams{} func (msg *MsgUpdateParams) Route() string { @@ -29,11 +114,11 @@ func (msg *MsgUpdateParams) GetSignBytes() []byte { func (msg *MsgUpdateParams) Validate() error { if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { - return errorsmod.Wrap(err, "authority is invalid") + return errors.Wrap(err, "authority is invalid") } if _, err := sdk.AccAddressFromBech32(msg.Params.SecurityAddress); err != nil { - return errorsmod.Wrap(err, "security_address is invalid") + return errors.Wrap(err, "security_address is invalid") } return nil diff --git a/x/cron/types/tx.pb.go b/x/cron/types/tx.pb.go index 217bb879c..141735a4e 100644 --- a/x/cron/types/tx.pb.go +++ b/x/cron/types/tx.pb.go @@ -31,13 +31,224 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// MsgUpdateParams is the MsgUpdateParams request type. +// The MsgAddSchedule request type. +type MsgAddSchedule struct { + // The address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // Name of the schedule + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + // Period in blocks + Period uint64 `protobuf:"varint,3,opt,name=period,proto3" json:"period,omitempty"` + // Msgs that will be executed every certain number of blocks, specified in the `period` field + Msgs []MsgExecuteContract `protobuf:"bytes,4,rep,name=msgs,proto3" json:"msgs"` + // Stage when messages will be executed + ExecutionStage ExecutionStage `protobuf:"varint,5,opt,name=execution_stage,json=executionStage,proto3,enum=neutron.cron.ExecutionStage" json:"execution_stage,omitempty"` +} + +func (m *MsgAddSchedule) Reset() { *m = MsgAddSchedule{} } +func (m *MsgAddSchedule) String() string { return proto.CompactTextString(m) } +func (*MsgAddSchedule) ProtoMessage() {} +func (*MsgAddSchedule) Descriptor() ([]byte, []int) { + return fileDescriptor_c9e0a673aba8d6fd, []int{0} +} +func (m *MsgAddSchedule) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAddSchedule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAddSchedule.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 *MsgAddSchedule) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAddSchedule.Merge(m, src) +} +func (m *MsgAddSchedule) XXX_Size() int { + return m.Size() +} +func (m *MsgAddSchedule) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAddSchedule.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAddSchedule proto.InternalMessageInfo + +func (m *MsgAddSchedule) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgAddSchedule) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *MsgAddSchedule) GetPeriod() uint64 { + if m != nil { + return m.Period + } + return 0 +} + +func (m *MsgAddSchedule) GetMsgs() []MsgExecuteContract { + if m != nil { + return m.Msgs + } + return nil +} + +func (m *MsgAddSchedule) GetExecutionStage() ExecutionStage { + if m != nil { + return m.ExecutionStage + } + return ExecutionStage_EXECUTION_STAGE_END_BLOCKER +} + +// Defines the response structure for executing a MsgAddSchedule message. +type MsgAddScheduleResponse struct { +} + +func (m *MsgAddScheduleResponse) Reset() { *m = MsgAddScheduleResponse{} } +func (m *MsgAddScheduleResponse) String() string { return proto.CompactTextString(m) } +func (*MsgAddScheduleResponse) ProtoMessage() {} +func (*MsgAddScheduleResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c9e0a673aba8d6fd, []int{1} +} +func (m *MsgAddScheduleResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAddScheduleResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAddScheduleResponse.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 *MsgAddScheduleResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAddScheduleResponse.Merge(m, src) +} +func (m *MsgAddScheduleResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgAddScheduleResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAddScheduleResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAddScheduleResponse proto.InternalMessageInfo + +// The MsgRemoveSchedule request type. +type MsgRemoveSchedule struct { + // The address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // Name of the schedule + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` +} + +func (m *MsgRemoveSchedule) Reset() { *m = MsgRemoveSchedule{} } +func (m *MsgRemoveSchedule) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveSchedule) ProtoMessage() {} +func (*MsgRemoveSchedule) Descriptor() ([]byte, []int) { + return fileDescriptor_c9e0a673aba8d6fd, []int{2} +} +func (m *MsgRemoveSchedule) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveSchedule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveSchedule.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 *MsgRemoveSchedule) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveSchedule.Merge(m, src) +} +func (m *MsgRemoveSchedule) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveSchedule) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveSchedule.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveSchedule proto.InternalMessageInfo + +func (m *MsgRemoveSchedule) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgRemoveSchedule) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +// Defines the response structure for executing a MsgRemoveSchedule message. +type MsgRemoveScheduleResponse struct { +} + +func (m *MsgRemoveScheduleResponse) Reset() { *m = MsgRemoveScheduleResponse{} } +func (m *MsgRemoveScheduleResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveScheduleResponse) ProtoMessage() {} +func (*MsgRemoveScheduleResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c9e0a673aba8d6fd, []int{3} +} +func (m *MsgRemoveScheduleResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveScheduleResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveScheduleResponse.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 *MsgRemoveScheduleResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveScheduleResponse.Merge(m, src) +} +func (m *MsgRemoveScheduleResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveScheduleResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveScheduleResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveScheduleResponse proto.InternalMessageInfo + +// The MsgUpdateParams request type. // // Since: 0.47 type MsgUpdateParams struct { - // Authority is the address of the governance account. + // The address of the governance account. Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` - // params defines the x/cron parameters to update. + // Defines the x/cron parameters to update. // // NOTE: All parameters must be supplied. Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` @@ -47,7 +258,7 @@ func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } func (*MsgUpdateParams) ProtoMessage() {} func (*MsgUpdateParams) Descriptor() ([]byte, []int) { - return fileDescriptor_c9e0a673aba8d6fd, []int{0} + return fileDescriptor_c9e0a673aba8d6fd, []int{4} } func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -90,8 +301,7 @@ func (m *MsgUpdateParams) GetParams() Params { return Params{} } -// MsgUpdateParamsResponse defines the response structure for executing a -// MsgUpdateParams message. +// Defines the response structure for executing a MsgUpdateParams message. // // Since: 0.47 type MsgUpdateParamsResponse struct { @@ -101,7 +311,7 @@ func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdateParamsResponse) ProtoMessage() {} func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c9e0a673aba8d6fd, []int{1} + return fileDescriptor_c9e0a673aba8d6fd, []int{5} } func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -131,6 +341,10 @@ func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo func init() { + proto.RegisterType((*MsgAddSchedule)(nil), "neutron.cron.MsgAddSchedule") + proto.RegisterType((*MsgAddScheduleResponse)(nil), "neutron.cron.MsgAddScheduleResponse") + proto.RegisterType((*MsgRemoveSchedule)(nil), "neutron.cron.MsgRemoveSchedule") + proto.RegisterType((*MsgRemoveScheduleResponse)(nil), "neutron.cron.MsgRemoveScheduleResponse") proto.RegisterType((*MsgUpdateParams)(nil), "neutron.cron.MsgUpdateParams") proto.RegisterType((*MsgUpdateParamsResponse)(nil), "neutron.cron.MsgUpdateParamsResponse") } @@ -138,28 +352,42 @@ func init() { func init() { proto.RegisterFile("neutron/cron/tx.proto", fileDescriptor_c9e0a673aba8d6fd) } var fileDescriptor_c9e0a673aba8d6fd = []byte{ - // 335 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcd, 0x4b, 0x2d, 0x2d, - 0x29, 0xca, 0xcf, 0xd3, 0x4f, 0x06, 0x11, 0x25, 0x15, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, - 0x3c, 0x50, 0x61, 0x3d, 0x90, 0xb0, 0x94, 0x60, 0x62, 0x6e, 0x66, 0x5e, 0xbe, 0x3e, 0x98, 0x84, - 0x28, 0x90, 0x12, 0x4f, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0xcf, 0x2d, 0x4e, 0xd7, 0x2f, 0x33, - 0x04, 0x51, 0x50, 0x09, 0x49, 0x88, 0x44, 0x3c, 0x98, 0xa7, 0x0f, 0xe1, 0x40, 0xa5, 0x44, 0xd2, - 0xf3, 0xd3, 0xf3, 0x21, 0xe2, 0x20, 0x16, 0x4c, 0x03, 0x8a, 0x0b, 0x0a, 0x12, 0x8b, 0x12, 0x73, - 0xa1, 0x1a, 0x94, 0x56, 0x33, 0x72, 0xf1, 0xfb, 0x16, 0xa7, 0x87, 0x16, 0xa4, 0x24, 0x96, 0xa4, - 0x06, 0x80, 0x65, 0x84, 0xcc, 0xb8, 0x38, 0x13, 0x4b, 0x4b, 0x32, 0xf2, 0x8b, 0x32, 0x4b, 0x2a, - 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, 0x9d, 0x24, 0x2e, 0x6d, 0xd1, 0x15, 0x81, 0xda, 0xe4, 0x98, - 0x92, 0x52, 0x94, 0x5a,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c, 0x02, 0x00, 0x00, + // 554 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xbf, 0x6b, 0xdb, 0x40, + 0x14, 0xf6, 0xd9, 0x8e, 0xc1, 0xe7, 0xe0, 0x10, 0xd5, 0x75, 0x64, 0x25, 0x55, 0x8c, 0x68, 0x1b, + 0xd7, 0x10, 0x89, 0xba, 0xa5, 0x05, 0x6f, 0x71, 0x31, 0x74, 0x11, 0xb4, 0x72, 0xbb, 0x64, 0x09, + 0x8a, 0x74, 0x9c, 0x05, 0x95, 0x4e, 0xe8, 0x4e, 0xc6, 0xd9, 0x4a, 0xc7, 0x4c, 0xed, 0x5f, 0xd0, + 0xb5, 0xd0, 0xc5, 0x43, 0xff, 0x88, 0x8c, 0xa1, 0x53, 0xa7, 0x52, 0xec, 0xc1, 0xff, 0x46, 0xd1, + 0xaf, 0x44, 0x17, 0x41, 0x0a, 0x85, 0x2c, 0xa7, 0x7b, 0xef, 0xfb, 0xde, 0xd3, 0x77, 0xdf, 0x3d, + 0x0e, 0xde, 0xf7, 0x50, 0xc8, 0x02, 0xe2, 0x69, 0x56, 0xb4, 0xb0, 0xb9, 0xea, 0x07, 0x84, 0x11, + 0x61, 0x33, 0x4d, 0xab, 0x51, 0x5a, 0xda, 0x36, 0x5d, 0xc7, 0x23, 0x5a, 0xbc, 0x26, 0x04, 0x69, + 0xc7, 0x22, 0xd4, 0x25, 0x54, 0x73, 0x29, 0xd6, 0x66, 0x4f, 0xa3, 0x4f, 0x0a, 0x74, 0x12, 0xe0, + 0x24, 0x8e, 0xb4, 0x24, 0x48, 0xa1, 0x16, 0x26, 0x98, 0x24, 0xf9, 0x68, 0x97, 0x15, 0x70, 0x0a, + 0x7c, 0x33, 0x30, 0xdd, 0xac, 0x60, 0x97, 0x83, 0xa8, 0x35, 0x45, 0x76, 0xf8, 0x01, 0x25, 0xa0, + 0xf2, 0xb5,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b, 0x00, 0x00, + 0xff, 0xff, 0xf7, 0xca, 0x79, 0x29, 0xcf, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -174,6 +402,11 @@ const _ = grpc.SupportPackageIsVersion4 // // 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 { + // Adds new schedule. + AddSchedule(ctx context.Context, in *MsgAddSchedule, opts ...grpc.CallOption) (*MsgAddScheduleResponse, error) + // Removes schedule. + RemoveSchedule(ctx context.Context, in *MsgRemoveSchedule, opts ...grpc.CallOption) (*MsgRemoveScheduleResponse, error) + // Updates the module parameters. UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) } @@ -185,6 +418,24 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } +func (c *msgClient) AddSchedule(ctx context.Context, in *MsgAddSchedule, opts ...grpc.CallOption) (*MsgAddScheduleResponse, error) { + out := new(MsgAddScheduleResponse) + err := c.cc.Invoke(ctx, "/neutron.cron.Msg/AddSchedule", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) RemoveSchedule(ctx context.Context, in *MsgRemoveSchedule, opts ...grpc.CallOption) (*MsgRemoveScheduleResponse, error) { + out := new(MsgRemoveScheduleResponse) + err := c.cc.Invoke(ctx, "/neutron.cron.Msg/RemoveSchedule", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { out := new(MsgUpdateParamsResponse) err := c.cc.Invoke(ctx, "/neutron.cron.Msg/UpdateParams", in, out, opts...) @@ -196,6 +447,11 @@ func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts // MsgServer is the server API for Msg service. type MsgServer interface { + // Adds new schedule. + AddSchedule(context.Context, *MsgAddSchedule) (*MsgAddScheduleResponse, error) + // Removes schedule. + RemoveSchedule(context.Context, *MsgRemoveSchedule) (*MsgRemoveScheduleResponse, error) + // Updates the module parameters. UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) } @@ -203,6 +459,12 @@ type MsgServer interface { type UnimplementedMsgServer struct { } +func (*UnimplementedMsgServer) AddSchedule(ctx context.Context, req *MsgAddSchedule) (*MsgAddScheduleResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AddSchedule not implemented") +} +func (*UnimplementedMsgServer) RemoveSchedule(ctx context.Context, req *MsgRemoveSchedule) (*MsgRemoveScheduleResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RemoveSchedule not implemented") +} func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") } @@ -211,6 +473,42 @@ func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } +func _Msg_AddSchedule_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgAddSchedule) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).AddSchedule(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.cron.Msg/AddSchedule", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).AddSchedule(ctx, req.(*MsgAddSchedule)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_RemoveSchedule_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRemoveSchedule) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RemoveSchedule(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.cron.Msg/RemoveSchedule", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RemoveSchedule(ctx, req.(*MsgRemoveSchedule)) + } + return interceptor(ctx, in, info, handler) +} + func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MsgUpdateParams) if err := dec(in); err != nil { @@ -233,6 +531,14 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "neutron.cron.Msg", HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ + { + MethodName: "AddSchedule", + Handler: _Msg_AddSchedule_Handler, + }, + { + MethodName: "RemoveSchedule", + Handler: _Msg_RemoveSchedule_Handler, + }, { MethodName: "UpdateParams", Handler: _Msg_UpdateParams_Handler, @@ -242,7 +548,7 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Metadata: "neutron/cron/tx.proto", } -func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) { +func (m *MsgAddSchedule) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -252,26 +558,47 @@ func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgAddSchedule) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgAddSchedule) 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 + if m.ExecutionStage != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.ExecutionStage)) + i-- + dAtA[i] = 0x28 + } + if len(m.Msgs) > 0 { + for iNdEx := len(m.Msgs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Msgs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) } - i-- - dAtA[i] = 0x12 + if m.Period != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Period)) + i-- + dAtA[i] = 0x18 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintTx(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x12 + } if len(m.Authority) > 0 { i -= len(m.Authority) copy(dAtA[i:], m.Authority) @@ -282,7 +609,7 @@ func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgUpdateParamsResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgAddScheduleResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -292,12 +619,12 @@ func (m *MsgUpdateParamsResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgAddScheduleResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgAddScheduleResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -305,46 +632,633 @@ func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } -func encodeVarintTx(dAtA []byte, offset int, v uint64) int { - offset -= sovTx(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ +func (m *MsgRemoveSchedule) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err } - dAtA[offset] = uint8(v) - return base + return dAtA[:n], nil } -func (m *MsgUpdateParams) Size() (n int) { - if m == nil { - return 0 - } + +func (m *MsgRemoveSchedule) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRemoveSchedule) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i var l int _ = l - l = len(m.Authority) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintTx(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x12 } - l = m.Params.Size() - n += 1 + l + sovTx(uint64(l)) - return n + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil } -func (m *MsgUpdateParamsResponse) Size() (n int) { - if m == nil { - return 0 +func (m *MsgRemoveScheduleResponse) 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 *MsgRemoveScheduleResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRemoveScheduleResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i var l int _ = l - return n + return len(dAtA) - i, nil } -func sovTx(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTx(x uint64) (n int) { - return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) 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 = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgAddSchedule) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Period != 0 { + n += 1 + sovTx(uint64(m.Period)) + } + if len(m.Msgs) > 0 { + for _, e := range m.Msgs { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + if m.ExecutionStage != 0 { + n += 1 + sovTx(uint64(m.ExecutionStage)) + } + return n +} + +func (m *MsgAddScheduleResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgRemoveSchedule) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRemoveScheduleResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgAddSchedule) 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 ErrIntOverflowTx + } + 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: MsgAddSchedule: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAddSchedule: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Period", wireType) + } + m.Period = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Period |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msgs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msgs = append(m.Msgs, MsgExecuteContract{}) + if err := m.Msgs[len(m.Msgs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExecutionStage", wireType) + } + m.ExecutionStage = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ExecutionStage |= ExecutionStage(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgAddScheduleResponse) 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 ErrIntOverflowTx + } + 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: MsgAddScheduleResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAddScheduleResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRemoveSchedule) 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 ErrIntOverflowTx + } + 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: MsgRemoveSchedule: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveSchedule: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRemoveScheduleResponse) 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 ErrIntOverflowTx + } + 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: MsgRemoveScheduleResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveScheduleResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil } func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { l := len(dAtA) diff --git a/x/cron/types/v1/schedule.pb.go b/x/cron/types/v1/schedule.pb.go new file mode 100644 index 000000000..3a35f34e6 --- /dev/null +++ b/x/cron/types/v1/schedule.pb.go @@ -0,0 +1,842 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/cron/v1/schedule.proto + +package v1 + +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 + +// Defines the schedule for execution +type Schedule struct { + // Name of schedule + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // Period in blocks + Period uint64 `protobuf:"varint,2,opt,name=period,proto3" json:"period,omitempty"` + // Msgs that will be executed every certain number of blocks, specified in the `period` field + Msgs []MsgExecuteContract `protobuf:"bytes,3,rep,name=msgs,proto3" json:"msgs"` + // Last execution's block height + LastExecuteHeight uint64 `protobuf:"varint,4,opt,name=last_execute_height,json=lastExecuteHeight,proto3" json:"last_execute_height,omitempty"` +} + +func (m *Schedule) Reset() { *m = Schedule{} } +func (m *Schedule) String() string { return proto.CompactTextString(m) } +func (*Schedule) ProtoMessage() {} +func (*Schedule) Descriptor() ([]byte, []int) { + return fileDescriptor_cd4938034d592826, []int{0} +} +func (m *Schedule) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Schedule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Schedule.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 *Schedule) XXX_Merge(src proto.Message) { + xxx_messageInfo_Schedule.Merge(m, src) +} +func (m *Schedule) XXX_Size() int { + return m.Size() +} +func (m *Schedule) XXX_DiscardUnknown() { + xxx_messageInfo_Schedule.DiscardUnknown(m) +} + +var xxx_messageInfo_Schedule proto.InternalMessageInfo + +func (m *Schedule) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *Schedule) GetPeriod() uint64 { + if m != nil { + return m.Period + } + return 0 +} + +func (m *Schedule) GetMsgs() []MsgExecuteContract { + if m != nil { + return m.Msgs + } + return nil +} + +func (m *Schedule) GetLastExecuteHeight() uint64 { + if m != nil { + return m.LastExecuteHeight + } + return 0 +} + +// Defines the contract and the message to pass +type MsgExecuteContract struct { + // The address of the smart contract + Contract string `protobuf:"bytes,1,opt,name=contract,proto3" json:"contract,omitempty"` + // JSON encoded message to be passed to the contract + Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` +} + +func (m *MsgExecuteContract) Reset() { *m = MsgExecuteContract{} } +func (m *MsgExecuteContract) String() string { return proto.CompactTextString(m) } +func (*MsgExecuteContract) ProtoMessage() {} +func (*MsgExecuteContract) Descriptor() ([]byte, []int) { + return fileDescriptor_cd4938034d592826, []int{1} +} +func (m *MsgExecuteContract) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgExecuteContract) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgExecuteContract.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 *MsgExecuteContract) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgExecuteContract.Merge(m, src) +} +func (m *MsgExecuteContract) XXX_Size() int { + return m.Size() +} +func (m *MsgExecuteContract) XXX_DiscardUnknown() { + xxx_messageInfo_MsgExecuteContract.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgExecuteContract proto.InternalMessageInfo + +func (m *MsgExecuteContract) GetContract() string { + if m != nil { + return m.Contract + } + return "" +} + +func (m *MsgExecuteContract) GetMsg() string { + if m != nil { + return m.Msg + } + return "" +} + +// Defines the number of current schedules +type ScheduleCount struct { + // The number of current schedules + Count int32 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` +} + +func (m *ScheduleCount) Reset() { *m = ScheduleCount{} } +func (m *ScheduleCount) String() string { return proto.CompactTextString(m) } +func (*ScheduleCount) ProtoMessage() {} +func (*ScheduleCount) Descriptor() ([]byte, []int) { + return fileDescriptor_cd4938034d592826, []int{2} +} +func (m *ScheduleCount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ScheduleCount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ScheduleCount.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 *ScheduleCount) XXX_Merge(src proto.Message) { + xxx_messageInfo_ScheduleCount.Merge(m, src) +} +func (m *ScheduleCount) XXX_Size() int { + return m.Size() +} +func (m *ScheduleCount) XXX_DiscardUnknown() { + xxx_messageInfo_ScheduleCount.DiscardUnknown(m) +} + +var xxx_messageInfo_ScheduleCount proto.InternalMessageInfo + +func (m *ScheduleCount) GetCount() int32 { + if m != nil { + return m.Count + } + return 0 +} + +func init() { + proto.RegisterType((*Schedule)(nil), "neutron.cron.v1.Schedule") + proto.RegisterType((*MsgExecuteContract)(nil), "neutron.cron.v1.MsgExecuteContract") + proto.RegisterType((*ScheduleCount)(nil), "neutron.cron.v1.ScheduleCount") +} + +func init() { proto.RegisterFile("neutron/cron/v1/schedule.proto", fileDescriptor_cd4938034d592826) } + +var fileDescriptor_cd4938034d592826 = []byte{ + // 316 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x91, 0xc1, 0x4a, 0xc3, 0x30, + 0x18, 0xc7, 0x1b, 0xd7, 0x8d, 0x2d, 0x22, 0x6a, 0x1c, 0x52, 0x76, 0x88, 0x63, 0x22, 0xec, 0x62, + 0x42, 0xd5, 0xab, 0x97, 0x0d, 0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0xe8, 0x5f, 0x8d, 0x4e, 0x60, + 0x2b, 0x51, 0xc2, 0x4e, 0xdd, 0x8b, 0x0c, 0x8e, 0xae, 0xe0, 0xd1, 0x7e, 0xd5, 0xa9, 0x2c, 0x52, + 0x8d, 0xfa, 0xb0, 0xcd, 0x0c, 0xd8, 0x6c, 0x3b, 0x6a, 0xc4, 0xe4, 0x69, 0x5b, 0x61, 0xb0, 0xab, + 0x30, 0xf8, 0xae, 0x30, 0x78, 0xaf, 0xb1, 0xb7, 0xab, 0xb1, 0xf7, 0x59, 0x63, 0xef, 0x35, 0x14, + 0x2b, 0x1d, 0x17, 0x0b, 0xc2, 0x64, 0x42, 0xdd, 0xbe, 0xd7, 0x32, 0x17, 0x7b, 0xa6, 0xe5, 0x1d, + 0xdd, 0x34, 0xff, 0xa1, 0xdf, 0x32, 0xae, 0x68, 0x19, 0x2e, 0x3a, 0xf6, 0x99, 0x6f, 0x7f, 0x02, + 0x00, 0x00, 0xff, 0xff, 0x4d, 0x2d, 0x47, 0x23, 0xaf, 0x01, 0x00, 0x00, +} + +func (m *Schedule) 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 *Schedule) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Schedule) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.LastExecuteHeight != 0 { + i = encodeVarintSchedule(dAtA, i, uint64(m.LastExecuteHeight)) + i-- + dAtA[i] = 0x20 + } + if len(m.Msgs) > 0 { + for iNdEx := len(m.Msgs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Msgs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintSchedule(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.Period != 0 { + i = encodeVarintSchedule(dAtA, i, uint64(m.Period)) + i-- + dAtA[i] = 0x10 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintSchedule(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgExecuteContract) 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 *MsgExecuteContract) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgExecuteContract) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Msg) > 0 { + i -= len(m.Msg) + copy(dAtA[i:], m.Msg) + i = encodeVarintSchedule(dAtA, i, uint64(len(m.Msg))) + i-- + dAtA[i] = 0x12 + } + if len(m.Contract) > 0 { + i -= len(m.Contract) + copy(dAtA[i:], m.Contract) + i = encodeVarintSchedule(dAtA, i, uint64(len(m.Contract))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ScheduleCount) 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 *ScheduleCount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ScheduleCount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Count != 0 { + i = encodeVarintSchedule(dAtA, i, uint64(m.Count)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintSchedule(dAtA []byte, offset int, v uint64) int { + offset -= sovSchedule(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Schedule) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovSchedule(uint64(l)) + } + if m.Period != 0 { + n += 1 + sovSchedule(uint64(m.Period)) + } + if len(m.Msgs) > 0 { + for _, e := range m.Msgs { + l = e.Size() + n += 1 + l + sovSchedule(uint64(l)) + } + } + if m.LastExecuteHeight != 0 { + n += 1 + sovSchedule(uint64(m.LastExecuteHeight)) + } + return n +} + +func (m *MsgExecuteContract) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Contract) + if l > 0 { + n += 1 + l + sovSchedule(uint64(l)) + } + l = len(m.Msg) + if l > 0 { + n += 1 + l + sovSchedule(uint64(l)) + } + return n +} + +func (m *ScheduleCount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Count != 0 { + n += 1 + sovSchedule(uint64(m.Count)) + } + return n +} + +func sovSchedule(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozSchedule(x uint64) (n int) { + return sovSchedule(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Schedule) 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 ErrIntOverflowSchedule + } + 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: Schedule: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Schedule: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + 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 ErrInvalidLengthSchedule + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchedule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Period", wireType) + } + m.Period = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Period |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msgs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthSchedule + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthSchedule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msgs = append(m.Msgs, MsgExecuteContract{}) + if err := m.Msgs[len(m.Msgs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LastExecuteHeight", wireType) + } + m.LastExecuteHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.LastExecuteHeight |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipSchedule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthSchedule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgExecuteContract) 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 ErrIntOverflowSchedule + } + 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: MsgExecuteContract: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgExecuteContract: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + 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 ErrInvalidLengthSchedule + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchedule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Contract = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + 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 ErrInvalidLengthSchedule + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchedule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msg = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipSchedule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthSchedule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ScheduleCount) 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 ErrIntOverflowSchedule + } + 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: ScheduleCount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ScheduleCount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Count", wireType) + } + m.Count = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Count |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipSchedule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthSchedule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipSchedule(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, ErrIntOverflowSchedule + } + 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, ErrIntOverflowSchedule + } + 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, ErrIntOverflowSchedule + } + 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, ErrInvalidLengthSchedule + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupSchedule + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthSchedule + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthSchedule = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowSchedule = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupSchedule = fmt.Errorf("proto: unexpected end of group") +)