github.com/aidoskuneen/adk-node@v0.0.0-20220315131952-2e32567cb7f4/adkgo-node/misccmd.go (about)

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