-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from ChorusOne/custom-testnets
Support for custom testnet config in mnemonic cmds
- Loading branch information
Showing
13 changed files
with
994 additions
and
625 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::path::Path; | ||
|
||
use eth2_network_config::Eth2NetworkConfig; | ||
use types::{ChainSpec, Config, MainnetEthSpec, MinimalEthSpec}; | ||
|
||
use crate::DepositError; | ||
|
||
pub fn chain_spec_for_network(network_name: String) -> Result<ChainSpec, DepositError> { | ||
if ["goerli", "prater", "mainnet", "holesky"].contains(&network_name.as_str()) { | ||
Ok(Eth2NetworkConfig::constant(&network_name) | ||
.unwrap() | ||
.unwrap() | ||
.chain_spec::<MainnetEthSpec>() | ||
.unwrap()) | ||
} else { | ||
Err(DepositError::InvalidNetworkName(format!( | ||
"unknown chain name: {network_name}" | ||
))) | ||
} | ||
} | ||
|
||
pub fn chain_spec_from_file(chain_spec_file: String) -> Result<ChainSpec, DepositError> { | ||
match Config::from_file(Path::new(chain_spec_file.as_str())) { | ||
Ok(cfg) => { | ||
let spec = if cfg.preset_base == "minimal" { | ||
cfg.apply_to_chain_spec::<MinimalEthSpec>(&ChainSpec::minimal()) | ||
.unwrap() | ||
} else { | ||
cfg.apply_to_chain_spec::<MainnetEthSpec>(&ChainSpec::mainnet()) | ||
.unwrap() | ||
}; | ||
Ok(spec) | ||
} | ||
Err(e) => { | ||
log::error!("Unable to load chain spec config: {:?}", e); | ||
Err(DepositError::NoCustomConfig( | ||
"Can not parse config file for custom network config".to_string(), | ||
)) | ||
} | ||
} | ||
} |
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
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.