wizard_explorer.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. // Select the server to interact with
  35. server := w.selectServer()
  36. if server == "" {
  37. return
  38. }
  39. client := w.servers[server]
  40. // Retrieve any active node configurations from the server
  41. infos, err := checkExplorer(client, w.network)
  42. if err != nil {
  43. infos = &explorerInfos{
  44. node: &nodeInfos{port: 30303},
  45. port: 80,
  46. host: client.server,
  47. }
  48. }
  49. existed := err == nil
  50. infos.node.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", " ")
  51. infos.node.network = w.conf.Genesis.Config.ChainID.Int64()
  52. // Figure out which port to listen on
  53. fmt.Println()
  54. fmt.Printf("Which port should the explorer listen on? (default = %d)\n", infos.port)
  55. infos.port = w.readDefaultInt(infos.port)
  56. // Figure which virtual-host to deploy ethstats on
  57. if infos.host, err = w.ensureVirtualHost(client, infos.port, infos.host); err != nil {
  58. log.Error("Failed to decide on explorer host", "err", err)
  59. return
  60. }
  61. // Figure out where the user wants to store the persistent data
  62. fmt.Println()
  63. if infos.node.datadir == "" {
  64. fmt.Printf("Where should node data be stored on the remote machine?\n")
  65. infos.node.datadir = w.readString()
  66. } else {
  67. fmt.Printf("Where should node data be stored on the remote machine? (default = %s)\n", infos.node.datadir)
  68. infos.node.datadir = w.readDefaultString(infos.node.datadir)
  69. }
  70. // Figure out where the user wants to store the persistent data for backend database
  71. fmt.Println()
  72. if infos.dbdir == "" {
  73. fmt.Printf("Where should postgres data be stored on the remote machine?\n")
  74. infos.dbdir = w.readString()
  75. } else {
  76. fmt.Printf("Where should postgres data be stored on the remote machine? (default = %s)\n", infos.dbdir)
  77. infos.dbdir = w.readDefaultString(infos.dbdir)
  78. }
  79. // Figure out which port to listen on
  80. fmt.Println()
  81. fmt.Printf("Which TCP/UDP port should the archive node listen on? (default = %d)\n", infos.node.port)
  82. infos.node.port = w.readDefaultInt(infos.node.port)
  83. // Set a proper name to report on the stats page
  84. fmt.Println()
  85. if infos.node.ethstats == "" {
  86. fmt.Printf("What should the explorer be called on the stats page?\n")
  87. infos.node.ethstats = w.readString() + ":" + w.conf.ethstats
  88. } else {
  89. fmt.Printf("What should the explorer be called on the stats page? (default = %s)\n", infos.node.ethstats)
  90. infos.node.ethstats = w.readDefaultString(infos.node.ethstats) + ":" + w.conf.ethstats
  91. }
  92. // Try to deploy the explorer on the host
  93. nocache := false
  94. if existed {
  95. fmt.Println()
  96. fmt.Printf("Should the explorer be built from scratch (y/n)? (default = no)\n")
  97. nocache = w.readDefaultYesNo(false)
  98. }
  99. if out, err := deployExplorer(client, w.network, w.conf.bootnodes, infos, nocache, w.conf.Genesis.Config.Clique != nil); err != nil {
  100. log.Error("Failed to deploy explorer container", "err", err)
  101. if len(out) > 0 {
  102. fmt.Printf("%s\n", out)
  103. }
  104. return
  105. }
  106. // All ok, run a network scan to pick any changes up
  107. log.Info("Waiting for node to finish booting")
  108. time.Sleep(3 * time.Second)
  109. w.networkStats()
  110. }