whallets_cli.py 2.9 KB

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