github.com/Gessiux/neatchain@v1.3.1/chain/neatchain/main.go (about)

     1  // neatchain is the official command-line client for NEAT Chain.
     2  package main
     3  
     4  import (
     5  	"fmt"
     6  	"os"
     7  	"runtime"
     8  	"sort"
     9  	"time"
    10  
    11  	"github.com/Gessiux/neatchain/chain/log"
    12  
    13  	"github.com/Gessiux/neatchain/internal/debug"
    14  	"github.com/Gessiux/neatchain/utilities/console"
    15  	"github.com/Gessiux/neatchain/utilities/metrics"
    16  	"github.com/Gessiux/neatchain/utilities/utils"
    17  	"gopkg.in/urfave/cli.v1"
    18  )
    19  
    20  const (
    21  	clientIdentifier = "neatchain" // Client identifier to advertise over the network
    22  )
    23  
    24  var (
    25  	// Git SHA1 commit hash of the release (set via linker flags)
    26  	gitCommit = ""
    27  	gitDate   = ""
    28  
    29  	// The app that holds all commands and flags.
    30  	app = utils.NewApp(gitCommit, "the neatchain command line interface")
    31  	// flags that configure the node
    32  	nodeFlags = []cli.Flag{
    33  		utils.IdentityFlag,
    34  		utils.UnlockedAccountFlag,
    35  		utils.PasswordFileFlag,
    36  		utils.BootnodesFlag,
    37  		utils.BootnodesV4Flag,
    38  		utils.BootnodesV5Flag,
    39  		utils.DataDirFlag,
    40  		utils.KeyStoreDirFlag,
    41  		utils.NoUSBFlag,
    42  		utils.TxPoolNoLocalsFlag,
    43  		utils.TxPoolJournalFlag,
    44  		utils.TxPoolRejournalFlag,
    45  		utils.TxPoolPriceLimitFlag,
    46  		utils.TxPoolPriceBumpFlag,
    47  		utils.TxPoolAccountSlotsFlag,
    48  		utils.TxPoolGlobalSlotsFlag,
    49  		utils.TxPoolAccountQueueFlag,
    50  		utils.TxPoolGlobalQueueFlag,
    51  		utils.TxPoolLifetimeFlag,
    52  		//utils.FastSyncFlag,
    53  		utils.SyncModeFlag,
    54  		utils.GCModeFlag,
    55  		utils.CacheFlag,
    56  		utils.CacheDatabaseFlag,
    57  		utils.CacheTrieFlag,
    58  		utils.CacheGCFlag,
    59  		utils.ListenPortFlag,
    60  		utils.MaxPeersFlag,
    61  		utils.MaxPendingPeersFlag,
    62  		utils.MiningEnabledFlag,
    63  		utils.MinerThreadsFlag,
    64  		utils.MinerGasTargetFlag,
    65  		utils.MinerGasLimitFlag,
    66  		utils.MinerGasPriceFlag,
    67  		utils.MinerCoinbaseFlag,
    68  		utils.NATFlag,
    69  		utils.NoDiscoverFlag,
    70  		utils.DiscoveryV5Flag,
    71  		utils.NetrestrictFlag,
    72  		utils.NodeKeyFileFlag,
    73  		utils.NodeKeyHexFlag,
    74  		utils.TestnetFlag,
    75  		utils.VMEnableDebugFlag,
    76  		utils.NetworkIdFlag,
    77  		utils.RPCCORSDomainFlag,
    78  		utils.RPCVirtualHostsFlag,
    79  		//utils.EthStatsURLFlag,
    80  		utils.MetricsEnabledFlag,
    81  		utils.NoCompactionFlag,
    82  		utils.GpoBlocksFlag,
    83  		utils.GpoPercentileFlag,
    84  		utils.ExtraDataFlag,
    85  		//configFileFlag,
    86  
    87  		//utils.LogDirFlag,
    88  		utils.SideChainFlag,
    89  	}
    90  
    91  	rpcFlags = []cli.Flag{
    92  		utils.RPCEnabledFlag,
    93  		utils.RPCListenAddrFlag,
    94  		utils.RPCPortFlag,
    95  		utils.RPCApiFlag,
    96  		utils.WSEnabledFlag,
    97  		utils.WSListenAddrFlag,
    98  		utils.WSPortFlag,
    99  		utils.WSApiFlag,
   100  		utils.WSAllowedOriginsFlag,
   101  		utils.IPCDisabledFlag,
   102  		utils.IPCPathFlag,
   103  	}
   104  )
   105  
   106  func init() {
   107  	// Initialize the CLI app and start neatchain
   108  	app.Action = neatchainCmd
   109  	app.HideVersion = true // we have a command to print the version
   110  	app.Copyright = "Copyright 2021 Neatio Developers"
   111  	app.Commands = []cli.Command{
   112  		// See chaincmd.go:
   113  		createValidatorCmd,
   114  		initNEATGenesisCmd,
   115  		initCommand,
   116  		//initSideChainCmd,
   117  		importCommand,
   118  		exportCommand,
   119  		copydbCommand,
   120  		removedbCommand,
   121  		dumpCommand,
   122  		// See monitorcmd.go:
   123  		monitorCommand,
   124  		// See accountcmd.go:
   125  		accountCommand,
   126  		//walletCommand,
   127  		// See consolecmd.go:
   128  		consoleCommand,
   129  		attachCommand,
   130  		javascriptCommand,
   131  		// See misccmd.go:
   132  
   133  		bugCommand,
   134  		// See config.go
   135  		dumpConfigCommand,
   136  		versionCommand,
   137  	}
   138  	sort.Sort(cli.CommandsByName(app.Commands))
   139  
   140  	app.Flags = append(app.Flags, nodeFlags...)
   141  	app.Flags = append(app.Flags, rpcFlags...)
   142  	app.Flags = append(app.Flags, consoleFlags...)
   143  	app.Flags = append(app.Flags, debug.Flags...)
   144  
   145  	app.Before = func(ctx *cli.Context) error {
   146  		runtime.GOMAXPROCS(runtime.NumCPU())
   147  
   148  		// Setup the Global Logger
   149  
   150  		log.NewLogger("", "", ctx.GlobalInt("verbosity"), ctx.GlobalBool("debug"), ctx.GlobalString("vmodule"), ctx.GlobalString("backtrace"))
   151  
   152  		if err := debug.Setup(ctx); err != nil {
   153  			return err
   154  		}
   155  
   156  		// Start system runtime metrics collection
   157  		go metrics.CollectProcessMetrics(3 * time.Second)
   158  
   159  		return nil
   160  	}
   161  
   162  	app.After = func(ctx *cli.Context) error {
   163  		debug.Exit()
   164  		console.Stdin.Close() // Resets terminal mode.
   165  		return nil
   166  	}
   167  }
   168  
   169  func main() {
   170  	if err := app.Run(os.Args); err != nil {
   171  		fmt.Fprintln(os.Stderr, err)
   172  		os.Exit(1)
   173  	}
   174  }