Skip to content

Commit

Permalink
feat: subscription plan details should not be updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ironman0x7b2 committed Jul 16, 2024
1 parent d7364da commit aac0eeb
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 608 deletions.
3 changes: 1 addition & 2 deletions proto/sentinel/plan/v3/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@ message EventUnlinkNode {
message EventUpdate {
uint64 id = 1 [(gogoproto.customname) = "ID"];
string prov_address = 2;
bool private = 3;
sentinel.types.v1.Status status = 4;
sentinel.types.v1.Status status = 3;
}
9 changes: 0 additions & 9 deletions proto/sentinel/plan/v3/msg.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ message MsgUnlinkNodeRequest {
string node_address = 3;
}

message MsgUpdatePlanDetailsRequest {
string from = 1;
uint64 id = 2 [(gogoproto.customname) = "ID"];
bool private = 3;
}

message MsgUpdatePlanStatusRequest {
string from = 1;
uint64 id = 2 [(gogoproto.customname) = "ID"];
Expand All @@ -67,8 +61,6 @@ message MsgLinkNodeResponse {}

message MsgUnlinkNodeResponse {}

message MsgUpdatePlanDetailsResponse {}

message MsgUpdatePlanStatusResponse {}

message MsgStartSessionResponse {
Expand All @@ -79,7 +71,6 @@ service MsgService {
rpc MsgCreatePlan(MsgCreatePlanRequest) returns (MsgCreatePlanResponse);
rpc MsgLinkNode(MsgLinkNodeRequest) returns (MsgLinkNodeResponse);
rpc MsgUnlinkNode(MsgUnlinkNodeRequest) returns (MsgUnlinkNodeResponse);
rpc MsgUpdatePlanDetails(MsgUpdatePlanDetailsRequest) returns (MsgUpdatePlanDetailsResponse);
rpc MsgUpdatePlanStatus(MsgUpdatePlanStatusRequest) returns (MsgUpdatePlanStatusResponse);
rpc MsgStartSession(MsgStartSessionRequest) returns (MsgStartSessionResponse);
}
1 change: 0 additions & 1 deletion x/plan/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func GetTxCommands() []*cobra.Command {
txCreatePlan(),
txLinkNode(),
txUnlinkNode(),
txUpdatePlanDetails(),
txUpdatePlanStatus(),
)

Expand Down
39 changes: 0 additions & 39 deletions x/plan/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,45 +146,6 @@ func txUnlinkNode() *cobra.Command {
return cmd
}

func txUpdatePlanDetails() *cobra.Command {
cmd := &cobra.Command{
Use: "update-plan-details [id] [private]",
Short: "Update the details of an existing subscription plan",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

id, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

private, err := strconv.ParseBool(args[1])
if err != nil {
return err
}

msg := v3.NewMsgUpdatePlanDetailsRequest(
ctx.FromAddress.Bytes(),
id,
private,
)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(ctx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}

func txUpdatePlanStatus() *cobra.Command {
cmd := &cobra.Command{
Use: "update-plan-status [id] [status]",
Expand Down
23 changes: 0 additions & 23 deletions x/plan/keeper/msg_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,6 @@ func (k *Keeper) HandleMsgUnlinkNode(ctx sdk.Context, msg *v3.MsgUnlinkNodeReque
return &v3.MsgUnlinkNodeResponse{}, nil
}

func (k *Keeper) HandleMsgUpdatePlanDetails(ctx sdk.Context, msg *v3.MsgUpdatePlanDetailsRequest) (*v3.MsgUpdatePlanDetailsResponse, error) {
plan, found := k.GetPlan(ctx, msg.ID)
if !found {
return nil, types.NewErrorPlanNotFound(msg.ID)
}
if msg.From != plan.ProvAddress {
return nil, types.NewErrorUnauthorized(msg.From)
}

plan.Private = msg.Private

k.SetPlan(ctx, plan)
ctx.EventManager().EmitTypedEvent(
&v3.EventUpdate{
ID: plan.ID,
ProvAddress: plan.ProvAddress,
Private: plan.Private,
},
)

return &v3.MsgUpdatePlanDetailsResponse{}, nil
}

func (k *Keeper) HandleMsgUpdatePlanStatus(ctx sdk.Context, msg *v3.MsgUpdatePlanStatusRequest) (*v3.MsgUpdatePlanStatusResponse, error) {
plan, found := k.GetPlan(ctx, msg.ID)
if !found {
Expand Down
5 changes: 0 additions & 5 deletions x/plan/services/v3/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ func (m *msgServer) MsgUnlinkNode(c context.Context, req *v3.MsgUnlinkNodeReques
return m.HandleMsgUnlinkNode(ctx, req)
}

func (m *msgServer) MsgUpdatePlanDetails(c context.Context, req *v3.MsgUpdatePlanDetailsRequest) (*v3.MsgUpdatePlanDetailsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
return m.HandleMsgUpdatePlanDetails(ctx, req)
}

func (m *msgServer) MsgUpdatePlanStatus(c context.Context, req *v3.MsgUpdatePlanStatusRequest) (*v3.MsgUpdatePlanStatusResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
return m.HandleMsgUpdatePlanStatus(ctx, req)
Expand Down
92 changes: 29 additions & 63 deletions x/plan/types/v3/events.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 0 additions & 31 deletions x/plan/types/v3/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,37 +148,6 @@ func (m *MsgUnlinkNodeRequest) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{from.Bytes()}
}

func NewMsgUpdatePlanDetailsRequest(from base.ProvAddress, id uint64, private bool) *MsgUpdatePlanDetailsRequest {
return &MsgUpdatePlanDetailsRequest{
From: from.String(),
ID: id,
Private: private,
}
}

func (m *MsgUpdatePlanDetailsRequest) ValidateBasic() error {
if m.From == "" {
return sdkerrors.Wrap(types.ErrorInvalidMessage, "from cannot be empty")
}
if _, err := base.ProvAddressFromBech32(m.From); err != nil {
return sdkerrors.Wrap(types.ErrorInvalidMessage, err.Error())
}
if m.ID == 0 {
return sdkerrors.Wrap(types.ErrorInvalidMessage, "id cannot be zero")
}

return nil
}

func (m *MsgUpdatePlanDetailsRequest) GetSigners() []sdk.AccAddress {
from, err := base.ProvAddressFromBech32(m.From)
if err != nil {
panic(err)
}

return []sdk.AccAddress{from.Bytes()}
}

func NewMsgUpdatePlanStatusRequest(from base.ProvAddress, id uint64, status v1base.Status) *MsgUpdatePlanStatusRequest {
return &MsgUpdatePlanStatusRequest{
From: from.String(),
Expand Down
Loading

0 comments on commit aac0eeb

Please sign in to comment.