KillDB command
This commit is contained in:
parent
6601fde328
commit
edb853ca35
@ -64,11 +64,19 @@ impl FromStr for DataFormat {
|
|||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum BlockchainCmd {
|
pub enum BlockchainCmd {
|
||||||
|
Kill(KillBlockchain),
|
||||||
Import(ImportBlockchain),
|
Import(ImportBlockchain),
|
||||||
Export(ExportBlockchain),
|
Export(ExportBlockchain),
|
||||||
ExportState(ExportState),
|
ExportState(ExportState),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct KillBlockchain {
|
||||||
|
pub spec: SpecType,
|
||||||
|
pub dirs: Directories,
|
||||||
|
pub pruning: Pruning,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct ImportBlockchain {
|
pub struct ImportBlockchain {
|
||||||
pub spec: SpecType,
|
pub spec: SpecType,
|
||||||
@ -128,6 +136,7 @@ pub struct ExportState {
|
|||||||
|
|
||||||
pub fn execute(cmd: BlockchainCmd) -> Result<String, String> {
|
pub fn execute(cmd: BlockchainCmd) -> Result<String, String> {
|
||||||
match cmd {
|
match cmd {
|
||||||
|
BlockchainCmd::Kill(kill_cmd) => kill_db(kill_cmd),
|
||||||
BlockchainCmd::Import(import_cmd) => execute_import(import_cmd),
|
BlockchainCmd::Import(import_cmd) => execute_import(import_cmd),
|
||||||
BlockchainCmd::Export(export_cmd) => execute_export(export_cmd),
|
BlockchainCmd::Export(export_cmd) => execute_export(export_cmd),
|
||||||
BlockchainCmd::ExportState(export_cmd) => execute_export_state(export_cmd),
|
BlockchainCmd::ExportState(export_cmd) => execute_export_state(export_cmd),
|
||||||
@ -473,6 +482,18 @@ fn execute_export_state(cmd: ExportState) -> Result<String, String> {
|
|||||||
Ok("Export completed.".into())
|
Ok("Export completed.".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn kill_db(cmd: KillBlockchain) -> Result<String, String> {
|
||||||
|
let spec = try!(cmd.spec.spec());
|
||||||
|
let genesis_hash = spec.genesis_header().hash();
|
||||||
|
let db_dirs = cmd.dirs.database(genesis_hash, None, spec.data_dir);
|
||||||
|
let user_defaults_path = db_dirs.user_defaults_path();
|
||||||
|
let user_defaults = try!(UserDefaults::load(&user_defaults_path));
|
||||||
|
let algorithm = cmd.pruning.to_algorithm(&user_defaults);
|
||||||
|
let dir = db_dirs.db_path(algorithm);
|
||||||
|
try!(fs::remove_dir_all(&dir).map_err(|e| format!("Error removing database: {:?}", e)));
|
||||||
|
Ok("Database deleted.".to_owned())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::DataFormat;
|
use super::DataFormat;
|
||||||
|
@ -36,6 +36,8 @@ usage! {
|
|||||||
cmd_ui: bool,
|
cmd_ui: bool,
|
||||||
cmd_tools: bool,
|
cmd_tools: bool,
|
||||||
cmd_hash: bool,
|
cmd_hash: bool,
|
||||||
|
cmd_kill: bool,
|
||||||
|
cmd_db: bool,
|
||||||
|
|
||||||
// Arguments
|
// Arguments
|
||||||
arg_pid_file: String,
|
arg_pid_file: String,
|
||||||
@ -512,6 +514,8 @@ mod tests {
|
|||||||
cmd_ui: false,
|
cmd_ui: false,
|
||||||
cmd_tools: false,
|
cmd_tools: false,
|
||||||
cmd_hash: false,
|
cmd_hash: false,
|
||||||
|
cmd_db: false,
|
||||||
|
cmd_kill: false,
|
||||||
|
|
||||||
// Arguments
|
// Arguments
|
||||||
arg_pid_file: "".into(),
|
arg_pid_file: "".into(),
|
||||||
|
@ -15,6 +15,7 @@ Usage:
|
|||||||
parity snapshot <file> [options]
|
parity snapshot <file> [options]
|
||||||
parity restore [ <file> ] [options]
|
parity restore [ <file> ] [options]
|
||||||
parity tools hash <file>
|
parity tools hash <file>
|
||||||
|
parity db kill [options]
|
||||||
|
|
||||||
Operating Options:
|
Operating Options:
|
||||||
--mode MODE Set the operating mode. MODE can be one of:
|
--mode MODE Set the operating mode. MODE can be one of:
|
||||||
@ -282,10 +283,8 @@ Import/Export Options:
|
|||||||
(default: {flag_format:?} = Import: auto, Export: binary)
|
(default: {flag_format:?} = Import: auto, Export: binary)
|
||||||
--no-seal-check Skip block seal check. (default: {flag_no_seal_check})
|
--no-seal-check Skip block seal check. (default: {flag_no_seal_check})
|
||||||
--at BLOCK Export state at the given block, which may be an
|
--at BLOCK Export state at the given block, which may be an
|
||||||
index, hash, or 'latest'. Note that taking snapshots at
|
index, hash, or 'latest'. (default: {flag_at})
|
||||||
non-recent blocks will only work with --pruning archive
|
--no-storage Don't export account storage. (default: {flag_no_storage})
|
||||||
(default: {flag_at})
|
|
||||||
--no-storage Don't export account storge. (default: {flag_no_storage})
|
|
||||||
--no-code Don't export account code. (default: {flag_no_code})
|
--no-code Don't export account code. (default: {flag_no_code})
|
||||||
--min-balance WEI Don't export accounts with balance less than specified.
|
--min-balance WEI Don't export accounts with balance less than specified.
|
||||||
(default: {flag_min_balance:?})
|
(default: {flag_min_balance:?})
|
||||||
|
@ -38,7 +38,7 @@ use dir::Directories;
|
|||||||
use dapps::Configuration as DappsConfiguration;
|
use dapps::Configuration as DappsConfiguration;
|
||||||
use signer::{Configuration as SignerConfiguration};
|
use signer::{Configuration as SignerConfiguration};
|
||||||
use run::RunCmd;
|
use run::RunCmd;
|
||||||
use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, ExportState, DataFormat};
|
use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, KillBlockchain, ExportState, DataFormat};
|
||||||
use presale::ImportWallet;
|
use presale::ImportWallet;
|
||||||
use account::{AccountCmd, NewAccount, ListAccounts, ImportAccounts, ImportFromGethAccounts};
|
use account::{AccountCmd, NewAccount, ListAccounts, ImportAccounts, ImportFromGethAccounts};
|
||||||
use snapshot::{self, SnapshotCommand};
|
use snapshot::{self, SnapshotCommand};
|
||||||
@ -107,6 +107,12 @@ impl Configuration {
|
|||||||
Cmd::SignerToken(signer_conf)
|
Cmd::SignerToken(signer_conf)
|
||||||
} else if self.args.cmd_tools && self.args.cmd_hash {
|
} else if self.args.cmd_tools && self.args.cmd_hash {
|
||||||
Cmd::Hash(self.args.arg_file)
|
Cmd::Hash(self.args.arg_file)
|
||||||
|
} else if self.args.cmd_db && self.args.cmd_kill {
|
||||||
|
Cmd::Blockchain(BlockchainCmd::Kill(KillBlockchain {
|
||||||
|
spec: spec,
|
||||||
|
dirs: dirs,
|
||||||
|
pruning: pruning,
|
||||||
|
}))
|
||||||
} else if self.args.cmd_account {
|
} else if self.args.cmd_account {
|
||||||
let account_cmd = if self.args.cmd_new {
|
let account_cmd = if self.args.cmd_new {
|
||||||
let new_acc = NewAccount {
|
let new_acc = NewAccount {
|
||||||
|
Loading…
Reference in New Issue
Block a user