Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #312 from tendermint/tendermint-rs/load-genesis-file
Browse files Browse the repository at this point in the history
tendermint-rs: Add `TendermintConfig::load_genesis_file`
  • Loading branch information
tarcieri committed Jul 26, 2019
2 parents 0ed2e1f + 9778794 commit 8341528
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions tendermint-rs/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub use self::{node_key::NodeKey, priv_validator_key::PrivValidatorKey};
use crate::{
abci::tag,
error::{Error, ErrorKind},
genesis::Genesis,
net, node, Moniker, Timeout,
};
use serde::{de, de::Error as _, ser, Deserialize, Serialize};
Expand Down Expand Up @@ -120,6 +121,18 @@ impl TendermintConfig {

Self::parse_toml(toml_string)
}

/// Load `genesis.json` file from the configured location
pub fn load_genesis_file<P>(&self, home: &P) -> Result<Genesis, Error>
where
P: AsRef<Path>,
{
let path = home.as_ref().join(&self.genesis_file);
let genesis_json = fs::read_to_string(&path)
.map_err(|e| err!(ErrorKind::Parse, "couldn't open {}: {}", path.display(), e))?;

Ok(serde_json::from_str(genesis_json.as_ref())?)
}
}

/// Database backend
Expand Down
2 changes: 1 addition & 1 deletion tendermint-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub mod channel;
pub mod config;
pub mod consensus;
pub mod evidence;
#[cfg(feature = "rpc")]
#[cfg(any(feature = "config", feature = "rpc"))]
pub mod genesis;
pub mod hash;
pub mod merkle;
Expand Down

0 comments on commit 8341528

Please sign in to comment.