Просмотр исходного кода

Merge branch 'master' of github.com:darkrenaissance/whallets

saliveja 4 лет назад
Родитель
Сommit
27f3cb4c54
4 измененных файлов с 216 добавлено и 98 удалено
  1. BIN
      __pycache__/texts_cli.cpython-38.pyc
  2. 59 16
      texts_cli.py
  3. 35 35
      wallets_dict.json
  4. 122 47
      whallets_cli.py

BIN
__pycache__/texts_cli.cpython-38.pyc


+ 59 - 16
texts_cli.py

@@ -40,7 +40,7 @@ def _menu_choice():
 
 def _missing_operation():
     """Inform about non-existing users choice"""
-    msg = "Sorry, but you had either choosen an unexisting option, "\
+    msg = "\nSorry, but you had either choosen an unexisting option, "\
     "or this operation has not been developped yet."
     return msg
 
@@ -63,11 +63,22 @@ def _choose_network():
     table = [ line_0, line, line_1, line_2, line_3]
     return table
 
-def _prompt_address():
+def _prompt_new_info(item):
     """Ask or the wallet address"""
-    msg = "\nEnter the wallet address:\n"
+    msg = f"\nEnter the wallet {item}:\n(if unknown press Enter)\n"
     return msg
 
+def _ask_more_wallets():
+    """ask user if an account has more wallet addresses"""
+    msg_0 = \
+        "\nDo you want to add another address to this username?" \
+        "\n1 - YES (add more wallets)\n2 - NO (continue)\n"
+    msg_1 = "\nEnter another wallet address:\n"
+
+    return msg_0, msg_1
+
+
+
 def _prompt_twitter():
     """Ask or the wallet address"""
     msg = "\nEnter the twitter link (full address):\n"
@@ -89,14 +100,16 @@ def _prompt_ens():
     return msg
 
 
-def _display_wallet_check_result(y):
+def _display_wallet_check_result(z):
     """displays answer based on added data"""
     msg_0 = \
-        f"{y.title()} already exists in your wallet dictionary."\
-        f"\nDo you want to continue?\n1 - YES\n2 - NO (change the item)"\
+        f"\nThis {z} already exists in your wallet dictionary."\
+        f"\nDo you want to continue?\n1 - YES (keep it duplicate)"\
+        f"\n2 - NO (change the item)"\
         f"{_menu_choice()}"
+
     msg_1 = \
-        f"This is your the wallet info:\n"
+        f"This is your the wallet info:\n(Press Enter to save, 'q' to cancell)"
     return (msg_0, msg_1)
 
 
@@ -105,17 +118,24 @@ def _enter_new_info(y):
     msg = f"\nPlease write a correct {y}:\n\n"
     return msg
 
-def _save_wallet_confirm(ntw_i, name, addr, twtr, ens, inf):
+def _save_wallet_confirm(addresses, new_wallet):
     """print wallet and ask user if to save it"""
-    ntw = _return_network(ntw_i)
+    network = new_wallet["Network"]
+    username = new_wallet["username"]
+    twtr = new_wallet["twitter address"]
+    ens = new_wallet["ENS"]
+    info = new_wallet["info/note"]
+    # addr = list(addresses)
+
     line_0 = ("****","This wallet will be saved to your dictionary:")
     line = ("-----","----------------------------------------------")
-    line_1 = (f"Network:",f"{ntw}")
-    line_2 = (f"Name:",f"{name}")
-    line_3 = (f"Address:",f"{addr}")
-    line_4 = (f"Twitter:",f"{twtr}")
-    line_5 = (f"ENS:",f"{ens}")
-    line_6 = (f"Info:", f"{inf}")
+    line_1 = (f"Network:",f"{network}")
+    line_2 = (f"Name:",f"{username}")
+    line_3 = (f"Twitter:",f"{twtr}")
+    line_4 = (f"ENS:",f"{ens}")
+    line_5 = (f"Info:", f"{info}")
+
+
     table = [
         line_0,
         line,
@@ -124,10 +144,33 @@ def _save_wallet_confirm(ntw_i, name, addr, twtr, ens, inf):
         line_3,
         line_4,
         line_5,
-        line_6
         ]
+
+    for i, address in enumerate(addresses):
+        line = (f"Address_{i}:", f"{address}")
+        table.append(line)
     return table
 
+def _confirm_entry():
+    """Asks user to confirm the wallet saving or repeat"""
+    msg_0 = \
+        "\nDo you want to save the wallet to the database?"\
+        "\n1 - YES\n2 - NO\n"
+    msg_1 = "\nThe wallet was saved to your database."
+    msg_2 = \
+        "\nDo you want to add another wallet?"\
+        "\n1 - YES\n2 - NO\n"
+
+    return msg_0, msg_1, msg_2
+
+
+# def _display_wallets(chain, user):
+#     """Text template for table of wallet display function"""
+#     line_0 = ("*****",f"{chain.upper} WALLETS")
+#     line = ("=====================================================",)
+#     line_1 = ("Username:",f"{user}")
+
+
 def _return_network(ntw_i):
     """Return network based on index"""
     if ntw_i == 0:

+ 35 - 35
wallets_dict.json

@@ -5,7 +5,7 @@
             "info": "ETH foundation, influencer, researcher, cult",
             "ens": "vitalik.eth",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
                     "networks": [
                         "erc",
@@ -18,7 +18,7 @@
                         "arb"
                     ]
                 },
-                "evm_1": {
+                "wallet_1": {
                     "address": "0xc1e42f862d202b4a0ed552c1145735ee088f6ccf",
                     "networks": [
                         "erc",
@@ -38,7 +38,7 @@
             "info": "3AC founder, enterpreteur, Deribit, uncommon core",
             "ens": " ",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0x4862733B5FdDFd35f35ea8CCf08F5045e57388B3",
                     "networks": [
                         "erc",
@@ -49,13 +49,13 @@
                         "avax"
                     ]
                 },
-                "evm_1": {
+                "wallet_1": {
                     "address": "0x4093fbe60ab50ab79a5bd32fa2adec255372f80e",
                     "networks": [
                         "erc"
                     ]
                 },
-                "evm_2": {
+                "wallet_2": {
                     "address": "0x3ba21b6477f48273f41d241aa3722ffb9e07e247",
                     "networks": [
                         "erc"
@@ -68,7 +68,7 @@
             "info": "ftx foundation",
             "ens": " ",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0xfa34bf9307f2f68a70b4369bb2f522b2b2bb222b",
                     "networks": [
                         "erc",
@@ -77,7 +77,7 @@
                         "avax"
                     ]
                 },
-                "evm_1": {
+                "wallet_1": {
                     "address": "0x84d34f4f83a87596cd3fb6887cff8f17bf5a7b83",
                     "networks": [
                         "erc",
@@ -97,7 +97,7 @@
             "info": "fund",
             "ens": " ",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0x43adde52c6c142912662d3e427709db5cac9b811",
                     "networks": [
                         "erc",
@@ -115,7 +115,7 @@
             "info": " VC fund",
             "ens": " ",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0x66b870ddf78c975af5cd8edc6de25eca81791de1",
                     "networks": [
                         "erc",
@@ -135,7 +135,7 @@
             "info": "#1 followers on debank.com",
             "ens": " ",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0xbdfa4f4492dd7b7cf211209c4791af8d52bf5c50",
                     "networks": [
                         "erc",
@@ -157,7 +157,7 @@
             "info": "small anon whale, sharp alt plays",
             "ens": "amelisa.eth",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0x3c9002cdb61c56b89467d94a2d93235dfd698089",
                     "networks": [
                         "erc",
@@ -176,7 +176,7 @@
             "info": " ",
             "ens": " ",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0x9c5083dd4838e120dbeac44c052179692aa5dac5",
                     "networks": [
                         "erc",
@@ -195,7 +195,7 @@
             "info": "smaller alt degen play wallet, name is made up",
             "ens": " ",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0x1d3db45f912c74de554409c1ad0d27dbcb26b726",
                     "networks": [
                         "erc",
@@ -214,7 +214,7 @@
             "info": "whale on eth",
             "ens": "obvio.eth",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0x179456bf16752FE5Eb8789148E5C98Eb39D87Fe5",
                     "networks": [
                         "erc",
@@ -233,7 +233,7 @@
             "info": "nft (eth) trader",
             "ens": "wed.eth",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0xAB6cA2017548A170699890214bFd66583A0C1754",
                     "networks": [
                         "erc",
@@ -250,7 +250,7 @@
             "info": "whale on fantom",
             "ens": "",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0xebf4fbb9c81b84dd5cf89bc75588e5d0018501b3",
                     "networks": [
                         "erc",
@@ -264,7 +264,7 @@
             "info": "fund",
             "ens": "",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0x4655b7ad0b5f5bacb9cf960bbffceb3f0e51f363",
                     "networks": [
                         "erc",
@@ -273,7 +273,7 @@
                     ]
                 },
 
-                "evm_1:": {
+                "wallet_1:": {
                     "address": "0x59cee32f3ffaeabc0d4991ac7569ebad09e1a7d4",
                     "networks": [
                         "erc"
@@ -286,7 +286,7 @@
             "info": "degen who was early in gmx, active small cap investor",
             "ens": "",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0x1e7127c81c8a58661a0811f026b6be66533934be",
                     "networks": [
                         "erc"
@@ -300,7 +300,7 @@
             "info": "gOHM investor, NFT whale, nansen smart money",
             "ens": "devmons.eth",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0x5efb87c9ff9da9ba445dfef71f0446682352c15d",
                     "networks": [
                         "erc",
@@ -323,7 +323,7 @@
             "info": "whale",
             "ens": " ",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0x23a5efe19aa966388e132077d733672cf5798c03",
                     "networks": [
                         "erc"
@@ -337,7 +337,7 @@
             "info": "gOHM investor",
             "ens": " ",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0xe2e4f2a725e42d0f0ef6291f46c430f963482001",
                     "networks": [
                         "erc",
@@ -346,7 +346,7 @@
                         "bsc"
                     ]
                 },
-                "evm_1:": {
+                "wallet_1:": {
                     "address": "0x0561a78021d8966ddd20c28c6c4318d8675ee1f0",
                     "networks": [
                         "erc",
@@ -363,7 +363,7 @@
             "info": "CEO and founder of Aave",
             "ens": " " ,
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0xf5fb27b912d987b5b6e02a1b1be0c1f0740e2c6f",
                     "networks": [
                         "erc",
@@ -380,7 +380,7 @@
             "info": "whale",
             "ens": "punkify.eth",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0xaf297dec752c909092a117a932a8ca4aaaff9795",
                     "networks": [
                         "erc",
@@ -401,7 +401,7 @@
             "info": "algo trading firm",
             "ens": "analytico.eth",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0xa0f75491720835b36edc92d06ddc468d201e9b73",
                     "networks": [
                         "erc",
@@ -421,7 +421,7 @@
             "info": "xmon investor",
             "ens": " ",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0xf6e2c94a609ca303964b65ec991a1a0d2991b961",
                     "networks": [
                         "erc",
@@ -429,7 +429,7 @@
                         "ftm"
                     ]
                 },
-                "evm_1:": {
+                "wallet_1:": {
                     "address": "0x39eea0258a5c3e3c5092b2f910371d124592a7fb",
                     "networks": [
                         "erc",
@@ -444,7 +444,7 @@
             "info": " ",
             "ens": " ",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "<0x332a4fb9603ecd65f3a4e321e8c10826c46049af",
                     "networks": [
                         "arb",
@@ -452,7 +452,7 @@
                         "ftm"
                     ]
                 },
-                "evm_1": {
+                "wallet_1": {
                     "address": "0x5058352e527694a554966154397af9ab79d75461",
                     "networks": [
                         "poly",
@@ -467,7 +467,7 @@
             "info": " ",
             "ens": " ",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "0xb0dafc466871c29662e5cbf4227322c96a8ccbe9",
                     "networks": [
                         "erc",
@@ -476,7 +476,7 @@
                         "arb"
                     ]
                 },
-                "evm_1": {
+                "wallet_1": {
                     "address": "0xf52bad5e97658f04b5228d58f428e98f9139d23f",
                     "networks": [
                         "erc"
@@ -491,7 +491,7 @@
             "info": "<info>",
             "ens": " ",
             "wallets": {
-                "evm_0": {
+                "wallet_0": {
                     "address": "<paste 0x... address>",
                     "networks": [
                         "erc",
@@ -499,14 +499,14 @@
 
                     ]
                 },
-                "<evm_1: in case another wallet of the same user>": {
+                "<wallet_1: in case another wallet of the same user>": {
                     "address": "<0x...>",
                     "networks": [
                         "<...>",
                         "<...>"
                     ]
                 },
-                "<evm_2: in case of another wallet of the same user>": {
+                "<wallet_2: in case of another wallet of the same user>": {
                     "address": "<0x...>",
                     "networks": [
                         "<..>"

+ 122 - 47
whallets_cli.py

@@ -6,6 +6,7 @@
 # - loop through each info separately
 # - ask to re-add info if matches
 # - ask for additional wallets for the same user
+# - add and print all the added wallets
 # 4) Prints options for the user (-h)
 
 import json
@@ -62,39 +63,106 @@ def _new_choice():
 
 def add_wallet():
     """A function to add wallet to the wallets_dict.json"""
-    ntw_i, name, addr, inf, twtr, ens = _get_inputs()
-    wlt = check_wallet(ntw_i, name, addr, twtr, ens, inf)
-    ntw_i, name, addr, twtr, ens, inf = \
-        wlt[0], wlt[1], wlt[2], wlt[3], wlt[4], wlt[5]
-    print(tabulate(tc._save_wallet_confirm(ntw_i, name, addr, twtr, ens, inf)))
+    new_wallet, addresses, ntw_i = get_inputs()
 
 
+    print(tabulate(tc._save_wallet_confirm(addresses, new_wallet)))
+    confirm_entry(addresses, new_wallet)
+    new_wallet_dictionary = refactor_wallet(addresses, new_wallet)
+    save_wallet(ntw_i, new_wallet_dictionary)
+
+def confirm_entry(addresses, new_wallet):
+    """Preview the new wallet and confirm saving it"""
+    x = input(tc._confirm_entry()[0])
+    if x == '1':
+        # new_wallet_dict = refactor_wallet(addresses, **new_wallet)
+        # save_wallet(**new_wallet_dict)
+        print(tc._confirm_entry()[1])
+
+        refactor_wallet(addresses, new_wallet)
+
+    x = input(tc._confirm_entry()[2])
+    if x == '1':
+        add_wallet()
 
 
-def _correct_item(y):
-    """Allows user to rewrite an exisitng item in the wallet"""
-    z = (input(tc._display_wallet_check_result(y)[0]))
-    if z =='1':
-        print(tc._display_wallet_check_result(y)[1])
-        return True
 
-    elif z == '2':
-        new_item = input(tc._enter_new_info(y))
-        return new_item
+
+def save_wallet(ntw_i, new_wallet_dictionary):
+    """Saves the wallet into the database/dictionary and informs the user"""
+   
+    filename = 'wallets_dict.json'
+
+    with open(filename) as f:
+        all_wallets = json.load(f)
+        dict = all_wallets[ntw_i]
+
+        all_wallets[dict].update(new_wallet_dictionary)
+        json.dump(f)
+
+
+
+def refactor_wallet(addresses, new_wallet):
+    """Refactor the wallet items to the wallet_dict format"""
+    username = new_wallet["username"]
+    twtr = new_wallet["twitter address"]
+    ens = new_wallet["ENS"]
+    info = new_wallet["info/note"]
+
+    new_wallet_dictionary = {username: {
+        "twitter": twtr,
+        "info": info,
+        "ens":ens,
+        "wallets": {}
+            }
+        }
+
+    for idx, addr in enumerate(addresses):
+        wallet = {f"wallet_{idx}":{
+            "address":f"{addr}",
+            "networks":[
+                "erc"
+                # need to add a code how to add networks
+                ]
+            }
+        }
+        new_wallet_dictionary[username]["wallets"].update(wallet)
+    print(f"\n\n\n{new_wallet_dictionary}")
+
+    return new_wallet_dictionary
 
 def remove_wallet():
     """Removes wallet from the wallet dictionary"""
-    # This function needs to be developped
+    # This function needs to be developed
 
-def _get_inputs():
+def get_inputs():
     """Get infor to add a new wallet"""
     ntw_i = _check_network()
-    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 ntw_i, name, addr, inf, twtr, ens
+    network = tc._return_network(ntw_i)
+    addresses = []
+    new_wallet = {
+            "username":" ",
+            "twitter address":" ",
+            "ENS":" ",
+            "info/note":" ",
+            "address": addresses
+    }
+
+    for item, value in new_wallet.items():
+        x = input(tc._prompt_new_info(item))
+        new_item = check_wallet_item(ntw_i,x)
+        if item == 'address':
+            addresses.append(new_item)
+            y = input(tc._ask_more_wallets()[0])
+            while y == '1':
+                new_item = input(tc._ask_more_wallets()[1])
+                addresses.append(new_item)
+                y = input(tc._ask_more_wallets()[0])
+        new_wallet[item] = new_item
+
+    new_wallet["Network"] = network
+
+    return new_wallet, addresses, ntw_i
 
 def _check_network():
     """Check if the existing network"""
@@ -107,46 +175,50 @@ def _check_network():
     else:
         return i
 
-def check_wallet(ntw_i,name, addr, twtr, ens, inf):
+def check_wallet_item(ntw_i,x):
     """
     Scans through wallets to check if a new wallet is not already in the
     database
     """
-    i = ntw_i
-
-    dict = get_wallets()[i]
+    dict = get_wallets()[ntw_i]
     for key, value in dict.items():
-        user = key
+        username = key
         wallets = value['wallets']
         info = value['info']
         twitter = value['twitter']
         ens_saved = value['ens']
-        if user == name:
-            x = [1,'name']
-        elif addr in wallets.values():
-            x = [2, 'address']
-        elif twtr == twitter:
-            x = [3, 'twitter']
-        elif ens == ens_saved:
-            x = [4, 'ENS']
+
+        if x == username:
+            new_item = _correct_item(x,'username')
+        elif x in wallets.values():
+            new_item = _correct_item(x,'wallet address')
+        elif x == twitter:
+            new_item = _correct_item(x,'twitter address')
+        elif x == ens_saved:
+            new_item = _correct_item(x, 'ENS')
         else:
-            x = [5, "none"]
+            new_item = x
 
-    y = x[1]
-    x = x[0]
+    return new_item
 
-    if x != 5:
-        new_item = _correct_item(y)
-    else:
-        print(tc._display_wallet_check_result(y)[1])
-        new_item = True
+def _correct_item(x,z):
+    """Allows user to rewrite an exisitng item in the wallet"""
+    a = '2'
+    while a == '2':
+        a = (input(tc._display_wallet_check_result(z)[0]))
 
-    wlt = [ntw_i, name, addr, twtr, ens, inf]
+        if a == '1':
+            new_item = x
 
-    if new_item != True:
-        wlt[x] = new_item
+        elif a == '2':
+            new_item = input(tc._enter_new_info(z))
+            if new_item == x:
+                a = '2'
+            else:
+                new_item = x
+        break
+    return new_item
 
-    return wlt
 
 
 
@@ -190,6 +262,9 @@ def display_wallets(chain):
             networks_str = ', '.join(networks)
             print(networks_str)
 
+
+
+
 def _chain_index(chain):
     """Asigns an index based on given parameter of the chain"""
     if chain.lower() == 'evm':