misccmd.go 3.6 KB

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