whallets_cli.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. """CLI for users to manage the wallet database and run research functions"""
  2. #TODO:
  3. # 1) Learn operating Blockscan APIs
  4. # 2) Program functions pulling APIs data based on users interaction
  5. # 3) CLI function to easy add new wallets and other data to the wallets_dict.json
  6. # - loop through each info separately
  7. # - ask to re-add info if matches
  8. # 4) Prints options for the user (-h)
  9. import json
  10. from tabulate import tabulate
  11. import texts_cli as tc
  12. def cli_main():
  13. """Main program for the cli"""
  14. print(tc.welcome_message())
  15. def main_menu():
  16. """main cli options"""
  17. def add_wallet():
  18. """A function to add wallet to the wallets_dict.json"""
  19. chain, name, addr, inf, twtr, ens = _get_inputs()
  20. msg = tc._check_wallet_result(chain, name, addr, twtr, ens)
  21. print(msg)
  22. def _get_inputs():
  23. """Get infor to add a new wallet"""
  24. chain = int(input(tc._choose_chain()))
  25. name = input(tc._prompt_name())
  26. addr = input(tc._prompt_address())
  27. inf = input(tc._prompt_info())
  28. twtr = input(tc._prompt_twitter())
  29. ens = input(tc._prompt_ens())
  30. return chain, name, addr, inf, twtr, ens
  31. def check_wallet(chain, name, addr, twtr, ens):
  32. """
  33. Scans through wallets to check if a new wallet is not already in the
  34. database
  35. """
  36. i = chain - 1
  37. dict = get_wallets()[i]
  38. for key, value in dict.items():
  39. user = key
  40. wallets = value['wallets']
  41. info = value['info']
  42. twitter = value['twitter']
  43. ens_saved = value['ens']
  44. if user == name:
  45. return 0
  46. elif addr in wallets.values():
  47. return 1
  48. elif twtr == twitter:
  49. return 2
  50. elif ens == ens_saved:
  51. return 3
  52. else:
  53. return 4
  54. def get_wallets():
  55. """ Gets the info from the dictionary """
  56. filename = 'wallets_dict.json'
  57. with open(filename) as f:
  58. all_wallets = json.load(f)
  59. evm_wallets = all_wallets['evm_wallets']
  60. spl_wallets = all_wallets['spl_wallets']
  61. return evm_wallets, spl_wallets
  62. def display_wallets(chain):
  63. """Displays the wallets according the given chain"""
  64. # Chains available 'evm','spl'
  65. # evm shows all the forks
  66. i = _chain_index(chain)
  67. dict = get_wallets()[i]
  68. print(f"\n\n{chain.upper()} WALLETS:")
  69. for key, value in dict.items():
  70. user = key
  71. info = value['info']
  72. twitter = value['twitter']
  73. wallets = {}
  74. wlts = value['wallets']
  75. for x, y in wlts.items():
  76. wallets[x] = y
  77. print(f"\nUser: {user}")
  78. print(f"Info: {info}")
  79. print(f"Twitter: {twitter}")
  80. for wlt,inf in wallets.items():
  81. print(f"Wallets: {wlt}")
  82. print(f"Address: {inf['address']}")
  83. print(f"Active networks:")
  84. networks = inf['networks']
  85. networks_str = ', '.join(networks)
  86. print(networks_str)
  87. def _chain_index(chain):
  88. """Asigns an index based on given parameter of the chain"""
  89. if chain.lower() == 'evm':
  90. i = 0
  91. elif chain.lower() == 'spl':
  92. i = 1
  93. return i
  94. def display_all_wallets():
  95. display_wallets('evm')
  96. display_wallets('spl')