wizard_explorer.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright 2017 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. "encoding/json"
  19. "fmt"
  20. "time"
  21. "github.com/ethereum/go-ethereum/log"
  22. )
  23. // deployExplorer creates a new block explorer based on some user input.
  24. func (w *wizard) deployExplorer() {
  25. // Do some sanity check before the user wastes time on input
  26. if w.conf.Genesis == nil {
  27. log.Error("No genesis block configured")
  28. return
  29. }
  30. if w.conf.ethstats == "" {
  31. log.Error("No ethstats server configured")
  32. return
  33. }
  34. if w.conf.Genesis.Config.Ethash == nil {
  35. log.Error("Only ethash network supported")
  36. return
  37. }
  38. // Select the server to interact with
  39. server := w.selectServer()
  40. if server == "" {
  41. return
  42. }
  43. client := w.servers[server]
  44. // Retrieve any active node configurations from the server
  45. infos, err := checkExplorer(client, w.network)
  46. if err != nil {
  47. infos = &explorerInfos{
  48. nodePort: 30303, webPort: 80, webHost: client.server,
  49. }
  50. }
  51. existed := err == nil
  52. chainspec, err := newParityChainSpec(w.network, w.conf.Genesis, w.conf.bootnodes)
  53. if err != nil {
  54. log.Error("Failed to create chain spec for explorer", "err", err)
  55. return
  56. }
  57. chain, _ := json.MarshalIndent(chainspec, "", " ")
  58. // Figure out which port to listen on
  59. fmt.Println()
  60. fmt.Printf("Which port should the explorer listen on? (default = %d)\n", infos.webPort)
  61. infos.webPort = w.readDefaultInt(infos.webPort)
  62. // Figure which virtual-host to deploy ethstats on
  63. if infos.webHost, err = w.ensureVirtualHost(client, infos.webPort, infos.webHost); err != nil {
  64. log.Error("Failed to decide on explorer host", "err", err)
  65. return
  66. }
  67. // Figure out where the user wants to store the persistent data
  68. fmt.Println()
  69. if infos.datadir == "" {
  70. fmt.Printf("Where should data be stored on the remote machine?\n")
  71. infos.datadir = w.readString()
  72. } else {
  73. fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.datadir)
  74. infos.datadir = w.readDefaultString(infos.datadir)
  75. }
  76. // Figure out which port to listen on
  77. fmt.Println()
  78. fmt.Printf("Which TCP/UDP port should the archive node listen on? (default = %d)\n", infos.nodePort)
  79. infos.nodePort = w.readDefaultInt(infos.nodePort)
  80. // Set a proper name to report on the stats page
  81. fmt.Println()
  82. if infos.ethstats == "" {
  83. fmt.Printf("What should the explorer be called on the stats page?\n")
  84. infos.ethstats = w.readString() + ":" + w.conf.ethstats
  85. } else {
  86. fmt.Printf("What should the explorer be called on the stats page? (default = %s)\n", infos.ethstats)
  87. infos.ethstats = w.readDefaultString(infos.ethstats) + ":" + w.conf.ethstats
  88. }
  89. // Try to deploy the explorer on the host
  90. nocache := false
  91. if existed {
  92. fmt.Println()
  93. fmt.Printf("Should the explorer be built from scratch (y/n)? (default = no)\n")
  94. nocache = w.readDefaultString("n") != "n"
  95. }
  96. if out, err := deployExplorer(client, w.network, chain, infos, nocache); err != nil {
  97. log.Error("Failed to deploy explorer container", "err", err)
  98. if len(out) > 0 {
  99. fmt.Printf("%s\n", out)
  100. }
  101. return
  102. }
  103. // All ok, run a network scan to pick any changes up
  104. log.Info("Waiting for node to finish booting")
  105. time.Sleep(3 * time.Second)
  106. w.networkStats()
  107. }