Skip to content

Commit

Permalink
feat(l1): add new_from_genesis method to Store (#2007)
Browse files Browse the repository at this point in the history
**Motivation**

Without this method, users must do the genesis file decoding manually,
sometimes needing to unnecessarily add the `serde_json` crate to their
`Cargo.toml`.

Having a method that initializes the genesis state in the `Store` allows
the user to start a new `Store` from the genesis file, which only has
the genesis path.

**Description**

Adds a new `new_from_genesis` method to `Store` that initializes a new
`Store` instance with the genesis (provided as a path to the genesis
file).
  • Loading branch information
ilitteri authored Feb 19, 2025
1 parent 5ae030a commit 519e648
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crates/storage/store/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ impl Store {
Ok(store)
}

pub fn new_from_genesis(
store_path: &str,
engine_type: EngineType,
genesis_path: &str,
) -> Result<Self, StoreError> {
let file = std::fs::File::open(genesis_path)
.map_err(|error| StoreError::Custom(format!("Failed to open genesis file: {error}")))?;
let reader = std::io::BufReader::new(file);
let genesis: Genesis =
serde_json::from_reader(reader).expect("Failed to deserialize genesis file");
let store = Self::new(store_path, engine_type)?;
store.add_initial_state(genesis)?;
Ok(store)
}

pub fn get_account_info(
&self,
block_number: BlockNumber,
Expand Down

0 comments on commit 519e648

Please sign in to comment.