github.com/digdeepmining/go-atheios@v1.5.13-0.20180902133602-d5687a2e6f43/cmd/gath/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/ethash"
    29  	"github.com/atheioschain/go-atheios/cmd/utils"
    30  	"github.com/atheioschain/go-atheios/eth"
    31  	"github.com/atheioschain/go-atheios/params"
    32  	"gopkg.in/urfave/cli.v1"
    33  )
    34  
    35  var (
    36  	makedagCommand = cli.Command{
    37  		Action:    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:    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:    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: gath 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.MakeDAG(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("Protocol Versions:", eth.ProtocolVersions)
   105  	fmt.Println("Network Id:", ctx.GlobalInt(utils.NetworkIdFlag.Name))
   106  	fmt.Println("Go Version:", runtime.Version())
   107  	fmt.Println("OS:", runtime.GOOS)
   108  	fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
   109  	fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
   110  	return nil
   111  }
   112  
   113  func license(_ *cli.Context) error {
   114  	fmt.Println(`gath is free software: you can redistribute it and/or modify
   115  it under the terms of the GNU General Public License as published by
   116  the Free Software Foundation, either version 3 of the License, or
   117  (at your option) any later version.
   118  
   119  gath is distributed in the hope that it will be useful,
   120  but WITHOUT ANY WARRANTY; without even the implied warranty of
   121  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   122  GNU General Public License for more details.
   123  
   124  You should have received a copy of the GNU General Public License
   125  along with gath. If not, see <http://www.gnu.org/licenses/>.
   126  `)
   127  	return nil
   128  }