2017-02-07 10:16:41 -08:00
|
|
|
package main
|
2017-01-30 06:56:47 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2017-03-08 23:19:07 -08:00
|
|
|
"github.com/spf13/cobra"
|
2017-01-30 06:56:47 -08:00
|
|
|
wire "github.com/tendermint/go-wire"
|
2017-02-07 10:16:41 -08:00
|
|
|
|
|
|
|
"github.com/tendermint/basecoin/cmd/commands"
|
|
|
|
"github.com/tendermint/basecoin/plugins/counter"
|
|
|
|
"github.com/tendermint/basecoin/types"
|
2017-03-08 23:19:07 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
//commands
|
|
|
|
var CounterTxCmd = &cobra.Command{
|
|
|
|
Use: "counter",
|
|
|
|
Short: "Create, sign, and broadcast a transaction to the counter plugin",
|
2017-04-15 09:07:27 -07:00
|
|
|
RunE: counterTxCmd,
|
2017-03-08 23:19:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
//flags
|
|
|
|
var (
|
|
|
|
validFlag bool
|
|
|
|
countFeeFlag string
|
2017-01-30 06:56:47 -08:00
|
|
|
)
|
|
|
|
|
2017-02-07 10:16:41 -08:00
|
|
|
func init() {
|
2017-03-08 23:19:07 -08:00
|
|
|
|
|
|
|
CounterTxCmd.Flags().BoolVar(&validFlag, "valid", false, "Set valid field in CounterTx")
|
|
|
|
CounterTxCmd.Flags().StringVar(&countFeeFlag, "countfee", "", "Coins for the counter fee of the format <amt><coin>")
|
|
|
|
|
2017-02-07 10:16:41 -08:00
|
|
|
commands.RegisterTxSubcommand(CounterTxCmd)
|
2017-02-07 13:10:17 -08:00
|
|
|
commands.RegisterStartPlugin("counter", func() types.Plugin { return counter.New() })
|
2017-02-07 10:16:41 -08:00
|
|
|
}
|
|
|
|
|
2017-04-15 09:07:27 -07:00
|
|
|
func counterTxCmd(cmd *cobra.Command, args []string) error {
|
2017-02-07 10:16:41 -08:00
|
|
|
|
2017-04-21 09:56:50 -07:00
|
|
|
countFee, err := types.ParseCoins(countFeeFlag)
|
2017-03-08 23:19:07 -08:00
|
|
|
if err != nil {
|
2017-04-15 09:07:27 -07:00
|
|
|
return err
|
2017-01-30 08:16:00 -08:00
|
|
|
}
|
2017-01-30 06:56:47 -08:00
|
|
|
|
|
|
|
counterTx := counter.CounterTx{
|
2017-03-08 23:19:07 -08:00
|
|
|
Valid: validFlag,
|
|
|
|
Fee: countFee,
|
2017-01-30 06:56:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("CounterTx:", string(wire.JSONBytes(counterTx)))
|
|
|
|
|
|
|
|
data := wire.BinaryBytes(counterTx)
|
|
|
|
name := "counter"
|
|
|
|
|
2017-04-15 09:07:27 -07:00
|
|
|
return commands.AppTx(name, data)
|
2017-01-30 06:56:47 -08:00
|
|
|
}
|