Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove electrum limit, sort by url #1153

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions utils/generate_app_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import requests
from scan_electrums import get_electrums_report
from ensure_chainids import ensure_chainids
from logger import logger


current_time = time.time()
Expand Down Expand Up @@ -447,7 +448,8 @@ def get_electrums(self):
e["url"] = k
del e["ws_url"]
valid_electrums.append(e)

if len(valid_electrums) > 0:
valid_electrums = sort_dicts_list(valid_electrums, "url")
self.data[self.ticker].update({"electrum": valid_electrums})

def get_bchd_urls(self):
Expand Down Expand Up @@ -484,7 +486,9 @@ def get_swap_contracts(self):
key = "rpc_urls"
else:
key = "nodes"
self.data[self.ticker].update({key: contract_data["rpc_nodes"]})

values = sort_dicts_list(contract_data["rpc_nodes"], "url")
self.data[self.ticker].update({key: values})

def get_explorers(self):
explorers = None
Expand Down Expand Up @@ -591,13 +595,14 @@ def filter_ssl(coins_config):
if "electrum" in coins_config[coin]:
electrums = []
for i in coins_config[coin]["electrum"]:
logger.loop("SSL", coin, i)
if "protocol" in i:
# For web, we only want SSL.
if i["protocol"] == "SSL":
electrums.append(i)
coins_config_ssl[coin]["electrum"] = electrums[:3]
if len(coins_config_ssl[coin]["electrum"]) == 0:
del coins_config_ssl[coin]
else:
coins_config_ssl[coin]["electrum"] = electrums

if "nodes" in coins_config[coin]:
coins_config_ssl[coin]["nodes"] = [
Expand Down Expand Up @@ -635,7 +640,7 @@ def filter_tcp(coins_config, coins_config_ssl):
if "nodes" in coins_config[coin]:
coins_config_tcp[coin]["nodes"] = [
i for i in coins_config[coin]["nodes"] if "gui_auth" not in i
][:3]
]
if "electrum" in coins_config[coin]:
electrums = []
# Prefer SSL
Expand All @@ -650,13 +655,16 @@ def filter_tcp(coins_config, coins_config_ssl):
if "protocol" in i:
# SSL is ok for legacy desktop so we allow them, else some coins with only SSL will be omited.
if i["protocol"] != "WSS":
logger.calc("TCP", coin, i)
electrums.append(i)
else:
electrums.append(i)
logger.merge("TCP", coin, i)

coins_config_tcp[coin]["electrum"] = electrums[:3]
if len(coins_config_tcp[coin]["electrum"]) == 0:
del coins_config_tcp[coin]
else:
coins_config_tcp[coin]["electrum"] = electrums

with open(f"{script_path}/coins_config_tcp.json", "w+") as f:
json.dump(coins_config_tcp, f, indent=4)
Expand All @@ -666,7 +674,6 @@ def filter_tcp(coins_config, coins_config_ssl):
def filter_wss(coins_config):
coins_config_wss = {}
for coin in coins_config:
coins_config_wss.update({coin: coins_config[coin]})
if "electrum" in coins_config[coin]:
electrums = []
for i in coins_config[coin]["electrum"]:
Expand All @@ -675,9 +682,9 @@ def filter_wss(coins_config):
electrums.append(i)
else:
print(i)
coins_config_wss[coin]["electrum"] = electrums[:3]
if len(coins_config_wss[coin]["electrum"]) == 0:
del coins_config_wss[coin]
if len(electrums) > 0:
coins_config_wss.update({coin: coins_config[coin]})
coins_config_wss[coin]["electrum"] = electrums

with open(f"{script_path}/coins_config_wss.json", "w+") as f:
json.dump(coins_config_wss, f, indent=4)
Expand Down Expand Up @@ -722,6 +729,14 @@ def generate_binance_api_ids(coins_config):
# Valid interval values are listed at https://binance-docs.github.io/apidocs/spot/en/#public-api-definitions


def sort_dict(d):
return {k: d[k] for k in sorted(d)}

def sort_dicts_list(data, sort_key):
return sorted(data, key=lambda x: x[sort_key])



if __name__ == "__main__":
ensure_chainids()
coins_config, nodata = parse_coins_repo()
Expand All @@ -741,9 +756,9 @@ def generate_binance_api_ids(coins_config):
coins_config_tcp = filter_tcp(deepcopy(coins_config), coins_config_ssl)
for coin in coins_config:
if (
coin in coins_config_ssl
and coin in coins_config_ssl
coin in coins_config_tcp
and coin in coins_config_ssl
and coin in coins_config_wss
):
color = "green"
else:
Expand Down