From 558df7da151b22d866caa7565d95ea63cc7bd6c6 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Mon, 13 Feb 2017 17:04:49 -0500 Subject: [PATCH] enable ibc by default --- app/app.go | 12 +++++++----- app/genesis.go | 2 +- cmd/basecoin/main.go | 4 ++-- cmd/commands/ibc.go | 12 +++++------- cmd/commands/start.go | 9 +++++++-- cmd/commands/tx.go | 5 +++-- state/execution.go | 4 ++-- 7 files changed, 27 insertions(+), 21 deletions(-) diff --git a/app/app.go b/app/app.go index 59f900347..54d9d22d0 100644 --- a/app/app.go +++ b/app/app.go @@ -51,14 +51,15 @@ func (app *Basecoin) RegisterPlugin(plugin types.Plugin) { } // ABCI::SetOption -func (app *Basecoin) SetOption(key string, value string) (log string) { - PluginName, key := splitKey(key) - if PluginName != PluginNameBase { +func (app *Basecoin) SetOption(key string, value string) string { + pluginName, key := splitKey(key) + if pluginName != PluginNameBase { // Set option on plugin - plugin := app.plugins.GetByName(PluginName) + plugin := app.plugins.GetByName(pluginName) if plugin == nil { - return "Invalid plugin name: " + PluginName + return "Invalid plugin name: " + pluginName } + log.Info("SetOption on plugin", "plugin", pluginName, "key", key, "value", value) return plugin.SetOption(app.state, key, value) } else { // Set option on basecoin @@ -74,6 +75,7 @@ func (app *Basecoin) SetOption(key string, value string) (log string) { return "Error decoding acc message: " + err.Error() } app.state.SetAccount(acc.PubKey.Address(), acc) + log.Info("SetAccount", "addr", acc.PubKey.Address(), "acc", acc) return "Success" } return "Unrecognized option key " + key diff --git a/app/genesis.go b/app/genesis.go index 93848c893..6933780b3 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -17,7 +17,7 @@ func (app *Basecoin) LoadGenesis(path string) error { for _, kv := range kvz { log := app.SetOption(kv.Key, kv.Value) // TODO: remove debug output - fmt.Printf("Set %v=%v. Log: %v", kv.Key, kv.Value, log) + fmt.Printf("Set %v=%v. Log: %v\n", kv.Key, kv.Value, log) } return nil } diff --git a/cmd/basecoin/main.go b/cmd/basecoin/main.go index 77f9827fd..8a39a4902 100644 --- a/cmd/basecoin/main.go +++ b/cmd/basecoin/main.go @@ -17,8 +17,8 @@ func main() { commands.TxCmd, commands.QueryCmd, commands.KeyCmd, - commands.VerifyCmd, // TODO: move to merkleeyes? - commands.BlockCmd, // TODO: move to adam? + commands.VerifyCmd, + commands.BlockCmd, commands.AccountCmd, } app.Run(os.Args) diff --git a/cmd/commands/ibc.go b/cmd/commands/ibc.go index f8d0e0b61..34f4b7923 100644 --- a/cmd/commands/ibc.go +++ b/cmd/commands/ibc.go @@ -9,7 +9,6 @@ import ( "github.com/urfave/cli" "github.com/tendermint/basecoin/plugins/ibc" - "github.com/tendermint/basecoin/types" cmn "github.com/tendermint/go-common" "github.com/tendermint/go-merkle" @@ -17,10 +16,9 @@ import ( tmtypes "github.com/tendermint/tendermint/types" ) -// Register the IBC plugin at start and for transactions -func RegisterIBC() { - RegisterTxSubcommand(IbcCmd) - RegisterStartPlugin("ibc", func() types.Plugin { return ibc.New() }) +// returns a new IBC plugin to be registered with Basecoin +func NewIBCPlugin() *ibc.IBCPlugin { + return ibc.New() } //--------------------------------------------------------------------- @@ -104,9 +102,9 @@ var ( // ibc commands var ( - IbcCmd = cli.Command{ + IbcTxCmd = cli.Command{ Name: "ibc", - Usage: "Send a transaction to the interblockchain (ibc) plugin", + Usage: "an IBC transaction, for InterBlockchain Communication", Flags: TxFlags, Subcommands: []cli.Command{ IbcRegisterTxCmd, diff --git a/cmd/commands/start.go b/cmd/commands/start.go index 16e47fa60..72a13107d 100644 --- a/cmd/commands/start.go +++ b/cmd/commands/start.go @@ -72,7 +72,10 @@ func cmdStart(c *cli.Context) error { // Create Basecoin app basecoinApp := app.NewBasecoin(eyesCli) - // register all plugins + // register IBC plugn + basecoinApp.RegisterPlugin(NewIBCPlugin()) + + // register all other plugins for _, p := range plugins { basecoinApp.RegisterPlugin(p.newPlugin()) } @@ -91,7 +94,9 @@ func cmdStart(c *cli.Context) error { if c.Bool("in-proc") { startTendermint(c, basecoinApp) } else { - startBasecoinABCI(c, basecoinApp) + if err := startBasecoinABCI(c, basecoinApp); err != nil { + return err + } } return nil diff --git a/cmd/commands/tx.go b/cmd/commands/tx.go index 9b8ce21cd..d2185609c 100644 --- a/cmd/commands/tx.go +++ b/cmd/commands/tx.go @@ -37,12 +37,13 @@ var ( Subcommands: []cli.Command{ SendTxCmd, AppTxCmd, + IbcTxCmd, }, } SendTxCmd = cli.Command{ Name: "send", - Usage: "Create, sign, and broadcast a SendTx transaction", + Usage: "a SendTx transaction, for sending tokens around", ArgsUsage: "", Action: func(c *cli.Context) error { return cmdSendTx(c) @@ -52,7 +53,7 @@ var ( AppTxCmd = cli.Command{ Name: "app", - Usage: "Create, sign, and broadcast a raw AppTx transaction", + Usage: "an AppTx transaction, for sending raw data to plugins", ArgsUsage: "", Action: func(c *cli.Context) error { return cmdAppTx(c) diff --git a/state/execution.go b/state/execution.go index 6e722bdc9..0b464c45a 100644 --- a/state/execution.go +++ b/state/execution.go @@ -95,7 +95,7 @@ func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc e } if !tx.Input.Coins.IsGTE(types.Coins{tx.Fee}) { log.Info(Fmt("Sender did not send enough to cover the fee %X", tx.Input.Address)) - return abci.ErrBaseInsufficientFunds + return abci.ErrBaseInsufficientFunds.AppendLog(Fmt("input coins is %d, but fee is %d", tx.Input.Coins, types.Coins{tx.Fee})) } // Validate call address @@ -238,7 +238,7 @@ func validateInputAdvanced(acc *types.Account, signBytes []byte, in types.TxInpu } // Check amount if !balance.IsGTE(in.Coins) { - return abci.ErrBaseInsufficientFunds + return abci.ErrBaseInsufficientFunds.AppendLog(Fmt("balance is %d, tried to send %d", balance, in.Coins)) } // Check signatures if !acc.PubKey.VerifyBytes(signBytes, in.Signature) {