2020-02-04 01:43:04 +00:00
|
|
|
use clap::ArgMatches;
|
2021-07-09 06:15:32 +00:00
|
|
|
use eth2_network_config::Eth2NetworkConfig;
|
|
|
|
use ssz::Encode;
|
2020-02-04 01:43:04 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::{Read, Write};
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use types::{BeaconState, EthSpec};
|
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
pub fn run<T: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(), String> {
|
2020-02-04 01:43:04 +00:00
|
|
|
let path = matches
|
|
|
|
.value_of("ssz-state")
|
2020-12-03 01:10:26 +00:00
|
|
|
.ok_or("ssz-state not specified")?
|
2020-02-04 01:43:04 +00:00
|
|
|
.parse::<PathBuf>()
|
|
|
|
.map_err(|e| format!("Unable to parse ssz-state: {}", e))?;
|
|
|
|
|
|
|
|
let genesis_time = matches
|
|
|
|
.value_of("genesis-time")
|
2020-12-03 01:10:26 +00:00
|
|
|
.ok_or("genesis-time not specified")?
|
2020-02-04 01:43:04 +00:00
|
|
|
.parse::<u64>()
|
|
|
|
.map_err(|e| format!("Unable to parse genesis-time: {}", e))?;
|
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let eth2_network_config = Eth2NetworkConfig::load(testnet_dir)?;
|
|
|
|
let spec = ð2_network_config.chain_spec::<T>()?;
|
|
|
|
|
2020-02-04 01:43:04 +00:00
|
|
|
let mut state: BeaconState<T> = {
|
|
|
|
let mut file = File::open(&path).map_err(|e| format!("Unable to open file: {}", e))?;
|
|
|
|
|
|
|
|
let mut ssz = vec![];
|
|
|
|
|
|
|
|
file.read_to_end(&mut ssz)
|
|
|
|
.map_err(|e| format!("Unable to read file: {}", e))?;
|
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
BeaconState::from_ssz_bytes(&ssz, spec)
|
|
|
|
.map_err(|e| format!("Unable to decode SSZ: {:?}", e))?
|
2020-02-04 01:43:04 +00:00
|
|
|
};
|
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
*state.genesis_time_mut() = genesis_time;
|
2020-02-04 01:43:04 +00:00
|
|
|
|
|
|
|
let mut file = File::create(path).map_err(|e| format!("Unable to create file: {}", e))?;
|
|
|
|
|
|
|
|
file.write_all(&state.as_ssz_bytes())
|
|
|
|
.map_err(|e| format!("Unable to write to file: {}", e))?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|