/
counter.go
52 lines (43 loc) · 1.22 KB
/
counter.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
package commands
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
sdk "github.com/cosmos/cosmos-sdk"
txcmd "github.com/cosmos/cosmos-sdk/client/commands/txs"
"github.com/cosmos/cosmos-sdk/examples/counter/plugins/counter"
"github.com/cosmos/cosmos-sdk/modules/coin"
)
//CounterTxCmd is the CLI command to execute the counter
// through the appTx Command
var CounterTxCmd = &cobra.Command{
Use: "counter",
Short: "add a vote to the counter",
Long: `Add a vote to the counter.
You must pass --valid for it to count and the countfee will be added to the counter.`,
RunE: counterTx,
}
// nolint - flags names
const (
FlagCountFee = "countfee"
FlagValid = "valid"
)
func init() {
fs := CounterTxCmd.Flags()
fs.String(FlagCountFee, "", "Coins to send in the format <amt><coin>,<amt><coin>...")
fs.Bool(FlagValid, false, "Is count valid?")
}
func counterTx(cmd *cobra.Command, args []string) error {
tx, err := readCounterTxFlags()
if err != nil {
return err
}
return txcmd.DoTx(tx)
}
func readCounterTxFlags() (tx sdk.Tx, err error) {
feeCoins, err := coin.ParseCoins(viper.GetString(FlagCountFee))
if err != nil {
return tx, err
}
tx = counter.NewTx(viper.GetBool(FlagValid), feeCoins)
return tx, nil
}