Skip to content

Commit e606fe5

Browse files
committed
feat: add field private for subscription plan
1 parent 4c9c4f4 commit e606fe5

File tree

17 files changed

+979
-123
lines changed

17 files changed

+979
-123
lines changed

proto/sentinel/plan/v3/events.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ message EventCreate {
1313
string bytes = 3;
1414
string duration = 4;
1515
string prices = 5;
16+
bool private = 6;
1617
}
1718

1819
message EventLinkNode {
@@ -27,6 +28,12 @@ message EventUnlinkNode {
2728
string node_address = 3;
2829
}
2930

31+
message EventUpdateDetails {
32+
uint64 plan_id = 1 [(gogoproto.customname) = "PlanID"];
33+
string prov_address = 2;
34+
bool private = 3;
35+
}
36+
3037
message EventUpdateStatus {
3138
uint64 plan_id = 1 [(gogoproto.customname) = "PlanID"];
3239
string prov_address = 2;

proto/sentinel/plan/v3/msg.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ message MsgCreatePlanRequest {
2222
(gogoproto.stdduration) = true
2323
];
2424
repeated sentinel.types.v1.Price prices = 4 [(gogoproto.nullable) = false];
25+
bool private = 5;
2526
}
2627

2728
message MsgLinkNodeRequest {
@@ -36,6 +37,12 @@ message MsgUnlinkNodeRequest {
3637
string node_address = 3;
3738
}
3839

40+
message MsgUpdatePlanDetailsRequest {
41+
string from = 1;
42+
uint64 id = 2 [(gogoproto.customname) = "ID"];
43+
bool private = 3;
44+
}
45+
3946
message MsgUpdatePlanStatusRequest {
4047
string from = 1;
4148
uint64 id = 2 [(gogoproto.customname) = "ID"];
@@ -58,6 +65,8 @@ message MsgLinkNodeResponse {}
5865

5966
message MsgUnlinkNodeResponse {}
6067

68+
message MsgUpdatePlanDetailsResponse {}
69+
6170
message MsgUpdatePlanStatusResponse {}
6271

6372
message MsgStartSessionResponse {
@@ -68,6 +77,7 @@ service MsgService {
6877
rpc MsgCreatePlan(MsgCreatePlanRequest) returns (MsgCreatePlanResponse);
6978
rpc MsgLinkNode(MsgLinkNodeRequest) returns (MsgLinkNodeResponse);
7079
rpc MsgUnlinkNode(MsgUnlinkNodeRequest) returns (MsgUnlinkNodeResponse);
80+
rpc MsgUpdatePlanDetails(MsgUpdatePlanDetailsRequest) returns (MsgUpdatePlanDetailsResponse);
7181
rpc MsgUpdatePlanStatus(MsgUpdatePlanStatusRequest) returns (MsgUpdatePlanStatusResponse);
7282
rpc MsgStartSession(MsgStartSessionRequest) returns (MsgStartSessionResponse);
7383
}

proto/sentinel/plan/v3/plan.proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ message Plan {
2323
(gogoproto.stdduration) = true
2424
];
2525
repeated sentinel.types.v1.Price prices = 5 [(gogoproto.nullable) = false];
26-
sentinel.types.v1.Status status = 6;
27-
google.protobuf.Timestamp status_at = 7 [
26+
bool private = 6;
27+
sentinel.types.v1.Status status = 7;
28+
google.protobuf.Timestamp status_at = 8 [
2829
(gogoproto.nullable) = false,
2930
(gogoproto.stdtime) = true
3031
];

x/node/types/v3/msg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (m *MsgRegisterNodeRequest) GetSigners() []sdk.AccAddress {
8080
return []sdk.AccAddress{from.Bytes()}
8181
}
8282

83-
// NewMsgUpdateNodeDetailsRequest creates a MsgUpdateNodeDetailsRequest for updating a nodes prices or remote URL.
83+
// NewMsgUpdateNodeDetailsRequest creates a MsgUpdateNodeDetailsRequest for updating a node's prices or remote URL.
8484
func NewMsgUpdateNodeDetailsRequest(from base.NodeAddress, gigabytePrices, hourlyPrices v1base.Prices, remoteAddrs []string) *MsgUpdateNodeDetailsRequest {
8585
return &MsgUpdateNodeDetailsRequest{
8686
From: from.String(),

x/plan/client/cli/cli.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func GetTxCommands() []*cobra.Command {
2121
txCreatePlan(),
2222
txLinkNode(),
2323
txUnlinkNode(),
24+
txUpdatePlanDetails(),
2425
txUpdatePlanStatus(),
2526
)
2627

x/plan/client/cli/flags.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import (
77
)
88

99
const (
10-
flagPrices = "prices"
10+
flagPrices = "prices"
11+
flagPrivate = "private"
1112
)
1213

1314
func GetPrices(flags *pflag.FlagSet) (v1base.Prices, error) {
@@ -22,3 +23,7 @@ func GetPrices(flags *pflag.FlagSet) (v1base.Prices, error) {
2223

2324
return v1base.NewPricesFromString(s)
2425
}
26+
27+
func GetPrivate(flags *pflag.FlagSet) (bool, error) {
28+
return flags.GetBool(flagPrivate)
29+
}

x/plan/client/cli/tx.go

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
func txCreatePlan() *cobra.Command {
2020
cmd := &cobra.Command{
2121
Use: "create-plan [bytes] [duration]",
22-
Short: "Create a new subscription plan with bytes, duration and pricing details",
22+
Short: "Create a new subscription plan with bytes, duration, pricing details, and privacy setting",
2323
Args: cobra.ExactArgs(2),
2424
RunE: func(cmd *cobra.Command, args []string) error {
2525
ctx, err := client.GetClientTxContext(cmd)
@@ -42,11 +42,17 @@ func txCreatePlan() *cobra.Command {
4242
return err
4343
}
4444

45+
private, err := GetPrivate(cmd.Flags())
46+
if err != nil {
47+
return err
48+
}
49+
4550
msg := v3.NewMsgCreatePlanRequest(
4651
ctx.FromAddress.Bytes(),
4752
bytes,
4853
duration,
4954
prices,
55+
private,
5056
)
5157
if err := msg.ValidateBasic(); err != nil {
5258
return err
@@ -57,6 +63,7 @@ func txCreatePlan() *cobra.Command {
5763
}
5864

5965
flags.AddTxFlagsToCmd(cmd)
66+
cmd.Flags().Bool(flagPrivate, false, "set whether the plan should be private or not")
6067
cmd.Flags().String(flagPrices, "", "specify the list of prices (e.g., 1000token)")
6168

6269
return cmd
@@ -140,6 +147,46 @@ func txUnlinkNode() *cobra.Command {
140147
return cmd
141148
}
142149

150+
func txUpdatePlanDetails() *cobra.Command {
151+
cmd := &cobra.Command{
152+
Use: "update-plan-details [id]",
153+
Short: "Update the details of an existing subscription plan",
154+
Args: cobra.ExactArgs(2),
155+
RunE: func(cmd *cobra.Command, args []string) error {
156+
ctx, err := client.GetClientTxContext(cmd)
157+
if err != nil {
158+
return err
159+
}
160+
161+
id, err := strconv.ParseUint(args[0], 10, 64)
162+
if err != nil {
163+
return err
164+
}
165+
166+
private, err := GetPrivate(cmd.Flags())
167+
if err != nil {
168+
return err
169+
}
170+
171+
msg := v3.NewMsgUpdatePlanDetailsRequest(
172+
ctx.FromAddress.Bytes(),
173+
id,
174+
private,
175+
)
176+
if err := msg.ValidateBasic(); err != nil {
177+
return err
178+
}
179+
180+
return tx.GenerateOrBroadcastTxCLI(ctx, cmd.Flags(), msg)
181+
},
182+
}
183+
184+
flags.AddTxFlagsToCmd(cmd)
185+
cmd.Flags().Bool(flagPrivate, false, "set whether the plan should be private or not")
186+
187+
return cmd
188+
}
189+
143190
func txUpdatePlanStatus() *cobra.Command {
144191
cmd := &cobra.Command{
145192
Use: "update-plan-status [id] [status]",

x/plan/keeper/msg_handler.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func (k *Keeper) HandleMsgCreatePlan(ctx sdk.Context, msg *v3.MsgCreatePlanReque
3737
Bytes: msg.Bytes,
3838
Duration: msg.Duration,
3939
Prices: msg.Prices,
40+
Private: msg.Private,
4041
Status: v1base.StatusInactive,
4142
StatusAt: ctx.BlockTime(),
4243
}
@@ -164,8 +165,38 @@ func (k *Keeper) HandleMsgUnlinkNode(ctx sdk.Context, msg *v3.MsgUnlinkNodeReque
164165
return &v3.MsgUnlinkNodeResponse{}, nil
165166
}
166167

168+
// HandleMsgUpdatePlanDetails processes a request to update the details of a plan.
169+
// It updates the plan's privacy setting and ensures that the plan's details are persisted.
170+
func (k *Keeper) HandleMsgUpdatePlanDetails(ctx sdk.Context, msg *v3.MsgUpdatePlanDetailsRequest) (*v3.MsgUpdatePlanDetailsResponse, error) {
171+
// Fetch and authorize the plan
172+
plan, found := k.GetPlan(ctx, msg.ID)
173+
if !found {
174+
return nil, types.NewErrorPlanNotFound(msg.ID)
175+
}
176+
177+
if msg.From != plan.ProvAddress {
178+
return nil, types.NewErrorUnauthorized(msg.From)
179+
}
180+
181+
// Apply the plan's privacy setting and persist the changes
182+
plan.Private = msg.Private
183+
184+
k.SetPlan(ctx, plan)
185+
186+
// Emit event to indicate details update
187+
ctx.EventManager().EmitTypedEvent(
188+
&v3.EventUpdateDetails{
189+
PlanID: plan.ID,
190+
ProvAddress: plan.ProvAddress,
191+
Private: plan.Private,
192+
},
193+
)
194+
195+
return &v3.MsgUpdatePlanDetailsResponse{}, nil
196+
}
197+
167198
// HandleMsgUpdatePlanStatus handles a request to update the activation status of a plan.
168-
// It updates the plans status and cleans up the old status index.
199+
// It updates the plan's status and cleans up the old status index.
169200
func (k *Keeper) HandleMsgUpdatePlanStatus(ctx sdk.Context, msg *v3.MsgUpdatePlanStatusRequest) (*v3.MsgUpdatePlanStatusResponse, error) {
170201
// Fetch and authorize the plan
171202
plan, found := k.GetPlan(ctx, msg.ID)

x/plan/migrations/migrator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (k *Migrator) migratePlans(ctx sdk.Context) {
7777
Bytes: base.Gigabyte.MulRaw(item.Gigabytes),
7878
Duration: item.Duration,
7979
Prices: prices,
80+
Private: false,
8081
Status: item.Status,
8182
StatusAt: item.StatusAt,
8283
}

x/plan/services/v3/msg_server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ func (m *msgServer) MsgUnlinkNode(c context.Context, req *v3.MsgUnlinkNodeReques
3939
return m.HandleMsgUnlinkNode(ctx, req)
4040
}
4141

42+
func (m *msgServer) MsgUpdatePlanDetails(c context.Context, req *v3.MsgUpdatePlanDetailsRequest) (*v3.MsgUpdatePlanDetailsResponse, error) {
43+
ctx := sdk.UnwrapSDKContext(c)
44+
45+
return m.HandleMsgUpdatePlanDetails(ctx, req)
46+
}
47+
4248
func (m *msgServer) MsgUpdatePlanStatus(c context.Context, req *v3.MsgUpdatePlanStatusRequest) (*v3.MsgUpdatePlanStatusResponse, error) {
4349
ctx := sdk.UnwrapSDKContext(c)
4450

0 commit comments

Comments
 (0)