2017-02-07 10:16:41 -08:00
|
|
|
package main
|
2017-01-30 06:56:47 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
wire "github.com/tendermint/go-wire"
|
|
|
|
"github.com/urfave/cli"
|
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-01-30 06:56:47 -08:00
|
|
|
)
|
|
|
|
|
2017-02-07 10:16:41 -08:00
|
|
|
func init() {
|
|
|
|
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-01-30 06:56:47 -08:00
|
|
|
var (
|
2017-02-07 10:16:41 -08:00
|
|
|
ValidFlag = cli.BoolFlag{
|
|
|
|
Name: "valid",
|
|
|
|
Usage: "Set valid field in CounterTx",
|
|
|
|
}
|
|
|
|
|
2017-01-30 06:56:47 -08:00
|
|
|
CounterTxCmd = cli.Command{
|
|
|
|
Name: "counter",
|
2017-02-07 10:16:41 -08:00
|
|
|
Usage: "Create, sign, and broadcast a transaction to the counter plugin",
|
2017-01-30 06:56:47 -08:00
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
return cmdCounterTx(c)
|
|
|
|
},
|
2017-02-07 10:16:41 -08:00
|
|
|
Flags: append(commands.TxFlags, ValidFlag),
|
2017-01-30 08:16:00 -08:00
|
|
|
}
|
2017-01-30 06:56:47 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func cmdCounterTx(c *cli.Context) error {
|
|
|
|
valid := c.Bool("valid")
|
|
|
|
|
|
|
|
counterTx := counter.CounterTx{
|
|
|
|
Valid: valid,
|
|
|
|
Fee: types.Coins{
|
|
|
|
{
|
2017-02-07 10:16:41 -08:00
|
|
|
Denom: c.String("coin"),
|
|
|
|
Amount: int64(c.Int("fee")),
|
2017-01-30 06:56:47 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("CounterTx:", string(wire.JSONBytes(counterTx)))
|
|
|
|
|
|
|
|
data := wire.BinaryBytes(counterTx)
|
|
|
|
name := "counter"
|
|
|
|
|
2017-02-07 10:16:41 -08:00
|
|
|
return commands.AppTx(c, name, data)
|
2017-01-30 06:56:47 -08:00
|
|
|
}
|