github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/cmd/puppeth/wizard_faucet.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 31 "github.com/ethereum/go-ethereum/accounts/keystore" 32 "github.com/ethereum/go-ethereum/log" 33 ) 34 35 //DeployFacet查询用户在部署水龙头时的各种输入, 36 //它执行它。 37 func (w *wizard) deployFaucet() { 38 // 39 server := w.selectServer() 40 if server == "" { 41 return 42 } 43 client := w.servers[server] 44 45 //从服务器检索任何活动的水龙头配置 46 infos, err := checkFaucet(client, w.network) 47 if err != nil { 48 infos = &faucetInfos{ 49 node: &nodeInfos{port: 30303, peersTotal: 25}, 50 port: 80, 51 host: client.server, 52 amount: 1, 53 minutes: 1440, 54 tiers: 3, 55 } 56 } 57 existed := err == nil 58 59 infos.node.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", " ") 60 infos.node.network = w.conf.Genesis.Config.ChainID.Int64() 61 62 //找出要监听的端口 63 fmt.Println() 64 fmt.Printf("Which port should the faucet listen on? (default = %d)\n", infos.port) 65 infos.port = w.readDefaultInt(infos.port) 66 67 //图1部署ethstats的虚拟主机 68 if infos.host, err = w.ensureVirtualHost(client, infos.port, infos.host); err != nil { 69 log.Error("Failed to decide on faucet host", "err", err) 70 return 71 } 72 // 73 fmt.Println() 74 fmt.Printf("How many Ethers to release per request? (default = %d)\n", infos.amount) 75 infos.amount = w.readDefaultInt(infos.amount) 76 77 fmt.Println() 78 fmt.Printf("How many minutes to enforce between requests? (default = %d)\n", infos.minutes) 79 infos.minutes = w.readDefaultInt(infos.minutes) 80 81 fmt.Println() 82 fmt.Printf("How many funding tiers to feature (x2.5 amounts, x3 timeout)? (default = %d)\n", infos.tiers) 83 infos.tiers = w.readDefaultInt(infos.tiers) 84 if infos.tiers == 0 { 85 log.Error("At least one funding tier must be set") 86 return 87 } 88 // 89 if infos.captchaToken != "" { 90 fmt.Println() 91 fmt.Println("Reuse previous reCaptcha API authorization (y/n)? (default = yes)") 92 if w.readDefaultString("y") != "y" { 93 infos.captchaToken, infos.captchaSecret = "", "" 94 } 95 } 96 if infos.captchaToken == "" { 97 // 98 fmt.Println() 99 fmt.Println("Enable reCaptcha protection against robots (y/n)? (default = no)") 100 if w.readDefaultString("n") == "n" { 101 log.Warn("Users will be able to requests funds via automated scripts") 102 } else { 103 // 104 fmt.Println() 105 fmt.Printf("What is the reCaptcha site key to authenticate human users?\n") 106 infos.captchaToken = w.readString() 107 108 fmt.Println() 109 fmt.Printf("What is the reCaptcha secret key to verify authentications? (won't be echoed)\n") 110 infos.captchaSecret = w.readPassword() 111 } 112 } 113 //找出用户希望存储持久数据的位置 114 fmt.Println() 115 if infos.node.datadir == "" { 116 fmt.Printf("Where should data be stored on the remote machine?\n") 117 infos.node.datadir = w.readString() 118 } else { 119 fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.node.datadir) 120 infos.node.datadir = w.readDefaultString(infos.node.datadir) 121 } 122 //找出要监听的端口 123 fmt.Println() 124 fmt.Printf("Which TCP/UDP port should the light client listen on? (default = %d)\n", infos.node.port) 125 infos.node.port = w.readDefaultInt(infos.node.port) 126 127 // 128 fmt.Println() 129 if infos.node.ethstats == "" { 130 fmt.Printf("What should the node be called on the stats page?\n") 131 infos.node.ethstats = w.readString() + ":" + w.conf.ethstats 132 } else { 133 fmt.Printf("What should the node be called on the stats page? (default = %s)\n", infos.node.ethstats) 134 infos.node.ethstats = w.readDefaultString(infos.node.ethstats) + ":" + w.conf.ethstats 135 } 136 // 137 if infos.node.keyJSON != "" { 138 if key, err := keystore.DecryptKey([]byte(infos.node.keyJSON), infos.node.keyPass); err != nil { 139 infos.node.keyJSON, infos.node.keyPass = "", "" 140 } else { 141 fmt.Println() 142 fmt.Printf("Reuse previous (%s) funding account (y/n)? (default = yes)\n", key.Address.Hex()) 143 if w.readDefaultString("y") != "y" { 144 infos.node.keyJSON, infos.node.keyPass = "", "" 145 } 146 } 147 } 148 for i := 0; i < 3 && infos.node.keyJSON == ""; i++ { 149 fmt.Println() 150 fmt.Println("Please paste the faucet's funding account key JSON:") 151 infos.node.keyJSON = w.readJSON() 152 153 fmt.Println() 154 fmt.Println("What's the unlock password for the account? (won't be echoed)") 155 infos.node.keyPass = w.readPassword() 156 157 if _, err := keystore.DecryptKey([]byte(infos.node.keyJSON), infos.node.keyPass); err != nil { 158 log.Error("Failed to decrypt key with given passphrase") 159 infos.node.keyJSON = "" 160 infos.node.keyPass = "" 161 } 162 } 163 // 164 noauth := "n" 165 if infos.noauth { 166 noauth = "y" 167 } 168 fmt.Println() 169 fmt.Printf("Permit non-authenticated funding requests (y/n)? (default = %v)\n", infos.noauth) 170 infos.noauth = w.readDefaultString(noauth) != "n" 171 172 //尝试在主机上部署水龙头服务器 173 nocache := false 174 if existed { 175 fmt.Println() 176 fmt.Printf("Should the faucet be built from scratch (y/n)? (default = no)\n") 177 nocache = w.readDefaultString("n") != "n" 178 } 179 if out, err := deployFaucet(client, w.network, w.conf.bootnodes, infos, nocache); err != nil { 180 log.Error("Failed to deploy faucet container", "err", err) 181 if len(out) > 0 { 182 fmt.Printf("%s\n", out) 183 } 184 return 185 } 186 // 187 w.networkStats() 188 }