github.com/codingfuture/orig-energi3@v0.8.4/cmd/puppeth/wizard_faucet.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  
    24  	"github.com/ethereum/go-ethereum/accounts/keystore"
    25  	"github.com/ethereum/go-ethereum/log"
    26  )
    27  
    28  // deployFaucet queries the user for various input on deploying a faucet, after
    29  // which it executes it.
    30  func (w *wizard) deployFaucet() {
    31  	// Select the server to interact with
    32  	server := w.selectServer()
    33  	if server == "" {
    34  		return
    35  	}
    36  	client := w.servers[server]
    37  
    38  	// Retrieve any active faucet configurations from the server
    39  	infos, err := checkFaucet(client, w.network)
    40  	if err != nil {
    41  		infos = &faucetInfos{
    42  			node:    &nodeInfos{port: 39797, peersTotal: 25},
    43  			port:    80,
    44  			host:    client.server,
    45  			amount:  1,
    46  			minutes: 1440,
    47  			tiers:   3,
    48  		}
    49  	}
    50  	existed := err == nil
    51  
    52  	infos.node.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", "  ")
    53  	infos.node.network = w.conf.Genesis.Config.ChainID.Int64()
    54  
    55  	// Figure out which port to listen on
    56  	fmt.Println()
    57  	fmt.Printf("Which port should the faucet listen on? (default = %d)\n", infos.port)
    58  	infos.port = w.readDefaultInt(infos.port)
    59  
    60  	// Figure which virtual-host to deploy ethstats on
    61  	if infos.host, err = w.ensureVirtualHost(client, infos.port, infos.host); err != nil {
    62  		log.Error("Failed to decide on faucet host", "err", err)
    63  		return
    64  	}
    65  	// Port and proxy settings retrieved, figure out the funding amount per period configurations
    66  	fmt.Println()
    67  	fmt.Printf("How many Ethers to release per request? (default = %d)\n", infos.amount)
    68  	infos.amount = w.readDefaultInt(infos.amount)
    69  
    70  	fmt.Println()
    71  	fmt.Printf("How many minutes to enforce between requests? (default = %d)\n", infos.minutes)
    72  	infos.minutes = w.readDefaultInt(infos.minutes)
    73  
    74  	fmt.Println()
    75  	fmt.Printf("How many funding tiers to feature (x2.5 amounts, x3 timeout)? (default = %d)\n", infos.tiers)
    76  	infos.tiers = w.readDefaultInt(infos.tiers)
    77  	if infos.tiers == 0 {
    78  		log.Error("At least one funding tier must be set")
    79  		return
    80  	}
    81  	// Accessing the reCaptcha service requires API authorizations, request it
    82  	if infos.captchaToken != "" {
    83  		fmt.Println()
    84  		fmt.Println("Reuse previous reCaptcha API authorization (y/n)? (default = yes)")
    85  		if !w.readDefaultYesNo(true) {
    86  			infos.captchaToken, infos.captchaSecret = "", ""
    87  		}
    88  	}
    89  	if infos.captchaToken == "" {
    90  		// No previous authorization (or old one discarded)
    91  		fmt.Println()
    92  		fmt.Println("Enable reCaptcha protection against robots (y/n)? (default = no)")
    93  		if !w.readDefaultYesNo(false) {
    94  			log.Warn("Users will be able to requests funds via automated scripts")
    95  		} else {
    96  			// Captcha protection explicitly requested, read the site and secret keys
    97  			fmt.Println()
    98  			fmt.Printf("What is the reCaptcha site key to authenticate human users?\n")
    99  			infos.captchaToken = w.readString()
   100  
   101  			fmt.Println()
   102  			fmt.Printf("What is the reCaptcha secret key to verify authentications? (won't be echoed)\n")
   103  			infos.captchaSecret = w.readPassword()
   104  		}
   105  	}
   106  	// Figure out where the user wants to store the persistent data
   107  	fmt.Println()
   108  	if infos.node.datadir == "" {
   109  		fmt.Printf("Where should data be stored on the remote machine?\n")
   110  		infos.node.datadir = w.readString()
   111  	} else {
   112  		fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.node.datadir)
   113  		infos.node.datadir = w.readDefaultString(infos.node.datadir)
   114  	}
   115  	// Figure out which port to listen on
   116  	fmt.Println()
   117  	fmt.Printf("Which TCP/UDP port should the light client listen on? (default = %d)\n", infos.node.port)
   118  	infos.node.port = w.readDefaultInt(infos.node.port)
   119  
   120  	// Set a proper name to report on the stats page
   121  	fmt.Println()
   122  	if infos.node.ethstats == "" {
   123  		fmt.Printf("What should the node be called on the stats page?\n")
   124  		infos.node.ethstats = w.readString() + ":" + w.conf.ethstats
   125  	} else {
   126  		fmt.Printf("What should the node be called on the stats page? (default = %s)\n", infos.node.ethstats)
   127  		infos.node.ethstats = w.readDefaultString(infos.node.ethstats) + ":" + w.conf.ethstats
   128  	}
   129  	// Load up the credential needed to release funds
   130  	if infos.node.keyJSON != "" {
   131  		if key, err := keystore.DecryptKey([]byte(infos.node.keyJSON), infos.node.keyPass); err != nil {
   132  			infos.node.keyJSON, infos.node.keyPass = "", ""
   133  		} else {
   134  			fmt.Println()
   135  			fmt.Printf("Reuse previous (%s) funding account (y/n)? (default = yes)\n", key.Address.Hex())
   136  			if !w.readDefaultYesNo(true) {
   137  				infos.node.keyJSON, infos.node.keyPass = "", ""
   138  			}
   139  		}
   140  	}
   141  	for i := 0; i < 3 && infos.node.keyJSON == ""; i++ {
   142  		fmt.Println()
   143  		fmt.Println("Please paste the faucet's funding account key JSON:")
   144  		infos.node.keyJSON = w.readJSON()
   145  
   146  		fmt.Println()
   147  		fmt.Println("What's the unlock password for the account? (won't be echoed)")
   148  		infos.node.keyPass = w.readPassword()
   149  
   150  		if _, err := keystore.DecryptKey([]byte(infos.node.keyJSON), infos.node.keyPass); err != nil {
   151  			log.Error("Failed to decrypt key with given passphrase")
   152  			infos.node.keyJSON = ""
   153  			infos.node.keyPass = ""
   154  		}
   155  	}
   156  	// Check if the user wants to run the faucet in debug mode (noauth)
   157  	noauth := "n"
   158  	if infos.noauth {
   159  		noauth = "y"
   160  	}
   161  	fmt.Println()
   162  	fmt.Printf("Permit non-authenticated funding requests (y/n)? (default = %v)\n", infos.noauth)
   163  	infos.noauth = w.readDefaultString(noauth) != "n"
   164  
   165  	// Try to deploy the faucet server on the host
   166  	nocache := false
   167  	if existed {
   168  		fmt.Println()
   169  		fmt.Printf("Should the faucet be built from scratch (y/n)? (default = no)\n")
   170  		nocache = w.readDefaultYesNo(false)
   171  	}
   172  	if out, err := deployFaucet(client, w.network, w.conf.bootnodes, infos, nocache); err != nil {
   173  		log.Error("Failed to deploy faucet container", "err", err)
   174  		if len(out) > 0 {
   175  			fmt.Printf("%s\n", out)
   176  		}
   177  		return
   178  	}
   179  	// All ok, run a network scan to pick any changes up
   180  	w.networkStats()
   181  }