From cf4331db037fe004297b80d95b85a11f405f7719 Mon Sep 17 00:00:00 2001 From: danb Date: Sat, 9 Sep 2023 09:26:35 -0400 Subject: [PATCH] rework plan info --- app.py | 25 +++++++++++++++++++++++-- upgrades.sh | 4 ++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 91d7992..a17b579 100644 --- a/app.py +++ b/app.py @@ -215,6 +215,7 @@ def reorder_data(data): ("source", data.get("source")), ("upgrade_block_height", data.get("upgrade_block_height")), ("estimated_upgrade_time", data.get("estimated_upgrade_time")), + ("upgrade_plan_dump", data.get("upgrade_plan_dump")), ("version", data.get("version")), ("error", data.get("error")), ] @@ -309,6 +310,8 @@ def fetch_current_upgrade_plan(rest_url): # Convert the plan to string and search for the version pattern plan_dump = json.dumps(plan) + upgrade_plan = json.loads(plan_dump) + info = json.loads(upgrade_plan.get("info", "{}")) # Get all version matches version_matches = SEMANTIC_VERSION_PATTERN.findall(plan_dump) @@ -320,7 +323,7 @@ def fetch_current_upgrade_plan(rest_url): height = int(plan.get("height", 0)) except ValueError: height = 0 - return plan_name, version, height + return plan_name, version, height, plan_dump return None, None, None except requests.RequestException as e: @@ -343,7 +346,7 @@ def fetch_data_for_network(network, network_type, repo_path): chain_json_path = os.path.join(repo_path, "testnets", network, "chain.json") else: raise ValueError(f"Invalid network type: {network_type}") - + output_data = {} err_output_data = { "network": network, "type": network_type, @@ -428,6 +431,7 @@ def fetch_data_for_network(network, network_type, repo_path): current_upgrade_name, current_upgrade_version, current_upgrade_height, + current_plan_dump, ) = fetch_current_upgrade_plan(current_endpoint) except: if index + 1 < len(healthy_rest_endpoints): @@ -456,13 +460,29 @@ def fetch_data_for_network(network, network_type, repo_path): if ( current_upgrade_version and (current_upgrade_height is not None) + and (current_plan_dump is not None) and current_upgrade_height > latest_block_height ): upgrade_block_height = current_upgrade_height + upgrade_plan = json.loads(current_plan_dump) upgrade_version = current_upgrade_version upgrade_name = current_upgrade_name source = "current_upgrade_plan" rest_server_used = current_endpoint + # Extract the relevant information from the parsed JSON + info = json.loads(upgrade_plan.get("info", "{}")) + binaries = info.get("binaries", {}) + + estimated_upgrade_time = info.get("time", None) + + # Include the expanded information in the output data + output_data["upgrade_plan_dump"] = { + "height": upgrade_plan.get("height", None), + "binaries": binaries, + "name": upgrade_plan.get("name", None), + "time": estimated_upgrade_time, + "upgraded_client_state": upgrade_plan.get("upgraded_client_state", None), + } break if not active_upgrade_version and not current_upgrade_version: @@ -505,6 +525,7 @@ def fetch_data_for_network(network, network_type, repo_path): "upgrade_name": upgrade_name, "source": source, "upgrade_block_height": upgrade_block_height, + "upgrade_plan_dump": output_data["upgrade_plan_dump"], "estimated_upgrade_time": estimated_upgrade_time, "version": upgrade_version, } diff --git a/upgrades.sh b/upgrades.sh index 1f41d9c..8c3c374 100755 --- a/upgrades.sh +++ b/upgrades.sh @@ -5,8 +5,8 @@ declare -A networks=( [testnets]="agorictestnet quasartestnet stridetestnet onomytestnet axelartestnet nibirutestnet nobletestnet dydxtestnet osmosistestnet cosmoshubtestnet" ) -base_url="https://cosmos-upgrades.apis.defiantlabs.net" -# base_url="http://localhost:5000" +# base_url="https://cosmos-upgrades.apis.defiantlabs.net" +base_url="http://localhost:5000" # Loop over both mainnets and testnets for type in "${!networks[@]}"; do