From 9778794a8f9a7e7a03098f986c4ba001258eab6e Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Thu, 25 Jul 2019 17:45:13 -0700 Subject: [PATCH] tendermint-rs: Add `TendermintConfig::load_genesis_file` Support for loading `genesis.json` from the path configured in `config.toml` (given a home directory) --- tendermint-rs/src/config.rs | 13 +++++++++++++ tendermint-rs/src/lib.rs | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tendermint-rs/src/config.rs b/tendermint-rs/src/config.rs index f9f2980..9042549 100644 --- a/tendermint-rs/src/config.rs +++ b/tendermint-rs/src/config.rs @@ -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}; @@ -120,6 +121,18 @@ impl TendermintConfig { Self::parse_toml(toml_string) } + + /// Load `genesis.json` file from the configured location + pub fn load_genesis_file

(&self, home: &P) -> Result + where + P: AsRef, + { + 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 diff --git a/tendermint-rs/src/lib.rs b/tendermint-rs/src/lib.rs index 345f42a..f9ba29d 100644 --- a/tendermint-rs/src/lib.rs +++ b/tendermint-rs/src/lib.rs @@ -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;