github.com/ethxdao/go-ethereum@v0.0.0-20221218102228-5ae34a9cc189/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/ethxdao/go-ethereum/cmd/utils" 27 "github.com/ethxdao/go-ethereum/consensus/ethash" 28 "github.com/ethxdao/go-ethereum/params" 29 ) 30 31 var ( 32 VersionCheckUrlFlag = &cli.StringFlag{ 33 Name: "check.url", 34 Usage: "URL to use when checking vulnerabilities", 35 Value: "https://geth.ethereum.org/docs/vulnerabilities/vulnerabilities.json", 36 } 37 VersionCheckVersionFlag = &cli.StringFlag{ 38 Name: "check.version", 39 Usage: "Version to check", 40 Value: fmt.Sprintf("Geth/v%v/%v-%v/%v", 41 params.VersionWithCommit(gitCommit, gitDate), 42 runtime.GOOS, runtime.GOARCH, runtime.Version()), 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: version, 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 version(ctx *cli.Context) error { 130 fmt.Println(strings.Title(clientIdentifier)) 131 fmt.Println("Version:", params.VersionWithMeta) 132 if gitCommit != "" { 133 fmt.Println("Git Commit:", gitCommit) 134 } 135 if gitDate != "" { 136 fmt.Println("Git Commit Date:", gitDate) 137 } 138 fmt.Println("Architecture:", runtime.GOARCH) 139 fmt.Println("Go Version:", runtime.Version()) 140 fmt.Println("Operating System:", runtime.GOOS) 141 fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH")) 142 fmt.Printf("GOROOT=%s\n", runtime.GOROOT()) 143 return nil 144 } 145 146 func license(_ *cli.Context) error { 147 fmt.Println(`Geth is free software: you can redistribute it and/or modify 148 it under the terms of the GNU General Public License as published by 149 the Free Software Foundation, either version 3 of the License, or 150 (at your option) any later version. 151 152 Geth is distributed in the hope that it will be useful, 153 but WITHOUT ANY WARRANTY; without even the implied warranty of 154 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 155 GNU General Public License for more details. 156 157 You should have received a copy of the GNU General Public License 158 along with geth. If not, see <http://www.gnu.org/licenses/>.`) 159 return nil 160 }