main.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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. /**
  17. * @authors
  18. * Jeffrey Wilcke <i@jev.io>
  19. */
  20. package main
  21. import (
  22. "fmt"
  23. "io"
  24. "io/ioutil"
  25. _ "net/http/pprof"
  26. "os"
  27. "path/filepath"
  28. "runtime"
  29. "strconv"
  30. "strings"
  31. "time"
  32. "github.com/codegangsta/cli"
  33. "github.com/ethereum/ethash"
  34. "github.com/ethereum/go-ethereum/accounts"
  35. "github.com/ethereum/go-ethereum/cmd/utils"
  36. "github.com/ethereum/go-ethereum/common"
  37. "github.com/ethereum/go-ethereum/core"
  38. "github.com/ethereum/go-ethereum/core/types"
  39. "github.com/ethereum/go-ethereum/eth"
  40. "github.com/ethereum/go-ethereum/ethdb"
  41. "github.com/ethereum/go-ethereum/logger"
  42. "github.com/ethereum/go-ethereum/logger/glog"
  43. "github.com/ethereum/go-ethereum/metrics"
  44. "github.com/ethereum/go-ethereum/rpc/codec"
  45. "github.com/ethereum/go-ethereum/rpc/comms"
  46. "github.com/mattn/go-colorable"
  47. "github.com/mattn/go-isatty"
  48. )
  49. const (
  50. ClientIdentifier = "Geth"
  51. Version = "0.9.35"
  52. )
  53. var (
  54. gitCommit string // set via linker flag
  55. nodeNameVersion string
  56. app *cli.App
  57. )
  58. func init() {
  59. if gitCommit == "" {
  60. nodeNameVersion = Version
  61. } else {
  62. nodeNameVersion = Version + "-" + gitCommit[:8]
  63. }
  64. app = utils.NewApp(Version, "the go-ethereum command line interface")
  65. app.Action = run
  66. app.HideVersion = true // we have a command to print the version
  67. app.Commands = []cli.Command{
  68. {
  69. Action: blockRecovery,
  70. Name: "recover",
  71. Usage: "attempts to recover a corrupted database by setting a new block by number or hash. See help recover.",
  72. Description: `
  73. The recover commands will attempt to read out the last
  74. block based on that.
  75. recover #number recovers by number
  76. recover <hex> recovers by hash
  77. `,
  78. },
  79. blocktestCommand,
  80. importCommand,
  81. exportCommand,
  82. upgradedbCommand,
  83. removedbCommand,
  84. dumpCommand,
  85. monitorCommand,
  86. {
  87. Action: makedag,
  88. Name: "makedag",
  89. Usage: "generate ethash dag (for testing)",
  90. Description: `
  91. The makedag command generates an ethash DAG in /tmp/dag.
  92. This command exists to support the system testing project.
  93. Regular users do not need to execute it.
  94. `,
  95. },
  96. {
  97. Action: version,
  98. Name: "version",
  99. Usage: "print ethereum version numbers",
  100. Description: `
  101. The output of this command is supposed to be machine-readable.
  102. `,
  103. },
  104. {
  105. Name: "wallet",
  106. Usage: "ethereum presale wallet",
  107. Subcommands: []cli.Command{
  108. {
  109. Action: importWallet,
  110. Name: "import",
  111. Usage: "import ethereum presale wallet",
  112. },
  113. },
  114. Description: `
  115. get wallet import /path/to/my/presale.wallet
  116. will prompt for your password and imports your ether presale account.
  117. It can be used non-interactively with the --password option taking a
  118. passwordfile as argument containing the wallet password in plaintext.
  119. `},
  120. {
  121. Action: accountList,
  122. Name: "account",
  123. Usage: "manage accounts",
  124. Description: `
  125. Manage accounts lets you create new accounts, list all existing accounts,
  126. import a private key into a new account.
  127. ' help' shows a list of subcommands or help for one subcommand.
  128. It supports interactive mode, when you are prompted for password as well as
  129. non-interactive mode where passwords are supplied via a given password file.
  130. Non-interactive mode is only meant for scripted use on test networks or known
  131. safe environments.
  132. Make sure you remember the password you gave when creating a new account (with
  133. either new or import). Without it you are not able to unlock your account.
  134. Note that exporting your key in unencrypted format is NOT supported.
  135. Keys are stored under <DATADIR>/keys.
  136. It is safe to transfer the entire directory or the individual keys therein
  137. between ethereum nodes by simply copying.
  138. Make sure you backup your keys regularly.
  139. In order to use your account to send transactions, you need to unlock them using the
  140. '--unlock' option. The argument is a comma
  141. And finally. DO NOT FORGET YOUR PASSWORD.
  142. `,
  143. Subcommands: []cli.Command{
  144. {
  145. Action: accountList,
  146. Name: "list",
  147. Usage: "print account addresses",
  148. },
  149. {
  150. Action: accountCreate,
  151. Name: "new",
  152. Usage: "create a new account",
  153. Description: `
  154. ethereum account new
  155. Creates a new account. Prints the address.
  156. The account is saved in encrypted format, you are prompted for a passphrase.
  157. You must remember this passphrase to unlock your account in the future.
  158. For non-interactive use the passphrase can be specified with the --password flag:
  159. ethereum --password <passwordfile> account new
  160. Note, this is meant to be used for testing only, it is a bad idea to save your
  161. password to file or expose in any other way.
  162. `,
  163. },
  164. {
  165. Action: accountUpdate,
  166. Name: "update",
  167. Usage: "update an existing account",
  168. Description: `
  169. ethereum account update <address>
  170. Update an existing account.
  171. The account is saved in the newest version in encrypted format, you are prompted
  172. for a passphrase to unlock the account and another to save the updated file.
  173. This same command can therefore be used to migrate an account of a deprecated
  174. format to the newest format or change the password for an account.
  175. For non-interactive use the passphrase can be specified with the --password flag:
  176. ethereum --password <passwordfile> account new
  177. Since only one password can be given, only format update can be performed,
  178. changing your password is only possible interactively.
  179. Note that account update has the a side effect that the order of your accounts
  180. changes.
  181. `,
  182. },
  183. {
  184. Action: accountImport,
  185. Name: "import",
  186. Usage: "import a private key into a new account",
  187. Description: `
  188. ethereum account import <keyfile>
  189. Imports an unencrypted private key from <keyfile> and creates a new account.
  190. Prints the address.
  191. The keyfile is assumed to contain an unencrypted private key in hexadecimal format.
  192. The account is saved in encrypted format, you are prompted for a passphrase.
  193. You must remember this passphrase to unlock your account in the future.
  194. For non-interactive use the passphrase can be specified with the -password flag:
  195. ethereum --password <passwordfile> account import <keyfile>
  196. Note:
  197. As you can directly copy your encrypted accounts to another ethereum instance,
  198. this import mechanism is not needed when you transfer an account between
  199. nodes.
  200. `,
  201. },
  202. },
  203. },
  204. {
  205. Action: console,
  206. Name: "console",
  207. Usage: `Geth Console: interactive JavaScript environment`,
  208. Description: `
  209. The Geth console is an interactive shell for the JavaScript runtime environment
  210. which exposes a node admin interface as well as the Ðapp JavaScript API.
  211. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console
  212. `},
  213. {
  214. Action: attach,
  215. Name: "attach",
  216. Usage: `Geth Console: interactive JavaScript environment (connect to node)`,
  217. Description: `
  218. The Geth console is an interactive shell for the JavaScript runtime environment
  219. which exposes a node admin interface as well as the Ðapp JavaScript API.
  220. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console.
  221. This command allows to open a console on a running geth node.
  222. `,
  223. },
  224. {
  225. Action: execJSFiles,
  226. Name: "js",
  227. Usage: `executes the given JavaScript files in the Geth JavaScript VM`,
  228. Description: `
  229. The JavaScript VM exposes a node admin interface as well as the Ðapp
  230. JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console
  231. `,
  232. },
  233. }
  234. app.Flags = []cli.Flag{
  235. utils.IdentityFlag,
  236. utils.UnlockedAccountFlag,
  237. utils.PasswordFileFlag,
  238. utils.GenesisNonceFlag,
  239. utils.BootnodesFlag,
  240. utils.DataDirFlag,
  241. utils.BlockchainVersionFlag,
  242. utils.JSpathFlag,
  243. utils.ListenPortFlag,
  244. utils.MaxPeersFlag,
  245. utils.MaxPendingPeersFlag,
  246. utils.EtherbaseFlag,
  247. utils.GasPriceFlag,
  248. utils.MinerThreadsFlag,
  249. utils.MiningEnabledFlag,
  250. utils.AutoDAGFlag,
  251. utils.NATFlag,
  252. utils.NatspecEnabledFlag,
  253. utils.NoDiscoverFlag,
  254. utils.NodeKeyFileFlag,
  255. utils.NodeKeyHexFlag,
  256. utils.RPCEnabledFlag,
  257. utils.RPCListenAddrFlag,
  258. utils.RPCPortFlag,
  259. utils.RpcApiFlag,
  260. utils.IPCDisabledFlag,
  261. utils.IPCApiFlag,
  262. utils.IPCPathFlag,
  263. utils.ExecFlag,
  264. utils.WhisperEnabledFlag,
  265. utils.VMDebugFlag,
  266. utils.NetworkIdFlag,
  267. utils.RPCCORSDomainFlag,
  268. utils.VerbosityFlag,
  269. utils.BacktraceAtFlag,
  270. utils.LogToStdErrFlag,
  271. utils.LogVModuleFlag,
  272. utils.LogFileFlag,
  273. utils.LogJSONFlag,
  274. utils.PProfEanbledFlag,
  275. utils.PProfPortFlag,
  276. utils.MetricsEnabledFlag,
  277. utils.SolcPathFlag,
  278. utils.GpoMinGasPriceFlag,
  279. utils.GpoMaxGasPriceFlag,
  280. utils.GpoFullBlockRatioFlag,
  281. utils.GpobaseStepDownFlag,
  282. utils.GpobaseStepUpFlag,
  283. utils.GpobaseCorrectionFactorFlag,
  284. }
  285. app.Before = func(ctx *cli.Context) error {
  286. utils.SetupLogger(ctx)
  287. if ctx.GlobalBool(utils.PProfEanbledFlag.Name) {
  288. utils.StartPProf(ctx)
  289. }
  290. return nil
  291. }
  292. // Start system runtime metrics collection
  293. go metrics.CollectProcessMetrics(3 * time.Second)
  294. }
  295. func main() {
  296. runtime.GOMAXPROCS(runtime.NumCPU())
  297. defer logger.Flush()
  298. if err := app.Run(os.Args); err != nil {
  299. fmt.Fprintln(os.Stderr, err)
  300. os.Exit(1)
  301. }
  302. }
  303. func run(ctx *cli.Context) {
  304. cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
  305. ethereum, err := eth.New(cfg)
  306. if err != nil {
  307. utils.Fatalf("%v", err)
  308. }
  309. startEth(ctx, ethereum)
  310. // this blocks the thread
  311. ethereum.WaitForShutdown()
  312. }
  313. func attach(ctx *cli.Context) {
  314. // Wrap the standard output with a colorified stream (windows)
  315. if isatty.IsTerminal(os.Stdout.Fd()) {
  316. if pr, pw, err := os.Pipe(); err == nil {
  317. go io.Copy(colorable.NewColorableStdout(), pr)
  318. os.Stdout = pw
  319. }
  320. }
  321. var client comms.EthereumClient
  322. var err error
  323. if ctx.Args().Present() {
  324. client, err = comms.ClientFromEndpoint(ctx.Args().First(), codec.JSON)
  325. } else {
  326. cfg := comms.IpcConfig{
  327. Endpoint: ctx.GlobalString(utils.IPCPathFlag.Name),
  328. }
  329. client, err = comms.NewIpcClient(cfg, codec.JSON)
  330. }
  331. if err != nil {
  332. utils.Fatalf("Unable to attach to geth node - %v", err)
  333. }
  334. repl := newLightweightJSRE(
  335. ctx.GlobalString(utils.JSpathFlag.Name),
  336. client,
  337. true,
  338. nil)
  339. if ctx.GlobalString(utils.ExecFlag.Name) != "" {
  340. repl.batch(ctx.GlobalString(utils.ExecFlag.Name))
  341. } else {
  342. repl.welcome()
  343. repl.interactive()
  344. }
  345. }
  346. func console(ctx *cli.Context) {
  347. // Wrap the standard output with a colorified stream (windows)
  348. if isatty.IsTerminal(os.Stdout.Fd()) {
  349. if pr, pw, err := os.Pipe(); err == nil {
  350. go io.Copy(colorable.NewColorableStdout(), pr)
  351. os.Stdout = pw
  352. }
  353. }
  354. cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
  355. ethereum, err := eth.New(cfg)
  356. if err != nil {
  357. utils.Fatalf("%v", err)
  358. }
  359. client := comms.NewInProcClient(codec.JSON)
  360. startEth(ctx, ethereum)
  361. repl := newJSRE(
  362. ethereum,
  363. ctx.GlobalString(utils.JSpathFlag.Name),
  364. ctx.GlobalString(utils.RPCCORSDomainFlag.Name),
  365. client,
  366. true,
  367. nil,
  368. )
  369. if ctx.GlobalString(utils.ExecFlag.Name) != "" {
  370. repl.batch(ctx.GlobalString(utils.ExecFlag.Name))
  371. } else {
  372. repl.welcome()
  373. repl.interactive()
  374. }
  375. ethereum.Stop()
  376. ethereum.WaitForShutdown()
  377. }
  378. func execJSFiles(ctx *cli.Context) {
  379. cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
  380. ethereum, err := eth.New(cfg)
  381. if err != nil {
  382. utils.Fatalf("%v", err)
  383. }
  384. client := comms.NewInProcClient(codec.JSON)
  385. startEth(ctx, ethereum)
  386. repl := newJSRE(
  387. ethereum,
  388. ctx.GlobalString(utils.JSpathFlag.Name),
  389. ctx.GlobalString(utils.RPCCORSDomainFlag.Name),
  390. client,
  391. false,
  392. nil,
  393. )
  394. for _, file := range ctx.Args() {
  395. repl.exec(file)
  396. }
  397. ethereum.Stop()
  398. ethereum.WaitForShutdown()
  399. }
  400. func unlockAccount(ctx *cli.Context, am *accounts.Manager, addr string, i int) (addrHex, auth string) {
  401. var err error
  402. addrHex = utils.ParamToAddress(addr, am)
  403. // Attempt to unlock the account 3 times
  404. attempts := 3
  405. for tries := 0; tries < attempts; tries++ {
  406. msg := fmt.Sprintf("Unlocking account %s | Attempt %d/%d", addr, tries+1, attempts)
  407. auth = getPassPhrase(ctx, msg, false, i)
  408. err = am.Unlock(common.HexToAddress(addrHex), auth)
  409. if err == nil {
  410. break
  411. }
  412. }
  413. if err != nil {
  414. utils.Fatalf("Unlock account failed '%v'", err)
  415. }
  416. fmt.Printf("Account '%s' unlocked.\n", addr)
  417. return
  418. }
  419. func blockRecovery(ctx *cli.Context) {
  420. arg := ctx.Args().First()
  421. if len(ctx.Args()) < 1 && len(arg) > 0 {
  422. glog.Fatal("recover requires block number or hash")
  423. }
  424. cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
  425. blockDb, err := ethdb.NewLDBDatabase(filepath.Join(cfg.DataDir, "blockchain"))
  426. if err != nil {
  427. glog.Fatalln("could not open db:", err)
  428. }
  429. var block *types.Block
  430. if arg[0] == '#' {
  431. block = core.GetBlockByNumber(blockDb, common.String2Big(arg[1:]).Uint64())
  432. } else {
  433. block = core.GetBlockByHash(blockDb, common.HexToHash(arg))
  434. }
  435. if block == nil {
  436. glog.Fatalln("block not found. Recovery failed")
  437. }
  438. err = core.WriteHead(blockDb, block)
  439. if err != nil {
  440. glog.Fatalln("block write err", err)
  441. }
  442. glog.Infof("Recovery succesful. New HEAD %x\n", block.Hash())
  443. }
  444. func startEth(ctx *cli.Context, eth *eth.Ethereum) {
  445. // Start Ethereum itself
  446. utils.StartEthereum(eth)
  447. am := eth.AccountManager()
  448. account := ctx.GlobalString(utils.UnlockedAccountFlag.Name)
  449. accounts := strings.Split(account, " ")
  450. for i, account := range accounts {
  451. if len(account) > 0 {
  452. if account == "primary" {
  453. utils.Fatalf("the 'primary' keyword is deprecated. You can use integer indexes, but the indexes are not permanent, they can change if you add external keys, export your keys or copy your keystore to another node.")
  454. }
  455. unlockAccount(ctx, am, account, i)
  456. }
  457. }
  458. // Start auxiliary services if enabled.
  459. if !ctx.GlobalBool(utils.IPCDisabledFlag.Name) {
  460. if err := utils.StartIPC(eth, ctx); err != nil {
  461. utils.Fatalf("Error string IPC: %v", err)
  462. }
  463. }
  464. if ctx.GlobalBool(utils.RPCEnabledFlag.Name) {
  465. if err := utils.StartRPC(eth, ctx); err != nil {
  466. utils.Fatalf("Error starting RPC: %v", err)
  467. }
  468. }
  469. if ctx.GlobalBool(utils.MiningEnabledFlag.Name) {
  470. if err := eth.StartMining(ctx.GlobalInt(utils.MinerThreadsFlag.Name)); err != nil {
  471. utils.Fatalf("%v", err)
  472. }
  473. }
  474. }
  475. func accountList(ctx *cli.Context) {
  476. am := utils.MakeAccountManager(ctx)
  477. accts, err := am.Accounts()
  478. if err != nil {
  479. utils.Fatalf("Could not list accounts: %v", err)
  480. }
  481. for i, acct := range accts {
  482. fmt.Printf("Account #%d: %x\n", i, acct)
  483. }
  484. }
  485. func getPassPhrase(ctx *cli.Context, desc string, confirmation bool, i int) (passphrase string) {
  486. passfile := ctx.GlobalString(utils.PasswordFileFlag.Name)
  487. if len(passfile) == 0 {
  488. fmt.Println(desc)
  489. auth, err := utils.PromptPassword("Passphrase: ", true)
  490. if err != nil {
  491. utils.Fatalf("%v", err)
  492. }
  493. if confirmation {
  494. confirm, err := utils.PromptPassword("Repeat Passphrase: ", false)
  495. if err != nil {
  496. utils.Fatalf("%v", err)
  497. }
  498. if auth != confirm {
  499. utils.Fatalf("Passphrases did not match.")
  500. }
  501. }
  502. passphrase = auth
  503. } else {
  504. passbytes, err := ioutil.ReadFile(passfile)
  505. if err != nil {
  506. utils.Fatalf("Unable to read password file '%s': %v", passfile, err)
  507. }
  508. // this is backwards compatible if the same password unlocks several accounts
  509. // it also has the consequence that trailing newlines will not count as part
  510. // of the password, so --password <(echo -n 'pass') will now work without -n
  511. passphrases := strings.Split(string(passbytes), "\n")
  512. if i >= len(passphrases) {
  513. passphrase = passphrases[len(passphrases)-1]
  514. } else {
  515. passphrase = passphrases[i]
  516. }
  517. }
  518. return
  519. }
  520. func accountCreate(ctx *cli.Context) {
  521. am := utils.MakeAccountManager(ctx)
  522. passphrase := getPassPhrase(ctx, "Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0)
  523. acct, err := am.NewAccount(passphrase)
  524. if err != nil {
  525. utils.Fatalf("Could not create the account: %v", err)
  526. }
  527. fmt.Printf("Address: %x\n", acct)
  528. }
  529. func accountUpdate(ctx *cli.Context) {
  530. am := utils.MakeAccountManager(ctx)
  531. arg := ctx.Args().First()
  532. if len(arg) == 0 {
  533. utils.Fatalf("account address or index must be given as argument")
  534. }
  535. addr, authFrom := unlockAccount(ctx, am, arg, 0)
  536. authTo := getPassPhrase(ctx, "Please give a new password. Do not forget this password.", true, 0)
  537. err := am.Update(common.HexToAddress(addr), authFrom, authTo)
  538. if err != nil {
  539. utils.Fatalf("Could not update the account: %v", err)
  540. }
  541. }
  542. func importWallet(ctx *cli.Context) {
  543. keyfile := ctx.Args().First()
  544. if len(keyfile) == 0 {
  545. utils.Fatalf("keyfile must be given as argument")
  546. }
  547. keyJson, err := ioutil.ReadFile(keyfile)
  548. if err != nil {
  549. utils.Fatalf("Could not read wallet file: %v", err)
  550. }
  551. am := utils.MakeAccountManager(ctx)
  552. passphrase := getPassPhrase(ctx, "", false, 0)
  553. acct, err := am.ImportPreSaleKey(keyJson, passphrase)
  554. if err != nil {
  555. utils.Fatalf("Could not create the account: %v", err)
  556. }
  557. fmt.Printf("Address: %x\n", acct)
  558. }
  559. func accountImport(ctx *cli.Context) {
  560. keyfile := ctx.Args().First()
  561. if len(keyfile) == 0 {
  562. utils.Fatalf("keyfile must be given as argument")
  563. }
  564. am := utils.MakeAccountManager(ctx)
  565. passphrase := getPassPhrase(ctx, "Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0)
  566. acct, err := am.Import(keyfile, passphrase)
  567. if err != nil {
  568. utils.Fatalf("Could not create the account: %v", err)
  569. }
  570. fmt.Printf("Address: %x\n", acct)
  571. }
  572. func makedag(ctx *cli.Context) {
  573. args := ctx.Args()
  574. wrongArgs := func() {
  575. utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`)
  576. }
  577. switch {
  578. case len(args) == 2:
  579. blockNum, err := strconv.ParseUint(args[0], 0, 64)
  580. dir := args[1]
  581. if err != nil {
  582. wrongArgs()
  583. } else {
  584. dir = filepath.Clean(dir)
  585. // seems to require a trailing slash
  586. if !strings.HasSuffix(dir, "/") {
  587. dir = dir + "/"
  588. }
  589. _, err = ioutil.ReadDir(dir)
  590. if err != nil {
  591. utils.Fatalf("Can't find dir")
  592. }
  593. fmt.Println("making DAG, this could take awhile...")
  594. ethash.MakeDAG(blockNum, dir)
  595. }
  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. }