Skip to content

Commit

Permalink
rework plan info
Browse files Browse the repository at this point in the history
  • Loading branch information
danbryan committed Sep 9, 2023
1 parent a739086 commit cf4331d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
25 changes: 23 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
]
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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,
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
}
Expand Down
4 changes: 2 additions & 2 deletions upgrades.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf4331d

Please sign in to comment.