Skip to content

Commit 74c47b1

Browse files
committed
copy cron module from neutron
1 parent 34d3fdb commit 74c47b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+8322
-0
lines changed

proto/secret/cron/genesis.proto

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
syntax = "proto3";
2+
package neutron.cron;
3+
4+
import "gogoproto/gogo.proto";
5+
import "neutron/cron/params.proto";
6+
import "neutron/cron/schedule.proto";
7+
// this line is used by starport scaffolding # genesis/proto/import
8+
9+
option go_package = "github.com/neutron-org/neutron/v5/x/cron/types";
10+
11+
// Defines the cron module's genesis state.
12+
message GenesisState {
13+
repeated Schedule scheduleList = 2 [(gogoproto.nullable) = false];
14+
Params params = 1 [(gogoproto.nullable) = false];
15+
// this line is used by starport scaffolding # genesis/proto/state
16+
}

proto/secret/cron/params.proto

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
syntax = "proto3";
2+
package neutron.cron;
3+
4+
import "gogoproto/gogo.proto";
5+
6+
option go_package = "github.com/neutron-org/neutron/v5/x/cron/types";
7+
8+
// Defines the parameters for the module.
9+
message Params {
10+
option (gogoproto.goproto_stringer) = false;
11+
// Security address that can remove schedules
12+
string security_address = 1;
13+
// Limit of schedules executed in one block
14+
uint64 limit = 2;
15+
}

proto/secret/cron/query.proto

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
syntax = "proto3";
2+
package neutron.cron;
3+
4+
import "cosmos/base/query/v1beta1/pagination.proto";
5+
import "gogoproto/gogo.proto";
6+
import "google/api/annotations.proto";
7+
import "neutron/cron/params.proto";
8+
import "neutron/cron/schedule.proto";
9+
// this line is used by starport scaffolding # 1
10+
11+
option go_package = "github.com/neutron-org/neutron/v5/x/cron/types";
12+
13+
// Defines the gRPC querier service.
14+
service Query {
15+
// Queries the parameters of the module.
16+
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
17+
option (google.api.http).get = "/neutron/cron/params";
18+
}
19+
20+
// Queries a Schedule by name.
21+
rpc Schedule(QueryGetScheduleRequest) returns (QueryGetScheduleResponse) {
22+
option (google.api.http).get = "/neutron/cron/schedule/{name}";
23+
}
24+
25+
// Queries a list of Schedule items.
26+
rpc Schedules(QuerySchedulesRequest) returns (QuerySchedulesResponse) {
27+
option (google.api.http).get = "/neutron/cron/schedule";
28+
}
29+
30+
// this line is used by starport scaffolding # 2
31+
}
32+
33+
// The request type for the Query/Params RPC method.
34+
message QueryParamsRequest {}
35+
36+
// The response type for the Query/Params RPC method.
37+
message QueryParamsResponse {
38+
// params holds all the parameters of this module.
39+
Params params = 1 [(gogoproto.nullable) = false];
40+
}
41+
42+
// The request type for the Query/Schedule RPC method.
43+
message QueryGetScheduleRequest {
44+
string name = 1;
45+
}
46+
47+
// The response type for the Query/Params RPC method.
48+
message QueryGetScheduleResponse {
49+
Schedule schedule = 1 [(gogoproto.nullable) = false];
50+
}
51+
52+
// The request type for the Query/Schedules RPC method.
53+
message QuerySchedulesRequest {
54+
cosmos.base.query.v1beta1.PageRequest pagination = 1;
55+
}
56+
57+
// The response type for the Query/Params RPC method.
58+
message QuerySchedulesResponse {
59+
repeated Schedule schedules = 1 [(gogoproto.nullable) = false];
60+
cosmos.base.query.v1beta1.PageResponse pagination = 2;
61+
}
62+
63+
// this line is used by starport scaffolding # 3

proto/secret/cron/schedule.proto

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
syntax = "proto3";
2+
package neutron.cron;
3+
4+
import "gogoproto/gogo.proto";
5+
6+
option go_package = "github.com/neutron-org/neutron/v5/x/cron/types";
7+
8+
// Defines when messages will be executed in the block
9+
enum ExecutionStage {
10+
// Execution at the end of the block
11+
EXECUTION_STAGE_END_BLOCKER = 0;
12+
// Execution at the beginning of the block
13+
EXECUTION_STAGE_BEGIN_BLOCKER = 1;
14+
}
15+
16+
// Defines the schedule for execution
17+
message Schedule {
18+
// Name of schedule
19+
string name = 1;
20+
// Period in blocks
21+
uint64 period = 2;
22+
// Msgs that will be executed every certain number of blocks, specified in the `period` field
23+
repeated MsgExecuteContract msgs = 3 [(gogoproto.nullable) = false];
24+
// Last execution's block height
25+
uint64 last_execute_height = 4;
26+
// Stage when messages will be executed
27+
ExecutionStage execution_stage = 5;
28+
}
29+
30+
// Defines the contract and the message to pass
31+
message MsgExecuteContract {
32+
// The address of the smart contract
33+
string contract = 1;
34+
// JSON encoded message to be passed to the contract
35+
string msg = 2;
36+
}
37+
38+
// Defines the number of current schedules
39+
message ScheduleCount {
40+
// The number of current schedules
41+
int32 count = 1;
42+
}

proto/secret/cron/tx.proto

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
syntax = "proto3";
2+
package neutron.cron;
3+
4+
import "amino/amino.proto";
5+
import "cosmos/msg/v1/msg.proto";
6+
import "cosmos_proto/cosmos.proto";
7+
import "gogoproto/gogo.proto";
8+
import "neutron/cron/params.proto";
9+
import "neutron/cron/schedule.proto";
10+
11+
// this line is used by starport scaffolding # proto/tx/import
12+
13+
option go_package = "github.com/neutron-org/neutron/v5/x/cron/types";
14+
15+
// Defines the Msg service.
16+
service Msg {
17+
option (cosmos.msg.v1.service) = true;
18+
19+
// Adds new schedule.
20+
rpc AddSchedule(MsgAddSchedule) returns (MsgAddScheduleResponse);
21+
// Removes schedule.
22+
rpc RemoveSchedule(MsgRemoveSchedule) returns (MsgRemoveScheduleResponse);
23+
// Updates the module parameters.
24+
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
25+
// this line is used by starport scaffolding # proto/tx/rpc
26+
}
27+
28+
// The MsgAddSchedule request type.
29+
message MsgAddSchedule {
30+
option (amino.name) = "cron/MsgAddSchedule";
31+
option (cosmos.msg.v1.signer) = "authority";
32+
33+
// The address of the governance account.
34+
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
35+
// Name of the schedule
36+
string name = 2;
37+
// Period in blocks
38+
uint64 period = 3;
39+
// Msgs that will be executed every certain number of blocks, specified in the `period` field
40+
repeated MsgExecuteContract msgs = 4 [(gogoproto.nullable) = false];
41+
// Stage when messages will be executed
42+
ExecutionStage execution_stage = 5;
43+
}
44+
45+
// Defines the response structure for executing a MsgAddSchedule message.
46+
message MsgAddScheduleResponse {}
47+
48+
// The MsgRemoveSchedule request type.
49+
message MsgRemoveSchedule {
50+
option (amino.name) = "cron/MsgRemoveSchedule";
51+
option (cosmos.msg.v1.signer) = "authority";
52+
53+
// The address of the governance account.
54+
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
55+
// Name of the schedule
56+
string name = 2;
57+
}
58+
59+
// Defines the response structure for executing a MsgRemoveSchedule message.
60+
message MsgRemoveScheduleResponse {}
61+
62+
// this line is used by starport scaffolding # proto/tx/message
63+
64+
// The MsgUpdateParams request type.
65+
//
66+
// Since: 0.47
67+
message MsgUpdateParams {
68+
option (amino.name) = "cron/MsgUpdateParams";
69+
option (cosmos.msg.v1.signer) = "authority";
70+
71+
// The address of the governance account.
72+
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
73+
74+
// Defines the x/cron parameters to update.
75+
//
76+
// NOTE: All parameters must be supplied.
77+
Params params = 2 [
78+
(gogoproto.nullable) = false,
79+
(amino.dont_omitempty) = true
80+
];
81+
}
82+
83+
// Defines the response structure for executing a MsgUpdateParams message.
84+
//
85+
// Since: 0.47
86+
message MsgUpdateParamsResponse {}

proto/secret/cron/v1/schedule.proto

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
syntax = "proto3";
2+
package neutron.cron.v1;
3+
4+
import "gogoproto/gogo.proto";
5+
6+
option go_package = "github.com/neutron-org/neutron/v5/x/cron/types/v1";
7+
8+
// Defines the schedule for execution
9+
message Schedule {
10+
// Name of schedule
11+
string name = 1;
12+
// Period in blocks
13+
uint64 period = 2;
14+
// Msgs that will be executed every certain number of blocks, specified in the `period` field
15+
repeated MsgExecuteContract msgs = 3 [(gogoproto.nullable) = false];
16+
// Last execution's block height
17+
uint64 last_execute_height = 4;
18+
}
19+
20+
// Defines the contract and the message to pass
21+
message MsgExecuteContract {
22+
// The address of the smart contract
23+
string contract = 1;
24+
// JSON encoded message to be passed to the contract
25+
string msg = 2;
26+
}
27+
28+
// Defines the number of current schedules
29+
message ScheduleCount {
30+
// The number of current schedules
31+
int32 count = 1;
32+
}

x/cron/client/cli/query.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
8+
"github.com/cosmos/cosmos-sdk/client"
9+
10+
"github.com/neutron-org/neutron/v5/x/cron/types"
11+
)
12+
13+
// GetQueryCmd returns the cli query commands for this module
14+
func GetQueryCmd(_ string) *cobra.Command {
15+
// Group cron queries under a subcommand
16+
cmd := &cobra.Command{
17+
Use: types.ModuleName,
18+
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
19+
DisableFlagParsing: true,
20+
SuggestionsMinimumDistance: 2,
21+
RunE: client.ValidateCmd,
22+
}
23+
24+
cmd.AddCommand(CmdQueryParams())
25+
cmd.AddCommand(CmdListSchedule())
26+
cmd.AddCommand(CmdShowSchedule())
27+
28+
return cmd
29+
}

x/cron/client/cli/query_params.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cli
2+
3+
import (
4+
"context"
5+
6+
"github.com/cosmos/cosmos-sdk/client"
7+
"github.com/cosmos/cosmos-sdk/client/flags"
8+
"github.com/spf13/cobra"
9+
10+
"github.com/neutron-org/neutron/v5/x/cron/types"
11+
)
12+
13+
func CmdQueryParams() *cobra.Command {
14+
cmd := &cobra.Command{
15+
Use: "params",
16+
Short: "shows the parameters of the module",
17+
Args: cobra.NoArgs,
18+
RunE: func(cmd *cobra.Command, _ []string) error {
19+
clientCtx := client.GetClientContextFromCmd(cmd)
20+
21+
queryClient := types.NewQueryClient(clientCtx)
22+
23+
res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{})
24+
if err != nil {
25+
return err
26+
}
27+
28+
return clientCtx.PrintProto(res)
29+
},
30+
}
31+
32+
flags.AddQueryFlagsToCmd(cmd)
33+
34+
return cmd
35+
}

0 commit comments

Comments
 (0)