github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/cmd/puppeth/wizard_explorer.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 19:16:33</date>
    10  //</624450069885620224>
    11  
    12  
    13  package main
    14  
    15  import (
    16  	"encoding/json"
    17  	"fmt"
    18  	"time"
    19  
    20  	"github.com/ethereum/go-ethereum/log"
    21  )
    22  
    23  //
    24  func (w *wizard) deployExplorer() {
    25  //在用户浪费输入时间之前做一些健全性检查
    26  	if w.conf.Genesis == nil {
    27  		log.Error("No genesis block configured")
    28  		return
    29  	}
    30  	if w.conf.ethstats == "" {
    31  		log.Error("No ethstats server configured")
    32  		return
    33  	}
    34  	if w.conf.Genesis.Config.Ethash == nil {
    35  		log.Error("Only ethash network supported")
    36  		return
    37  	}
    38  //选择要与之交互的服务器
    39  	server := w.selectServer()
    40  	if server == "" {
    41  		return
    42  	}
    43  	client := w.servers[server]
    44  
    45  //从服务器检索任何活动节点配置
    46  	infos, err := checkExplorer(client, w.network)
    47  	if err != nil {
    48  		infos = &explorerInfos{
    49  			nodePort: 30303, webPort: 80, webHost: client.server,
    50  		}
    51  	}
    52  	existed := err == nil
    53  
    54  	chainspec, err := newParityChainSpec(w.network, w.conf.Genesis, w.conf.bootnodes)
    55  	if err != nil {
    56  		log.Error("Failed to create chain spec for explorer", "err", err)
    57  		return
    58  	}
    59  	chain, _ := json.MarshalIndent(chainspec, "", "  ")
    60  
    61  //找出要监听的端口
    62  	fmt.Println()
    63  	fmt.Printf("Which port should the explorer listen on? (default = %d)\n", infos.webPort)
    64  	infos.webPort = w.readDefaultInt(infos.webPort)
    65  
    66  //图1部署ethstats的虚拟主机
    67  	if infos.webHost, err = w.ensureVirtualHost(client, infos.webPort, infos.webHost); err != nil {
    68  		log.Error("Failed to decide on explorer host", "err", err)
    69  		return
    70  	}
    71  //找出用户希望存储持久数据的位置
    72  	fmt.Println()
    73  	if infos.datadir == "" {
    74  		fmt.Printf("Where should data be stored on the remote machine?\n")
    75  		infos.datadir = w.readString()
    76  	} else {
    77  		fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.datadir)
    78  		infos.datadir = w.readDefaultString(infos.datadir)
    79  	}
    80  //找出要监听的端口
    81  	fmt.Println()
    82  	fmt.Printf("Which TCP/UDP port should the archive node listen on? (default = %d)\n", infos.nodePort)
    83  	infos.nodePort = w.readDefaultInt(infos.nodePort)
    84  
    85  //
    86  	fmt.Println()
    87  	if infos.ethstats == "" {
    88  		fmt.Printf("What should the explorer be called on the stats page?\n")
    89  		infos.ethstats = w.readString() + ":" + w.conf.ethstats
    90  	} else {
    91  		fmt.Printf("What should the explorer be called on the stats page? (default = %s)\n", infos.ethstats)
    92  		infos.ethstats = w.readDefaultString(infos.ethstats) + ":" + w.conf.ethstats
    93  	}
    94  //尝试在主机上部署资源管理器
    95  	nocache := false
    96  	if existed {
    97  		fmt.Println()
    98  		fmt.Printf("Should the explorer be built from scratch (y/n)? (default = no)\n")
    99  		nocache = w.readDefaultYesNo(false)
   100  	}
   101  	if out, err := deployExplorer(client, w.network, chain, infos, nocache); err != nil {
   102  		log.Error("Failed to deploy explorer container", "err", err)
   103  		if len(out) > 0 {
   104  			fmt.Printf("%s\n", out)
   105  		}
   106  		return
   107  	}
   108  //一切正常,运行网络扫描以获取任何更改
   109  	log.Info("Waiting for node to finish booting")
   110  	time.Sleep(3 * time.Second)
   111  
   112  	w.networkStats()
   113  }
   114