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

     1  // Copyright 2016 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  package main
    18  
    19  import (
    20  	"fmt"
    21  	"os"
    22  	"runtime"
    23  	"strconv"
    24  	"strings"
    25  
    26  	"github.com/kisexp/xdchain/cmd/utils"
    27  	"github.com/kisexp/xdchain/consensus/ethash"
    28  	"github.com/kisexp/xdchain/eth"
    29  	"github.com/kisexp/xdchain/params"
    30  	"gopkg.in/urfave/cli.v1"
    31  )
    32  
    33  var (
    34  	VersionCheckUrlFlag = cli.StringFlag{
    35  		Name:  "check.url",
    36  		Usage: "URL to use when checking vulnerabilities",
    37  		Value: "https://geth.ethereum.org/docs/vulnerabilities/vulnerabilities.json",
    38  	}
    39  	VersionCheckVersionFlag = cli.StringFlag{
    40  		Name:  "check.version",
    41  		Usage: "Version to check",
    42  		Value: fmt.Sprintf("Geth/v%v/%v-%v/%v",
    43  			params.VersionWithCommit(gitCommit, gitDate),
    44  			runtime.GOOS, runtime.GOARCH, runtime.Version()),
    45  	}
    46  	makecacheCommand = cli.Command{
    47  		Action:    utils.MigrateFlags(makecache),
    48  		Name:      "makecache",
    49  		Usage:     "Generate ethash verification cache (for testing)",
    50  		ArgsUsage: "<blockNum> <outputDir>",
    51  		Category:  "MISCELLANEOUS COMMANDS",
    52  		Description: `
    53  The makecache command generates an ethash cache in <outputDir>.
    54  
    55  This command exists to support the system testing project.
    56  Regular users do not need to execute it.
    57  `,
    58  	}
    59  	makedagCommand = cli.Command{
    60  		Action:    utils.MigrateFlags(makedag),
    61  		Name:      "makedag",
    62  		Usage:     "Generate ethash mining DAG (for testing)",
    63  		ArgsUsage: "<blockNum> <outputDir>",
    64  		Category:  "MISCELLANEOUS COMMANDS",
    65  		Description: `
    66  The makedag command generates an ethash DAG in <outputDir>.
    67  
    68  This command exists to support the system testing project.
    69  Regular users do not need to execute it.
    70  `,
    71  	}
    72  	versionCommand = cli.Command{
    73  		Action:    utils.MigrateFlags(version),
    74  		Name:      "version",
    75  		Usage:     "Print version numbers",
    76  		ArgsUsage: " ",
    77  		Category:  "MISCELLANEOUS COMMANDS",
    78  		Description: `
    79  The output of this command is supposed to be machine-readable.
    80  `,
    81  	}
    82  	versionCheckCommand = cli.Command{
    83  		Action: utils.MigrateFlags(versionCheck),
    84  		Flags: []cli.Flag{
    85  			VersionCheckUrlFlag,
    86  			VersionCheckVersionFlag,
    87  		},
    88  		Name:      "version-check",
    89  		Usage:     "Checks (online) whether the current version suffers from any known security vulnerabilities",
    90  		ArgsUsage: "<versionstring (optional)>",
    91  		Category:  "MISCELLANEOUS COMMANDS",
    92  		Description: `
    93  The version-check command fetches vulnerability-information from https://geth.ethereum.org/docs/vulnerabilities/vulnerabilities.json, 
    94  and displays information about any security vulnerabilities that affect the currently executing version.
    95  `,
    96  	}
    97  	licenseCommand = cli.Command{
    98  		Action:    utils.MigrateFlags(license),
    99  		Name:      "license",
   100  		Usage:     "Display license information",
   101  		ArgsUsage: " ",
   102  		Category:  "MISCELLANEOUS COMMANDS",
   103  	}
   104  )
   105  
   106  // makecache generates an ethash verification cache into the provided folder.
   107  func makecache(ctx *cli.Context) error {
   108  	args := ctx.Args()
   109  	if len(args) != 2 {
   110  		utils.Fatalf(`Usage: geth makecache <block number> <outputdir>`)
   111  	}
   112  	block, err := strconv.ParseUint(args[0], 0, 64)
   113  	if err != nil {
   114  		utils.Fatalf("Invalid block number: %v", err)
   115  	}
   116  	ethash.MakeCache(block, args[1])
   117  
   118  	return nil
   119  }
   120  
   121  // makedag generates an ethash mining DAG into the provided folder.
   122  func makedag(ctx *cli.Context) error {
   123  	args := ctx.Args()
   124  	if len(args) != 2 {
   125  		utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`)
   126  	}
   127  	block, err := strconv.ParseUint(args[0], 0, 64)
   128  	if err != nil {
   129  		utils.Fatalf("Invalid block number: %v", err)
   130  	}
   131  	ethash.MakeDataset(block, args[1])
   132  
   133  	return nil
   134  }
   135  
   136  func version(ctx *cli.Context) error {
   137  	fmt.Println(strings.Title(clientIdentifier))
   138  	fmt.Println("Version:", params.VersionWithMeta)
   139  	if gitCommit != "" {
   140  		fmt.Println("Git Commit:", gitCommit)
   141  	}
   142  	if gitDate != "" {
   143  		fmt.Println("Git Commit Date:", gitDate)
   144  	}
   145  	fmt.Println("Quorum Version:", params.QuorumVersion)
   146  	fmt.Println("Architecture:", runtime.GOARCH)
   147  	fmt.Println("Protocol Versions:", eth.ProtocolVersions)
   148  	fmt.Println("Network Id:", eth.DefaultConfig.NetworkId)
   149  	fmt.Println("Go Version:", runtime.Version())
   150  	fmt.Println("Operating System:", runtime.GOOS)
   151  	fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
   152  	fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
   153  	return nil
   154  }
   155  
   156  func license(_ *cli.Context) error {
   157  	fmt.Println(`Geth is free software: you can redistribute it and/or modify
   158  it under the terms of the GNU General Public License as published by
   159  the Free Software Foundation, either version 3 of the License, or
   160  (at your option) any later version.
   161  
   162  Geth is distributed in the hope that it will be useful,
   163  but WITHOUT ANY WARRANTY; without even the implied warranty of
   164  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   165  GNU General Public License for more details.
   166  
   167  You should have received a copy of the GNU General Public License
   168  along with geth. If not, see <http://www.gnu.org/licenses/>.`)
   169  	return nil
   170  }