added use of Cobra CLIpull/439/head
@ -0,0 +1,27 @@ | |||
package commands | |||
import ( | |||
"fmt" | |||
"github.com/spf13/cobra" | |||
"github.com/tendermint/go-wire" | |||
"github.com/tendermint/tendermint/types" | |||
) | |||
var genValidatorCmd = &cobra.Command{ | |||
Use: "gen_validator", | |||
Short: "Generate new validator keypair", | |||
Run: genValidator, | |||
} | |||
func init() { | |||
RootCmd.AddCommand(genValidatorCmd) | |||
} | |||
func genValidator(cmd *cobra.Command, args []string) { | |||
privValidator := types.GenPrivValidator() | |||
privValidatorJSONBytes := wire.JSONBytesPretty(privValidator) | |||
fmt.Printf(`%v | |||
`, string(privValidatorJSONBytes)) | |||
} |
@ -0,0 +1,40 @@ | |||
package commands | |||
import ( | |||
"fmt" | |||
"github.com/tendermint/tendermint/consensus" | |||
"github.com/spf13/cobra" | |||
) | |||
var replayCmd = &cobra.Command{ | |||
Use: "replay [walfile]", | |||
Short: "Replay messages from WAL", | |||
Run: func(cmd *cobra.Command, args []string) { | |||
if len(args) > 1 { | |||
consensus.RunReplayFile(config, args[1], false) | |||
} else { | |||
fmt.Println("replay requires an argument (walfile)") | |||
} | |||
}, | |||
} | |||
var replayConsoleCmd = &cobra.Command{ | |||
Use: "replay_console [walfile]", | |||
Short: "Replay messages from WAL in a console", | |||
Run: func(cmd *cobra.Command, args []string) { | |||
if len(args) > 1 { | |||
consensus.RunReplayFile(config, args[1], true) | |||
} else { | |||
fmt.Println("replay_console requires an argument (walfile)") | |||
} | |||
}, | |||
} | |||
func init() { | |||
RootCmd.AddCommand(replayCmd) | |||
RootCmd.AddCommand(replayConsoleCmd) | |||
} |
@ -0,0 +1,35 @@ | |||
package commands | |||
import ( | |||
"github.com/spf13/cobra" | |||
cfg "github.com/tendermint/go-config" | |||
"github.com/tendermint/go-logger" | |||
tmcfg "github.com/tendermint/tendermint/config/tendermint" | |||
) | |||
var config cfg.Config | |||
var log = logger.New("module", "main") | |||
//global flag | |||
var logLevel string | |||
var RootCmd = &cobra.Command{ | |||
Use: "tendermint", | |||
Short: "Tendermint Core (BFT Consensus) in Go", | |||
PersistentPreRun: func(cmd *cobra.Command, args []string) { | |||
config.Set("log_level", logLevel) | |||
}, | |||
} | |||
func init() { | |||
// Get configuration | |||
config = tmcfg.GetConfig("") | |||
//parse flag and set config | |||
RootCmd.PersistentFlags().StringVar(&logLevel, "log_level", config.GetString("log_level"), "Log level") | |||
// set the log level | |||
logger.SetLogLevel(config.GetString("log_level")) | |||
} |
@ -0,0 +1,124 @@ | |||
package commands | |||
import ( | |||
"io/ioutil" | |||
"time" | |||
"github.com/spf13/cobra" | |||
. "github.com/tendermint/go-common" | |||
"github.com/tendermint/tendermint/node" | |||
"github.com/tendermint/tendermint/types" | |||
) | |||
var runNodeCmd = &cobra.Command{ | |||
Use: "node", | |||
Short: "Run the tendermint node", | |||
PreRun: setConfigFlags, | |||
Run: runNode, | |||
} | |||
//flags | |||
var ( | |||
moniker string | |||
nodeLaddr string | |||
seeds string | |||
fastSync bool | |||
skipUPNP bool | |||
rpcLaddr string | |||
grpcLaddr string | |||
proxyApp string | |||
abciTransport string | |||
pex bool | |||
) | |||
func init() { | |||
// configuration options | |||
runNodeCmd.Flags().StringVar(&moniker, "moniker", config.GetString("moniker"), | |||
"Node Name") | |||
runNodeCmd.Flags().StringVar(&nodeLaddr, "node_laddr", config.GetString("node_laddr"), | |||
"Node listen address. (0.0.0.0:0 means any interface, any port)") | |||
runNodeCmd.Flags().StringVar(&seeds, "seeds", config.GetString("seeds"), | |||
"Comma delimited host:port seed nodes") | |||
runNodeCmd.Flags().BoolVar(&fastSync, "fast_sync", config.GetBool("fast_sync"), | |||
"Fast blockchain syncing") | |||
runNodeCmd.Flags().BoolVar(&skipUPNP, "skip_upnp", config.GetBool("skip_upnp"), | |||
"Skip UPNP configuration") | |||
runNodeCmd.Flags().StringVar(&rpcLaddr, "rpc_laddr", config.GetString("rpc_laddr"), | |||
"RPC listen address. Port required") | |||
runNodeCmd.Flags().StringVar(&grpcLaddr, "grpc_laddr", config.GetString("grpc_laddr"), | |||
"GRPC listen address (BroadcastTx only). Port required") | |||
runNodeCmd.Flags().StringVar(&proxyApp, "proxy_app", config.GetString("proxy_app"), | |||
"Proxy app address, or 'nilapp' or 'dummy' for local testing.") | |||
runNodeCmd.Flags().StringVar(&abciTransport, "abci", config.GetString("abci"), | |||
"Specify abci transport (socket | grpc)") | |||
// feature flags | |||
runNodeCmd.Flags().BoolVar(&pex, "pex", config.GetBool("pex_reactor"), | |||
"Enable Peer-Exchange (dev feature)") | |||
RootCmd.AddCommand(runNodeCmd) | |||
} | |||
func setConfigFlags(cmd *cobra.Command, args []string) { | |||
// Merge parsed flag values onto config | |||
config.Set("moniker", moniker) | |||
config.Set("node_laddr", nodeLaddr) | |||
config.Set("seeds", seeds) | |||
config.Set("fast_sync", fastSync) | |||
config.Set("skip_upnp", skipUPNP) | |||
config.Set("rpc_laddr", rpcLaddr) | |||
config.Set("grpc_laddr", grpcLaddr) | |||
config.Set("proxy_app", proxyApp) | |||
config.Set("abci", abciTransport) | |||
config.Set("pex_reactor", pex) | |||
} | |||
// Users wishing to: | |||
// * Use an external signer for their validators | |||
// * Supply an in-proc abci app | |||
// should import github.com/tendermint/tendermint/node and implement | |||
// their own run_node to call node.NewNode (instead of node.NewNodeDefault) | |||
// with their custom priv validator and/or custom proxy.ClientCreator | |||
func runNode(cmd *cobra.Command, args []string) { | |||
// Wait until the genesis doc becomes available | |||
// This is for Mintnet compatibility. | |||
// TODO: If Mintnet gets deprecated or genesis_file is | |||
// always available, remove. | |||
genDocFile := config.GetString("genesis_file") | |||
if !FileExists(genDocFile) { | |||
log.Notice(Fmt("Waiting for genesis file %v...", genDocFile)) | |||
for { | |||
time.Sleep(time.Second) | |||
if !FileExists(genDocFile) { | |||
continue | |||
} | |||
jsonBlob, err := ioutil.ReadFile(genDocFile) | |||
if err != nil { | |||
Exit(Fmt("Couldn't read GenesisDoc file: %v", err)) | |||
} | |||
genDoc, err := types.GenesisDocFromJSON(jsonBlob) | |||
if err != nil { | |||
Exit(Fmt("Error reading GenesisDoc: %v", err)) | |||
} | |||
if genDoc.ChainID == "" { | |||
Exit(Fmt("Genesis doc %v must include non-empty chain_id", genDocFile)) | |||
} | |||
config.Set("chain_id", genDoc.ChainID) | |||
} | |||
} | |||
// Create & start node | |||
n := node.NewNodeDefault(config) | |||
if _, err := n.Start(); err != nil { | |||
Exit(Fmt("Failed to start node: %v", err)) | |||
} else { | |||
log.Notice("Started node", "nodeInfo", n.Switch().NodeInfo()) | |||
} | |||
// Trap signal, run forever. | |||
n.RunForever() | |||
} |
@ -0,0 +1,21 @@ | |||
package commands | |||
import ( | |||
"fmt" | |||
"github.com/spf13/cobra" | |||
"github.com/tendermint/tendermint/version" | |||
) | |||
var versionCmd = &cobra.Command{ | |||
Use: "version", | |||
Short: "Show version info", | |||
Run: func(cmd *cobra.Command, args []string) { | |||
fmt.Println(version.Version) | |||
}, | |||
} | |||
func init() { | |||
RootCmd.AddCommand(versionCmd) | |||
} |
@ -1,66 +0,0 @@ | |||
package main | |||
import ( | |||
flag "github.com/spf13/pflag" | |||
"os" | |||
cfg "github.com/tendermint/go-config" | |||
) | |||
func parseFlags(config cfg.Config, args []string) { | |||
var ( | |||
printHelp bool | |||
moniker string | |||
nodeLaddr string | |||
seeds string | |||
fastSync bool | |||
skipUPNP bool | |||
rpcLaddr string | |||
grpcLaddr string | |||
logLevel string | |||
proxyApp string | |||
abciTransport string | |||
pex bool | |||
) | |||
// Declare flags | |||
var flags = flag.NewFlagSet("main", flag.ExitOnError) | |||
flags.BoolVar(&printHelp, "help", false, "Print this help message.") | |||
// configuration options | |||
flags.StringVar(&moniker, "moniker", config.GetString("moniker"), "Node Name") | |||
flags.StringVar(&nodeLaddr, "node_laddr", config.GetString("node_laddr"), "Node listen address. (0.0.0.0:0 means any interface, any port)") | |||
flags.StringVar(&seeds, "seeds", config.GetString("seeds"), "Comma delimited host:port seed nodes") | |||
flags.BoolVar(&fastSync, "fast_sync", config.GetBool("fast_sync"), "Fast blockchain syncing") | |||
flags.BoolVar(&skipUPNP, "skip_upnp", config.GetBool("skip_upnp"), "Skip UPNP configuration") | |||
flags.StringVar(&rpcLaddr, "rpc_laddr", config.GetString("rpc_laddr"), "RPC listen address. Port required") | |||
flags.StringVar(&grpcLaddr, "grpc_laddr", config.GetString("grpc_laddr"), "GRPC listen address (BroadcastTx only). Port required") | |||
flags.StringVar(&logLevel, "log_level", config.GetString("log_level"), "Log level") | |||
flags.StringVar(&proxyApp, "proxy_app", config.GetString("proxy_app"), | |||
"Proxy app address, or 'nilapp' or 'dummy' for local testing.") | |||
flags.StringVar(&abciTransport, "abci", config.GetString("abci"), "Specify abci transport (socket | grpc)") | |||
// feature flags | |||
flags.BoolVar(&pex, "pex", config.GetBool("pex_reactor"), "Enable Peer-Exchange (dev feature)") | |||
flags.Parse(args) | |||
if printHelp { | |||
flags.PrintDefaults() | |||
os.Exit(0) | |||
} | |||
// Merge parsed flag values onto app. | |||
config.Set("moniker", moniker) | |||
config.Set("node_laddr", nodeLaddr) | |||
config.Set("seeds", seeds) | |||
config.Set("fast_sync", fastSync) | |||
config.Set("skip_upnp", skipUPNP) | |||
config.Set("rpc_laddr", rpcLaddr) | |||
config.Set("grpc_laddr", grpcLaddr) | |||
config.Set("log_level", logLevel) | |||
config.Set("proxy_app", proxyApp) | |||
config.Set("abci", abciTransport) | |||
config.Set("pex_reactor", pex) | |||
} |
@ -1,15 +0,0 @@ | |||
package main | |||
import ( | |||
"fmt" | |||
"github.com/tendermint/go-wire" | |||
"github.com/tendermint/tendermint/types" | |||
) | |||
func gen_validator() { | |||
privValidator := types.GenPrivValidator() | |||
privValidatorJSONBytes := wire.JSONBytesPretty(privValidator) | |||
fmt.Printf(`%v | |||
`, string(privValidatorJSONBytes)) | |||
} |
@ -1,7 +0,0 @@ | |||
package main | |||
import ( | |||
"github.com/tendermint/go-logger" | |||
) | |||
var log = logger.New("module", "main") |
@ -1,59 +0,0 @@ | |||
package main | |||
import ( | |||
"io/ioutil" | |||
"time" | |||
. "github.com/tendermint/go-common" | |||
cfg "github.com/tendermint/go-config" | |||
"github.com/tendermint/tendermint/node" | |||
"github.com/tendermint/tendermint/types" | |||
) | |||
// Users wishing to: | |||
// * Use an external signer for their validators | |||
// * Supply an in-proc abci app | |||
// should import github.com/tendermint/tendermint/node and implement | |||
// their own run_node to call node.NewNode (instead of node.NewNodeDefault) | |||
// with their custom priv validator and/or custom proxy.ClientCreator | |||
func run_node(config cfg.Config) { | |||
// Wait until the genesis doc becomes available | |||
// This is for Mintnet compatibility. | |||
// TODO: If Mintnet gets deprecated or genesis_file is | |||
// always available, remove. | |||
genDocFile := config.GetString("genesis_file") | |||
if !FileExists(genDocFile) { | |||
log.Notice(Fmt("Waiting for genesis file %v...", genDocFile)) | |||
for { | |||
time.Sleep(time.Second) | |||
if !FileExists(genDocFile) { | |||
continue | |||
} | |||
jsonBlob, err := ioutil.ReadFile(genDocFile) | |||
if err != nil { | |||
Exit(Fmt("Couldn't read GenesisDoc file: %v", err)) | |||
} | |||
genDoc, err := types.GenesisDocFromJSON(jsonBlob) | |||
if err != nil { | |||
Exit(Fmt("Error reading GenesisDoc: %v", err)) | |||
} | |||
if genDoc.ChainID == "" { | |||
Exit(Fmt("Genesis doc %v must include non-empty chain_id", genDocFile)) | |||
} | |||
config.Set("chain_id", genDoc.ChainID) | |||
} | |||
} | |||
// Create & start node | |||
n := node.NewNodeDefault(config) | |||
if _, err := n.Start(); err != nil { | |||
Exit(Fmt("Failed to start node: %v", err)) | |||
} else { | |||
log.Notice("Started node", "nodeInfo", n.Switch().NodeInfo()) | |||
} | |||
// Trap signal, run forever. | |||
n.RunForever() | |||
} |