-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[Feature]: Add Opstack superchain registry support for genesis files #14260
Draft
18aaddy
wants to merge
1
commit into
paradigmxyz:main
Choose a base branch
from
18aaddy:feat/add-opstack-superchain-registry-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "op-chain-registry" | ||
version.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
license.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
exclude.workspace = true | ||
|
||
[dependencies] | ||
reqwest = { version = "0.12.12", features = ["stream"] } | ||
tokio = { version = "1.0", features = ["full"] } | ||
serde_json = "1.0" | ||
zstd = "0.12" | ||
anyhow = "1.0" | ||
|
||
[lints] | ||
workspace = true |
Binary file not shown.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool, these functions just need some docs |
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,59 @@ | ||
use reqwest; | ||
use serde_json::Value; | ||
use zstd::stream::read::Decoder; | ||
use zstd::dict::DecoderDictionary; | ||
use anyhow::{Result, Context}; | ||
|
||
async fn download_file(url: &str) -> Result<Vec<u8>> { | ||
println!("Downloading from URL: {}", url); | ||
let response = reqwest::get(url) | ||
.await | ||
.context("Failed to download file")?; | ||
|
||
if !response.status().is_success() { | ||
anyhow::bail!("Failed to download: Status {}", response.status()); | ||
} | ||
|
||
Ok(response.bytes().await?.to_vec()) | ||
} | ||
|
||
async fn download_and_parse_zst(url: &str, dict_url: &str) -> Result<Value> { | ||
// Download the dictionary | ||
let dict_bytes = download_file(dict_url).await?; | ||
println!("Downloaded dictionary: {} bytes", dict_bytes.len()); | ||
|
||
let dictionary = DecoderDictionary::copy(&dict_bytes); | ||
|
||
// Download the main file | ||
let compressed_bytes = download_file(url).await?; | ||
println!("Downloaded compressed file: {} bytes", compressed_bytes.len()); | ||
|
||
// Create decoder with dictionary | ||
let decoder = Decoder::with_prepared_dictionary(&compressed_bytes[..], &dictionary) | ||
.context("Failed to create decoder with dictionary")?; | ||
|
||
// Parse JSON | ||
println!("Parsing JSON..."); | ||
let json: Value = serde_json::from_reader(decoder) | ||
.context("Failed to parse JSON")?; | ||
|
||
Ok(json) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use anyhow::Result; | ||
|
||
#[tokio::test] | ||
async fn test_download_and_parse_genesis() -> Result<()> { | ||
let file_url = "https://raw.githubusercontent.com/ethereum-optimism/superchain-registry/main/superchain/extra/genesis/mainnet/arena-z.json.zst"; | ||
let dict_url = "https://raw.githubusercontent.com/ethereum-optimism/superchain-registry/main/superchain/extra/dictionary"; | ||
Comment on lines
+50
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should convert the base paths into constants |
||
|
||
let json_data = download_and_parse_zst(file_url, dict_url).await?; | ||
|
||
assert!(json_data.is_object(), "Parsed JSON should be an object"); | ||
|
||
Ok(()) | ||
} | ||
} |
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 @@ | ||
mod chain_registry; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should use workspace