misccmd.go 3.6 KB

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