github.com/aigarnetwork/aigar@v0.0.0-20191115204914-d59a6eb70f8e/cmd/puppeth/wizard_explorer.go (about) 1 // Copyright 2018 The go-ethereum Authors 2 // Copyright 2019 The go-aigar Authors 3 // This file is part of the go-aigar library. 4 // 5 // The go-aigar library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // The go-aigar library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with the go-aigar library. If not, see <http://www.gnu.org/licenses/>. 17 18 package main 19 20 import ( 21 "encoding/json" 22 "fmt" 23 "time" 24 25 "github.com/AigarNetwork/aigar/log" 26 ) 27 28 // deployExplorer creates a new block explorer based on some user input. 29 func (w *wizard) deployExplorer() { 30 // Do some sanity check before the user wastes time on input 31 if w.conf.Genesis == nil { 32 log.Error("No genesis block configured") 33 return 34 } 35 if w.conf.ethstats == "" { 36 log.Error("No ethstats server configured") 37 return 38 } 39 // Select the server to interact with 40 server := w.selectServer() 41 if server == "" { 42 return 43 } 44 client := w.servers[server] 45 46 // Retrieve any active node configurations from the server 47 infos, err := checkExplorer(client, w.network) 48 if err != nil { 49 infos = &explorerInfos{ 50 node: &nodeInfos{port: 30303}, 51 port: 80, 52 host: client.server, 53 } 54 } 55 existed := err == nil 56 57 infos.node.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", " ") 58 infos.node.network = w.conf.Genesis.Config.ChainID.Int64() 59 60 // Figure out which port to listen on 61 fmt.Println() 62 fmt.Printf("Which port should the explorer listen on? (default = %d)\n", infos.port) 63 infos.port = w.readDefaultInt(infos.port) 64 65 // Figure which virtual-host to deploy ethstats on 66 if infos.host, err = w.ensureVirtualHost(client, infos.port, infos.host); err != nil { 67 log.Error("Failed to decide on explorer host", "err", err) 68 return 69 } 70 // Figure out where the user wants to store the persistent data 71 fmt.Println() 72 if infos.node.datadir == "" { 73 fmt.Printf("Where should node data be stored on the remote machine?\n") 74 infos.node.datadir = w.readString() 75 } else { 76 fmt.Printf("Where should node data be stored on the remote machine? (default = %s)\n", infos.node.datadir) 77 infos.node.datadir = w.readDefaultString(infos.node.datadir) 78 } 79 // Figure out where the user wants to store the persistent data for backend database 80 fmt.Println() 81 if infos.dbdir == "" { 82 fmt.Printf("Where should postgres data be stored on the remote machine?\n") 83 infos.dbdir = w.readString() 84 } else { 85 fmt.Printf("Where should postgres data be stored on the remote machine? (default = %s)\n", infos.dbdir) 86 infos.dbdir = w.readDefaultString(infos.dbdir) 87 } 88 // Figure out which port to listen on 89 fmt.Println() 90 fmt.Printf("Which TCP/UDP port should the archive node listen on? (default = %d)\n", infos.node.port) 91 infos.node.port = w.readDefaultInt(infos.node.port) 92 93 // Set a proper name to report on the stats page 94 fmt.Println() 95 if infos.node.ethstats == "" { 96 fmt.Printf("What should the explorer be called on the stats page?\n") 97 infos.node.ethstats = w.readString() + ":" + w.conf.ethstats 98 } else { 99 fmt.Printf("What should the explorer be called on the stats page? (default = %s)\n", infos.node.ethstats) 100 infos.node.ethstats = w.readDefaultString(infos.node.ethstats) + ":" + w.conf.ethstats 101 } 102 // Try to deploy the explorer on the host 103 nocache := false 104 if existed { 105 fmt.Println() 106 fmt.Printf("Should the explorer be built from scratch (y/n)? (default = no)\n") 107 nocache = w.readDefaultYesNo(false) 108 } 109 if out, err := deployExplorer(client, w.network, w.conf.bootnodes, infos, nocache, w.conf.Genesis.Config.Clique != nil); err != nil { 110 log.Error("Failed to deploy explorer container", "err", err) 111 if len(out) > 0 { 112 fmt.Printf("%s\n", out) 113 } 114 return 115 } 116 // All ok, run a network scan to pick any changes up 117 log.Info("Waiting for node to finish booting") 118 time.Sleep(3 * time.Second) 119 120 w.networkStats() 121 }