commit
f484beb7e1
@ -374,6 +374,16 @@ impl<V> Client<V> where V: Verifier {
|
|||||||
self.chain.configure_cache(pref_cache_size, max_cache_size);
|
self.chain.configure_cache(pref_cache_size, max_cache_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Look up the block number for the given block ID.
|
||||||
|
pub fn block_number(&self, id: BlockID) -> Option<BlockNumber> {
|
||||||
|
match id {
|
||||||
|
BlockID::Number(number) => Some(number),
|
||||||
|
BlockID::Hash(ref hash) => self.chain.block_number(hash),
|
||||||
|
BlockID::Earliest => Some(0),
|
||||||
|
BlockID::Latest => Some(self.chain.best_block_number())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn block_hash(chain: &BlockChain, id: BlockID) -> Option<H256> {
|
fn block_hash(chain: &BlockChain, id: BlockID) -> Option<H256> {
|
||||||
match id {
|
match id {
|
||||||
BlockID::Hash(hash) => Some(hash),
|
BlockID::Hash(hash) => Some(hash),
|
||||||
@ -383,15 +393,6 @@ impl<V> Client<V> where V: Verifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_number(&self, id: BlockID) -> Option<BlockNumber> {
|
|
||||||
match id {
|
|
||||||
BlockID::Number(number) => Some(number),
|
|
||||||
BlockID::Hash(ref hash) => self.chain.block_number(hash),
|
|
||||||
BlockID::Earliest => Some(0),
|
|
||||||
BlockID::Latest => Some(self.chain.best_block_number())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn transaction_address(&self, id: TransactionID) -> Option<TransactionAddress> {
|
fn transaction_address(&self, id: TransactionID) -> Option<TransactionAddress> {
|
||||||
match id {
|
match id {
|
||||||
TransactionID::Hash(ref hash) => self.chain.transaction_address(hash),
|
TransactionID::Hash(ref hash) => self.chain.transaction_address(hash),
|
||||||
|
@ -24,6 +24,7 @@ Parity. Ethereum Client.
|
|||||||
Usage:
|
Usage:
|
||||||
parity daemon <pid-file> [options]
|
parity daemon <pid-file> [options]
|
||||||
parity account (new | list) [options]
|
parity account (new | list) [options]
|
||||||
|
parity export [ <file> ] [options]
|
||||||
parity [options]
|
parity [options]
|
||||||
|
|
||||||
Protocol Options:
|
Protocol Options:
|
||||||
@ -42,9 +43,9 @@ Account Options:
|
|||||||
ACCOUNTS is a comma-delimited list of addresses.
|
ACCOUNTS is a comma-delimited list of addresses.
|
||||||
--password FILE Provide a file containing a password for unlocking
|
--password FILE Provide a file containing a password for unlocking
|
||||||
an account.
|
an account.
|
||||||
--keys-iterations NUM Specify the number of iterations to use when deriving key
|
--keys-iterations NUM Specify the number of iterations to use when
|
||||||
from the password (bigger is more secure)
|
deriving key from the password (bigger is more
|
||||||
[default: 10240].
|
secure) [default: 10240].
|
||||||
--no-import-keys Do not import keys from legacy clients.
|
--no-import-keys Do not import keys from legacy clients.
|
||||||
|
|
||||||
Networking Options:
|
Networking Options:
|
||||||
@ -142,6 +143,14 @@ Footprint Options:
|
|||||||
the entire system, overrides other cache and queue
|
the entire system, overrides other cache and queue
|
||||||
options.
|
options.
|
||||||
|
|
||||||
|
Export Options:
|
||||||
|
--from BLOCK Export from block BLOCK, which may be an index or
|
||||||
|
hash [default: 0].
|
||||||
|
--to BLOCK Export to (including) block NUMBER, which may be an
|
||||||
|
index, hash or 'latest' [default: latest].
|
||||||
|
--format FORMAT Export in given format. FORMAT must be one of 'hex'
|
||||||
|
and 'binary' [default: hex].
|
||||||
|
|
||||||
Virtual Machine Options:
|
Virtual Machine Options:
|
||||||
--jitvm Enable the JIT VM.
|
--jitvm Enable the JIT VM.
|
||||||
|
|
||||||
@ -186,7 +195,9 @@ pub struct Args {
|
|||||||
pub cmd_account: bool,
|
pub cmd_account: bool,
|
||||||
pub cmd_new: bool,
|
pub cmd_new: bool,
|
||||||
pub cmd_list: bool,
|
pub cmd_list: bool,
|
||||||
|
pub cmd_export: bool,
|
||||||
pub arg_pid_file: String,
|
pub arg_pid_file: String,
|
||||||
|
pub arg_file: Option<String>,
|
||||||
pub flag_chain: String,
|
pub flag_chain: String,
|
||||||
pub flag_db_path: String,
|
pub flag_db_path: String,
|
||||||
pub flag_identity: String,
|
pub flag_identity: String,
|
||||||
@ -230,6 +241,9 @@ pub struct Args {
|
|||||||
pub flag_tx_limit: usize,
|
pub flag_tx_limit: usize,
|
||||||
pub flag_logging: Option<String>,
|
pub flag_logging: Option<String>,
|
||||||
pub flag_version: bool,
|
pub flag_version: bool,
|
||||||
|
pub flag_from: String,
|
||||||
|
pub flag_to: String,
|
||||||
|
pub flag_format: String,
|
||||||
pub flag_jitvm: bool,
|
pub flag_jitvm: bool,
|
||||||
// legacy...
|
// legacy...
|
||||||
pub flag_geth: bool,
|
pub flag_geth: bool,
|
||||||
|
@ -65,7 +65,9 @@ mod configuration;
|
|||||||
|
|
||||||
use ctrlc::CtrlC;
|
use ctrlc::CtrlC;
|
||||||
use util::*;
|
use util::*;
|
||||||
|
use std::fs::File;
|
||||||
use util::panics::{MayPanic, ForwardPanic, PanicHandler};
|
use util::panics::{MayPanic, ForwardPanic, PanicHandler};
|
||||||
|
use ethcore::client::{BlockID, BlockChainClient};
|
||||||
use ethcore::service::ClientService;
|
use ethcore::service::ClientService;
|
||||||
use ethsync::EthSync;
|
use ethsync::EthSync;
|
||||||
use ethminer::{Miner, MinerService, ExternalMiner};
|
use ethminer::{Miner, MinerService, ExternalMiner};
|
||||||
@ -104,6 +106,11 @@ fn execute(conf: Configuration) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conf.args.cmd_export {
|
||||||
|
execute_export(conf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
execute_client(conf);
|
execute_client(conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,6 +223,80 @@ fn flush_stdout() {
|
|||||||
::std::io::stdout().flush().expect("stdout is flushable; qed");
|
::std::io::stdout().flush().expect("stdout is flushable; qed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum DataFormat {
|
||||||
|
Hex,
|
||||||
|
Binary,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn execute_export(conf: Configuration) {
|
||||||
|
println!("Exporting to {:?} from {}, to {}", conf.args.arg_file, conf.args.flag_from, conf.args.flag_to);
|
||||||
|
|
||||||
|
// Setup panic handler
|
||||||
|
let panic_handler = PanicHandler::new_in_arc();
|
||||||
|
|
||||||
|
// Raise fdlimit
|
||||||
|
unsafe { ::fdlimit::raise_fd_limit(); }
|
||||||
|
|
||||||
|
let spec = conf.spec();
|
||||||
|
let net_settings = NetworkConfiguration {
|
||||||
|
config_path: None,
|
||||||
|
listen_address: None,
|
||||||
|
public_address: None,
|
||||||
|
udp_port: None,
|
||||||
|
nat_enabled: false,
|
||||||
|
discovery_enabled: false,
|
||||||
|
pin: true,
|
||||||
|
boot_nodes: Vec::new(),
|
||||||
|
use_secret: None,
|
||||||
|
ideal_peers: 0,
|
||||||
|
};
|
||||||
|
let client_config = conf.client_config(&spec);
|
||||||
|
|
||||||
|
// Build client
|
||||||
|
let service = ClientService::start(
|
||||||
|
client_config, spec, net_settings, Path::new(&conf.path())
|
||||||
|
).unwrap_or_else(|e| die_with_error("Client", e));
|
||||||
|
|
||||||
|
panic_handler.forward_from(&service);
|
||||||
|
let client = service.client();
|
||||||
|
|
||||||
|
// we have a client!
|
||||||
|
let parse_block_id = |s: &str, arg: &str| -> u64 {
|
||||||
|
if s == "latest" {
|
||||||
|
client.chain_info().best_block_number
|
||||||
|
} else if let Ok(n) = s.parse::<u64>() {
|
||||||
|
n
|
||||||
|
} else if let Ok(h) = H256::from_str(s) {
|
||||||
|
client.block_number(BlockID::Hash(h)).unwrap_or_else(|| {
|
||||||
|
die!("Unknown block hash passed to {} parameter: {:?}", arg, s);
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
die!("Invalid {} parameter given: {:?}", arg, s);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let from = parse_block_id(&conf.args.flag_from, "--from");
|
||||||
|
let to = parse_block_id(&conf.args.flag_to, "--to");
|
||||||
|
let format = match conf.args.flag_format.deref() {
|
||||||
|
"binary" | "bin" => DataFormat::Binary,
|
||||||
|
"hex" => DataFormat::Hex,
|
||||||
|
x => die!("Invalid --format parameter given: {:?}", x),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut out: Box<Write> = if let Some(f) = conf.args.arg_file {
|
||||||
|
Box::new(File::create(&f).unwrap_or_else(|_| die!("Cannot write to file given: {}", f)))
|
||||||
|
} else {
|
||||||
|
Box::new(::std::io::stdout())
|
||||||
|
};
|
||||||
|
|
||||||
|
for i in from..(to + 1) {
|
||||||
|
let b = client.deref().block(BlockID::Number(i)).unwrap();
|
||||||
|
match format {
|
||||||
|
DataFormat::Binary => { out.write(&b).expect("Couldn't write to stream."); }
|
||||||
|
DataFormat::Hex => { out.write_fmt(format_args!("{}", b.pretty())).expect("Couldn't write to stream."); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn execute_account_cli(conf: Configuration) {
|
fn execute_account_cli(conf: Configuration) {
|
||||||
use util::keys::store::SecretStore;
|
use util::keys::store::SecretStore;
|
||||||
use rpassword::read_password;
|
use rpassword::read_password;
|
||||||
|
Loading…
Reference in New Issue
Block a user