github.com/codingfuture/orig-energi3@v0.8.4/cmd/puppeth/wizard_explorer.go (about)

     1  // Copyright 2018 The Energi Core Authors
     2  // Copyright 2017 The go-ethereum Authors
     3  // This file is part of Energi Core.
     4  //
     5  // Energi Core is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU 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  // Energi Core 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 General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU General Public License
    16  // along with Energi Core. 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/ethereum/go-ethereum/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  	if w.conf.Genesis.Config.Ethash == nil {
    40  		log.Error("Only ethash network supported")
    41  		return
    42  	}
    43  	// Select the server to interact with
    44  	server := w.selectServer()
    45  	if server == "" {
    46  		return
    47  	}
    48  	client := w.servers[server]
    49  
    50  	// Retrieve any active node configurations from the server
    51  	infos, err := checkExplorer(client, w.network)
    52  	if err != nil {
    53  		infos = &explorerInfos{
    54  			nodePort: 39797, webPort: 80, webHost: client.server,
    55  		}
    56  	}
    57  	existed := err == nil
    58  
    59  	chainspec, err := newParityChainSpec(w.network, w.conf.Genesis, w.conf.bootnodes)
    60  	if err != nil {
    61  		log.Error("Failed to create chain spec for explorer", "err", err)
    62  		return
    63  	}
    64  	chain, _ := json.MarshalIndent(chainspec, "", "  ")
    65  
    66  	// Figure out which port to listen on
    67  	fmt.Println()
    68  	fmt.Printf("Which port should the explorer listen on? (default = %d)\n", infos.webPort)
    69  	infos.webPort = w.readDefaultInt(infos.webPort)
    70  
    71  	// Figure which virtual-host to deploy ethstats on
    72  	if infos.webHost, err = w.ensureVirtualHost(client, infos.webPort, infos.webHost); err != nil {
    73  		log.Error("Failed to decide on explorer host", "err", err)
    74  		return
    75  	}
    76  	// Figure out where the user wants to store the persistent data
    77  	fmt.Println()
    78  	if infos.datadir == "" {
    79  		fmt.Printf("Where should data be stored on the remote machine?\n")
    80  		infos.datadir = w.readString()
    81  	} else {
    82  		fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.datadir)
    83  		infos.datadir = w.readDefaultString(infos.datadir)
    84  	}
    85  	// Figure out which port to listen on
    86  	fmt.Println()
    87  	fmt.Printf("Which TCP/UDP port should the archive node listen on? (default = %d)\n", infos.nodePort)
    88  	infos.nodePort = w.readDefaultInt(infos.nodePort)
    89  
    90  	// Set a proper name to report on the stats page
    91  	fmt.Println()
    92  	if infos.ethstats == "" {
    93  		fmt.Printf("What should the explorer be called on the stats page?\n")
    94  		infos.ethstats = w.readString() + ":" + w.conf.ethstats
    95  	} else {
    96  		fmt.Printf("What should the explorer be called on the stats page? (default = %s)\n", infos.ethstats)
    97  		infos.ethstats = w.readDefaultString(infos.ethstats) + ":" + w.conf.ethstats
    98  	}
    99  	// Try to deploy the explorer on the host
   100  	nocache := false
   101  	if existed {
   102  		fmt.Println()
   103  		fmt.Printf("Should the explorer be built from scratch (y/n)? (default = no)\n")
   104  		nocache = w.readDefaultYesNo(false)
   105  	}
   106  	if out, err := deployExplorer(client, w.network, chain, infos, nocache); err != nil {
   107  		log.Error("Failed to deploy explorer container", "err", err)
   108  		if len(out) > 0 {
   109  			fmt.Printf("%s\n", out)
   110  		}
   111  		return
   112  	}
   113  	// All ok, run a network scan to pick any changes up
   114  	log.Info("Waiting for node to finish booting")
   115  	time.Sleep(3 * time.Second)
   116  
   117  	w.networkStats()
   118  }