/
tx_notifications.go
107 lines (91 loc) · 2.42 KB
/
tx_notifications.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package cli
import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/jackalLabs/canine-chain/x/notifications/types"
"github.com/spf13/cast"
"github.com/spf13/cobra"
)
func CmdCreateNotifications() *cobra.Command {
cmd := &cobra.Command{
Use: "create-notifications [notification] [address]",
Short: "Create a new notifications",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
// Get value arguments
argNotification := args[0]
argAddress := args[1]
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewMsgCreateNotifications(
clientCtx.GetFromAddress().String(),
argNotification,
argAddress,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
func CmdUpdateNotifications() *cobra.Command {
cmd := &cobra.Command{
Use: "update-notifications [count] [notification] [address]",
Short: "Update a notifications",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
// Get indexes
indexCount, err := cast.ToUint64E(args[0])
if err != nil {
return err
}
// Get value arguments
argNotification := args[1]
argAddress := args[2]
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewMsgUpdateNotifications(
clientCtx.GetFromAddress().String(),
indexCount,
argNotification,
argAddress,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
func CmdDeleteNotifications() *cobra.Command {
cmd := &cobra.Command{
Use: "delete-notifications",
Short: "Delete a notifications",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewMsgDeleteNotifications(
clientCtx.GetFromAddress().String(),
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}