Skip to content

Commit

Permalink
Added subscribe command for plan
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Aug 13, 2023
1 parent a8815a8 commit 8f0927f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions x/plan/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func GetTxCommands() []*cobra.Command {
txUpdateStatus(),
txLinkNode(),
txUnlinkNode(),
txSubscribe(),
)

return []*cobra.Command{cmd}
Expand Down
40 changes: 37 additions & 3 deletions x/plan/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func txCreate() *cobra.Command {

func txUpdateStatus() *cobra.Command {
cmd := &cobra.Command{
Use: "update-status [id] [status]",
Use: "update-status [plan-id] [status]",
Short: "Update status for a subscription plan",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -97,7 +97,7 @@ func txUpdateStatus() *cobra.Command {

func txLinkNode() *cobra.Command {
cmd := &cobra.Command{
Use: "add-node [id] [node-addr]",
Use: "add-node [plan-id] [node-addr]",
Short: "Add node to a subscription plan",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -136,7 +136,7 @@ func txLinkNode() *cobra.Command {

func txUnlinkNode() *cobra.Command {
cmd := &cobra.Command{
Use: "remove-node [id] [node-addr]",
Use: "remove-node [plan-id] [node-addr]",
Short: "Remove node from a subscription plan",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -172,3 +172,37 @@ func txUnlinkNode() *cobra.Command {

return cmd
}

func txSubscribe() *cobra.Command {
cmd := &cobra.Command{
Use: "subscribe [plan-id] [denom]",
Short: "Subscribe to a 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
}

msg := types.NewMsgSubscribeRequest(
ctx.FromAddress,
id,
args[1],
)
if err = msg.ValidateBasic(); err != nil {
return err
}

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

flags.AddTxFlagsToCmd(cmd)

return cmd
}

0 comments on commit 8f0927f

Please sign in to comment.