github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/cmd/puppeth/wizard_intro.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 "bufio" 29 "encoding/json" 30 "fmt" 31 "io/ioutil" 32 "os" 33 "path/filepath" 34 "strings" 35 "sync" 36 37 "github.com/ethereum/go-ethereum/log" 38 ) 39 40 // 41 func makeWizard(network string) *wizard { 42 return &wizard{ 43 network: network, 44 conf: config{ 45 Servers: make(map[string][]byte), 46 }, 47 servers: make(map[string]*sshClient), 48 services: make(map[string][]string), 49 in: bufio.NewReader(os.Stdin), 50 } 51 } 52 53 // 54 // 55 func (w *wizard) run() { 56 fmt.Println("+-----------------------------------------------------------+") 57 fmt.Println("| Welcome to puppeth, your Ethereum private network manager |") 58 fmt.Println("| |") 59 fmt.Println("| This tool lets you create a new Ethereum network down to |") 60 fmt.Println("| the genesis block, bootnodes, miners and ethstats servers |") 61 fmt.Println("| without the hassle that it would normally entail. |") 62 fmt.Println("| |") 63 fmt.Println("| Puppeth uses SSH to dial in to remote servers, and builds |") 64 fmt.Println("| its network components out of Docker containers using the |") 65 fmt.Println("| docker-compose toolset. |") 66 fmt.Println("+-----------------------------------------------------------+") 67 fmt.Println() 68 69 // 70 // 71 if w.network == "" { 72 fmt.Println("Please specify a network name to administer (no spaces or hyphens, please)") 73 for { 74 w.network = w.readString() 75 if !strings.Contains(w.network, " ") && !strings.Contains(w.network, "-") { 76 fmt.Printf("\nSweet, you can set this via --network=%s next time!\n\n", w.network) 77 break 78 } 79 log.Error("I also like to live dangerously, still no spaces or hyphens") 80 } 81 } 82 log.Info("Administering Ethereum network", "name", w.network) 83 84 // 85 w.conf.path = filepath.Join(os.Getenv("HOME"), ".puppeth", w.network) 86 87 blob, err := ioutil.ReadFile(w.conf.path) 88 if err != nil { 89 log.Warn("No previous configurations found", "path", w.conf.path) 90 } else if err := json.Unmarshal(blob, &w.conf); err != nil { 91 log.Crit("Previous configuration corrupted", "path", w.conf.path, "err", err) 92 } else { 93 // 94 var pend sync.WaitGroup 95 for server, pubkey := range w.conf.Servers { 96 pend.Add(1) 97 98 go func(server string, pubkey []byte) { 99 defer pend.Done() 100 101 log.Info("Dialing previously configured server", "server", server) 102 client, err := dial(server, pubkey) 103 if err != nil { 104 log.Error("Previous server unreachable", "server", server, "err", err) 105 } 106 w.lock.Lock() 107 w.servers[server] = client 108 w.lock.Unlock() 109 }(server, pubkey) 110 } 111 pend.Wait() 112 w.networkStats() 113 } 114 // 115 for { 116 fmt.Println() 117 fmt.Println("What would you like to do? (default = stats)") 118 fmt.Println(" 1. Show network stats") 119 if w.conf.Genesis == nil { 120 fmt.Println(" 2. Configure new genesis") 121 } else { 122 fmt.Println(" 2. Manage existing genesis") 123 } 124 if len(w.servers) == 0 { 125 fmt.Println(" 3. Track new remote server") 126 } else { 127 fmt.Println(" 3. Manage tracked machines") 128 } 129 if len(w.services) == 0 { 130 fmt.Println(" 4. Deploy network components") 131 } else { 132 fmt.Println(" 4. Manage network components") 133 } 134 135 choice := w.read() 136 switch { 137 case choice == "" || choice == "1": 138 w.networkStats() 139 140 case choice == "2": 141 if w.conf.Genesis == nil { 142 w.makeGenesis() 143 } else { 144 w.manageGenesis() 145 } 146 case choice == "3": 147 if len(w.servers) == 0 { 148 if w.makeServer() != "" { 149 w.networkStats() 150 } 151 } else { 152 w.manageServers() 153 } 154 case choice == "4": 155 if len(w.services) == 0 { 156 w.deployComponent() 157 } else { 158 w.manageComponents() 159 } 160 161 default: 162 log.Error("That's not something I can do") 163 } 164 } 165 }