This repository has been archived by the owner on Aug 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32b5468
commit d488697
Showing
34 changed files
with
549 additions
and
202 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
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
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
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,16 @@ | ||
[package] | ||
name = "mc-genesis-data-provider" | ||
authors.workspace = true | ||
edition.workspace = true | ||
repository.workspace = true | ||
version.workspace = true | ||
|
||
[dependencies] | ||
anyhow = { workspace = true } | ||
jsonrpsee = { workspace = true, default-features = true } | ||
log = { workspace = true, default-features = true } | ||
mp-genesis-config = { workspace = true } | ||
pallet-starknet = { workspace = true, default-features = true } | ||
serde = { workspace = true, default-features = true } | ||
serde_json = { workspace = true, default-features = true } | ||
thiserror = { workspace = true } |
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,2 @@ | ||
pub const GENESIS_ASSETS_DIR: &str = "genesis-assets"; | ||
pub const GENESIS_ASSETS_FILE: &str = "genesis.json"; |
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,42 @@ | ||
mod constants; | ||
|
||
use std::path::PathBuf; | ||
|
||
use constants::{GENESIS_ASSETS_DIR, GENESIS_ASSETS_FILE}; | ||
use jsonrpsee::types::error::CallError; | ||
use mp_genesis_config::GenesisData; | ||
|
||
pub trait GenesisProvider { | ||
type LoadGenesisDataError: std::error::Error; | ||
fn load_genesis_data(&self) -> Result<GenesisData, LoadGenesisDataError>; | ||
} | ||
|
||
pub struct OnDiskGenesisConfig(pub PathBuf); | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum LoadGenesisDataError { | ||
#[error("File cannot be deserialized into a GenesisData struct")] | ||
InvalidJson, | ||
#[error("Unable to read genesis file: invalid path")] | ||
InvalidPath, | ||
} | ||
|
||
impl From<LoadGenesisDataError> for jsonrpsee::core::Error { | ||
fn from(e: LoadGenesisDataError) -> Self { | ||
jsonrpsee::core::Error::Call(CallError::Failed(anyhow::Error::from(e))) | ||
} | ||
} | ||
|
||
impl GenesisProvider for OnDiskGenesisConfig { | ||
type LoadGenesisDataError = LoadGenesisDataError; | ||
|
||
fn load_genesis_data(&self) -> Result<GenesisData, Self::LoadGenesisDataError> { | ||
let genesis_path = self.0.join(GENESIS_ASSETS_DIR).join(GENESIS_ASSETS_FILE); | ||
|
||
log::info!("Loading genesis data at: {}", genesis_path.display()); | ||
|
||
std::fs::read_to_string(genesis_path.clone()).map_or(Err(LoadGenesisDataError::InvalidPath), |s| { | ||
serde_json::from_str::<GenesisData>(&s).map_err(|_| LoadGenesisDataError::InvalidJson) | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.