github.com/kisexp/xdchain@v0.0.0-20211206025815-490d6b732aa7/cmd/geth/usage.go (about)

     1  // Copyright 2015 The go-ethereum Authors
     2  // This file is part of go-ethereum.
     3  //
     4  // go-ethereum is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // go-ethereum is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU General Public License
    15  // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  // Contains the geth command usage template and generator.
    18  
    19  package main
    20  
    21  import (
    22  	"io"
    23  	"sort"
    24  
    25  	"github.com/kisexp/xdchain/cmd/utils"
    26  	"github.com/kisexp/xdchain/internal/debug"
    27  	"github.com/kisexp/xdchain/internal/flags"
    28  	"gopkg.in/urfave/cli.v1"
    29  )
    30  
    31  // Quorum
    32  var quorumAccountFlagGroup = "QUORUM ACCOUNT"
    33  
    34  // End Quorum
    35  
    36  // AppHelpFlagGroups is the application flags, grouped by functionality.
    37  var AppHelpFlagGroups = []flags.FlagGroup{
    38  	{
    39  		Name: "ETHEREUM",
    40  		Flags: []cli.Flag{
    41  			configFileFlag,
    42  			utils.DataDirFlag,
    43  			utils.AncientFlag,
    44  			utils.KeyStoreDirFlag,
    45  			utils.NoUSBFlag,
    46  			utils.SmartCardDaemonPathFlag,
    47  			utils.NetworkIdFlag,
    48  			utils.GoerliFlag,
    49  			utils.RinkebyFlag,
    50  			utils.YoloV2Flag,
    51  			utils.RopstenFlag,
    52  			utils.SyncModeFlag,
    53  			utils.ExitWhenSyncedFlag,
    54  			utils.GCModeFlag,
    55  			utils.TxLookupLimitFlag,
    56  			utils.EthStatsURLFlag,
    57  			utils.IdentityFlag,
    58  			utils.LightKDFFlag,
    59  			utils.AuthorizationListFlag,
    60  		},
    61  	},
    62  	{
    63  		Name: "LIGHT CLIENT",
    64  		Flags: []cli.Flag{
    65  			utils.LightServeFlag,
    66  			utils.LightIngressFlag,
    67  			utils.LightEgressFlag,
    68  			utils.LightMaxPeersFlag,
    69  			utils.UltraLightServersFlag,
    70  			utils.UltraLightFractionFlag,
    71  			utils.UltraLightOnlyAnnounceFlag,
    72  			utils.LightNoPruneFlag,
    73  		},
    74  	},
    75  	{
    76  		Name: "DEVELOPER CHAIN",
    77  		Flags: []cli.Flag{
    78  			utils.DeveloperFlag,
    79  			utils.DeveloperPeriodFlag,
    80  		},
    81  	},
    82  	{
    83  		Name: "ETHASH",
    84  		Flags: []cli.Flag{
    85  			utils.EthashCacheDirFlag,
    86  			utils.EthashCachesInMemoryFlag,
    87  			utils.EthashCachesOnDiskFlag,
    88  			utils.EthashCachesLockMmapFlag,
    89  			utils.EthashDatasetDirFlag,
    90  			utils.EthashDatasetsInMemoryFlag,
    91  			utils.EthashDatasetsOnDiskFlag,
    92  			utils.EthashDatasetsLockMmapFlag,
    93  		},
    94  	},
    95  	{
    96  		Name: "TRANSACTION POOL",
    97  		Flags: []cli.Flag{
    98  			utils.TxPoolLocalsFlag,
    99  			utils.TxPoolNoLocalsFlag,
   100  			utils.TxPoolJournalFlag,
   101  			utils.TxPoolRejournalFlag,
   102  			utils.TxPoolPriceLimitFlag,
   103  			utils.TxPoolPriceBumpFlag,
   104  			utils.TxPoolAccountSlotsFlag,
   105  			utils.TxPoolGlobalSlotsFlag,
   106  			utils.TxPoolAccountQueueFlag,
   107  			utils.TxPoolGlobalQueueFlag,
   108  			utils.TxPoolLifetimeFlag,
   109  		},
   110  	},
   111  	{
   112  		Name: "PERFORMANCE TUNING",
   113  		Flags: []cli.Flag{
   114  			utils.CacheFlag,
   115  			utils.CacheDatabaseFlag,
   116  			utils.CacheTrieFlag,
   117  			utils.CacheTrieJournalFlag,
   118  			utils.CacheTrieRejournalFlag,
   119  			utils.CacheGCFlag,
   120  			utils.CacheSnapshotFlag,
   121  			utils.CacheNoPrefetchFlag,
   122  			utils.CachePreimagesFlag,
   123  		},
   124  	},
   125  	{
   126  		Name: "ACCOUNT",
   127  		Flags: []cli.Flag{
   128  			utils.UnlockedAccountFlag,
   129  			utils.PasswordFileFlag,
   130  			utils.ExternalSignerFlag,
   131  			utils.InsecureUnlockAllowedFlag,
   132  		},
   133  	},
   134  	{
   135  		Name: "API AND CONSOLE",
   136  		Flags: []cli.Flag{
   137  			utils.IPCDisabledFlag,
   138  			utils.IPCPathFlag,
   139  			utils.HTTPEnabledFlag,
   140  			utils.HTTPListenAddrFlag,
   141  			utils.HTTPPortFlag,
   142  			utils.HTTPApiFlag,
   143  			utils.HTTPCORSDomainFlag,
   144  			utils.HTTPVirtualHostsFlag,
   145  			utils.WSEnabledFlag,
   146  			utils.WSListenAddrFlag,
   147  			utils.WSPortFlag,
   148  			utils.WSApiFlag,
   149  			utils.WSAllowedOriginsFlag,
   150  			utils.GraphQLEnabledFlag,
   151  			utils.GraphQLCORSDomainFlag,
   152  			utils.GraphQLVirtualHostsFlag,
   153  			utils.RPCGlobalGasCapFlag,
   154  			utils.RPCGlobalTxFeeCapFlag,
   155  			utils.JSpathFlag,
   156  			utils.ExecFlag,
   157  			utils.PreloadJSFlag,
   158  			utils.RPCClientToken,
   159  			utils.RPCClientTLSInsecureSkipVerify,
   160  			utils.RPCClientTLSCert,
   161  			utils.RPCClientTLSCaCert,
   162  			utils.RPCClientTLSCipherSuites,
   163  		},
   164  	},
   165  	{
   166  		Name: "NETWORKING",
   167  		Flags: []cli.Flag{
   168  			utils.BootnodesFlag,
   169  			utils.LegacyBootnodesV4Flag,
   170  			utils.LegacyBootnodesV5Flag,
   171  			utils.DNSDiscoveryFlag,
   172  			utils.ListenPortFlag,
   173  			utils.MaxPeersFlag,
   174  			utils.MaxPendingPeersFlag,
   175  			utils.NATFlag,
   176  			utils.NoDiscoverFlag,
   177  			utils.DiscoveryV5Flag,
   178  			utils.NetrestrictFlag,
   179  			utils.NodeKeyFileFlag,
   180  			utils.NodeKeyHexFlag,
   181  		},
   182  	},
   183  	{
   184  		Name: "MINER",
   185  		Flags: []cli.Flag{
   186  			utils.MiningEnabledFlag,
   187  			utils.MinerThreadsFlag,
   188  			utils.MinerNotifyFlag,
   189  			utils.MinerGasPriceFlag,
   190  			utils.MinerGasTargetFlag,
   191  			utils.MinerGasLimitFlag,
   192  			utils.MinerEtherbaseFlag,
   193  			utils.MinerExtraDataFlag,
   194  			utils.MinerRecommitIntervalFlag,
   195  			utils.MinerNoVerfiyFlag,
   196  		},
   197  	},
   198  	{
   199  		Name: "GAS PRICE ORACLE",
   200  		Flags: []cli.Flag{
   201  			utils.GpoBlocksFlag,
   202  			utils.GpoPercentileFlag,
   203  			utils.GpoMaxGasPriceFlag,
   204  		},
   205  	},
   206  	{
   207  		Name: "VIRTUAL MACHINE",
   208  		Flags: []cli.Flag{
   209  			utils.VMEnableDebugFlag,
   210  			utils.EVMInterpreterFlag,
   211  			utils.EWASMInterpreterFlag,
   212  			// Quorum - timout for calls
   213  			utils.EVMCallTimeOutFlag,
   214  		},
   215  	},
   216  	{
   217  		Name: "LOGGING AND DEBUGGING",
   218  		Flags: append([]cli.Flag{
   219  			utils.FakePoWFlag,
   220  			utils.NoCompactionFlag,
   221  		}, debug.Flags...),
   222  	},
   223  	{
   224  		Name:  "METRICS AND STATS",
   225  		Flags: metricsFlags,
   226  	},
   227  	{
   228  		Name:  "WHISPER (deprecated)",
   229  		Flags: whisperFlags,
   230  	},
   231  	{
   232  		Name: "ALIASED (deprecated)",
   233  		Flags: append([]cli.Flag{
   234  			utils.LegacyRPCEnabledFlag,
   235  			utils.LegacyRPCListenAddrFlag,
   236  			utils.LegacyRPCPortFlag,
   237  			utils.LegacyRPCCORSDomainFlag,
   238  			utils.LegacyRPCVirtualHostsFlag,
   239  			utils.LegacyRPCApiFlag,
   240  			utils.LegacyWSListenAddrFlag,
   241  			utils.LegacyWSPortFlag,
   242  			utils.LegacyWSAllowedOriginsFlag,
   243  			utils.LegacyWSApiFlag,
   244  			utils.LegacyGpoBlocksFlag,
   245  			utils.LegacyGpoPercentileFlag,
   246  			utils.LegacyGraphQLListenAddrFlag,
   247  			utils.LegacyGraphQLPortFlag,
   248  		}, debug.DeprecatedFlags...),
   249  	},
   250  	// QUORUM
   251  	{
   252  		Name: "QUORUM",
   253  		Flags: []cli.Flag{
   254  			utils.QuorumImmutabilityThreshold,
   255  			utils.EnableNodePermissionFlag,
   256  			utils.PluginSettingsFlag,
   257  			utils.PluginSkipVerifyFlag,
   258  			utils.PluginLocalVerifyFlag,
   259  			utils.PluginPublicKeyFlag,
   260  			utils.AllowedFutureBlockTimeFlag,
   261  			utils.MultitenancyFlag,
   262  			utils.RevertReasonFlag,
   263  			utils.PrivateCacheTrieJournalFlag,
   264  			utils.QuorumEnablePrivacyMarker,
   265  		},
   266  	},
   267  	{
   268  		Name: "QUORUM PRIVATE TRANSACTION MANAGER",
   269  		Flags: []cli.Flag{
   270  			utils.QuorumPTMUnixSocketFlag,
   271  			utils.QuorumPTMUrlFlag,
   272  			utils.QuorumPTMTimeoutFlag,
   273  			utils.QuorumPTMDialTimeoutFlag,
   274  			utils.QuorumPTMHttpIdleTimeoutFlag,
   275  			utils.QuorumPTMHttpWriteBufferSizeFlag,
   276  			utils.QuorumPTMHttpReadBufferSizeFlag,
   277  			utils.QuorumPTMTlsModeFlag,
   278  			utils.QuorumPTMTlsRootCaFlag,
   279  			utils.QuorumPTMTlsClientCertFlag,
   280  			utils.QuorumPTMTlsClientKeyFlag,
   281  			utils.QuorumPTMTlsInsecureSkipVerify,
   282  		},
   283  	},
   284  	{
   285  		Name: quorumAccountFlagGroup,
   286  		Flags: []cli.Flag{
   287  			utils.AccountPluginNewAccountConfigFlag,
   288  		},
   289  	},
   290  	{
   291  		Name: "RAFT",
   292  		Flags: []cli.Flag{
   293  			utils.RaftModeFlag,
   294  			utils.RaftBlockTimeFlag,
   295  			utils.RaftJoinExistingFlag,
   296  			utils.RaftPortFlag,
   297  			utils.RaftDNSEnabledFlag,
   298  		},
   299  	},
   300  	{
   301  		Name: "ISTANBUL",
   302  		Flags: []cli.Flag{
   303  			utils.IstanbulRequestTimeoutFlag,
   304  			utils.IstanbulBlockPeriodFlag,
   305  		},
   306  	},
   307  	// END QUORUM
   308  	{
   309  		Name: "MISC",
   310  		Flags: []cli.Flag{
   311  			utils.SnapshotFlag,
   312  			cli.HelpFlag,
   313  		},
   314  	},
   315  }
   316  
   317  func init() {
   318  	// Override the default app help template
   319  	cli.AppHelpTemplate = flags.AppHelpTemplate
   320  
   321  	// Override the default app help printer, but only for the global app help
   322  	originalHelpPrinter := cli.HelpPrinter
   323  	cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) {
   324  		if tmpl == flags.AppHelpTemplate {
   325  			// Iterate over all the flags and add any uncategorized ones
   326  			categorized := make(map[string]struct{})
   327  			for _, group := range AppHelpFlagGroups {
   328  				for _, flag := range group.Flags {
   329  					categorized[flag.String()] = struct{}{}
   330  				}
   331  			}
   332  			deprecated := make(map[string]struct{})
   333  			for _, flag := range utils.DeprecatedFlags {
   334  				deprecated[flag.String()] = struct{}{}
   335  			}
   336  			// Only add uncategorized flags if they are not deprecated
   337  			var uncategorized []cli.Flag
   338  			for _, flag := range data.(*cli.App).Flags {
   339  				if _, ok := categorized[flag.String()]; !ok {
   340  					if _, ok := deprecated[flag.String()]; !ok {
   341  						uncategorized = append(uncategorized, flag)
   342  					}
   343  				}
   344  			}
   345  			if len(uncategorized) > 0 {
   346  				// Append all ungategorized options to the misc group
   347  				miscs := len(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags)
   348  				AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = append(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags, uncategorized...)
   349  
   350  				// Make sure they are removed afterwards
   351  				defer func() {
   352  					AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags[:miscs]
   353  				}()
   354  			}
   355  
   356  			// remove the Quorum account options from the main app usage as these should only be used by the geth account sub commands
   357  			for i, group := range AppHelpFlagGroups {
   358  				if group.Name == quorumAccountFlagGroup {
   359  					AppHelpFlagGroups = append(AppHelpFlagGroups[:i], AppHelpFlagGroups[i+1:]...)
   360  				}
   361  			}
   362  
   363  			// Render out custom usage screen
   364  			originalHelpPrinter(w, tmpl, flags.HelpData{App: data, FlagGroups: AppHelpFlagGroups})
   365  		} else if tmpl == flags.CommandHelpTemplate {
   366  			// Iterate over all command specific flags and categorize them
   367  			categorized := make(map[string][]cli.Flag)
   368  			for _, flag := range data.(cli.Command).Flags {
   369  				if _, ok := categorized[flag.String()]; !ok {
   370  					categorized[flags.FlagCategory(flag, AppHelpFlagGroups)] = append(categorized[flags.FlagCategory(flag, AppHelpFlagGroups)], flag)
   371  				}
   372  			}
   373  
   374  			// sort to get a stable ordering
   375  			sorted := make([]flags.FlagGroup, 0, len(categorized))
   376  			for cat, flgs := range categorized {
   377  				sorted = append(sorted, flags.FlagGroup{Name: cat, Flags: flgs})
   378  			}
   379  			sort.Sort(flags.ByCategory(sorted))
   380  
   381  			// add sorted array to data and render with default printer
   382  			originalHelpPrinter(w, tmpl, map[string]interface{}{
   383  				"cmd":              data,
   384  				"categorizedFlags": sorted,
   385  			})
   386  		} else {
   387  			originalHelpPrinter(w, tmpl, data)
   388  		}
   389  	}
   390  }