github.hscsec.cn/scroll-tech/go-ethereum@v1.9.7/cmd/puppeth/wizard_explorer.go (about) 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 17 package main 18 19 import ( 20 "encoding/json" 21 "fmt" 22 "time" 23 24 "github.com/ethereum/go-ethereum/log" 25 ) 26 27 // deployExplorer creates a new block explorer based on some user input. 28 func (w *wizard) deployExplorer() { 29 // Do some sanity check before the user wastes time on input 30 if w.conf.Genesis == nil { 31 log.Error("No genesis block configured") 32 return 33 } 34 if w.conf.ethstats == "" { 35 log.Error("No ethstats server configured") 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 45 // Retrieve any active node configurations from the server 46 infos, err := checkExplorer(client, w.network) 47 if err != nil { 48 infos = &explorerInfos{ 49 node: &nodeInfos{port: 30303}, 50 port: 80, 51 host: client.server, 52 } 53 } 54 existed := err == nil 55 56 infos.node.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", " ") 57 infos.node.network = w.conf.Genesis.Config.ChainID.Int64() 58 59 // Figure out which port to listen on 60 fmt.Println() 61 fmt.Printf("Which port should the explorer listen on? (default = %d)\n", infos.port) 62 infos.port = w.readDefaultInt(infos.port) 63 64 // Figure which virtual-host to deploy ethstats on 65 if infos.host, err = w.ensureVirtualHost(client, infos.port, infos.host); err != nil { 66 log.Error("Failed to decide on explorer host", "err", err) 67 return 68 } 69 // Figure out where the user wants to store the persistent data 70 fmt.Println() 71 if infos.node.datadir == "" { 72 fmt.Printf("Where should node data be stored on the remote machine?\n") 73 infos.node.datadir = w.readString() 74 } else { 75 fmt.Printf("Where should node data be stored on the remote machine? (default = %s)\n", infos.node.datadir) 76 infos.node.datadir = w.readDefaultString(infos.node.datadir) 77 } 78 // Figure out where the user wants to store the persistent data for backend database 79 fmt.Println() 80 if infos.dbdir == "" { 81 fmt.Printf("Where should postgres data be stored on the remote machine?\n") 82 infos.dbdir = w.readString() 83 } else { 84 fmt.Printf("Where should postgres data be stored on the remote machine? (default = %s)\n", infos.dbdir) 85 infos.dbdir = w.readDefaultString(infos.dbdir) 86 } 87 // Figure out which port to listen on 88 fmt.Println() 89 fmt.Printf("Which TCP/UDP port should the archive node listen on? (default = %d)\n", infos.node.port) 90 infos.node.port = w.readDefaultInt(infos.node.port) 91 92 // Set a proper name to report on the stats page 93 fmt.Println() 94 if infos.node.ethstats == "" { 95 fmt.Printf("What should the explorer be called on the stats page?\n") 96 infos.node.ethstats = w.readString() + ":" + w.conf.ethstats 97 } else { 98 fmt.Printf("What should the explorer be called on the stats page? (default = %s)\n", infos.node.ethstats) 99 infos.node.ethstats = w.readDefaultString(infos.node.ethstats) + ":" + w.conf.ethstats 100 } 101 // Try to deploy the explorer on the host 102 nocache := false 103 if existed { 104 fmt.Println() 105 fmt.Printf("Should the explorer be built from scratch (y/n)? (default = no)\n") 106 nocache = w.readDefaultYesNo(false) 107 } 108 if out, err := deployExplorer(client, w.network, w.conf.bootnodes, infos, nocache, w.conf.Genesis.Config.Clique != nil); err != nil { 109 log.Error("Failed to deploy explorer container", "err", err) 110 if len(out) > 0 { 111 fmt.Printf("%s\n", out) 112 } 113 return 114 } 115 // All ok, run a network scan to pick any changes up 116 log.Info("Waiting for node to finish booting") 117 time.Sleep(3 * time.Second) 118 119 w.networkStats() 120 }