Jelajahi Sumber

add a wallet interface

serinko 4 tahun lalu
induk
melakukan
e431c37d39
4 mengubah file dengan 161 tambahan dan 0 penghapusan
  1. TEMPAT SAMPAH
      __pycache__/texts_cli.cpython-38.pyc
  2. TEMPAT SAMPAH
      __pycache__/whallets_cli.cpython-38.pyc
  3. 54 0
      texts_cli.py
  4. 107 0
      whallets_cli.py

TEMPAT SAMPAH
__pycache__/texts_cli.cpython-38.pyc


TEMPAT SAMPAH
__pycache__/whallets_cli.cpython-38.pyc


+ 54 - 0
texts_cli.py

@@ -0,0 +1,54 @@
+"""A module with all the display info for whallets-cli."""
+
+import whallets_cli as cli
+
+def welcome_message():
+    """welcoming message to the cli"""
+    msg = \
+        "WELCOME TO WHALLETS CLI"\
+        "\n ========================================= \n"
+    return msg
+
+def _choose_chain():
+    msg = \
+        "\nPlease chose the network for the wallet address:"\
+        "\n1 - EVM; Etherum main net and any forks (BSC, Poly..)"\
+        "\n2 - SPL; Solana Program Platform"\
+        "\n3 - BTC; Bitcoin"
+    return msg
+
+def _prompt_address():
+    """Ask or the wallet address"""
+    msg = "\nEnter the wallet address:\n"
+    return msg
+
+def _prompt_twitter():
+    """Ask or the wallet address"""
+    msg = "\nEnter the twitter link (full address):\n"
+    return msg
+
+def _prompt_info():
+    """Ask or the wallet address"""
+    msg = "\nEnter short info about the user:\n"
+    return msg
+
+def _prompt_name():
+    """Ask or the wallet address"""
+    msg = "\nEnter user/wallet name/tag:\n"
+    return msg
+
+def _prompt_ens():
+    """Ask or the wallet address"""
+    msg = "\nEnter user's ENS:\n"
+    return msg
+
+def _check_wallet_result(chain, name, addr, twtr, ens):
+    """Messages informing about existing wallet"""
+    ix = cli.check_wallet(chain, name, addr, twtr, ens)
+    if ix < 4:
+        items = ['name','address','twitter','ens']
+        item = items[ix]
+        msg = f"This {item} is already saved in the databse."
+    else:
+        msg = "New wallet was saved."
+    return msg

+ 107 - 0
whallets_cli.py

@@ -0,0 +1,107 @@
+"""CLI for users to manage the wallet database and run research functions"""
+#TODO:
+# 1) Interacting with APIs
+# 2) easy adding data to the wallets_dict.json
+# - loop through each info separatedly
+# - ask to re-add info if matches
+# 3) Scanning through APIs based on given parameters
+# 4) Prints options for the user (-h)
+
+import json
+import texts_cli as tc
+
+def cli_main():
+    """Main program for the cli"""
+    print(tc.welcome_message())
+
+def main_menu():
+    """main cli options"""
+
+def add_wallet():
+    """A function to add wallet to the wallets_dict.json"""
+    chain, name, addr, inf, twtr, ens = _get_inputs()
+    msg = tc._check_wallet_result(chain, name, addr, twtr, ens)
+    print(msg)
+
+def _get_inputs():
+    """Get infor to add a new wallet"""
+    chain = int(input(tc._choose_chain()))
+    name = input(tc._prompt_name())
+    addr = input(tc._prompt_address())
+    inf = input(tc._prompt_info())
+    twtr = input(tc._prompt_twitter())
+    ens = input(tc._prompt_ens())
+    return chain, name, addr, inf, twtr, ens
+
+
+def check_wallet(chain, name, addr, twtr, ens):
+    """
+    Scans through wallets to check if a new wallet is not already in the
+    database
+    """
+
+    i = chain - 1
+    dict = get_wallets()[i]
+    for key, value in dict.items():
+        user = key
+        wallets = value['wallets']
+        info = value['info']
+        twitter = value['twitter']
+        ens_saved = value['ens']
+        if user == name:
+            return 0
+        elif addr in wallets.values():
+            return 1
+        elif twtr == twitter:
+            return 2
+        elif ens == ens_saved:
+            return 3
+        else:
+            return 4
+
+
+
+def get_wallets():
+    """ Gets the info from the dictionary """
+    filename = 'wallets_dict.json'
+    with open(filename) as f:
+        all_wallets = json.load(f)
+    evm_wallets = all_wallets['evm_wallets']
+    spl_wallets = all_wallets['spl_wallets']
+    return evm_wallets, spl_wallets
+
+
+def display_wallets(chain):
+    """Displays the wallets according the given chain"""
+    # Chains available 'evm','spl'
+    # evm shows all the forks
+    i = _chain_index(chain)
+    dict = get_wallets()[i]
+    print(f"\n\n{chain.upper()} WALLETS:")
+
+    for key, value in dict.items():
+        user = key
+        wallets = value['wallets']
+        info = value['info']
+        twitter = value['twitter']
+        chains = []
+        for key, value in wallets.items():
+            chains.append(key)
+        print(f"\nUser: {user}")
+        print(f"Info: {info}")
+        print(f"Twitter: {twitter}")
+        print(f"Wallet address: {value}")
+        print(f"Active networks: {chains}")
+
+def _chain_index(chain):
+    '''Asigns an index based on given parameter of the chain'''
+    if chain.lower() == 'evm':
+        i = 0
+    elif chain.lower() == 'spl':
+        i = 1
+    return i
+
+def display_all_wallets():
+    display_wallets('evm')
+    display_wallets('spl')
+