-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using blobscan API or GUI, depending on blobs-url config param
- Loading branch information
Showing
12 changed files
with
168 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,14 @@ | ||
[package] | ||
name = "blobscan-client" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
eyre = "0.6.8" | ||
hex = "0.4.3" | ||
reqwest = "0.11.24" | ||
serde = { version = "1.0.189", features = ["derive"] } | ||
serde_json = { version = "1.0.107", features = ["std"] } | ||
thiserror = "1.0.50" | ||
tokio = { version = "1.33.0", features = ["signal"] } | ||
tracing = "0.1.40" |
17 changes: 17 additions & 0 deletions
17
state-reconstruct-fetcher/blobscan-client/src/blob_support.rs
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,17 @@ | ||
use thiserror::Error; | ||
|
||
#[allow(clippy::enum_variant_names)] | ||
#[derive(Error, Debug)] | ||
pub enum BlobError { | ||
#[error("blob storage error: {0}")] | ||
StorageError(String), | ||
|
||
#[error("blob format error")] | ||
FormatError(String, String), | ||
} | ||
|
||
pub trait BlobSupport { | ||
fn format_url(&self, kzg_commitment: &[u8]) -> String; | ||
|
||
fn get_blob_data(&self, json_str: &str) -> Result<String, BlobError>; | ||
} |
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,4 @@ | ||
mod blob_support; | ||
pub use crate::blob_support::{BlobError, BlobSupport}; | ||
mod scraping_support; | ||
pub use crate::scraping_support::ScrapingSupport; |
52 changes: 52 additions & 0 deletions
52
state-reconstruct-fetcher/blobscan-client/src/scraping_support.rs
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,52 @@ | ||
use serde::Deserialize; | ||
use serde_json::json; | ||
|
||
use crate::blob_support::{BlobError, BlobSupport}; | ||
|
||
#[derive(Deserialize)] | ||
struct JsonResponse { | ||
result: JsonResponseResult, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct JsonResponseResult { | ||
data: JsonResponseData, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct JsonResponseData { | ||
json: JsonResponseJson, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct JsonResponseJson { | ||
data: String, | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct ScrapingSupport {} | ||
|
||
impl BlobSupport for ScrapingSupport { | ||
fn format_url(&self, kzg_commitment: &[u8]) -> String { | ||
let id = format!("0x{}", hex::encode(kzg_commitment)); | ||
let json_source = json!({ | ||
"json": { | ||
"id": id | ||
} | ||
}); | ||
let json_string = json_source.to_string(); | ||
let url = reqwest::Url::parse_with_params( | ||
"https://blobscan.com/api/trpc/blob.getByBlobIdFull", | ||
&[("input", &json_string)], | ||
) | ||
.unwrap(); | ||
url.to_string() | ||
} | ||
|
||
fn get_blob_data(&self, json_str: &str) -> Result<String, BlobError> { | ||
match serde_json::from_str::<JsonResponse>(json_str) { | ||
Ok(rsp) => Ok(rsp.result.data.json.data), | ||
Err(e) => Err(BlobError::FormatError(json_str.to_string(), e.to_string())), | ||
} | ||
} | ||
} |
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,30 @@ | ||
use blobscan_client::{BlobError, BlobSupport}; | ||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
struct JsonResponse { | ||
data: String, | ||
} | ||
|
||
pub struct ApiSupport { | ||
url_base: String, | ||
} | ||
|
||
impl ApiSupport { | ||
pub fn new(blob_url: String) -> Self { | ||
Self { url_base: blob_url } | ||
} | ||
} | ||
|
||
impl BlobSupport for ApiSupport { | ||
fn format_url(&self, kzg_commitment: &[u8]) -> String { | ||
format!("{}0x{}", self.url_base, hex::encode(kzg_commitment)) | ||
} | ||
|
||
fn get_blob_data(&self, json_str: &str) -> Result<String, BlobError> { | ||
match serde_json::from_str::<JsonResponse>(json_str) { | ||
Ok(data) => Ok(data.data), | ||
Err(e) => Err(BlobError::FormatError(json_str.to_string(), e.to_string())), | ||
} | ||
} | ||
} |
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
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