-
Notifications
You must be signed in to change notification settings - Fork 44
/
tx.go
74 lines (63 loc) · 2.02 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
package cli
import (
"fmt"
"strconv"
"strings"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/spf13/cobra"
"github.com/bnb-chain/greenfield/x/virtualgroup/types"
)
// 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,
}
cmd.AddCommand(CmdSettle())
return cmd
}
func CmdSettle() *cobra.Command {
cmd := &cobra.Command{
Use: "settle [gvg family id] [gvg ids]",
Short: "Broadcast message settle",
Long: `Settle will do the settlement of a GVG family or several GVGs (by specifying comma seperated ids).
If zero is provided for GVG family, then the provided GVGs will be settled.
If none zero is provided for GVG family, then the provided GVG family will be settled and the provided GVGs will be ignored.`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
gvgFamilyId, err := strconv.ParseInt(args[0], 10, 32)
if err != nil || gvgFamilyId < 0 {
return fmt.Errorf("invalid GVG family id %s", args[0])
}
gvgIds := make([]uint32, 0)
splits := strings.Split(args[1], ",")
for _, split := range splits {
gvgId, err := strconv.ParseInt(split, 10, 32)
if err != nil || gvgId < 0 {
return fmt.Errorf("invalid GVG id %s", args[1])
}
gvgIds = append(gvgIds, uint32(gvgId))
}
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewMsgSettle(
clientCtx.GetFromAddress(),
uint32(gvgFamilyId),
gvgIds,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}