github.hscsec.cn/scroll-tech/go-ethereum@v1.9.7/cmd/puppeth/wizard_wallet.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of go-ethereum. 3 // 4 // go-ethereum is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // go-ethereum is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 import ( 20 "encoding/json" 21 "fmt" 22 "time" 23 24 "github.com/ethereum/go-ethereum/log" 25 ) 26 27 // deployWallet creates a new web wallet based on some user input. 28 func (w *wizard) deployWallet() { 29 // Do some sanity check before the user wastes time on input 30 if w.conf.Genesis == nil { 31 log.Error("No genesis block configured") 32 return 33 } 34 if w.conf.ethstats == "" { 35 log.Error("No ethstats server configured") 36 return 37 } 38 // Select the server to interact with 39 server := w.selectServer() 40 if server == "" { 41 return 42 } 43 client := w.servers[server] 44 45 // Retrieve any active node configurations from the server 46 infos, err := checkWallet(client, w.network) 47 if err != nil { 48 infos = &walletInfos{ 49 nodePort: 30303, rpcPort: 8545, webPort: 80, webHost: client.server, 50 } 51 } 52 existed := err == nil 53 54 infos.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", " ") 55 infos.network = w.conf.Genesis.Config.ChainID.Int64() 56 57 // Figure out which port to listen on 58 fmt.Println() 59 fmt.Printf("Which port should the wallet listen on? (default = %d)\n", infos.webPort) 60 infos.webPort = w.readDefaultInt(infos.webPort) 61 62 // Figure which virtual-host to deploy ethstats on 63 if infos.webHost, err = w.ensureVirtualHost(client, infos.webPort, infos.webHost); err != nil { 64 log.Error("Failed to decide on wallet host", "err", err) 65 return 66 } 67 // Figure out where the user wants to store the persistent data 68 fmt.Println() 69 if infos.datadir == "" { 70 fmt.Printf("Where should data be stored on the remote machine?\n") 71 infos.datadir = w.readString() 72 } else { 73 fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.datadir) 74 infos.datadir = w.readDefaultString(infos.datadir) 75 } 76 // Figure out which port to listen on 77 fmt.Println() 78 fmt.Printf("Which TCP/UDP port should the backing node listen on? (default = %d)\n", infos.nodePort) 79 infos.nodePort = w.readDefaultInt(infos.nodePort) 80 81 fmt.Println() 82 fmt.Printf("Which port should the backing RPC API listen on? (default = %d)\n", infos.rpcPort) 83 infos.rpcPort = w.readDefaultInt(infos.rpcPort) 84 85 // Set a proper name to report on the stats page 86 fmt.Println() 87 if infos.ethstats == "" { 88 fmt.Printf("What should the wallet be called on the stats page?\n") 89 infos.ethstats = w.readString() + ":" + w.conf.ethstats 90 } else { 91 fmt.Printf("What should the wallet be called on the stats page? (default = %s)\n", infos.ethstats) 92 infos.ethstats = w.readDefaultString(infos.ethstats) + ":" + w.conf.ethstats 93 } 94 // Try to deploy the wallet on the host 95 nocache := false 96 if existed { 97 fmt.Println() 98 fmt.Printf("Should the wallet be built from scratch (y/n)? (default = no)\n") 99 nocache = w.readDefaultYesNo(false) 100 } 101 if out, err := deployWallet(client, w.network, w.conf.bootnodes, infos, nocache); err != nil { 102 log.Error("Failed to deploy wallet container", "err", err) 103 if len(out) > 0 { 104 fmt.Printf("%s\n", out) 105 } 106 return 107 } 108 // All ok, run a network scan to pick any changes up 109 log.Info("Waiting for node to finish booting") 110 time.Sleep(3 * time.Second) 111 112 w.networkStats() 113 }