github.com/alexdevranger/node-1.8.27@v0.0.0-20221128213301-aa5841e41d2d/cmd/puppeth/wizard_explorer.go (about)

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