github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/cmd/puppeth/wizard_wallet.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 //</624450070250524672> 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) deployWallet() { 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 //选择要与之交互的服务器 35 server := w.selectServer() 36 if server == "" { 37 return 38 } 39 client := w.servers[server] 40 41 //从服务器检索任何活动节点配置 42 infos, err := checkWallet(client, w.network) 43 if err != nil { 44 infos = &walletInfos{ 45 nodePort: 30303, rpcPort: 8545, webPort: 80, webHost: client.server, 46 } 47 } 48 existed := err == nil 49 50 infos.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", " ") 51 infos.network = w.conf.Genesis.Config.ChainID.Int64() 52 53 //找出要监听的端口 54 fmt.Println() 55 fmt.Printf("Which port should the wallet listen on? (default = %d)\n", infos.webPort) 56 infos.webPort = w.readDefaultInt(infos.webPort) 57 58 //图1部署ethstats的虚拟主机 59 if infos.webHost, err = w.ensureVirtualHost(client, infos.webPort, infos.webHost); err != nil { 60 log.Error("Failed to decide on wallet host", "err", err) 61 return 62 } 63 //找出用户希望存储持久数据的位置 64 fmt.Println() 65 if infos.datadir == "" { 66 fmt.Printf("Where should data be stored on the remote machine?\n") 67 infos.datadir = w.readString() 68 } else { 69 fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.datadir) 70 infos.datadir = w.readDefaultString(infos.datadir) 71 } 72 //找出要监听的端口 73 fmt.Println() 74 fmt.Printf("Which TCP/UDP port should the backing node listen on? (default = %d)\n", infos.nodePort) 75 infos.nodePort = w.readDefaultInt(infos.nodePort) 76 77 fmt.Println() 78 fmt.Printf("Which port should the backing RPC API listen on? (default = %d)\n", infos.rpcPort) 79 infos.rpcPort = w.readDefaultInt(infos.rpcPort) 80 81 //在统计页面上设置要报告的正确名称 82 fmt.Println() 83 if infos.ethstats == "" { 84 fmt.Printf("What should the wallet be called on the stats page?\n") 85 infos.ethstats = w.readString() + ":" + w.conf.ethstats 86 } else { 87 fmt.Printf("What should the wallet be called on the stats page? (default = %s)\n", infos.ethstats) 88 infos.ethstats = w.readDefaultString(infos.ethstats) + ":" + w.conf.ethstats 89 } 90 //尝试在主机上部署钱包 91 nocache := false 92 if existed { 93 fmt.Println() 94 fmt.Printf("Should the wallet be built from scratch (y/n)? (default = no)\n") 95 nocache = w.readDefaultYesNo(false) 96 } 97 if out, err := deployWallet(client, w.network, w.conf.bootnodes, infos, nocache); err != nil { 98 log.Error("Failed to deploy wallet container", "err", err) 99 if len(out) > 0 { 100 fmt.Printf("%s\n", out) 101 } 102 return 103 } 104 //一切正常,运行网络扫描以获取任何更改 105 log.Info("Waiting for node to finish booting") 106 time.Sleep(3 * time.Second) 107 108 w.networkStats() 109 } 110