Merge pull request #784 from cosmos/cwgoes/more-cli-fixes
More CLI fixes
This commit is contained in:
commit
e90805436a
|
@ -7,9 +7,13 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
|
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||||
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
"github.com/tendermint/tmlibs/cli"
|
"github.com/tendermint/tmlibs/cli"
|
||||||
|
tmflags "github.com/tendermint/tmlibs/cli/flags"
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
dbm "github.com/tendermint/tmlibs/db"
|
dbm "github.com/tendermint/tmlibs/db"
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
|
@ -21,9 +25,31 @@ import (
|
||||||
|
|
||||||
// basecoindCmd is the entry point for this binary
|
// basecoindCmd is the entry point for this binary
|
||||||
var (
|
var (
|
||||||
|
context = server.NewContext(nil, nil)
|
||||||
basecoindCmd = &cobra.Command{
|
basecoindCmd = &cobra.Command{
|
||||||
Use: "gaiad",
|
Use: "gaiad",
|
||||||
Short: "Gaia Daemon (server)",
|
Short: "Gaia Daemon (server)",
|
||||||
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if cmd.Name() == version.VersionCmd.Name() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
config, err := tcmd.ParseConfig()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
|
||||||
|
logger, err = tmflags.ParseLogLevel(config.LogLevel, logger, cfg.DefaultLogLevel())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if viper.GetBool(cli.TraceFlag) {
|
||||||
|
logger = log.NewTracingLogger(logger)
|
||||||
|
}
|
||||||
|
logger = logger.With("module", "main")
|
||||||
|
context.Config = config
|
||||||
|
context.Logger = logger
|
||||||
|
return nil
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -76,16 +102,12 @@ func generateApp(rootDir string, logger log.Logger) (abci.Application, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// TODO: set logger through CLI
|
|
||||||
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).
|
|
||||||
With("module", "main")
|
|
||||||
|
|
||||||
basecoindCmd.AddCommand(
|
basecoindCmd.AddCommand(
|
||||||
server.InitCmd(defaultOptions, logger),
|
server.InitCmd(defaultOptions, context),
|
||||||
server.StartCmd(generateApp, logger),
|
server.StartCmd(generateApp, context),
|
||||||
server.UnsafeResetAllCmd(logger),
|
server.UnsafeResetAllCmd(context),
|
||||||
server.ShowNodeIdCmd(logger),
|
server.ShowNodeIdCmd(context),
|
||||||
server.ShowValidatorCmd(logger),
|
server.ShowValidatorCmd(context),
|
||||||
version.VersionCmd,
|
version.VersionCmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,13 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
|
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||||
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
"github.com/tendermint/tmlibs/cli"
|
"github.com/tendermint/tmlibs/cli"
|
||||||
|
tmflags "github.com/tendermint/tmlibs/cli/flags"
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
dbm "github.com/tendermint/tmlibs/db"
|
dbm "github.com/tendermint/tmlibs/db"
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
|
@ -21,9 +25,31 @@ import (
|
||||||
|
|
||||||
// democoindCmd is the entry point for this binary
|
// democoindCmd is the entry point for this binary
|
||||||
var (
|
var (
|
||||||
|
context = server.NewContext(nil, nil)
|
||||||
democoindCmd = &cobra.Command{
|
democoindCmd = &cobra.Command{
|
||||||
Use: "democoind",
|
Use: "democoind",
|
||||||
Short: "Gaia Daemon (server)",
|
Short: "Gaia Daemon (server)",
|
||||||
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if cmd.Name() == version.VersionCmd.Name() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
config, err := tcmd.ParseConfig()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
|
||||||
|
logger, err = tmflags.ParseLogLevel(config.LogLevel, logger, cfg.DefaultLogLevel())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if viper.GetBool(cli.TraceFlag) {
|
||||||
|
logger = log.NewTracingLogger(logger)
|
||||||
|
}
|
||||||
|
logger = logger.With("module", "main")
|
||||||
|
context.Config = config
|
||||||
|
context.Logger = logger
|
||||||
|
return nil
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -82,16 +108,12 @@ func generateApp(rootDir string, logger log.Logger) (abci.Application, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// TODO: set logger through CLI
|
|
||||||
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).
|
|
||||||
With("module", "main")
|
|
||||||
|
|
||||||
democoindCmd.AddCommand(
|
democoindCmd.AddCommand(
|
||||||
server.InitCmd(defaultOptions, logger),
|
server.InitCmd(defaultOptions, context),
|
||||||
server.StartCmd(generateApp, logger),
|
server.StartCmd(generateApp, context),
|
||||||
server.UnsafeResetAllCmd(logger),
|
server.UnsafeResetAllCmd(context),
|
||||||
server.ShowNodeIdCmd(logger),
|
server.ShowNodeIdCmd(context),
|
||||||
server.ShowValidatorCmd(logger),
|
server.ShowValidatorCmd(context),
|
||||||
version.VersionCmd,
|
version.VersionCmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,13 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
|
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||||
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
"github.com/tendermint/tmlibs/cli"
|
"github.com/tendermint/tmlibs/cli"
|
||||||
|
tmflags "github.com/tendermint/tmlibs/cli/flags"
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
|
|
||||||
|
@ -19,9 +23,31 @@ import (
|
||||||
|
|
||||||
// gaiadCmd is the entry point for this binary
|
// gaiadCmd is the entry point for this binary
|
||||||
var (
|
var (
|
||||||
|
context = server.NewContext(nil, nil)
|
||||||
gaiadCmd = &cobra.Command{
|
gaiadCmd = &cobra.Command{
|
||||||
Use: "gaiad",
|
Use: "gaiad",
|
||||||
Short: "Gaia Daemon (server)",
|
Short: "Gaia Daemon (server)",
|
||||||
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if cmd.Name() == version.VersionCmd.Name() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
config, err := tcmd.ParseConfig()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
|
||||||
|
logger, err = tmflags.ParseLogLevel(config.LogLevel, logger, cfg.DefaultLogLevel())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if viper.GetBool(cli.TraceFlag) {
|
||||||
|
logger = log.NewTracingLogger(logger)
|
||||||
|
}
|
||||||
|
logger = logger.With("module", "main")
|
||||||
|
context.Config = config
|
||||||
|
context.Logger = logger
|
||||||
|
return nil
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -56,13 +82,10 @@ func generateApp(rootDir string, logger log.Logger) (abci.Application, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).
|
|
||||||
With("module", "main")
|
|
||||||
|
|
||||||
gaiadCmd.AddCommand(
|
gaiadCmd.AddCommand(
|
||||||
server.InitCmd(defaultOptions, logger),
|
server.InitCmd(defaultOptions, context),
|
||||||
server.StartCmd(generateApp, logger),
|
server.StartCmd(generateApp, context),
|
||||||
server.UnsafeResetAllCmd(logger),
|
server.UnsafeResetAllCmd(context),
|
||||||
version.VersionCmd,
|
version.VersionCmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
|
"github.com/tendermint/tmlibs/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Context struct {
|
||||||
|
Config *cfg.Config
|
||||||
|
Logger log.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewContext(config *cfg.Config, logger log.Logger) *Context {
|
||||||
|
return &Context{config, logger}
|
||||||
|
}
|
|
@ -7,13 +7,10 @@ import (
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
|
||||||
"github.com/tendermint/tmlibs/log"
|
|
||||||
|
|
||||||
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testnetInformation struct {
|
type testnetInformation struct {
|
||||||
|
@ -29,10 +26,10 @@ type testnetInformation struct {
|
||||||
// The application can pass in a function to generate
|
// The application can pass in a function to generate
|
||||||
// proper state. And may want to use GenerateCoinKey
|
// proper state. And may want to use GenerateCoinKey
|
||||||
// to create default account(s).
|
// to create default account(s).
|
||||||
func InitCmd(gen GenAppState, logger log.Logger) *cobra.Command {
|
func InitCmd(gen GenAppState, ctx *Context) *cobra.Command {
|
||||||
cmd := initCmd{
|
cmd := initCmd{
|
||||||
genAppState: gen,
|
genAppState: gen,
|
||||||
logger: logger,
|
context: ctx,
|
||||||
}
|
}
|
||||||
cobraCmd := cobra.Command{
|
cobraCmd := cobra.Command{
|
||||||
Use: "init",
|
Use: "init",
|
||||||
|
@ -50,7 +47,7 @@ type GenAppState func(args []string) (json.RawMessage, string, cmn.HexBytes, err
|
||||||
|
|
||||||
type initCmd struct {
|
type initCmd struct {
|
||||||
genAppState GenAppState
|
genAppState GenAppState
|
||||||
logger log.Logger
|
context *Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c initCmd) run(cmd *cobra.Command, args []string) error {
|
func (c initCmd) run(cmd *cobra.Command, args []string) error {
|
||||||
|
@ -59,11 +56,8 @@ func (c initCmd) run(cmd *cobra.Command, args []string) error {
|
||||||
|
|
||||||
// Run the basic tendermint initialization,
|
// Run the basic tendermint initialization,
|
||||||
// set up a default genesis with no app_options
|
// set up a default genesis with no app_options
|
||||||
config, err := tcmd.ParseConfig()
|
config := c.context.Config
|
||||||
if err != nil {
|
err := c.initTendermintFiles(config, &testnetInfo)
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = c.initTendermintFiles(config, &testnetInfo)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -109,17 +103,17 @@ func (c initCmd) initTendermintFiles(config *cfg.Config, info *testnetInformatio
|
||||||
var privValidator *tmtypes.PrivValidatorFS
|
var privValidator *tmtypes.PrivValidatorFS
|
||||||
if cmn.FileExists(privValFile) {
|
if cmn.FileExists(privValFile) {
|
||||||
privValidator = tmtypes.LoadPrivValidatorFS(privValFile)
|
privValidator = tmtypes.LoadPrivValidatorFS(privValFile)
|
||||||
c.logger.Info("Found private validator", "path", privValFile)
|
c.context.Logger.Info("Found private validator", "path", privValFile)
|
||||||
} else {
|
} else {
|
||||||
privValidator = tmtypes.GenPrivValidatorFS(privValFile)
|
privValidator = tmtypes.GenPrivValidatorFS(privValFile)
|
||||||
privValidator.Save()
|
privValidator.Save()
|
||||||
c.logger.Info("Generated private validator", "path", privValFile)
|
c.context.Logger.Info("Generated private validator", "path", privValFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// genesis file
|
// genesis file
|
||||||
genFile := config.GenesisFile()
|
genFile := config.GenesisFile()
|
||||||
if cmn.FileExists(genFile) {
|
if cmn.FileExists(genFile) {
|
||||||
c.logger.Info("Found genesis file", "path", genFile)
|
c.context.Logger.Info("Found genesis file", "path", genFile)
|
||||||
} else {
|
} else {
|
||||||
genDoc := tmtypes.GenesisDoc{
|
genDoc := tmtypes.GenesisDoc{
|
||||||
ChainID: cmn.Fmt("test-chain-%v", cmn.RandStr(6)),
|
ChainID: cmn.Fmt("test-chain-%v", cmn.RandStr(6)),
|
||||||
|
@ -132,7 +126,7 @@ func (c initCmd) initTendermintFiles(config *cfg.Config, info *testnetInformatio
|
||||||
if err := genDoc.SaveAs(genFile); err != nil {
|
if err := genDoc.SaveAs(genFile); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.logger.Info("Generated genesis file", "path", genFile)
|
c.context.Logger.Info("Generated genesis file", "path", genFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// reload the config file and find our validator info
|
// reload the config file and find our validator info
|
||||||
|
|
|
@ -8,13 +8,17 @@ import (
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/mock"
|
"github.com/cosmos/cosmos-sdk/mock"
|
||||||
|
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInit(t *testing.T) {
|
func TestInit(t *testing.T) {
|
||||||
defer setupViper(t)()
|
defer setupViper(t)()
|
||||||
|
|
||||||
logger := log.NewNopLogger()
|
logger := log.NewNopLogger()
|
||||||
cmd := InitCmd(mock.GenInitOptions, logger)
|
cfg, err := tcmd.ParseConfig()
|
||||||
err := cmd.RunE(nil, nil)
|
require.Nil(t, err)
|
||||||
|
ctx := NewContext(cfg, logger)
|
||||||
|
cmd := InitCmd(mock.GenInitOptions, ctx)
|
||||||
|
err = cmd.RunE(nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,11 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||||
"github.com/tendermint/tmlibs/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// UnsafeResetAllCmd - extension of the tendermint command, resets initialization
|
// UnsafeResetAllCmd - extension of the tendermint command, resets initialization
|
||||||
func UnsafeResetAllCmd(logger log.Logger) *cobra.Command {
|
func UnsafeResetAllCmd(ctx *Context) *cobra.Command {
|
||||||
cmd := resetAll{logger}
|
cmd := resetAll{ctx}
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "unsafe_reset_all",
|
Use: "unsafe_reset_all",
|
||||||
Short: "Reset all blockchain data",
|
Short: "Reset all blockchain data",
|
||||||
|
@ -18,14 +17,11 @@ func UnsafeResetAllCmd(logger log.Logger) *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
type resetAll struct {
|
type resetAll struct {
|
||||||
logger log.Logger
|
context *Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r resetAll) run(cmd *cobra.Command, args []string) error {
|
func (r resetAll) run(cmd *cobra.Command, args []string) error {
|
||||||
cfg, err := tcmd.ParseConfig()
|
cfg := r.context.Config
|
||||||
if err != nil {
|
tcmd.ResetAll(cfg.DBDir(), cfg.PrivValidatorFile(), r.context.Logger)
|
||||||
return err
|
|
||||||
}
|
|
||||||
tcmd.ResetAll(cfg.DBDir(), cfg.PrivValidatorFile(), r.logger)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,12 @@ import (
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
"github.com/tendermint/tmlibs/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ShowNodeIdCmd - ported from Tendermint, dump node ID to stdout
|
// ShowNodeIdCmd - ported from Tendermint, dump node ID to stdout
|
||||||
func ShowNodeIdCmd(logger log.Logger) *cobra.Command {
|
func ShowNodeIdCmd(ctx *Context) *cobra.Command {
|
||||||
cmd := showNodeId{logger}
|
cmd := showNodeId{ctx}
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "show_node_id",
|
Use: "show_node_id",
|
||||||
Short: "Show this node's ID",
|
Short: "Show this node's ID",
|
||||||
|
@ -21,14 +19,11 @@ func ShowNodeIdCmd(logger log.Logger) *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
type showNodeId struct {
|
type showNodeId struct {
|
||||||
logger log.Logger
|
context *Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s showNodeId) run(cmd *cobra.Command, args []string) error {
|
func (s showNodeId) run(cmd *cobra.Command, args []string) error {
|
||||||
cfg, err := tcmd.ParseConfig()
|
cfg := s.context.Config
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile())
|
nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -6,14 +6,12 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/tendermint/go-wire/data"
|
"github.com/tendermint/go-wire/data"
|
||||||
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
"github.com/tendermint/tmlibs/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ShowValidator - ported from Tendermint, show this node's validator info
|
// ShowValidator - ported from Tendermint, show this node's validator info
|
||||||
func ShowValidatorCmd(logger log.Logger) *cobra.Command {
|
func ShowValidatorCmd(ctx *Context) *cobra.Command {
|
||||||
cmd := showValidator{logger}
|
cmd := showValidator{ctx}
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "show_validator",
|
Use: "show_validator",
|
||||||
Short: "Show this node's validator info",
|
Short: "Show this node's validator info",
|
||||||
|
@ -22,14 +20,11 @@ func ShowValidatorCmd(logger log.Logger) *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
type showValidator struct {
|
type showValidator struct {
|
||||||
logger log.Logger
|
context *Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s showValidator) run(cmd *cobra.Command, args []string) error {
|
func (s showValidator) run(cmd *cobra.Command, args []string) error {
|
||||||
cfg, err := tcmd.ParseConfig()
|
cfg := s.context.Config
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
privValidator := types.LoadOrGenPrivValidatorFS(cfg.PrivValidatorFile())
|
privValidator := types.LoadOrGenPrivValidatorFS(cfg.PrivValidatorFile())
|
||||||
pubKeyJSONBytes, err := data.ToJSON(privValidator.PubKey)
|
pubKeyJSONBytes, err := data.ToJSON(privValidator.PubKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -27,10 +27,10 @@ type appCreator func(string, log.Logger) (abci.Application, error)
|
||||||
|
|
||||||
// StartCmd runs the service passed in, either
|
// StartCmd runs the service passed in, either
|
||||||
// stand-alone, or in-process with tendermint
|
// stand-alone, or in-process with tendermint
|
||||||
func StartCmd(app appCreator, logger log.Logger) *cobra.Command {
|
func StartCmd(app appCreator, ctx *Context) *cobra.Command {
|
||||||
start := startCmd{
|
start := startCmd{
|
||||||
appCreator: app,
|
appCreator: app,
|
||||||
logger: logger,
|
context: ctx,
|
||||||
}
|
}
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "start",
|
Use: "start",
|
||||||
|
@ -49,15 +49,15 @@ func StartCmd(app appCreator, logger log.Logger) *cobra.Command {
|
||||||
|
|
||||||
type startCmd struct {
|
type startCmd struct {
|
||||||
appCreator appCreator
|
appCreator appCreator
|
||||||
logger log.Logger
|
context *Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s startCmd) run(cmd *cobra.Command, args []string) error {
|
func (s startCmd) run(cmd *cobra.Command, args []string) error {
|
||||||
if !viper.GetBool(flagWithTendermint) {
|
if !viper.GetBool(flagWithTendermint) {
|
||||||
s.logger.Info("Starting ABCI without Tendermint")
|
s.context.Logger.Info("Starting ABCI without Tendermint")
|
||||||
return s.startStandAlone()
|
return s.startStandAlone()
|
||||||
}
|
}
|
||||||
s.logger.Info("Starting ABCI with Tendermint")
|
s.context.Logger.Info("Starting ABCI with Tendermint")
|
||||||
return s.startInProcess()
|
return s.startInProcess()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ func (s startCmd) startStandAlone() error {
|
||||||
// Generate the app in the proper dir
|
// Generate the app in the proper dir
|
||||||
addr := viper.GetString(flagAddress)
|
addr := viper.GetString(flagAddress)
|
||||||
home := viper.GetString("home")
|
home := viper.GetString("home")
|
||||||
app, err := s.appCreator(home, s.logger)
|
app, err := s.appCreator(home, s.context.Logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ func (s startCmd) startStandAlone() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Errorf("Error creating listener: %v\n", err)
|
return errors.Errorf("Error creating listener: %v\n", err)
|
||||||
}
|
}
|
||||||
svr.SetLogger(s.logger.With("module", "abci-server"))
|
svr.SetLogger(s.context.Logger.With("module", "abci-server"))
|
||||||
svr.Start()
|
svr.Start()
|
||||||
|
|
||||||
// Wait forever
|
// Wait forever
|
||||||
|
@ -86,13 +86,9 @@ func (s startCmd) startStandAlone() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s startCmd) startInProcess() error {
|
func (s startCmd) startInProcess() error {
|
||||||
cfg, err := tcmd.ParseConfig()
|
cfg := s.context.Config
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
home := cfg.RootDir
|
home := cfg.RootDir
|
||||||
app, err := s.appCreator(home, s.logger)
|
app, err := s.appCreator(home, s.context.Logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -103,7 +99,7 @@ func (s startCmd) startInProcess() error {
|
||||||
proxy.NewLocalClientCreator(app),
|
proxy.NewLocalClientCreator(app),
|
||||||
node.DefaultGenesisDocProviderFunc(cfg),
|
node.DefaultGenesisDocProviderFunc(cfg),
|
||||||
node.DefaultDBProvider,
|
node.DefaultDBProvider,
|
||||||
s.logger.With("module", "node"))
|
s.context.Logger.With("module", "node"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/mock"
|
"github.com/cosmos/cosmos-sdk/mock"
|
||||||
"github.com/tendermint/abci/server"
|
"github.com/tendermint/abci/server"
|
||||||
|
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,7 +22,10 @@ func TestStartStandAlone(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
logger := log.NewNopLogger()
|
logger := log.NewNopLogger()
|
||||||
initCmd := InitCmd(mock.GenInitOptions, logger)
|
cfg, err := tcmd.ParseConfig()
|
||||||
|
require.Nil(t, err)
|
||||||
|
ctx := NewContext(cfg, logger)
|
||||||
|
initCmd := InitCmd(mock.GenInitOptions, ctx)
|
||||||
err = initCmd.RunE(nil, nil)
|
err = initCmd.RunE(nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -37,7 +41,6 @@ func TestStartStandAlone(t *testing.T) {
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
svr.Stop()
|
svr.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStartWithTendermint(t *testing.T) {
|
func TestStartWithTendermint(t *testing.T) {
|
||||||
|
@ -45,13 +48,16 @@ func TestStartWithTendermint(t *testing.T) {
|
||||||
|
|
||||||
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).
|
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).
|
||||||
With("module", "mock-cmd")
|
With("module", "mock-cmd")
|
||||||
initCmd := InitCmd(mock.GenInitOptions, logger)
|
cfg, err := tcmd.ParseConfig()
|
||||||
err := initCmd.RunE(nil, nil)
|
require.Nil(t, err)
|
||||||
|
ctx := NewContext(cfg, logger)
|
||||||
|
initCmd := InitCmd(mock.GenInitOptions, ctx)
|
||||||
|
err = initCmd.RunE(nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// set up app and start up
|
// set up app and start up
|
||||||
viper.Set(flagWithTendermint, true)
|
viper.Set(flagWithTendermint, true)
|
||||||
startCmd := StartCmd(mock.NewApp, logger)
|
startCmd := StartCmd(mock.NewApp, ctx)
|
||||||
startCmd.Flags().Set(flagAddress, FreeTCPAddr(t)) // set to a new free address
|
startCmd.Flags().Set(flagAddress, FreeTCPAddr(t)) // set to a new free address
|
||||||
timeout := time.Duration(5) * time.Second
|
timeout := time.Duration(5) * time.Second
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||||
"github.com/tendermint/tmlibs/cli"
|
"github.com/tendermint/tmlibs/cli"
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
)
|
)
|
||||||
|
@ -44,14 +45,18 @@ func setupViper(t *testing.T) func() {
|
||||||
func StartServer(t *testing.T) chan error {
|
func StartServer(t *testing.T) chan error {
|
||||||
defer setupViper(t)()
|
defer setupViper(t)()
|
||||||
|
|
||||||
|
cfg, err := tcmd.ParseConfig()
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
// init server
|
// init server
|
||||||
initCmd := InitCmd(mock.GenInitOptions, log.NewNopLogger())
|
ctx := NewContext(cfg, log.NewNopLogger())
|
||||||
err := initCmd.RunE(nil, nil)
|
initCmd := InitCmd(mock.GenInitOptions, ctx)
|
||||||
|
err = initCmd.RunE(nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// start server
|
// start server
|
||||||
viper.Set(flagWithTendermint, true)
|
viper.Set(flagWithTendermint, true)
|
||||||
startCmd := StartCmd(mock.NewApp, log.NewNopLogger())
|
startCmd := StartCmd(mock.NewApp, ctx)
|
||||||
startCmd.Flags().Set(flagAddress, FreeTCPAddr(t)) // set to a new free address
|
startCmd.Flags().Set(flagAddress, FreeTCPAddr(t)) // set to a new free address
|
||||||
startCmd.Flags().Set("rpc.laddr", FreeTCPAddr(t)) // set to a new free address
|
startCmd.Flags().Set("rpc.laddr", FreeTCPAddr(t)) // set to a new free address
|
||||||
timeout := time.Duration(3) * time.Second
|
timeout := time.Duration(3) * time.Second
|
||||||
|
|
Loading…
Reference in New Issue