github.com/myafeier/go-ethereum@v1.6.8-0.20170719123245-3e0dbe0eaa72/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  	"io/ioutil"
    22  	"os"
    23  	"path/filepath"
    24  	"runtime"
    25  	"strconv"
    26  	"strings"
    27  
    28  	"github.com/ethereum/go-ethereum/cmd/utils"
    29  	"github.com/ethereum/go-ethereum/consensus/ethash"
    30  	"github.com/ethereum/go-ethereum/eth"
    31  	"github.com/ethereum/go-ethereum/params"
    32  	"gopkg.in/urfave/cli.v1"
    33  )
    34  
    35  var (
    36  	makedagCommand = cli.Command{
    37  		Action:    utils.MigrateFlags(makedag),
    38  		Name:      "makedag",
    39  		Usage:     "Generate ethash DAG (for testing)",
    40  		ArgsUsage: "<blockNum> <outputDir>",
    41  		Category:  "MISCELLANEOUS COMMANDS",
    42  		Description: `
    43  The makedag command generates an ethash DAG in /tmp/dag.
    44  
    45  This command exists to support the system testing project.
    46  Regular users do not need to execute it.
    47  `,
    48  	}
    49  	versionCommand = cli.Command{
    50  		Action:    utils.MigrateFlags(version),
    51  		Name:      "version",
    52  		Usage:     "Print version numbers",
    53  		ArgsUsage: " ",
    54  		Category:  "MISCELLANEOUS COMMANDS",
    55  		Description: `
    56  The output of this command is supposed to be machine-readable.
    57  `,
    58  	}
    59  	licenseCommand = cli.Command{
    60  		Action:    utils.MigrateFlags(license),
    61  		Name:      "license",
    62  		Usage:     "Display license information",
    63  		ArgsUsage: " ",
    64  		Category:  "MISCELLANEOUS COMMANDS",
    65  	}
    66  )
    67  
    68  func makedag(ctx *cli.Context) error {
    69  	args := ctx.Args()
    70  	wrongArgs := func() {
    71  		utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`)
    72  	}
    73  	switch {
    74  	case len(args) == 2:
    75  		blockNum, err := strconv.ParseUint(args[0], 0, 64)
    76  		dir := args[1]
    77  		if err != nil {
    78  			wrongArgs()
    79  		} else {
    80  			dir = filepath.Clean(dir)
    81  			// seems to require a trailing slash
    82  			if !strings.HasSuffix(dir, "/") {
    83  				dir = dir + "/"
    84  			}
    85  			_, err = ioutil.ReadDir(dir)
    86  			if err != nil {
    87  				utils.Fatalf("Can't find dir")
    88  			}
    89  			fmt.Println("making DAG, this could take awhile...")
    90  			ethash.MakeDataset(blockNum, dir)
    91  		}
    92  	default:
    93  		wrongArgs()
    94  	}
    95  	return nil
    96  }
    97  
    98  func version(ctx *cli.Context) error {
    99  	fmt.Println(strings.Title(clientIdentifier))
   100  	fmt.Println("Version:", params.Version)
   101  	if gitCommit != "" {
   102  		fmt.Println("Git Commit:", gitCommit)
   103  	}
   104  	fmt.Println("Architecture:", runtime.GOARCH)
   105  	fmt.Println("Protocol Versions:", eth.ProtocolVersions)
   106  	fmt.Println("Network Id:", eth.DefaultConfig.NetworkId)
   107  	fmt.Println("Go Version:", runtime.Version())
   108  	fmt.Println("Operating System:", runtime.GOOS)
   109  	fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
   110  	fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
   111  	return nil
   112  }
   113  
   114  func license(_ *cli.Context) error {
   115  	fmt.Println(`Geth is free software: you can redistribute it and/or modify
   116  it under the terms of the GNU General Public License as published by
   117  the Free Software Foundation, either version 3 of the License, or
   118  (at your option) any later version.
   119  
   120  Geth is distributed in the hope that it will be useful,
   121  but WITHOUT ANY WARRANTY; without even the implied warranty of
   122  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   123  GNU General Public License for more details.
   124  
   125  You should have received a copy of the GNU General Public License
   126  along with geth. If not, see <http://www.gnu.org/licenses/>.
   127  `)
   128  	return nil
   129  }