2017-01-30 06:56:47 -08:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/tendermint/basecoin/plugins/counter"
|
|
|
|
"github.com/tendermint/basecoin/types"
|
|
|
|
wire "github.com/tendermint/go-wire"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
CounterTxCmd = cli.Command{
|
|
|
|
Name: "counter",
|
|
|
|
Usage: "Craft a transaction to the counter plugin",
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
return cmdCounterTx(c)
|
|
|
|
},
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
ValidFlag,
|
|
|
|
},
|
|
|
|
}
|
2017-01-30 08:16:00 -08:00
|
|
|
|
|
|
|
CounterPluginFlag = cli.BoolFlag{
|
|
|
|
Name: "counter-plugin",
|
|
|
|
Usage: "Enable the counter plugin",
|
|
|
|
}
|
2017-01-30 06:56:47 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2017-01-30 08:16:00 -08:00
|
|
|
RegisterTxPlugin(CounterTxCmd)
|
|
|
|
RegisterStartPlugin(CounterPluginFlag,
|
|
|
|
func() types.Plugin { return counter.New("counter") })
|
2017-01-30 06:56:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func cmdCounterTx(c *cli.Context) error {
|
|
|
|
valid := c.Bool("valid")
|
|
|
|
parent := c.Parent()
|
|
|
|
|
|
|
|
counterTx := counter.CounterTx{
|
|
|
|
Valid: valid,
|
|
|
|
Fee: types.Coins{
|
|
|
|
{
|
|
|
|
Denom: parent.String("coin"),
|
|
|
|
Amount: int64(parent.Int("fee")),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("CounterTx:", string(wire.JSONBytes(counterTx)))
|
|
|
|
|
|
|
|
data := wire.BinaryBytes(counterTx)
|
|
|
|
name := "counter"
|
|
|
|
|
|
|
|
return AppTx(parent, name, data)
|
|
|
|
}
|