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