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

tendermint-rs: Add TendermintConfig::load_genesis_file #312

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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