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