misccmd.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. "os"
  20. "runtime"
  21. "strconv"
  22. "strings"
  23. "github.com/ethereum/go-ethereum/cmd/utils"
  24. "github.com/ethereum/go-ethereum/consensus/ethash"
  25. "github.com/ethereum/go-ethereum/eth"
  26. "github.com/ethereum/go-ethereum/params"
  27. "gopkg.in/urfave/cli.v1"
  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. This command exists to support the system testing project.
  39. Regular users do not need to execute it.
  40. `,
  41. }
  42. makedagCommand = cli.Command{
  43. Action: utils.MigrateFlags(makedag),
  44. Name: "makedag",
  45. Usage: "Generate ethash mining DAG (for testing)",
  46. ArgsUsage: "<blockNum> <outputDir>",
  47. Category: "MISCELLANEOUS COMMANDS",
  48. Description: `
  49. The makedag command generates an ethash DAG in <outputDir>.
  50. This command exists to support the system testing project.
  51. Regular users do not need to execute it.
  52. `,
  53. }
  54. versionCommand = cli.Command{
  55. Action: utils.MigrateFlags(version),
  56. Name: "version",
  57. Usage: "Print version numbers",
  58. ArgsUsage: " ",
  59. Category: "MISCELLANEOUS COMMANDS",
  60. Description: `
  61. The output of this command is supposed to be machine-readable.
  62. `,
  63. }
  64. licenseCommand = cli.Command{
  65. Action: utils.MigrateFlags(license),
  66. Name: "license",
  67. Usage: "Display license information",
  68. ArgsUsage: " ",
  69. Category: "MISCELLANEOUS COMMANDS",
  70. }
  71. )
  72. // makecache generates an ethash verification cache into the provided folder.
  73. func makecache(ctx *cli.Context) error {
  74. args := ctx.Args()
  75. if len(args) != 2 {
  76. utils.Fatalf(`Usage: geth makecache <block number> <outputdir>`)
  77. }
  78. block, err := strconv.ParseUint(args[0], 0, 64)
  79. if err != nil {
  80. utils.Fatalf("Invalid block number: %v", err)
  81. }
  82. ethash.MakeCache(block, args[1])
  83. return nil
  84. }
  85. // makedag generates an ethash mining DAG into the provided folder.
  86. func makedag(ctx *cli.Context) error {
  87. args := ctx.Args()
  88. if len(args) != 2 {
  89. utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`)
  90. }
  91. block, err := strconv.ParseUint(args[0], 0, 64)
  92. if err != nil {
  93. utils.Fatalf("Invalid block number: %v", err)
  94. }
  95. ethash.MakeDataset(block, args[1])
  96. return nil
  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. func license(_ *cli.Context) error {
  114. fmt.Println(`Geth 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. Geth is distributed in the hope that it will be useful,
  119. but WITHOUT ANY WARRANTY; without even the implied warranty of
  120. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  121. GNU General Public License for more details.
  122. You should have received a copy of the GNU General Public License
  123. along with geth. If not, see <http://www.gnu.org/licenses/>.`)
  124. return nil
  125. }