Skip to content

Commit

Permalink
feat: add id field to archives (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
belopash authored Nov 25, 2024
1 parent 426f3cd commit 5131947
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 2 deletions.
4 changes: 3 additions & 1 deletion scripts/archives/add_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def update_parser(parser: argparse.ArgumentParser):

def _run(parsed_args):
console = Console()
registry_name = Prompt.ask("Registry name")
hr_name = Prompt.ask("Human readable name")
data_source_id = Prompt.ask("Data source identifier")
registry_name = Prompt.ask("Registry name", default=data_source_id)
entry = {}
match parsed_args.variant:
case "evm":
Expand All @@ -38,6 +38,7 @@ def _run(parsed_args):
elif not logo_url.startswith("http://") and not logo_url.startswith("https://"):
logo_url = "https://cdn.subsquid.io/img/networks/" + logo_url
entry = {
"id": data_source_id,
"chainId": int(chain_id) if chain_id.isdecimal() else None,
"chainName": hr_name,
"isTestnet": chain_testnet,
Expand All @@ -59,6 +60,7 @@ def _run(parsed_args):
genesis_hash = Prompt.ask("Genesis hash", default="")
support_tier = int(Prompt.ask("Support tier", default="2", choices=["1", "2", "3"]))
entry = {
"id": data_source_id,
"chainName": hr_name,
"chainSS58Prefix": (
int(chain_ss58_prefix) if chain_ss58_prefix.isdecimal() else None
Expand Down
19 changes: 19 additions & 0 deletions scripts/archives/fix-ids.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fs = require('fs')

function populateIds(file) {
const data = fs.readFileSync(file, 'utf-8')
const json = JSON.parse(data)

const archives = []
for (const archive of json.archives) {
archives.push({
id: archive.providers[0].dataSourceUrl.split('/').pop(),
...archive
})
}

fs.writeFileSync(file, JSON.stringify({archives: archives}, null, 2))
}

populateIds('src/archives/evm.json')
populateIds('src/archives/substrate.json')
2 changes: 1 addition & 1 deletion scripts/archives/sort_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _run(parsed_args):
root_p = Path(os.path.realpath(__file__)).parent.parent.parent
with open(root_p / f"src/archives/{parsed_args.variant}.json") as f:
archives = json.load(f)
archives["archives"] = sorted(archives["archives"], key=lambda x: x["network"])
archives["archives"] = sorted(archives["archives"], key=lambda x: x["id"])
with open(root_p / f"src/archives/{parsed_args.variant}.json", "w") as f:
json.dump(archives, f, indent=2, sort_keys=True)
console.print("Done!")
Loading

0 comments on commit 5131947

Please sign in to comment.