github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/cmd/puppeth/wizard_explorer.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 package main 13 14 import ( 15 "encoding/json" 16 "fmt" 17 "time" 18 19 "github.com/Sberex/go-sberex/log" 20 ) 21 22 // deployExplorer creates a new block explorer based on some user input. 23 func (w *wizard) deployExplorer() { 24 // Do some sanity check before the user wastes time on input 25 if w.conf.Genesis == nil { 26 log.Error("No genesis block configured") 27 return 28 } 29 if w.conf.ethstats == "" { 30 log.Error("No ethstats server configured") 31 return 32 } 33 if w.conf.Genesis.Config.Ethash == nil { 34 log.Error("Only ethash network supported") 35 return 36 } 37 // Select the server to interact with 38 server := w.selectServer() 39 if server == "" { 40 return 41 } 42 client := w.servers[server] 43 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 53 chainspec, err := newParityChainSpec(w.network, w.conf.Genesis, w.conf.bootnodes) 54 if err != nil { 55 log.Error("Failed to create chain spec for explorer", "err", err) 56 return 57 } 58 chain, _ := json.MarshalIndent(chainspec, "", " ") 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.webPort) 63 infos.webPort = w.readDefaultInt(infos.webPort) 64 65 // Figure which virtual-host to deploy ethstats on 66 if infos.webHost, err = w.ensureVirtualHost(client, infos.webPort, infos.webHost); 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.datadir == "" { 73 fmt.Printf("Where should data be stored on the remote machine?\n") 74 infos.datadir = w.readString() 75 } else { 76 fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.datadir) 77 infos.datadir = w.readDefaultString(infos.datadir) 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.nodePort) 82 infos.nodePort = w.readDefaultInt(infos.nodePort) 83 84 // Set a proper name to report on the stats page 85 fmt.Println() 86 if infos.ethstats == "" { 87 fmt.Printf("What should the explorer be called on the stats page?\n") 88 infos.ethstats = w.readString() + ":" + w.conf.ethstats 89 } else { 90 fmt.Printf("What should the explorer be called on the stats page? (default = %s)\n", infos.ethstats) 91 infos.ethstats = w.readDefaultString(infos.ethstats) + ":" + w.conf.ethstats 92 } 93 // Try to deploy the explorer on the host 94 nocache := false 95 if existed { 96 fmt.Println() 97 fmt.Printf("Should the explorer be built from scratch (y/n)? (default = no)\n") 98 nocache = w.readDefaultString("n") != "n" 99 } 100 if out, err := deployExplorer(client, w.network, chain, infos, nocache); err != nil { 101 log.Error("Failed to deploy explorer container", "err", err) 102 if len(out) > 0 { 103 fmt.Printf("%s\n", out) 104 } 105 return 106 } 107 // All ok, run a network scan to pick any changes up 108 log.Info("Waiting for node to finish booting") 109 time.Sleep(3 * time.Second) 110 111 w.networkStats() 112 }