github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/cmd/puppeth/wizard_wallet.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  //版权所有2017 Go Ethereum作者
    10  //此文件是Go以太坊的一部分。
    11  //
    12  //Go以太坊是免费软件:您可以重新发布和/或修改它
    13  //根据GNU通用公共许可证的条款
    14  //自由软件基金会,或者许可证的第3版,或者
    15  //(由您选择)任何更高版本。
    16  //
    17  //Go以太坊的分布希望它会有用,
    18  //但没有任何保证;甚至没有
    19  //适销性或特定用途的适用性。见
    20  //GNU通用公共许可证了解更多详细信息。
    21  //
    22  //你应该已经收到一份GNU通用公共许可证的副本
    23  //一起去以太坊吧。如果没有,请参见<http://www.gnu.org/licenses/>。
    24  
    25  package main
    26  
    27  import (
    28  	"encoding/json"
    29  	"fmt"
    30  	"time"
    31  
    32  	"github.com/ethereum/go-ethereum/log"
    33  )
    34  
    35  //
    36  func (w *wizard) deployWallet() {
    37  //在用户浪费输入时间之前做一些健全性检查
    38  	if w.conf.Genesis == nil {
    39  		log.Error("No genesis block configured")
    40  		return
    41  	}
    42  	if w.conf.ethstats == "" {
    43  		log.Error("No ethstats server configured")
    44  		return
    45  	}
    46  //选择要与之交互的服务器
    47  	server := w.selectServer()
    48  	if server == "" {
    49  		return
    50  	}
    51  	client := w.servers[server]
    52  
    53  //从服务器检索任何活动节点配置
    54  	infos, err := checkWallet(client, w.network)
    55  	if err != nil {
    56  		infos = &walletInfos{
    57  			nodePort: 30303, rpcPort: 8545, webPort: 80, webHost: client.server,
    58  		}
    59  	}
    60  	existed := err == nil
    61  
    62  	infos.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", "  ")
    63  	infos.network = w.conf.Genesis.Config.ChainID.Int64()
    64  
    65  //找出要监听的端口
    66  	fmt.Println()
    67  	fmt.Printf("Which port should the wallet listen on? (default = %d)\n", infos.webPort)
    68  	infos.webPort = w.readDefaultInt(infos.webPort)
    69  
    70  //图1部署ethstats的虚拟主机
    71  	if infos.webHost, err = w.ensureVirtualHost(client, infos.webPort, infos.webHost); err != nil {
    72  		log.Error("Failed to decide on wallet host", "err", err)
    73  		return
    74  	}
    75  //找出用户希望存储持久数据的位置
    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  //找出要监听的端口
    85  	fmt.Println()
    86  	fmt.Printf("Which TCP/UDP port should the backing node listen on? (default = %d)\n", infos.nodePort)
    87  	infos.nodePort = w.readDefaultInt(infos.nodePort)
    88  
    89  	fmt.Println()
    90  	fmt.Printf("Which port should the backing RPC API listen on? (default = %d)\n", infos.rpcPort)
    91  	infos.rpcPort = w.readDefaultInt(infos.rpcPort)
    92  
    93  //
    94  	fmt.Println()
    95  	if infos.ethstats == "" {
    96  		fmt.Printf("What should the wallet be called on the stats page?\n")
    97  		infos.ethstats = w.readString() + ":" + w.conf.ethstats
    98  	} else {
    99  		fmt.Printf("What should the wallet be called on the stats page? (default = %s)\n", infos.ethstats)
   100  		infos.ethstats = w.readDefaultString(infos.ethstats) + ":" + w.conf.ethstats
   101  	}
   102  //
   103  	nocache := false
   104  	if existed {
   105  		fmt.Println()
   106  		fmt.Printf("Should the wallet be built from scratch (y/n)? (default = no)\n")
   107  		nocache = w.readDefaultString("n") != "n"
   108  	}
   109  	if out, err := deployWallet(client, w.network, w.conf.bootnodes, infos, nocache); err != nil {
   110  		log.Error("Failed to deploy wallet container", "err", err)
   111  		if len(out) > 0 {
   112  			fmt.Printf("%s\n", out)
   113  		}
   114  		return
   115  	}
   116  //一切正常,运行网络扫描以获取任何更改
   117  	log.Info("Waiting for node to finish booting")
   118  	time.Sleep(3 * time.Second)
   119  
   120  	w.networkStats()
   121  }