2020-05-06 05:24:25 +00:00
|
|
|
//! Downloads a testnet configuration from Github.
|
|
|
|
|
2020-10-07 10:10:35 +00:00
|
|
|
use eth2_config::{altona, medalla, spadina, zinken, Eth2NetArchiveAndDirectory};
|
2020-09-11 01:43:13 +00:00
|
|
|
use std::fs;
|
2020-03-03 23:02:44 +00:00
|
|
|
use std::fs::File;
|
2020-09-11 01:43:13 +00:00
|
|
|
use std::io;
|
|
|
|
use zip::ZipArchive;
|
2020-03-03 23:02:44 +00:00
|
|
|
|
2020-09-26 01:58:31 +00:00
|
|
|
const ETH2_NET_DIRS: &[Eth2NetArchiveAndDirectory<'static>] = &[
|
|
|
|
altona::ETH2_NET_DIR,
|
|
|
|
medalla::ETH2_NET_DIR,
|
|
|
|
spadina::ETH2_NET_DIR,
|
2020-10-07 10:10:35 +00:00
|
|
|
zinken::ETH2_NET_DIR,
|
2020-09-26 01:58:31 +00:00
|
|
|
];
|
2020-03-03 23:02:44 +00:00
|
|
|
|
|
|
|
fn main() {
|
2020-07-29 06:39:29 +00:00
|
|
|
for testnet in ETH2_NET_DIRS {
|
2020-09-26 01:58:31 +00:00
|
|
|
match uncompress(testnet) {
|
|
|
|
Ok(()) => (),
|
|
|
|
Err(e) => panic!("Failed to uncompress testnet zip file: {}", e),
|
2020-03-19 00:22:15 +00:00
|
|
|
}
|
2020-03-03 23:02:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-26 01:58:31 +00:00
|
|
|
/// Uncompress the testnet configs archive into a testnet configs folder.
|
|
|
|
fn uncompress(testnet: &Eth2NetArchiveAndDirectory<'static>) -> Result<(), String> {
|
|
|
|
let archive_file = File::open(&testnet.archive_fullpath())
|
|
|
|
.map_err(|e| format!("Failed to open archive file: {:?}", e))?;
|
|
|
|
|
2020-09-11 01:43:13 +00:00
|
|
|
let mut archive =
|
|
|
|
ZipArchive::new(archive_file).map_err(|e| format!("Error with zip file: {}", e))?;
|
2020-09-26 01:58:31 +00:00
|
|
|
|
|
|
|
// Create testnet dir
|
|
|
|
fs::create_dir_all(testnet.dir())
|
|
|
|
.map_err(|e| format!("Failed to create testnet directory: {:?}", e))?;
|
|
|
|
|
|
|
|
// Create empty genesis.ssz if genesis is unknown
|
|
|
|
if !testnet.genesis_is_known {
|
|
|
|
File::create(testnet.dir().join("genesis.ssz"))
|
|
|
|
.map_err(|e| format!("Failed to create genesis.ssz: {}", e))?;
|
|
|
|
}
|
|
|
|
|
2020-09-11 01:43:13 +00:00
|
|
|
for i in 0..archive.len() {
|
|
|
|
let mut file = archive
|
|
|
|
.by_index(i)
|
|
|
|
.map_err(|e| format!("Error retrieving file {} inside zip: {}", i, e))?;
|
2020-03-03 23:02:44 +00:00
|
|
|
|
2020-09-26 01:58:31 +00:00
|
|
|
let path = testnet.dir().join(file.name());
|
2020-03-03 23:02:44 +00:00
|
|
|
|
2020-09-26 01:58:31 +00:00
|
|
|
let mut outfile = File::create(&path)
|
|
|
|
.map_err(|e| format!("Error while creating file {:?}: {}", path, e))?;
|
|
|
|
io::copy(&mut file, &mut outfile)
|
|
|
|
.map_err(|e| format!("Error writing file {:?}: {}", path, e))?;
|
2020-09-11 01:43:13 +00:00
|
|
|
}
|
2020-03-03 23:02:44 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|