main.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. // Copyright 2014 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. // geth is the official command-line client for Ethereum.
  17. package main
  18. import (
  19. "fmt"
  20. "io/ioutil"
  21. "os"
  22. "path/filepath"
  23. "runtime"
  24. "strconv"
  25. "strings"
  26. "time"
  27. "github.com/codegangsta/cli"
  28. "github.com/ethereum/ethash"
  29. "github.com/ethereum/go-ethereum/accounts"
  30. "github.com/ethereum/go-ethereum/cmd/utils"
  31. "github.com/ethereum/go-ethereum/common"
  32. "github.com/ethereum/go-ethereum/eth"
  33. "github.com/ethereum/go-ethereum/internal/debug"
  34. "github.com/ethereum/go-ethereum/logger"
  35. "github.com/ethereum/go-ethereum/logger/glog"
  36. "github.com/ethereum/go-ethereum/metrics"
  37. "github.com/ethereum/go-ethereum/node"
  38. "github.com/ethereum/go-ethereum/params"
  39. "github.com/ethereum/go-ethereum/rlp"
  40. )
  41. const (
  42. ClientIdentifier = "Geth"
  43. Version = "1.4.0-unstable"
  44. VersionMajor = 1
  45. VersionMinor = 4
  46. VersionPatch = 0
  47. )
  48. var (
  49. gitCommit string // set via linker flagg
  50. nodeNameVersion string
  51. app *cli.App
  52. )
  53. func init() {
  54. if gitCommit == "" {
  55. nodeNameVersion = Version
  56. } else {
  57. nodeNameVersion = Version + "-" + gitCommit[:8]
  58. }
  59. app = utils.NewApp(Version, "the go-ethereum command line interface")
  60. app.Action = geth
  61. app.HideVersion = true // we have a command to print the version
  62. app.Commands = []cli.Command{
  63. importCommand,
  64. exportCommand,
  65. upgradedbCommand,
  66. removedbCommand,
  67. dumpCommand,
  68. monitorCommand,
  69. {
  70. Action: makedag,
  71. Name: "makedag",
  72. Usage: "generate ethash dag (for testing)",
  73. Description: `
  74. The makedag command generates an ethash DAG in /tmp/dag.
  75. This command exists to support the system testing project.
  76. Regular users do not need to execute it.
  77. `,
  78. },
  79. {
  80. Action: gpuinfo,
  81. Name: "gpuinfo",
  82. Usage: "gpuinfo",
  83. Description: `
  84. Prints OpenCL device info for all found GPUs.
  85. `,
  86. },
  87. {
  88. Action: gpubench,
  89. Name: "gpubench",
  90. Usage: "benchmark GPU",
  91. Description: `
  92. Runs quick benchmark on first GPU found.
  93. `,
  94. },
  95. {
  96. Action: version,
  97. Name: "version",
  98. Usage: "print ethereum version numbers",
  99. Description: `
  100. The output of this command is supposed to be machine-readable.
  101. `,
  102. },
  103. {
  104. Name: "wallet",
  105. Usage: "ethereum presale wallet",
  106. Subcommands: []cli.Command{
  107. {
  108. Action: importWallet,
  109. Name: "import",
  110. Usage: "import ethereum presale wallet",
  111. },
  112. },
  113. Description: `
  114. get wallet import /path/to/my/presale.wallet
  115. will prompt for your password and imports your ether presale account.
  116. It can be used non-interactively with the --password option taking a
  117. passwordfile as argument containing the wallet password in plaintext.
  118. `},
  119. {
  120. Action: accountList,
  121. Name: "account",
  122. Usage: "manage accounts",
  123. Description: `
  124. Manage accounts lets you create new accounts, list all existing accounts,
  125. import a private key into a new account.
  126. ' help' shows a list of subcommands or help for one subcommand.
  127. It supports interactive mode, when you are prompted for password as well as
  128. non-interactive mode where passwords are supplied via a given password file.
  129. Non-interactive mode is only meant for scripted use on test networks or known
  130. safe environments.
  131. Make sure you remember the password you gave when creating a new account (with
  132. either new or import). Without it you are not able to unlock your account.
  133. Note that exporting your key in unencrypted format is NOT supported.
  134. Keys are stored under <DATADIR>/keys.
  135. It is safe to transfer the entire directory or the individual keys therein
  136. between ethereum nodes by simply copying.
  137. Make sure you backup your keys regularly.
  138. In order to use your account to send transactions, you need to unlock them using
  139. the '--unlock' option. The argument is a space separated list of addresses or
  140. indexes. If used non-interactively with a passwordfile, the file should contain
  141. the respective passwords one per line. If you unlock n accounts and the password
  142. file contains less than n entries, then the last password is meant to apply to
  143. all remaining accounts.
  144. And finally. DO NOT FORGET YOUR PASSWORD.
  145. `,
  146. Subcommands: []cli.Command{
  147. {
  148. Action: accountList,
  149. Name: "list",
  150. Usage: "print account addresses",
  151. },
  152. {
  153. Action: accountCreate,
  154. Name: "new",
  155. Usage: "create a new account",
  156. Description: `
  157. ethereum account new
  158. Creates a new account. Prints the address.
  159. The account is saved in encrypted format, you are prompted for a passphrase.
  160. You must remember this passphrase to unlock your account in the future.
  161. For non-interactive use the passphrase can be specified with the --password flag:
  162. ethereum --password <passwordfile> account new
  163. Note, this is meant to be used for testing only, it is a bad idea to save your
  164. password to file or expose in any other way.
  165. `,
  166. },
  167. {
  168. Action: accountUpdate,
  169. Name: "update",
  170. Usage: "update an existing account",
  171. Description: `
  172. ethereum account update <address>
  173. Update an existing account.
  174. The account is saved in the newest version in encrypted format, you are prompted
  175. for a passphrase to unlock the account and another to save the updated file.
  176. This same command can therefore be used to migrate an account of a deprecated
  177. format to the newest format or change the password for an account.
  178. For non-interactive use the passphrase can be specified with the --password flag:
  179. ethereum --password <passwordfile> account update <address>
  180. Since only one password can be given, only format update can be performed,
  181. changing your password is only possible interactively.
  182. Note that account update has the a side effect that the order of your accounts
  183. changes.
  184. `,
  185. },
  186. {
  187. Action: accountImport,
  188. Name: "import",
  189. Usage: "import a private key into a new account",
  190. Description: `
  191. ethereum account import <keyfile>
  192. Imports an unencrypted private key from <keyfile> and creates a new account.
  193. Prints the address.
  194. The keyfile is assumed to contain an unencrypted private key in hexadecimal format.
  195. The account is saved in encrypted format, you are prompted for a passphrase.
  196. You must remember this passphrase to unlock your account in the future.
  197. For non-interactive use the passphrase can be specified with the -password flag:
  198. ethereum --password <passwordfile> account import <keyfile>
  199. Note:
  200. As you can directly copy your encrypted accounts to another ethereum instance,
  201. this import mechanism is not needed when you transfer an account between
  202. nodes.
  203. `,
  204. },
  205. },
  206. },
  207. {
  208. Action: console,
  209. Name: "console",
  210. Usage: `Geth Console: interactive JavaScript environment`,
  211. Description: `
  212. The Geth console is an interactive shell for the JavaScript runtime environment
  213. which exposes a node admin interface as well as the Ðapp JavaScript API.
  214. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console
  215. `},
  216. {
  217. Action: attach,
  218. Name: "attach",
  219. Usage: `Geth Console: interactive JavaScript environment (connect to node)`,
  220. Description: `
  221. The Geth console is an interactive shell for the JavaScript runtime environment
  222. which exposes a node admin interface as well as the Ðapp JavaScript API.
  223. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console.
  224. This command allows to open a console on a running geth node.
  225. `,
  226. },
  227. {
  228. Action: execScripts,
  229. Name: "js",
  230. Usage: `executes the given JavaScript files in the Geth JavaScript VM`,
  231. Description: `
  232. The JavaScript VM exposes a node admin interface as well as the Ðapp
  233. JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console
  234. `,
  235. },
  236. }
  237. app.Flags = []cli.Flag{
  238. utils.IdentityFlag,
  239. utils.UnlockedAccountFlag,
  240. utils.PasswordFileFlag,
  241. utils.GenesisFileFlag,
  242. utils.BootnodesFlag,
  243. utils.DataDirFlag,
  244. utils.BlockchainVersionFlag,
  245. utils.OlympicFlag,
  246. utils.FastSyncFlag,
  247. utils.CacheFlag,
  248. utils.LightKDFFlag,
  249. utils.JSpathFlag,
  250. utils.ListenPortFlag,
  251. utils.MaxPeersFlag,
  252. utils.MaxPendingPeersFlag,
  253. utils.EtherbaseFlag,
  254. utils.GasPriceFlag,
  255. utils.MinerThreadsFlag,
  256. utils.MiningEnabledFlag,
  257. utils.MiningGPUFlag,
  258. utils.AutoDAGFlag,
  259. utils.NATFlag,
  260. utils.NatspecEnabledFlag,
  261. utils.NoDiscoverFlag,
  262. utils.NodeKeyFileFlag,
  263. utils.NodeKeyHexFlag,
  264. utils.RPCEnabledFlag,
  265. utils.RPCListenAddrFlag,
  266. utils.RPCPortFlag,
  267. utils.RPCApiFlag,
  268. utils.WSEnabledFlag,
  269. utils.WSListenAddrFlag,
  270. utils.WSPortFlag,
  271. utils.WSApiFlag,
  272. utils.WSAllowedDomainsFlag,
  273. utils.IPCDisabledFlag,
  274. utils.IPCApiFlag,
  275. utils.IPCPathFlag,
  276. utils.ExecFlag,
  277. utils.WhisperEnabledFlag,
  278. utils.DevModeFlag,
  279. utils.TestNetFlag,
  280. utils.VMDebugFlag,
  281. utils.VMForceJitFlag,
  282. utils.VMJitCacheFlag,
  283. utils.VMEnableJitFlag,
  284. utils.NetworkIdFlag,
  285. utils.RPCCORSDomainFlag,
  286. utils.MetricsEnabledFlag,
  287. utils.SolcPathFlag,
  288. utils.GpoMinGasPriceFlag,
  289. utils.GpoMaxGasPriceFlag,
  290. utils.GpoFullBlockRatioFlag,
  291. utils.GpobaseStepDownFlag,
  292. utils.GpobaseStepUpFlag,
  293. utils.GpobaseCorrectionFactorFlag,
  294. utils.ExtraDataFlag,
  295. }
  296. app.Flags = append(app.Flags, debug.Flags...)
  297. app.Before = func(ctx *cli.Context) error {
  298. runtime.GOMAXPROCS(runtime.NumCPU())
  299. if err := debug.Setup(ctx); err != nil {
  300. return err
  301. }
  302. // Start system runtime metrics collection
  303. go metrics.CollectProcessMetrics(3 * time.Second)
  304. utils.SetupNetwork(ctx)
  305. utils.SetupVM(ctx)
  306. return nil
  307. }
  308. app.After = func(ctx *cli.Context) error {
  309. logger.Flush()
  310. debug.Exit()
  311. return nil
  312. }
  313. }
  314. func main() {
  315. if err := app.Run(os.Args); err != nil {
  316. fmt.Fprintln(os.Stderr, err)
  317. os.Exit(1)
  318. }
  319. }
  320. func makeDefaultExtra() []byte {
  321. var clientInfo = struct {
  322. Version uint
  323. Name string
  324. GoVersion string
  325. Os string
  326. }{uint(VersionMajor<<16 | VersionMinor<<8 | VersionPatch), ClientIdentifier, runtime.Version(), runtime.GOOS}
  327. extra, err := rlp.EncodeToBytes(clientInfo)
  328. if err != nil {
  329. glog.V(logger.Warn).Infoln("error setting canonical miner information:", err)
  330. }
  331. if uint64(len(extra)) > params.MaximumExtraDataSize.Uint64() {
  332. glog.V(logger.Warn).Infoln("error setting canonical miner information: extra exceeds", params.MaximumExtraDataSize)
  333. glog.V(logger.Debug).Infof("extra: %x\n", extra)
  334. return nil
  335. }
  336. return extra
  337. }
  338. // geth is the main entry point into the system if no special subcommand is ran.
  339. // It creates a default node based on the command line arguments and runs it in
  340. // blocking mode, waiting for it to be shut down.
  341. func geth(ctx *cli.Context) {
  342. node := utils.MakeSystemNode(ClientIdentifier, nodeNameVersion, makeDefaultExtra(), ctx)
  343. startNode(ctx, node)
  344. node.Wait()
  345. }
  346. // attach will connect to a running geth instance attaching a JavaScript console and to it.
  347. func attach(ctx *cli.Context) {
  348. // attach to a running geth instance
  349. client, err := utils.NewRemoteRPCClient(ctx)
  350. if err != nil {
  351. utils.Fatalf("Unable to attach to geth - %v", err)
  352. }
  353. repl := newLightweightJSRE(
  354. ctx.GlobalString(utils.JSpathFlag.Name),
  355. client,
  356. ctx.GlobalString(utils.DataDirFlag.Name),
  357. true,
  358. )
  359. if ctx.GlobalString(utils.ExecFlag.Name) != "" {
  360. repl.batch(ctx.GlobalString(utils.ExecFlag.Name))
  361. } else {
  362. repl.welcome()
  363. repl.interactive()
  364. }
  365. }
  366. // console starts a new geth node, attaching a JavaScript console to it at the
  367. // same time.
  368. func console(ctx *cli.Context) {
  369. // Create and start the node based on the CLI flags
  370. node := utils.MakeSystemNode(ClientIdentifier, nodeNameVersion, makeDefaultExtra(), ctx)
  371. startNode(ctx, node)
  372. // Attach to the newly started node, and either execute script or become interactive
  373. client := utils.NewInProcRPCClient(node)
  374. repl := newJSRE(node,
  375. ctx.GlobalString(utils.JSpathFlag.Name),
  376. ctx.GlobalString(utils.RPCCORSDomainFlag.Name),
  377. client, true)
  378. if script := ctx.GlobalString(utils.ExecFlag.Name); script != "" {
  379. repl.batch(script)
  380. } else {
  381. repl.welcome()
  382. repl.interactive()
  383. }
  384. node.Stop()
  385. }
  386. // execScripts starts a new geth node based on the CLI flags, and executes each
  387. // of the JavaScript files specified as command arguments.
  388. func execScripts(ctx *cli.Context) {
  389. // Create and start the node based on the CLI flags
  390. node := utils.MakeSystemNode(ClientIdentifier, nodeNameVersion, makeDefaultExtra(), ctx)
  391. startNode(ctx, node)
  392. // Attach to the newly started node and execute the given scripts
  393. client := utils.NewInProcRPCClient(node)
  394. repl := newJSRE(node,
  395. ctx.GlobalString(utils.JSpathFlag.Name),
  396. ctx.GlobalString(utils.RPCCORSDomainFlag.Name),
  397. client, false)
  398. for _, file := range ctx.Args() {
  399. repl.exec(file)
  400. }
  401. node.Stop()
  402. }
  403. // tries unlocking the specified account a few times.
  404. func unlockAccount(ctx *cli.Context, accman *accounts.Manager, address string, i int, passwords []string) (common.Address, string) {
  405. account, err := utils.MakeAddress(accman, address)
  406. if err != nil {
  407. utils.Fatalf("Unlock error: %v", err)
  408. }
  409. for trials := 0; trials < 3; trials++ {
  410. prompt := fmt.Sprintf("Unlocking account %s | Attempt %d/%d", address, trials+1, 3)
  411. password := getPassPhrase(prompt, false, i, passwords)
  412. if err := accman.Unlock(account, password); err == nil {
  413. return account, password
  414. }
  415. }
  416. // All trials expended to unlock account, bail out
  417. utils.Fatalf("Failed to unlock account: %s", address)
  418. return common.Address{}, ""
  419. }
  420. // startNode boots up the system node and all registered protocols, after which
  421. // it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
  422. // miner.
  423. func startNode(ctx *cli.Context, stack *node.Node) {
  424. // Start up the node itself
  425. utils.StartNode(stack)
  426. // Unlock any account specifically requested
  427. var ethereum *eth.Ethereum
  428. if err := stack.Service(&ethereum); err != nil {
  429. utils.Fatalf("ethereum service not running: %v", err)
  430. }
  431. accman := ethereum.AccountManager()
  432. passwords := utils.MakePasswordList(ctx)
  433. accounts := strings.Split(ctx.GlobalString(utils.UnlockedAccountFlag.Name), ",")
  434. for i, account := range accounts {
  435. if trimmed := strings.TrimSpace(account); trimmed != "" {
  436. unlockAccount(ctx, accman, trimmed, i, passwords)
  437. }
  438. }
  439. // Start auxiliary services if enabled.
  440. if !ctx.GlobalBool(utils.IPCDisabledFlag.Name) {
  441. if err := utils.StartIPC(stack, ctx); err != nil {
  442. utils.Fatalf("Failed to start IPC: %v", err)
  443. }
  444. }
  445. if ctx.GlobalBool(utils.RPCEnabledFlag.Name) {
  446. if err := utils.StartRPC(stack, ctx); err != nil {
  447. utils.Fatalf("Failed to start RPC: %v", err)
  448. }
  449. }
  450. if ctx.GlobalBool(utils.WSEnabledFlag.Name) {
  451. if err := utils.StartWS(stack, ctx); err != nil {
  452. utils.Fatalf("Failed to start WS: %v", err)
  453. }
  454. }
  455. if ctx.GlobalBool(utils.MiningEnabledFlag.Name) {
  456. if err := ethereum.StartMining(ctx.GlobalInt(utils.MinerThreadsFlag.Name), ctx.GlobalString(utils.MiningGPUFlag.Name)); err != nil {
  457. utils.Fatalf("Failed to start mining: %v", err)
  458. }
  459. }
  460. }
  461. func accountList(ctx *cli.Context) {
  462. accman := utils.MakeAccountManager(ctx)
  463. accts, err := accman.Accounts()
  464. if err != nil {
  465. utils.Fatalf("Could not list accounts: %v", err)
  466. }
  467. for i, acct := range accts {
  468. fmt.Printf("Account #%d: %x\n", i, acct)
  469. }
  470. }
  471. // getPassPhrase retrieves the passwor associated with an account, either fetched
  472. // from a list of preloaded passphrases, or requested interactively from the user.
  473. func getPassPhrase(prompt string, confirmation bool, i int, passwords []string) string {
  474. // If a list of passwords was supplied, retrieve from them
  475. if len(passwords) > 0 {
  476. if i < len(passwords) {
  477. return passwords[i]
  478. }
  479. return passwords[len(passwords)-1]
  480. }
  481. // Otherwise prompt the user for the password
  482. fmt.Println(prompt)
  483. password, err := utils.PromptPassword("Passphrase: ", true)
  484. if err != nil {
  485. utils.Fatalf("Failed to read passphrase: %v", err)
  486. }
  487. if confirmation {
  488. confirm, err := utils.PromptPassword("Repeat passphrase: ", false)
  489. if err != nil {
  490. utils.Fatalf("Failed to read passphrase confirmation: %v", err)
  491. }
  492. if password != confirm {
  493. utils.Fatalf("Passphrases do not match")
  494. }
  495. }
  496. return password
  497. }
  498. // accountCreate creates a new account into the keystore defined by the CLI flags.
  499. func accountCreate(ctx *cli.Context) {
  500. accman := utils.MakeAccountManager(ctx)
  501. password := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx))
  502. account, err := accman.NewAccount(password)
  503. if err != nil {
  504. utils.Fatalf("Failed to create account: %v", err)
  505. }
  506. fmt.Printf("Address: %x\n", account)
  507. }
  508. // accountUpdate transitions an account from a previous format to the current
  509. // one, also providing the possibility to change the pass-phrase.
  510. func accountUpdate(ctx *cli.Context) {
  511. if len(ctx.Args()) == 0 {
  512. utils.Fatalf("No accounts specified to update")
  513. }
  514. accman := utils.MakeAccountManager(ctx)
  515. account, oldPassword := unlockAccount(ctx, accman, ctx.Args().First(), 0, nil)
  516. newPassword := getPassPhrase("Please give a new password. Do not forget this password.", true, 0, nil)
  517. if err := accman.Update(account, oldPassword, newPassword); err != nil {
  518. utils.Fatalf("Could not update the account: %v", err)
  519. }
  520. }
  521. func importWallet(ctx *cli.Context) {
  522. keyfile := ctx.Args().First()
  523. if len(keyfile) == 0 {
  524. utils.Fatalf("keyfile must be given as argument")
  525. }
  526. keyJson, err := ioutil.ReadFile(keyfile)
  527. if err != nil {
  528. utils.Fatalf("Could not read wallet file: %v", err)
  529. }
  530. accman := utils.MakeAccountManager(ctx)
  531. passphrase := getPassPhrase("", false, 0, utils.MakePasswordList(ctx))
  532. acct, err := accman.ImportPreSaleKey(keyJson, passphrase)
  533. if err != nil {
  534. utils.Fatalf("Could not create the account: %v", err)
  535. }
  536. fmt.Printf("Address: %x\n", acct)
  537. }
  538. func accountImport(ctx *cli.Context) {
  539. keyfile := ctx.Args().First()
  540. if len(keyfile) == 0 {
  541. utils.Fatalf("keyfile must be given as argument")
  542. }
  543. accman := utils.MakeAccountManager(ctx)
  544. passphrase := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx))
  545. acct, err := accman.Import(keyfile, passphrase)
  546. if err != nil {
  547. utils.Fatalf("Could not create the account: %v", err)
  548. }
  549. fmt.Printf("Address: %x\n", acct)
  550. }
  551. func makedag(ctx *cli.Context) {
  552. args := ctx.Args()
  553. wrongArgs := func() {
  554. utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`)
  555. }
  556. switch {
  557. case len(args) == 2:
  558. blockNum, err := strconv.ParseUint(args[0], 0, 64)
  559. dir := args[1]
  560. if err != nil {
  561. wrongArgs()
  562. } else {
  563. dir = filepath.Clean(dir)
  564. // seems to require a trailing slash
  565. if !strings.HasSuffix(dir, "/") {
  566. dir = dir + "/"
  567. }
  568. _, err = ioutil.ReadDir(dir)
  569. if err != nil {
  570. utils.Fatalf("Can't find dir")
  571. }
  572. fmt.Println("making DAG, this could take awhile...")
  573. ethash.MakeDAG(blockNum, dir)
  574. }
  575. default:
  576. wrongArgs()
  577. }
  578. }
  579. func gpuinfo(ctx *cli.Context) {
  580. eth.PrintOpenCLDevices()
  581. }
  582. func gpubench(ctx *cli.Context) {
  583. args := ctx.Args()
  584. wrongArgs := func() {
  585. utils.Fatalf(`Usage: geth gpubench <gpu number>`)
  586. }
  587. switch {
  588. case len(args) == 1:
  589. n, err := strconv.ParseUint(args[0], 0, 64)
  590. if err != nil {
  591. wrongArgs()
  592. }
  593. eth.GPUBench(n)
  594. case len(args) == 0:
  595. eth.GPUBench(0)
  596. default:
  597. wrongArgs()
  598. }
  599. }
  600. func version(c *cli.Context) {
  601. fmt.Println(ClientIdentifier)
  602. fmt.Println("Version:", Version)
  603. if gitCommit != "" {
  604. fmt.Println("Git Commit:", gitCommit)
  605. }
  606. fmt.Println("Protocol Versions:", eth.ProtocolVersions)
  607. fmt.Println("Network Id:", c.GlobalInt(utils.NetworkIdFlag.Name))
  608. fmt.Println("Go Version:", runtime.Version())
  609. fmt.Println("OS:", runtime.GOOS)
  610. fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
  611. fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
  612. }