github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/cmd/geth/misccmd.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 12:09:29</date>
    10  //</624342594658242560>
    11  
    12  
    13  package main
    14  
    15  import (
    16  	"fmt"
    17  	"os"
    18  	"runtime"
    19  	"strconv"
    20  	"strings"
    21  
    22  	"github.com/ethereum/go-ethereum/cmd/utils"
    23  	"github.com/ethereum/go-ethereum/consensus/ethash"
    24  	"github.com/ethereum/go-ethereum/eth"
    25  	"github.com/ethereum/go-ethereum/params"
    26  	"gopkg.in/urfave/cli.v1"
    27  )
    28  
    29  var (
    30  	makecacheCommand = cli.Command{
    31  		Action:    utils.MigrateFlags(makecache),
    32  		Name:      "makecache",
    33  		Usage:     "Generate ethash verification cache (for testing)",
    34  		ArgsUsage: "<blockNum> <outputDir>",
    35  		Category:  "MISCELLANEOUS COMMANDS",
    36  		Description: `
    37  The makecache command generates an ethash cache in <outputDir>.
    38  
    39  This command exists to support the system testing project.
    40  Regular users do not need to execute it.
    41  `,
    42  	}
    43  	makedagCommand = cli.Command{
    44  		Action:    utils.MigrateFlags(makedag),
    45  		Name:      "makedag",
    46  		Usage:     "Generate ethash mining DAG (for testing)",
    47  		ArgsUsage: "<blockNum> <outputDir>",
    48  		Category:  "MISCELLANEOUS COMMANDS",
    49  		Description: `
    50  The makedag command generates an ethash DAG 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  	versionCommand = cli.Command{
    57  		Action:    utils.MigrateFlags(version),
    58  		Name:      "version",
    59  		Usage:     "Print version numbers",
    60  		ArgsUsage: " ",
    61  		Category:  "MISCELLANEOUS COMMANDS",
    62  		Description: `
    63  The output of this command is supposed to be machine-readable.
    64  `,
    65  	}
    66  	licenseCommand = cli.Command{
    67  		Action:    utils.MigrateFlags(license),
    68  		Name:      "license",
    69  		Usage:     "Display license information",
    70  		ArgsUsage: " ",
    71  		Category:  "MISCELLANEOUS COMMANDS",
    72  	}
    73  )
    74  
    75  //
    76  func makecache(ctx *cli.Context) error {
    77  	args := ctx.Args()
    78  	if len(args) != 2 {
    79  		utils.Fatalf(`Usage: geth makecache <block number> <outputdir>`)
    80  	}
    81  	block, err := strconv.ParseUint(args[0], 0, 64)
    82  	if err != nil {
    83  		utils.Fatalf("Invalid block number: %v", err)
    84  	}
    85  	ethash.MakeCache(block, args[1])
    86  
    87  	return nil
    88  }
    89  
    90  //
    91  func makedag(ctx *cli.Context) error {
    92  	args := ctx.Args()
    93  	if len(args) != 2 {
    94  		utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`)
    95  	}
    96  	block, err := strconv.ParseUint(args[0], 0, 64)
    97  	if err != nil {
    98  		utils.Fatalf("Invalid block number: %v", err)
    99  	}
   100  	ethash.MakeDataset(block, args[1])
   101  
   102  	return nil
   103  }
   104  
   105  func version(ctx *cli.Context) error {
   106  	fmt.Println(strings.Title(clientIdentifier))
   107  	fmt.Println("Version:", params.VersionWithMeta)
   108  	if gitCommit != "" {
   109  		fmt.Println("Git Commit:", gitCommit)
   110  	}
   111  	fmt.Println("Architecture:", runtime.GOARCH)
   112  	fmt.Println("Protocol Versions:", eth.ProtocolVersions)
   113  	fmt.Println("Network Id:", eth.DefaultConfig.NetworkId)
   114  	fmt.Println("Go Version:", runtime.Version())
   115  	fmt.Println("Operating System:", runtime.GOOS)
   116  	fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
   117  	fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
   118  	return nil
   119  }
   120  
   121  func license(_ *cli.Context) error {
   122  	fmt.Println(`Geth is free software: you can redistribute it and/or modify
   123  it under the terms of the GNU General Public License as published by
   124  the Free Software Foundation, either version 3 of the License, or
   125  (at your option) any later version.
   126  
   127  Geth is distributed in the hope that it will be useful,
   128  but WITHOUT ANY WARRANTY; without even the implied warranty of
   129  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   130  GNU General Public License for more details.
   131  
   132  You should have received a copy of the GNU General Public License
   133  along with geth. If not, see <http://www.gnu.org/licenses/>.`)
   134  	return nil
   135  }
   136