@ -2,7 +2,6 @@ package commands
import (
import (
"fmt"
"fmt"
"io/ioutil"
"time"
"time"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
@ -19,28 +18,33 @@ var runNodeCmd = &cobra.Command{
}
}
func init ( ) {
func init ( ) {
AddNodeFlags ( runNodeCmd )
RootCmd . AddCommand ( runNodeCmd )
}
// AddNodeFlags exposes some common configuration options on the command-line
// These are exposed for convenience of commands embedding a tendermint node
func AddNodeFlags ( cmd * cobra . Command ) {
// bind flags
// bind flags
runNodeCmd . Flags ( ) . String ( "moniker" , config . Moniker , "Node Name" )
c md. Flags ( ) . String ( "moniker" , config . Moniker , "Node Name" )
// node flags
// node flags
runNodeCmd . Flags ( ) . Bool ( "fast_sync" , config . FastSync , "Fast blockchain syncing" )
c md. Flags ( ) . Bool ( "fast_sync" , config . FastSync , "Fast blockchain syncing" )
// abci flags
// abci flags
runNodeC md. Flags ( ) . String ( "proxy_app" , config . ProxyApp , "Proxy app address, or 'nilapp' or 'dummy' for local testing." )
runNodeC md. Flags ( ) . String ( "abci" , config . ABCI , "Specify abci transport (socket | grpc)" )
c md. Flags ( ) . String ( "proxy_app" , config . ProxyApp , "Proxy app address, or 'nilapp' or 'dummy' for local testing." )
c md. Flags ( ) . String ( "abci" , config . ABCI , "Specify abci transport (socket | grpc)" )
// rpc flags
// rpc flags
runNodeC md. Flags ( ) . String ( "rpc.laddr" , config . RPC . ListenAddress , "RPC listen address. Port required" )
runNodeC md. Flags ( ) . String ( "rpc.grpc_laddr" , config . RPC . GRPCListenAddress , "GRPC listen address (BroadcastTx only). Port required" )
runNodeC md. Flags ( ) . Bool ( "rpc.unsafe" , config . RPC . Unsafe , "Enabled unsafe rpc methods" )
c md. Flags ( ) . String ( "rpc.laddr" , config . RPC . ListenAddress , "RPC listen address. Port required" )
c md. Flags ( ) . String ( "rpc.grpc_laddr" , config . RPC . GRPCListenAddress , "GRPC listen address (BroadcastTx only). Port required" )
c md. Flags ( ) . Bool ( "rpc.unsafe" , config . RPC . Unsafe , "Enabled unsafe rpc methods" )
// p2p flags
// p2p flags
runNodeCmd . Flags ( ) . String ( "p2p.laddr" , config . P2P . ListenAddress , "Node listen address. (0.0.0.0:0 means any interface, any port)" )
runNodeCmd . Flags ( ) . String ( "p2p.seeds" , config . P2P . Seeds , "Comma delimited host:port seed nodes" )
runNodeCmd . Flags ( ) . Bool ( "p2p.skip_upnp" , config . P2P . SkipUPNP , "Skip UPNP configuration" )
runNodeCmd . Flags ( ) . Bool ( "p2p.pex" , config . P2P . PexReactor , "Enable Peer-Exchange (dev feature)" )
RootCmd . AddCommand ( runNodeCmd )
cmd . Flags ( ) . String ( "p2p.laddr" , config . P2P . ListenAddress , "Node listen address. (0.0.0.0:0 means any interface, any port)" )
cmd . Flags ( ) . String ( "p2p.seeds" , config . P2P . Seeds , "Comma delimited host:port seed nodes" )
cmd . Flags ( ) . Bool ( "p2p.skip_upnp" , config . P2P . SkipUPNP , "Skip UPNP configuration" )
cmd . Flags ( ) . Bool ( "p2p.pex" , config . P2P . PexReactor , "Enable Peer-Exchange (dev feature)" )
}
}
// Users wishing to:
// Users wishing to:
@ -56,27 +60,16 @@ func runNode(cmd *cobra.Command, args []string) error {
// TODO: If Mintnet gets deprecated or genesis_file is
// TODO: If Mintnet gets deprecated or genesis_file is
// always available, remove.
// always available, remove.
genDocFile := config . GenesisFile ( )
genDocFile := config . GenesisFile ( )
i f ! cmn . FileExists ( genDocFile ) {
for ! cmn . FileExists ( genDocFile ) {
logger . Info ( cmn . Fmt ( "Waiting for genesis file %v..." , genDocFile ) )
logger . Info ( cmn . Fmt ( "Waiting for genesis file %v..." , genDocFile ) )
for {
time . Sleep ( time . Second )
if ! cmn . FileExists ( genDocFile ) {
continue
}
jsonBlob , err := ioutil . ReadFile ( genDocFile )
if err != nil {
return fmt . Errorf ( "Couldn't read GenesisDoc file: %v" , err )
}
genDoc , err := types . GenesisDocFromJSON ( jsonBlob )
if err != nil {
return fmt . Errorf ( "Error reading GenesisDoc: %v" , err )
}
if genDoc . ChainID == "" {
return fmt . Errorf ( "Genesis doc %v must include non-empty chain_id" , genDocFile )
}
config . ChainID = genDoc . ChainID
}
time . Sleep ( time . Second )
}
genDoc , err := types . GenesisDocFromFile ( genDocFile )
if err != nil {
return err
}
}
config . ChainID = genDoc . ChainID
// Create & start node
// Create & start node
n := node . NewNodeDefault ( config , logger . With ( "module" , "node" ) )
n := node . NewNodeDefault ( config , logger . With ( "module" , "node" ) )