-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding auto update for ledger app flag
- Loading branch information
Showing
5 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Update Generic Ledger App Networks | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0,12 * * *' # Runs twice a day at 00:00 and 12:00 | ||
workflow_dispatch: | ||
pull_request: | ||
|
||
jobs: | ||
update-networks: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout current repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: 🛠 Set up actual paths | ||
uses: ./.github/workflows/setup-path | ||
|
||
- name: Run update script | ||
id: run-script | ||
run: | | ||
make init | ||
make update-ledger-networks | ||
- name: Make Pull Request | ||
id: make-pr | ||
uses: ./.github/workflows/make-pull-request | ||
with: | ||
commit-files: | | ||
./chains/* | ||
./scripts/data/check_metadata_hash_mapping.json | ||
commit-message: Update Generic Ledger App Networks | ||
app-id: ${{ secrets.PR_APP_ID}} | ||
app-token: ${{ secrets.PR_APP_TOKEN}} | ||
pr-reviewer: 'ERussel,leohar,valentunn,stepanLav' | ||
branch-name: update-generic-ledger-app-networks | ||
pr-title: 📒 Ledger have got support new networks! | ||
pr-body: | | ||
This PR was generated automatically 🤖 | ||
If you see empty chainId in [check_metadata_hash_mapping.json](./scripts/data/check_metadata_hash_mapping.json) | ||
please checkout that branch, add chainId and run `make update-ledger-networks` | ||
pr-base: master | ||
|
||
- name: Send Telegram Notification | ||
if: steps.make-pr.outputs.pr-url != '' | ||
uses: appleboy/telegram-action@master | ||
with: | ||
to: ${{ secrets.TELEGRAM_TO }} | ||
token: ${{ secrets.TELEGRAM_TOKEN }} | ||
message: | | ||
📒 New networks have been added to Generic Ledger App! | ||
PR: ${{ steps.make-pr.outputs.pr-url }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
[ | ||
{ | ||
"name": "kusamaassethub", | ||
"chain": "kusama", | ||
"chainId": "48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a" | ||
}, | ||
{ | ||
"name": "encointer", | ||
"chain": "kusama", | ||
"chainId": "7dd99936c1e9e6d1ce7d90eb6f33bea8393b4bf87677d675aa63c9cb3e8c5b5b" | ||
}, | ||
{ | ||
"name": "kusama", | ||
"chain": "kusama", | ||
"chainId": "b0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe" | ||
}, | ||
{ | ||
"name": "kusamabridgehub", | ||
"chain": "kusama", | ||
"chainId": "00dcb981df86429de8bbacf9803401f09485366c44efbf53af9ecfab03adc7e5" | ||
}, | ||
{ | ||
"name": "kusamacoretime", | ||
"chain": "kusama", | ||
"chainId": "638cd2b9af4b3bb54b8c1f0d22711fc89924ca93300f0caf25a580432b29d050" | ||
}, | ||
{ | ||
"name": "kusamapeople", | ||
"chain": "kusama", | ||
"chainId": "c1af4cb4eb3918e5db15086c0cc5ec17fb334f728b7c65dd44bfe1e174ff8b3f" | ||
}, | ||
{ | ||
"name": "polkadotassethub", | ||
"chain": "polkadot", | ||
"chainId": "68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f" | ||
}, | ||
{ | ||
"name": "polkadot", | ||
"chain": "polkadot", | ||
"chainId": "91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3" | ||
}, | ||
{ | ||
"name": "polkadotbridgehub", | ||
"chain": "polkadot", | ||
"chainId": "dcf691b5a3fbe24adc99ddc959c0561b973e329b1aef4c4b22e7bb2ddecb4464" | ||
}, | ||
{ | ||
"name": "polkadotcollectives", | ||
"chain": "polkadot", | ||
"chainId": "46ee89aa2eedd13e988962630ec9fb7565964cf5023bb351f2b6b25c1b68b0b2" | ||
}, | ||
{ | ||
"name": "rococoassethub", | ||
"chain": "rococo", | ||
"chainId": "7c34d42fc815d392057c78b49f2755c753440ccd38bcb0405b3bcfb601d08734" | ||
}, | ||
{ | ||
"name": "rococo", | ||
"chain": "rococo", | ||
"chainId": "6408de7737c59c238890533af25896a2c20608d8b380bb01029acb392781063e" | ||
}, | ||
{ | ||
"name": "westendassethub", | ||
"chain": "westend", | ||
"chainId": "67f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9" | ||
}, | ||
{ | ||
"name": "westend", | ||
"chain": "westend", | ||
"chainId": "e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import json | ||
import os | ||
import requests | ||
from pathlib import Path | ||
from collections import OrderedDict | ||
|
||
CHAINS_FILE_PATH = Path(os.getenv("CHAINS_JSON_PATH", 'chains/v20/chains.json')) | ||
CHAINS_FILE_PATH_DEV = Path(os.getenv("DEV_CHAINS_JSON_PATH", 'chains/v20/chains_dev.json')) | ||
MAPPING_FILE_PATH = Path('scripts/data/check_metadata_hash_mapping.json') | ||
FETCH_METADATA_URL = 'https://dashboards.data.paritytech.io/data/metadata000000000000.jsonl' | ||
|
||
def fetch_metadata(): | ||
response = requests.get(FETCH_METADATA_URL) | ||
response.raise_for_status() | ||
return [json.loads(line) for line in response.text.splitlines()] | ||
|
||
def find_networks_with_check_metadata_hash(metadata): | ||
return [ | ||
{ | ||
'name': item['chain'].lower(), | ||
'chain': item['relay_chain'] | ||
} | ||
for item in metadata if item.get('CheckMetadataHash') == 'yes' | ||
] | ||
|
||
def load_json_file(file_path): | ||
if file_path.exists(): | ||
with open(file_path, 'r') as f: | ||
return json.load(f, object_pairs_hook=OrderedDict) | ||
return [] | ||
|
||
def update_networks_with_mapping(networks, mapping_data): | ||
updated_networks = [] | ||
for new_network in networks: | ||
existing_network = next((network for network in mapping_data if network['name'] == new_network['name']), None) | ||
if existing_network: | ||
existing_network.update(new_network) | ||
else: | ||
new_network['chainId'] = '' | ||
updated_networks.append(new_network) | ||
mapping_data.extend(updated_networks) | ||
|
||
with open(MAPPING_FILE_PATH, 'w') as f: | ||
json.dump(mapping_data, f, indent=4) | ||
|
||
def find_new_networks(existing_data, networks): | ||
existing_networks = { | ||
network['name'].lower().replace(' ', '') | ||
for network in existing_data | ||
if 'additional' in network and 'supportsGenericLedgerApp' in network['additional'] | ||
} | ||
return [network for network in networks if network['name'] not in existing_networks] | ||
|
||
def update_existing_data_with_new_networks(existing_data, new_networks): | ||
for new_network in new_networks: | ||
if not new_network['chainId']: | ||
print(f"Skipping network with no chainId: {new_network}") | ||
continue | ||
|
||
matching_network = next((network for network in existing_data if network['chainId'] == new_network['chainId']), None) | ||
if matching_network: | ||
if 'additional' not in matching_network: | ||
matching_network['additional'] = {} | ||
matching_network['additional']['supportsGenericLedgerApp'] = True | ||
|
||
def process_file(chains_file_path): | ||
metadata = fetch_metadata() | ||
networks = find_networks_with_check_metadata_hash(metadata) | ||
|
||
existing_data = load_json_file(chains_file_path) | ||
mapping_data = load_json_file(MAPPING_FILE_PATH) | ||
|
||
if mapping_data: | ||
update_networks_with_mapping(networks, mapping_data) | ||
|
||
new_networks = find_new_networks(existing_data, mapping_data) | ||
|
||
if new_networks: | ||
update_existing_data_with_new_networks(existing_data, new_networks) | ||
with open(chains_file_path, 'w') as f: | ||
json.dump(existing_data, f, indent=4) | ||
|
||
def main(): | ||
process_file(CHAINS_FILE_PATH) | ||
process_file(CHAINS_FILE_PATH_DEV) | ||
|
||
if __name__ == "__main__": | ||
main() |