1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use diem_config::config::RocksdbConfig;
use diem_management::{config::ConfigPath, error::Error, secure_backend::SharedBackend};
use diem_temppath::TempPath;
use diem_types::{chain_id::ChainId, transaction::Transaction, waypoint::Waypoint};
use diem_vm::DiemVM;
use diemdb::DiemDB;
use executor::db_bootstrapper;
use storage_interface::DbReaderWriter;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
pub struct CreateWaypoint {
#[structopt(flatten)]
config: ConfigPath,
#[structopt(long, required_unless("config"))]
chain_id: Option<ChainId>,
#[structopt(flatten)]
shared_backend: SharedBackend,
}
impl CreateWaypoint {
pub fn execute(self) -> Result<Waypoint, Error> {
let genesis_helper = crate::genesis::Genesis {
config: self.config,
chain_id: self.chain_id,
backend: self.shared_backend,
path: None,
};
let genesis = genesis_helper.execute()?;
create_genesis_waypoint(&genesis)
}
}
pub fn create_genesis_waypoint(genesis: &Transaction) -> Result<Waypoint, Error> {
let path = TempPath::new();
let diemdb = DiemDB::open(&path, false, None, RocksdbConfig::default())
.map_err(|e| Error::UnexpectedError(e.to_string()))?;
let db_rw = DbReaderWriter::new(diemdb);
db_bootstrapper::generate_waypoint::<DiemVM>(&db_rw, genesis)
.map_err(|e| Error::UnexpectedError(e.to_string()))
}