cmd: fix some serialization

This commit is contained in:
Ethan Buchman 2017-01-29 20:06:14 -08:00
parent 530694f93c
commit e69395c01f
5 changed files with 50 additions and 24 deletions

View File

@ -19,7 +19,8 @@ var (
genesisFlag, genesisFlag,
inProcTMFlag, inProcTMFlag,
chainIDFlag, chainIDFlag,
pluginFlag, ibcPluginFlag,
counterPluginFlag,
}, },
} }
@ -89,6 +90,18 @@ var (
Usage: "Send a transaction to the interblockchain (ibc) plugin", Usage: "Send a transaction to the interblockchain (ibc) plugin",
Flags: []cli.Flag{ Flags: []cli.Flag{
nodeFlag, nodeFlag,
chainIDFlag,
fromFlag,
amountFlag,
coinFlag,
gasFlag,
feeFlag,
seqFlag,
nameFlag,
dataFlag,
}, },
Subcommands: []cli.Command{ Subcommands: []cli.Command{
ibcRegisterTxCmd, ibcRegisterTxCmd,

View File

@ -38,10 +38,14 @@ var (
Usage: "Run Tendermint in-process with the App", Usage: "Run Tendermint in-process with the App",
} }
pluginFlag = cli.StringFlag{ ibcPluginFlag = cli.BoolFlag{
Name: "plugin", Name: "ibc-plugin",
Value: "counter", // load the counter by default Usage: "Enable the ibc plugin",
Usage: "Plugin to enable", }
counterPluginFlag = cli.BoolFlag{
Name: "counter-plugin",
Usage: "Enable the counter plugin",
} }
) )

View File

@ -35,8 +35,10 @@ func cmdIBCRegisterTx(c *cli.Context) error {
fmt.Println("IBCTx:", string(wire.JSONBytes(ibcTx))) fmt.Println("IBCTx:", string(wire.JSONBytes(ibcTx)))
data := wire.BinaryBytes(ibcTx) data := []byte(wire.BinaryBytes(struct {
name := "ibc" ibc.IBCTx `json:"unwrap"`
}{ibcTx}))
name := "IBC"
return appTx(parent, name, data) return appTx(parent, name, data)
} }
@ -53,8 +55,8 @@ func cmdIBCUpdateTx(c *cli.Context) error {
return errors.New(cmn.Fmt("Commit (%v) is invalid hex: %v", c.String("commit"), err)) return errors.New(cmn.Fmt("Commit (%v) is invalid hex: %v", c.String("commit"), err))
} }
var header tmtypes.Header header := new(tmtypes.Header)
var commit tmtypes.Commit commit := new(tmtypes.Commit)
if err := wire.ReadBinaryBytes(headerBytes, &header); err != nil { if err := wire.ReadBinaryBytes(headerBytes, &header); err != nil {
return errors.New(cmn.Fmt("Error unmarshalling header: %v", err)) return errors.New(cmn.Fmt("Error unmarshalling header: %v", err))
@ -64,14 +66,16 @@ func cmdIBCUpdateTx(c *cli.Context) error {
} }
ibcTx := ibc.IBCUpdateChainTx{ ibcTx := ibc.IBCUpdateChainTx{
Header: header, Header: *header,
Commit: commit, Commit: *commit,
} }
fmt.Println("IBCTx:", string(wire.JSONBytes(ibcTx))) fmt.Println("IBCTx:", string(wire.JSONBytes(ibcTx)))
data := wire.BinaryBytes(ibcTx) data := []byte(wire.BinaryBytes(struct {
name := "ibc" ibc.IBCTx `json:"unwrap"`
}{ibcTx}))
name := "IBC"
return appTx(parent, name, data) return appTx(parent, name, data)
} }
@ -102,9 +106,11 @@ func cmdIBCPacketCreateTx(c *cli.Context) error {
fmt.Println("IBCTx:", string(wire.JSONBytes(ibcTx))) fmt.Println("IBCTx:", string(wire.JSONBytes(ibcTx)))
data := wire.BinaryBytes(ibcTx) data := []byte(wire.BinaryBytes(struct {
ibc.IBCTx `json:"unwrap"`
}{ibcTx}))
return appTx(c.Parent(), "ibc", data) return appTx(c.Parent(), "IBC", data)
} }
func cmdIBCPacketPostTx(c *cli.Context) error { func cmdIBCPacketPostTx(c *cli.Context) error {
@ -138,9 +144,11 @@ func cmdIBCPacketPostTx(c *cli.Context) error {
fmt.Println("IBCTx:", string(wire.JSONBytes(ibcTx))) fmt.Println("IBCTx:", string(wire.JSONBytes(ibcTx)))
data := wire.BinaryBytes(ibcTx) data := []byte(wire.BinaryBytes(struct {
ibc.IBCTx `json:"unwrap"`
}{ibcTx}))
return appTx(c.Parent(), "ibc", data) return appTx(c.Parent(), "IBC", data)
} }
func getIBCSequence(c *cli.Context) (uint64, error) { func getIBCSequence(c *cli.Context) (uint64, error) {

View File

@ -18,6 +18,7 @@ import (
"github.com/tendermint/basecoin/app" "github.com/tendermint/basecoin/app"
"github.com/tendermint/basecoin/plugins/counter" "github.com/tendermint/basecoin/plugins/counter"
"github.com/tendermint/basecoin/plugins/ibc"
) )
var config cfg.Config var config cfg.Config
@ -41,13 +42,13 @@ func cmdStart(c *cli.Context) error {
// Create Basecoin app // Create Basecoin app
basecoinApp := app.NewBasecoin(eyesCli) basecoinApp := app.NewBasecoin(eyesCli)
switch c.String("plugin") { if c.Bool("counter-plugin") {
case "counter":
basecoinApp.RegisterPlugin(counter.New("counter")) basecoinApp.RegisterPlugin(counter.New("counter"))
case "": }
// no plugins to register
default: if c.Bool("ibc-plugin") {
return errors.New(cmn.Fmt("Unknown plugin: %v", c.String("plugin"))) basecoinApp.RegisterPlugin(ibc.New())
} }
// If genesis file was specified, set key-value options // If genesis file was specified, set key-value options

View File

@ -154,7 +154,7 @@ func (ibc *IBCPlugin) RunTx(store types.KVStore, ctx types.CallContext, txBytes
var tx IBCTx var tx IBCTx
err := wire.ReadBinaryBytes(txBytes, &tx) err := wire.ReadBinaryBytes(txBytes, &tx)
if err != nil { if err != nil {
return abci.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error()) return abci.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error()).PrependLog("IBCTx Error: ")
} }
// Validate tx // Validate tx