github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/cmd/puppeth/wizard_wallet.go (about)

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