diff --git a/CHANGELOG.md b/CHANGELOG.md index fdd0e7a5840a..b32a976b7fbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ # Changelog +## 0.6.1 (TBD) + +Make lots of small cli fixes that arose when people were using the tools for +the testnet. + +IMPROVEMENTS: +- basecoin + - `basecoin start` supports all flags that `tendermint node` does, such as + `--rpc.laddr`, `--p2p.seeds`, and `--p2p.skip_upnp` + - fully supports `--log_level` and `--trace` for logger configuration +- basecli + - `basecli query account` accepts hex account address with or without `0x` + prefix + - `basecli init` is more intelligent and only complains if there really was + a connected chain, not just random files + - support `localhost:46657` or `http://localhost:46657` format for nodes, + not just `tcp://localhost:46657` + - gives error message when running commands on an unitialized chain, rather + than some unintelligable panic + - Add `--genesis` to init + - Example: `basecli init --node=localhost:46657 --genesis=$HOME/.basecoin/genesis.json` + + ## 0.6.0 (June 22, 2017) Make the basecli command the only way to use client-side, to enforce best @@ -31,7 +54,7 @@ BREAKING CHANGES: - app - Implements ABCI handshake by proxying merkleeyes.Info() -ENHANCEMENTS: +IMPROVEMENTS: - `basecoin init` support `--chain-id` - intergrates tendermint 0.10.0 (not the rc-2, but the real thing) - commands return error code (1) on failure for easier script testing @@ -60,7 +83,7 @@ BUG FIXES: BREAKING CHANGES: - only those related to the tendermint 0.9 -> 0.10 upgrade -ENHANCEMENTS: +IMPROVEMENTS: - basecoin cli - integrates tendermint 0.10.0 and unifies cli (init, unsafe_reset_all, ...) - integrate viper, all command line flags can also be defined in environmental variables or config.toml diff --git a/cmd/basecli/commands/cmds.go b/cmd/basecli/commands/cmds.go index e71a8a35fb48..d0e10e8aaed8 100644 --- a/cmd/basecli/commands/cmds.go +++ b/cmd/basecli/commands/cmds.go @@ -24,7 +24,7 @@ import ( var SendTxCmd = &cobra.Command{ Use: "send", Short: "send tokens from one account to another", - RunE: doSendTx, + RunE: commands.RequireInit(doSendTx), } //nolint @@ -47,7 +47,6 @@ func init() { // runDemo is an example of how to make a tx func doSendTx(cmd *cobra.Command, args []string) error { - // load data from json or flags tx := new(btypes.SendTx) found, err := txcmd.LoadJSON(tx) diff --git a/cmd/basecli/commands/query.go b/cmd/basecli/commands/query.go index ac17cbdd92c9..250078032db5 100644 --- a/cmd/basecli/commands/query.go +++ b/cmd/basecli/commands/query.go @@ -6,6 +6,7 @@ import ( wire "github.com/tendermint/go-wire" lc "github.com/tendermint/light-client" + lcmd "github.com/tendermint/light-client/commands" proofcmd "github.com/tendermint/light-client/commands/proofs" "github.com/tendermint/light-client/proofs" @@ -15,7 +16,7 @@ import ( var AccountQueryCmd = &cobra.Command{ Use: "account [address]", Short: "Get details of an account, with proof", - RunE: doAccountQuery, + RunE: lcmd.RequireInit(doAccountQuery), } func doAccountQuery(cmd *cobra.Command, args []string) error { diff --git a/cmd/basecoin/commands/init.go b/cmd/basecoin/commands/init.go index e9f20247ac52..cd3447b32b2b 100644 --- a/cmd/basecoin/commands/init.go +++ b/cmd/basecoin/commands/init.go @@ -7,6 +7,8 @@ import ( "path" "github.com/spf13/cobra" + + tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" ) //commands @@ -45,7 +47,7 @@ func setupFile(path, data string, perm os.FileMode) (int, error) { func initCmd(cmd *cobra.Command, args []string) error { // this will ensure that config.toml is there if not yet created, and create dir - cfg, err := getTendermintConfig() + cfg, err := tcmd.ParseConfig() if err != nil { return err } diff --git a/cmd/basecoin/commands/reset.go b/cmd/basecoin/commands/reset.go index 4d38f94bfe12..00c3d71718b8 100644 --- a/cmd/basecoin/commands/reset.go +++ b/cmd/basecoin/commands/reset.go @@ -3,7 +3,7 @@ package commands import ( "github.com/spf13/cobra" - tmcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" + tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" ) var UnsafeResetAllCmd = &cobra.Command{ @@ -13,10 +13,10 @@ var UnsafeResetAllCmd = &cobra.Command{ } func unsafeResetAllCmd(cmd *cobra.Command, args []string) error { - cfg, err := getTendermintConfig() + cfg, err := tcmd.ParseConfig() if err != nil { return err } - tmcmd.ResetAll(cfg.DBDir(), cfg.PrivValidatorFile(), logger) + tcmd.ResetAll(cfg.DBDir(), cfg.PrivValidatorFile(), logger) return nil } diff --git a/cmd/basecoin/commands/root.go b/cmd/basecoin/commands/root.go index ff70f1980710..bdcc25d728af 100644 --- a/cmd/basecoin/commands/root.go +++ b/cmd/basecoin/commands/root.go @@ -3,9 +3,39 @@ package commands import ( "os" + "github.com/spf13/cobra" + "github.com/spf13/viper" + + "github.com/tendermint/tmlibs/cli" + tmflags "github.com/tendermint/tmlibs/cli/flags" "github.com/tendermint/tmlibs/log" ) +const ( + defaultLogLevel = "error" + FlagLogLevel = "log_level" +) + var ( logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "main") ) + +var RootCmd = &cobra.Command{ + Use: "basecoin", + Short: "A cryptocurrency framework in Golang based on Tendermint-Core", + PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) { + level := viper.GetString(FlagLogLevel) + logger, err = tmflags.ParseLogLevel(level, logger, defaultLogLevel) + if err != nil { + return err + } + if viper.GetBool(cli.TraceFlag) { + logger = log.NewTracingLogger(logger) + } + return nil + }, +} + +func init() { + RootCmd.PersistentFlags().String(FlagLogLevel, defaultLogLevel, "Log level") +} diff --git a/cmd/basecoin/commands/start.go b/cmd/basecoin/commands/start.go index 33bd7e61c66a..bbcc3d84a732 100644 --- a/cmd/basecoin/commands/start.go +++ b/cmd/basecoin/commands/start.go @@ -12,10 +12,9 @@ import ( "github.com/tendermint/abci/server" eyes "github.com/tendermint/merkleeyes/client" "github.com/tendermint/tmlibs/cli" - cliflags "github.com/tendermint/tmlibs/cli/flags" cmn "github.com/tendermint/tmlibs/common" - "github.com/tendermint/tendermint/config" + tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" "github.com/tendermint/tendermint/node" "github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/types" @@ -29,38 +28,36 @@ var StartCmd = &cobra.Command{ RunE: startCmd, } -//flags -var ( - addrFlag string - eyesFlag string - dirFlag string - withoutTendermintFlag bool -) - // TODO: move to config file const EyesCacheSize = 10000 -func init() { +//nolint +const ( + FlagAddress = "address" + FlagEyes = "eyes" + FlagWithoutTendermint = "without-tendermint" +) - flags := []Flag2Register{ - {&addrFlag, "address", "tcp://0.0.0.0:46658", "Listen address"}, - {&eyesFlag, "eyes", "local", "MerkleEyes address, or 'local' for embedded"}, - {&dirFlag, "dir", ".", "Root directory"}, - {&withoutTendermintFlag, "without-tendermint", false, "Run Tendermint in-process with the App"}, - } - RegisterFlags(StartCmd, flags) +func init() { + flags := StartCmd.Flags() + flags.String(FlagAddress, "tcp://0.0.0.0:46658", "Listen address") + flags.String(FlagEyes, "local", "MerkleEyes address, or 'local' for embedded") + flags.Bool(FlagWithoutTendermint, false, "Only run basecoin abci app, assume external tendermint process") + // add all standard 'tendermint node' flags + tcmd.AddNodeFlags(StartCmd) } func startCmd(cmd *cobra.Command, args []string) error { rootDir := viper.GetString(cli.HomeFlag) + meyes := viper.GetString(FlagEyes) // Connect to MerkleEyes var eyesCli *eyes.Client - if eyesFlag == "local" { + if meyes == "local" { eyesCli = eyes.NewLocalClient(path.Join(rootDir, "data", "merkleeyes.db"), EyesCacheSize) } else { var err error - eyesCli, err = eyes.NewClient(eyesFlag) + eyesCli, err = eyes.NewClient(meyes) if err != nil { return errors.Errorf("Error connecting to MerkleEyes: %v\n", err) } @@ -94,7 +91,7 @@ func startCmd(cmd *cobra.Command, args []string) error { } chainID := basecoinApp.GetState().GetChainID() - if withoutTendermintFlag { + if viper.GetBool(FlagWithoutTendermint) { logger.Info("Starting Basecoin without Tendermint", "chain_id", chainID) // run just the abci app/server return startBasecoinABCI(basecoinApp) @@ -107,7 +104,8 @@ func startCmd(cmd *cobra.Command, args []string) error { func startBasecoinABCI(basecoinApp *app.Basecoin) error { // Start the ABCI listener - svr, err := server.NewServer(addrFlag, "socket", basecoinApp) + addr := viper.GetString(FlagAddress) + svr, err := server.NewServer(addr, "socket", basecoinApp) if err != nil { return errors.Errorf("Error creating listener: %v\n", err) } @@ -122,31 +120,15 @@ func startBasecoinABCI(basecoinApp *app.Basecoin) error { return nil } -func getTendermintConfig() (*config.Config, error) { - cfg := config.DefaultConfig() - err := viper.Unmarshal(cfg) - if err != nil { - return nil, err - } - cfg.SetRoot(cfg.RootDir) - config.EnsureRoot(cfg.RootDir) - return cfg, nil -} - func startTendermint(dir string, basecoinApp *app.Basecoin) error { - cfg, err := getTendermintConfig() - if err != nil { - return err - } - - tmLogger, err := cliflags.ParseLogLevel(cfg.LogLevel, logger, config.DefaultConfig().LogLevel) + cfg, err := tcmd.ParseConfig() if err != nil { return err } // Create & start tendermint node - privValidator := types.LoadOrGenPrivValidator(cfg.PrivValidatorFile(), tmLogger) - n := node.NewNode(cfg, privValidator, proxy.NewLocalClientCreator(basecoinApp), tmLogger.With("module", "node")) + privValidator := types.LoadOrGenPrivValidator(cfg.PrivValidatorFile(), logger) + n := node.NewNode(cfg, privValidator, proxy.NewLocalClientCreator(basecoinApp), logger.With("module", "node")) _, err = n.Start() if err != nil { diff --git a/cmd/basecoin/main.go b/cmd/basecoin/main.go index 23c46c768071..a0ce5a263041 100644 --- a/cmd/basecoin/main.go +++ b/cmd/basecoin/main.go @@ -3,19 +3,14 @@ package main import ( "os" - "github.com/spf13/cobra" - "github.com/tendermint/basecoin/cmd/basecoin/commands" "github.com/tendermint/tmlibs/cli" ) func main() { - var RootCmd = &cobra.Command{ - Use: "basecoin", - Short: "A cryptocurrency framework in Golang based on Tendermint-Core", - } + rt := commands.RootCmd - RootCmd.AddCommand( + rt.AddCommand( commands.InitCmd, commands.StartCmd, commands.RelayCmd, @@ -23,7 +18,7 @@ func main() { commands.VersionCmd, ) - cmd := cli.PrepareMainCmd(RootCmd, "BC", os.ExpandEnv("$HOME/.basecoin")) + cmd := cli.PrepareMainCmd(rt, "BC", os.ExpandEnv("$HOME/.basecoin")) if err := cmd.Execute(); err != nil { os.Exit(1) } diff --git a/glide.lock b/glide.lock index 461e15df802e..b8eed3c0623e 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: 6eb1119dccf2ab4d0adb870a14cb4408047119be53c8ec4afeaa281bd1d2b457 -updated: 2017-06-21T19:51:10.330315159+02:00 +hash: 0075efad18304d9958e655550e042eb4cbeaf78ba5fbebc5f2c5bf0b2a48910b +updated: 2017-06-26T21:33:20.786071254+02:00 imports: - name: github.com/bgentry/speakeasy version: 4aabc24848ce5fd31929f7d1e4ea74d3709c14cd @@ -32,7 +32,7 @@ imports: - name: github.com/go-stack/stack version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 - name: github.com/golang/protobuf - version: b50ceb1fa9818fa4d78b016c2d4ae025593a7ce3 + version: 18c9bb3261723cd5401db4d0c9fbc5c3b6c70fe8 subpackages: - proto - ptypes/any @@ -47,7 +47,7 @@ imports: - name: github.com/gorilla/websocket version: a91eba7f97777409bc2c443f5534d41dd20c5720 - name: github.com/hashicorp/hcl - version: a4b07c25de5ff55ad3b8936cea69a79a3d95a855 + version: 392dba7d905ed5d04a5794ba89f558b27e2ba1ca subpackages: - hcl/ast - hcl/parser @@ -82,11 +82,11 @@ imports: - name: github.com/spf13/cast version: acbeb36b902d72a7a4c18e8f3241075e7ab763e4 - name: github.com/spf13/cobra - version: db6b9a8b3f3f400c8ecb4a4d7d02245b8facad66 + version: 4cdb38c072b86bf795d2c81de50784d9fdd6eb77 - name: github.com/spf13/jwalterweatherman - version: fa7ca7e836cf3a8bb4ebf799f472c12d7e903d66 + version: 8f07c835e5cc1450c082fe3a439cf87b0cbb2d99 - name: github.com/spf13/pflag - version: 80fe0fb4eba54167e2ccae1c6c950e72abf61b73 + version: e57e3eeb33f795204c1ca35f56c44f83227c6e66 - name: github.com/spf13/viper version: 0967fc9aceab2ce9da34061253ac10fb99bba5b2 - name: github.com/syndtr/goleveldb @@ -117,7 +117,7 @@ imports: - edwards25519 - extra25519 - name: github.com/tendermint/go-crypto - version: ad70b2222698a2018c4bf18bab86f3727621f492 + version: d31cfbaeaa4d930798ec327b52917975f3203c11 subpackages: - cmd - keys @@ -132,7 +132,7 @@ imports: - data - data/base58 - name: github.com/tendermint/light-client - version: b66b57d193d2fdeda7b999aebfdc9531cbee39b0 + version: bf3063db6253fc2e9a837eda38de4a26da299bcb subpackages: - certifiers - certifiers/client @@ -150,7 +150,7 @@ imports: - client - iavl - name: github.com/tendermint/tendermint - version: 4f0f50c62d41d39ad64e07ad642f705cc13c8229 + version: e4caf96bcb1ab80fc3b5dca4c9a8f0648653929b subpackages: - blockchain - cmd/tendermint/commands @@ -176,7 +176,7 @@ imports: - types - version - name: github.com/tendermint/tmlibs - version: bd9d0d1637dadf1330e167189d5e5031aadcda6f + version: efb56aaea7517220bb3f42ff87b8004d554a17ff subpackages: - autofile - cli @@ -201,7 +201,7 @@ imports: - ripemd160 - salsa20/salsa - name: golang.org/x/net - version: c9b681d35165f1995d6f3034e61f8761d4b90c99 + version: feeb485667d1fdabe727840fe00adc22431bc86e subpackages: - context - http2 @@ -211,7 +211,7 @@ imports: - lex/httplex - trace - name: golang.org/x/sys - version: 9ccfe848b9db8435a24c424abbc07a921adf1df5 + version: e62c3de784db939836898e5c19ffd41bece347da subpackages: - unix - name: golang.org/x/text @@ -226,7 +226,7 @@ imports: subpackages: - googleapis/rpc/status - name: google.golang.org/grpc - version: a0c3e72252b6fbf4826bb143e450eb05588a9d6d + version: 844f573616520565fdc6fb4db242321b5456fd6d subpackages: - codes - credentials diff --git a/glide.yaml b/glide.yaml index 7e7727aac488..233ff148a7b4 100644 --- a/glide.yaml +++ b/glide.yaml @@ -35,7 +35,7 @@ import: - client - iavl - package: github.com/tendermint/tendermint - version: develop + version: feature/554-embed-commands subpackages: - config - node diff --git a/tests/cli/basictx.sh b/tests/cli/basictx.sh index 58f27ceba7e4..70f614b8c5be 100755 --- a/tests/cli/basictx.sh +++ b/tests/cli/basictx.sh @@ -23,7 +23,7 @@ test00GetAccount() { checkAccount $SENDER "0" "9007199254740992" - ACCT2=$(${CLIENT_EXE} query account $RECV) + ACCT2=$(${CLIENT_EXE} query account $RECV 2>/dev/null) assertFalse "has no genesis account" $? } @@ -39,6 +39,8 @@ test01SendTx() { TX_HEIGHT=$(echo $TX | jq .height) checkAccount $SENDER "1" "9007199254740000" + # make sure 0x prefix also works + checkAccount "0x$SENDER" "1" "9007199254740000" checkAccount $RECV "0" "992" # Make sure tx is indexed diff --git a/tests/cli/common.sh b/tests/cli/common.sh index 576bef0a48a9..8d7afd185e89 100644 --- a/tests/cli/common.sh +++ b/tests/cli/common.sh @@ -127,7 +127,7 @@ getAddr() { checkAccount() { # make sure sender goes down ACCT=$(${CLIENT_EXE} query account $1) - if ! assertTrue "account must exist: $ACCT" $?; then + if ! assertTrue "account must exist" $?; then return 1 fi diff --git a/tests/cli/counter.sh b/tests/cli/counter.sh index 28ade7466c14..1b8492df5209 100755 --- a/tests/cli/counter.sh +++ b/tests/cli/counter.sh @@ -23,7 +23,7 @@ test00GetAccount() { checkAccount $SENDER "0" "9007199254740992" - ACCT2=$(${CLIENT_EXE} query account $RECV) + ACCT2=$(${CLIENT_EXE} query account $RECV 2>/dev/null) assertFalse "has no genesis account" $? } @@ -46,7 +46,7 @@ test01SendTx() { } test02GetCounter() { - COUNT=$(${CLIENT_EXE} query counter) + COUNT=$(${CLIENT_EXE} query counter 2>/dev/null) assertFalse "no default count" $? } diff --git a/tests/cli/ibc.sh b/tests/cli/ibc.sh index 9819f5d87db5..ba2fcc9d79b6 100755 --- a/tests/cli/ibc.sh +++ b/tests/cli/ibc.sh @@ -66,16 +66,16 @@ test00GetAccount() { RECV_1=$(BC_HOME=${CLIENT_1} getAddr $POOR) export BC_HOME=${CLIENT_1} - assertFalse "requires arg" "${CLIENT_EXE} query account" - assertFalse "has no genesis account" "${CLIENT_EXE} query account $RECV_1" + assertFalse "requires arg" "${CLIENT_EXE} query account 2>/dev/null" + assertFalse "has no genesis account" "${CLIENT_EXE} query account $RECV_1 2>/dev/null" checkAccount $SENDER_1 "0" "9007199254740992" export BC_HOME=${CLIENT_2} SENDER_2=$(getAddr $RICH) RECV_2=$(getAddr $POOR) - assertFalse "requires arg" "${CLIENT_EXE} query account" - assertFalse "has no genesis account" "${CLIENT_EXE} query account $RECV_2" + assertFalse "requires arg" "${CLIENT_EXE} query account 2>/dev/null" + assertFalse "has no genesis account" "${CLIENT_EXE} query account $RECV_2 2>/dev/null" checkAccount $SENDER_2 "0" "9007199254740992" # Make sure that they have different addresses on both chains (they are random keys)