Skip to content

Commit

Permalink
copy cron module from neutron
Browse files Browse the repository at this point in the history
  • Loading branch information
cboh4 committed Feb 21, 2025
1 parent 34d3fdb commit 74c47b1
Show file tree
Hide file tree
Showing 47 changed files with 8,322 additions and 0 deletions.
16 changes: 16 additions & 0 deletions proto/secret/cron/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";
package neutron.cron;

import "gogoproto/gogo.proto";
import "neutron/cron/params.proto";
import "neutron/cron/schedule.proto";
// this line is used by starport scaffolding # genesis/proto/import

option go_package = "github.com/neutron-org/neutron/v5/x/cron/types";

// Defines the cron module's genesis state.
message GenesisState {
repeated Schedule scheduleList = 2 [(gogoproto.nullable) = false];
Params params = 1 [(gogoproto.nullable) = false];
// this line is used by starport scaffolding # genesis/proto/state
}
15 changes: 15 additions & 0 deletions proto/secret/cron/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";
package neutron.cron;

import "gogoproto/gogo.proto";

option go_package = "github.com/neutron-org/neutron/v5/x/cron/types";

// Defines the parameters for the module.
message Params {
option (gogoproto.goproto_stringer) = false;
// Security address that can remove schedules
string security_address = 1;
// Limit of schedules executed in one block
uint64 limit = 2;
}
63 changes: 63 additions & 0 deletions proto/secret/cron/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
syntax = "proto3";
package neutron.cron;

import "cosmos/base/query/v1beta1/pagination.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "neutron/cron/params.proto";
import "neutron/cron/schedule.proto";
// this line is used by starport scaffolding # 1

option go_package = "github.com/neutron-org/neutron/v5/x/cron/types";

// Defines the gRPC querier service.
service Query {
// Queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/neutron/cron/params";
}

// Queries a Schedule by name.
rpc Schedule(QueryGetScheduleRequest) returns (QueryGetScheduleResponse) {
option (google.api.http).get = "/neutron/cron/schedule/{name}";
}

// Queries a list of Schedule items.
rpc Schedules(QuerySchedulesRequest) returns (QuerySchedulesResponse) {
option (google.api.http).get = "/neutron/cron/schedule";
}

// 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;
}

// this line is used by starport scaffolding # 3
42 changes: 42 additions & 0 deletions proto/secret/cron/schedule.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
syntax = "proto3";
package neutron.cron;

import "gogoproto/gogo.proto";

option go_package = "github.com/neutron-org/neutron/v5/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 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 {
// 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;
}
86 changes: 86 additions & 0 deletions proto/secret/cron/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
syntax = "proto3";
package neutron.cron;

import "amino/amino.proto";
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/v5/x/cron/types";

// 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

// The MsgUpdateParams request type.
//
// Since: 0.47
message MsgUpdateParams {
option (amino.name) = "cron/MsgUpdateParams";
option (cosmos.msg.v1.signer) = "authority";

// The address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// Defines the x/cron parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
}

// Defines the response structure for executing a MsgUpdateParams message.
//
// Since: 0.47
message MsgUpdateParamsResponse {}
32 changes: 32 additions & 0 deletions proto/secret/cron/v1/schedule.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
syntax = "proto3";
package neutron.cron.v1;

import "gogoproto/gogo.proto";

option go_package = "github.com/neutron-org/neutron/v5/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;
}
29 changes: 29 additions & 0 deletions x/cron/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"

"github.com/neutron-org/neutron/v5/x/cron/types"
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(_ string) *cobra.Command {
// Group cron queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdListSchedule())
cmd.AddCommand(CmdShowSchedule())

return cmd
}
35 changes: 35 additions & 0 deletions x/cron/client/cli/query_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cli

import (
"context"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"

"github.com/neutron-org/neutron/v5/x/cron/types"
)

func CmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "shows the parameters of the module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
Loading

0 comments on commit 74c47b1

Please sign in to comment.