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