-
Notifications
You must be signed in to change notification settings - Fork 8
/
tx.go
83 lines (68 loc) · 2.2 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
package cli
import (
"encoding/json"
"io/ioutil"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/bianjieai/tibc-go/modules/tibc/core/26-routing/types"
)
// NewSetRoutingRulesProposalCmd implements a command handler for submitting a setting rules proposal transaction.
func NewSetRoutingRulesProposalCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "set-rules [path/to/routing_rules.json] [flags]",
Args: cobra.ExactArgs(1),
Short: "Submit a rules set proposal",
Long: "set routing rules",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
routingRulesBz, err := ioutil.ReadFile(args[0])
if err != nil {
return errors.Wrap(err, "neither JSON input nor path to .json file for routing rules were provided")
}
var rules []string
if err := json.Unmarshal(routingRulesBz, &rules); err != nil {
return errors.Wrap(err, "error unmarshalling rules file")
}
title, err := cmd.Flags().GetString(cli.FlagTitle)
if err != nil {
return err
}
description, err := cmd.Flags().GetString(cli.FlagDescription)
if err != nil {
return err
}
content, err := types.NewSetRoutingRulesProposal(title, description, rules)
if err != nil {
return err
}
depositStr, err := cmd.Flags().GetString(cli.FlagDeposit)
if err != nil {
return err
}
deposit, err := sdk.ParseCoinsNormalized(depositStr)
if err != nil {
return err
}
msg, err := govv1beta1.NewMsgSubmitProposal(content, deposit, clientCtx.GetFromAddress())
if err != nil {
return err
}
if err = msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(cli.FlagTitle, "", "title of proposal")
cmd.Flags().String(cli.FlagDescription, "", "description of proposal")
cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal")
return cmd
}