From e69395c01fec38e174d11aec3718e7a5831a075f Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 29 Jan 2017 20:06:14 -0800 Subject: [PATCH] cmd: fix some serialization --- cmd/basecoin/cmd.go | 15 ++++++++++++++- cmd/basecoin/flags.go | 12 ++++++++---- cmd/basecoin/ibc.go | 32 ++++++++++++++++++++------------ cmd/basecoin/start.go | 13 +++++++------ plugins/ibc/ibc.go | 2 +- 5 files changed, 50 insertions(+), 24 deletions(-) diff --git a/cmd/basecoin/cmd.go b/cmd/basecoin/cmd.go index 6cb56d30e8..e5fb7d2a42 100644 --- a/cmd/basecoin/cmd.go +++ b/cmd/basecoin/cmd.go @@ -19,7 +19,8 @@ var ( genesisFlag, inProcTMFlag, chainIDFlag, - pluginFlag, + ibcPluginFlag, + counterPluginFlag, }, } @@ -89,6 +90,18 @@ var ( Usage: "Send a transaction to the interblockchain (ibc) plugin", Flags: []cli.Flag{ nodeFlag, + chainIDFlag, + + fromFlag, + + amountFlag, + coinFlag, + gasFlag, + feeFlag, + seqFlag, + + nameFlag, + dataFlag, }, Subcommands: []cli.Command{ ibcRegisterTxCmd, diff --git a/cmd/basecoin/flags.go b/cmd/basecoin/flags.go index dd454c53eb..7e349933f9 100644 --- a/cmd/basecoin/flags.go +++ b/cmd/basecoin/flags.go @@ -38,10 +38,14 @@ var ( Usage: "Run Tendermint in-process with the App", } - pluginFlag = cli.StringFlag{ - Name: "plugin", - Value: "counter", // load the counter by default - Usage: "Plugin to enable", + ibcPluginFlag = cli.BoolFlag{ + Name: "ibc-plugin", + Usage: "Enable the ibc plugin", + } + + counterPluginFlag = cli.BoolFlag{ + Name: "counter-plugin", + Usage: "Enable the counter plugin", } ) diff --git a/cmd/basecoin/ibc.go b/cmd/basecoin/ibc.go index 39c32b2c8b..a991e28fd1 100644 --- a/cmd/basecoin/ibc.go +++ b/cmd/basecoin/ibc.go @@ -35,8 +35,10 @@ func cmdIBCRegisterTx(c *cli.Context) error { fmt.Println("IBCTx:", string(wire.JSONBytes(ibcTx))) - data := wire.BinaryBytes(ibcTx) - name := "ibc" + data := []byte(wire.BinaryBytes(struct { + ibc.IBCTx `json:"unwrap"` + }{ibcTx})) + name := "IBC" 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)) } - var header tmtypes.Header - var commit tmtypes.Commit + header := new(tmtypes.Header) + commit := new(tmtypes.Commit) if err := wire.ReadBinaryBytes(headerBytes, &header); err != nil { return errors.New(cmn.Fmt("Error unmarshalling header: %v", err)) @@ -64,14 +66,16 @@ func cmdIBCUpdateTx(c *cli.Context) error { } ibcTx := ibc.IBCUpdateChainTx{ - Header: header, - Commit: commit, + Header: *header, + Commit: *commit, } fmt.Println("IBCTx:", string(wire.JSONBytes(ibcTx))) - data := wire.BinaryBytes(ibcTx) - name := "ibc" + data := []byte(wire.BinaryBytes(struct { + ibc.IBCTx `json:"unwrap"` + }{ibcTx})) + name := "IBC" return appTx(parent, name, data) } @@ -102,9 +106,11 @@ func cmdIBCPacketCreateTx(c *cli.Context) error { 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 { @@ -138,9 +144,11 @@ func cmdIBCPacketPostTx(c *cli.Context) error { 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) { diff --git a/cmd/basecoin/start.go b/cmd/basecoin/start.go index e483737a4d..687685d12b 100644 --- a/cmd/basecoin/start.go +++ b/cmd/basecoin/start.go @@ -18,6 +18,7 @@ import ( "github.com/tendermint/basecoin/app" "github.com/tendermint/basecoin/plugins/counter" + "github.com/tendermint/basecoin/plugins/ibc" ) var config cfg.Config @@ -41,13 +42,13 @@ func cmdStart(c *cli.Context) error { // Create Basecoin app basecoinApp := app.NewBasecoin(eyesCli) - switch c.String("plugin") { - case "counter": + if c.Bool("counter-plugin") { basecoinApp.RegisterPlugin(counter.New("counter")) - case "": - // no plugins to register - default: - return errors.New(cmn.Fmt("Unknown plugin: %v", c.String("plugin"))) + } + + if c.Bool("ibc-plugin") { + basecoinApp.RegisterPlugin(ibc.New()) + } // If genesis file was specified, set key-value options diff --git a/plugins/ibc/ibc.go b/plugins/ibc/ibc.go index 087f336d91..ce4bf3ccde 100644 --- a/plugins/ibc/ibc.go +++ b/plugins/ibc/ibc.go @@ -154,7 +154,7 @@ func (ibc *IBCPlugin) RunTx(store types.KVStore, ctx types.CallContext, txBytes var tx IBCTx err := wire.ReadBinaryBytes(txBytes, &tx) 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