whallets-cli.py 2.8 KB

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