github.com/codingfuture/orig-energi3@v0.8.4/cmd/puppeth/wizard_wallet.go (about)

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