-
Notifications
You must be signed in to change notification settings - Fork 207
/
tx.go
146 lines (122 loc) · 4.19 KB
/
tx.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package cli
import (
"fmt"
"strings"
"time"
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/version"
// "github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/lavanet/lava/x/plans/client/utils"
"github.com/lavanet/lava/x/plans/types"
)
var DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds())
const (
flagPacketTimeoutTimestamp = "packet-timeout-timestamp"
listSeparator = ","
)
// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
// this line is used by starport scaffolding # 1
return cmd
}
// NewSubmitPlansAddProposalTxCmd returns a CLI command handler for creating
// a new plan proposal governance transaction.
func NewSubmitPlansAddProposalTxCmd() *cobra.Command {
return &cobra.Command{
Use: "plans-add [proposal-file,proposal-file,...]",
Args: cobra.ExactArgs(1),
Short: "Submit a plans add proposal",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a plans add proposal.
The proposal details must be supplied via a JSON file. For values that contains
objects, only non-empty fields will be updated.
IMPORTANT: Currently changes are evaluated but not validated, so it is
very important that any "value" change is valid (ie. correct type and within bounds)
Proper vetting of a plans add proposal should prevent this from happening
(no deposits should occur during the governance process), but it should be noted
regardless.
Example:
$ %s tx gov plans-proposal plans-add <path/to/proposal.json> --from=<key_or_address>
`,
version.AppName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
proposal, err := utils.ParsePlansAddProposalJSON(args[0])
if err != nil {
return err
}
from := clientCtx.GetFromAddress()
content := &proposal.Proposal
deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit)
if err != nil {
return err
}
msg, err := v1beta1.NewMsgSubmitProposal(content, deposit, from)
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
}
// NewSubmitPlansDelProposalTxCmd returns a CLI command handler for creating
// a delete plan proposal governance transaction.
func NewSubmitPlansDelProposalTxCmd() *cobra.Command {
return &cobra.Command{
Use: "plans-del [proposal-file,proposal-file,...]",
Args: cobra.ExactArgs(1),
Short: "Submit a plans delete proposal",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a plans delete proposal.
The proposal details must be supplied via a JSON file. For values that contains
objects, only non-empty fields will be updated.
IMPORTANT: Currently changes are evaluated but not validated, so it is
very important that any "value" change is valid (ie. correct type and within bounds)
Proper vetting of a plans add proposal should prevent this from happening
(no deposits should occur during the governance process), but it should be noted
regardless.
Example:
$ %s tx gov plans-proposal plans-del <path/to/proposal.json> --from=<key_or_address>
`,
version.AppName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
proposal, err := utils.ParsePlansDelProposalJSON(clientCtx.LegacyAmino, args[0])
if err != nil {
return err
}
from := clientCtx.GetFromAddress()
content := &proposal.Proposal
deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit)
if err != nil {
return err
}
msg, err := v1beta1.NewMsgSubmitProposal(content, deposit, from)
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
}