wizard_wallet.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. package main
  17. import (
  18. "encoding/json"
  19. "fmt"
  20. "time"
  21. "github.com/ethereum/go-ethereum/log"
  22. )
  23. // deployWallet creates a new web wallet based on some user input.
  24. func (w *wizard) deployWallet() {
  25. // Do some sanity check before the user wastes time on input
  26. if w.conf.Genesis == nil {
  27. log.Error("No genesis block configured")
  28. return
  29. }
  30. if w.conf.ethstats == "" {
  31. log.Error("No ethstats server configured")
  32. return
  33. }
  34. // Select the server to interact with
  35. server := w.selectServer()
  36. if server == "" {
  37. return
  38. }
  39. client := w.servers[server]
  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. infos.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", " ")
  49. infos.network = w.conf.Genesis.Config.ChainID.Int64()
  50. // Figure out which port to listen on
  51. fmt.Println()
  52. fmt.Printf("Which port should the wallet listen on? (default = %d)\n", infos.webPort)
  53. infos.webPort = w.readDefaultInt(infos.webPort)
  54. // Figure which virtual-host to deploy ethstats on
  55. if infos.webHost, err = w.ensureVirtualHost(client, infos.webPort, infos.webHost); err != nil {
  56. log.Error("Failed to decide on wallet host", "err", err)
  57. return
  58. }
  59. // Figure out where the user wants to store the persistent data
  60. fmt.Println()
  61. if infos.datadir == "" {
  62. fmt.Printf("Where should data be stored on the remote machine?\n")
  63. infos.datadir = w.readString()
  64. } else {
  65. fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.datadir)
  66. infos.datadir = w.readDefaultString(infos.datadir)
  67. }
  68. // Figure out which port to listen on
  69. fmt.Println()
  70. fmt.Printf("Which TCP/UDP port should the backing node listen on? (default = %d)\n", infos.nodePort)
  71. infos.nodePort = w.readDefaultInt(infos.nodePort)
  72. fmt.Println()
  73. fmt.Printf("Which port should the backing RPC API listen on? (default = %d)\n", infos.rpcPort)
  74. infos.rpcPort = w.readDefaultInt(infos.rpcPort)
  75. // Set a proper name to report on the stats page
  76. fmt.Println()
  77. if infos.ethstats == "" {
  78. fmt.Printf("What should the wallet be called on the stats page?\n")
  79. infos.ethstats = w.readString() + ":" + w.conf.ethstats
  80. } else {
  81. fmt.Printf("What should the wallet be called on the stats page? (default = %s)\n", infos.ethstats)
  82. infos.ethstats = w.readDefaultString(infos.ethstats) + ":" + w.conf.ethstats
  83. }
  84. // Try to deploy the wallet on the host
  85. nocache := false
  86. if existed {
  87. fmt.Println()
  88. fmt.Printf("Should the wallet be built from scratch (y/n)? (default = no)\n")
  89. nocache = w.readDefaultYesNo(false)
  90. }
  91. if out, err := deployWallet(client, w.network, w.conf.bootnodes, infos, nocache); err != nil {
  92. log.Error("Failed to deploy wallet container", "err", err)
  93. if len(out) > 0 {
  94. fmt.Printf("%s\n", out)
  95. }
  96. return
  97. }
  98. // All ok, run a network scan to pick any changes up
  99. log.Info("Waiting for node to finish booting")
  100. time.Sleep(3 * time.Second)
  101. w.networkStats()
  102. }