You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.6 KiB

  1. // Copyright 2017-2018 DERO Project. All rights reserved.
  2. // Use of this source code in any form is governed by RESEARCH license.
  3. // license can be found in the LICENSE file.
  4. // GPG: 0F39 E425 8C65 3947 702A 8234 08B2 0360 A03A 9DE8
  5. //
  6. //
  7. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  8. // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  9. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  10. // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  12. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  13. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  14. // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  15. // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. package main
  17. import "io"
  18. import "fmt"
  19. import "strings"
  20. import "github.com/chzyer/readline"
  21. import "github.com/deroproject/derosuite/globals"
  22. import "github.com/deroproject/derosuite/walletapi"
  23. // handle menu if a wallet is currently opened
  24. func display_easymenu_post_open_command(l *readline.Instance) {
  25. w := l.Stderr()
  26. io.WriteString(w, "Menu:\n")
  27. io.WriteString(w, "\t\033[1m1\033[0m\tDisplay account Address \n")
  28. if !account.ViewOnly { // hide some commands, if view only wallet
  29. io.WriteString(w, "\t\033[1m2\033[0m\tDisplay Seed "+color_red+"(Please save seed otherwise your wallet is LOST)\n\033[0m")
  30. }
  31. io.WriteString(w, "\t\033[1m3\033[0m\tDisplay Keys (hex)\n")
  32. io.WriteString(w, "\t\033[1m4\033[0m\tDisplay Watch-able View only wallet key ( cannot spend any funds from this wallet) (hex)\n")
  33. if !account.ViewOnly { // hide some commands, if view only wallet
  34. io.WriteString(w, "\t\033[1m5\033[0m\tTransfer ( send DERO) To Another Wallet\n")
  35. io.WriteString(w, "\t\033[1m6\033[0m\tTransfer ( send DERO) To Exchange (payment id mandatory\n")
  36. io.WriteString(w, "\t\033[1m7\033[0m\tCreate Transaction in offline mode\n")
  37. }
  38. io.WriteString(w, "\t\033[1m8\033[0m\tClose Wallet\n")
  39. io.WriteString(w, "\n\t\033[1m9\033[0m\tExit menu and start prompt\n")
  40. io.WriteString(w, "\t\033[1m0\033[0m\tExit Wallet\n")
  41. }
  42. // this handles all the commands if wallet in menu mode and a wallet is opened
  43. func handle_easymenu_post_open_command(l *readline.Instance, line string) {
  44. var err error
  45. _ = err
  46. line = strings.TrimSpace(line)
  47. line_parts := strings.Fields(line)
  48. if len(line_parts) < 1 { // if no command return
  49. return
  50. }
  51. command := ""
  52. if len(line_parts) >= 1 {
  53. command = strings.ToLower(line_parts[0])
  54. }
  55. switch command {
  56. case "1":
  57. if account_valid {
  58. fmt.Fprintf(l.Stderr(), "%s\n", account.GetAddress())
  59. }
  60. case "2": // give user his seed
  61. if !account.ViewOnly {
  62. display_seed(l)
  63. }
  64. case "3": // give user his keys in hex form
  65. display_spend_key(l)
  66. display_view_key(l)
  67. case "4": // display user keys to create view only wallet
  68. display_viewwallet_key(l)
  69. case "5", "6", "7":
  70. if !account.ViewOnly {
  71. globals.Logger.Warnf("This command is NOT yet implemented")
  72. }
  73. case "8": // close and discard user key
  74. account_valid = false
  75. account = &walletapi.Account{} // overwrite previous instance
  76. address = "" // empty the address
  77. Wallet_Height = 0
  78. case "9": // enable prompt mode
  79. menu_mode = false
  80. globals.Logger.Infof("Prompt mode enabled")
  81. case "0", "bye", "exit", "quit":
  82. globals.Exit_In_Progress = true
  83. default: // just loop
  84. }
  85. }