whallets-cli.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 = input(tc._choose_chain())
  17. name = input(tc._prompt_name())
  18. addr = input(tc._prompt_address())
  19. inf = input(tc._prompt_info())
  20. twtr = input(tc._prompt_twitter())
  21. ens = input(tc._prompt_ens())
  22. check_wallet(chain, name, addr, inf, twtr, ens)
  23. def check_wallet(chain, name, addr, twtr, ens):
  24. """
  25. Scans through wallets to check if a new wallet is not already in the
  26. database"
  27. """
  28. i = _chain_index(chain)
  29. dict = get_wallets()[i]
  30. for key, value in dict.items():
  31. user = key
  32. wallets = value['wallets']
  33. for key
  34. info = value['info']
  35. twitter = value['twitter']
  36. if user == name:
  37. return 0
  38. elif addr in wallets.values():
  39. return 1
  40. elif
  41. def get_wallets():
  42. ''' Gets the info from the dictionary '''
  43. filename = 'wallets_dict.json'
  44. with open(filename) as f:
  45. all_wallets = json.load(f)
  46. evm_wallets = all_wallets['evm_wallets']
  47. spl_wallets = all_wallets['spl_wallets']
  48. return evm_wallets, spl_wallets
  49. def display_wallets(chain):
  50. """Displays the wallets according the given chain"""
  51. # Chains available 'evm','spl'
  52. # evm shows all the forks
  53. i = _chain_index(chain)
  54. dict = get_wallets()[i]
  55. print(f"\n\n{chain.upper()} WALLETS:")
  56. for key, value in dict.items():
  57. user = key
  58. wallets = value['wallets']
  59. info = value['info']
  60. twitter = value['twitter']
  61. chains = []
  62. for key, value in wallets.items():
  63. chains.append(key)
  64. print(f"\nUser: {user}")
  65. print(f"Info: {info}")
  66. print(f"Twitter: {twitter}")
  67. print(f"Wallet address: {value}")
  68. print(f"Active networks: {chains}")
  69. def _chain_index(chain):
  70. '''Asigns an index based on given parameter of the chain'''
  71. if chain.lower() == 'evm':
  72. i = 0
  73. elif chain.lower() == 'spl':
  74. i = 1
  75. return i
  76. def display_all_wallets():
  77. display_wallets('evm')
  78. display_wallets('spl')
  79. display_all_wallets()