This commit is contained in:
debris
2017-08-31 11:35:41 +02:00
parent f0e8abb07b
commit 7849fff41e
43 changed files with 130 additions and 95 deletions

View File

@@ -21,7 +21,8 @@ use std::time::{Instant, Duration};
use std::thread::sleep;
use std::sync::Arc;
use rustc_hex::FromHex;
use util::{ToPretty, U256, H256, Address, Hashable};
use hash::{keccak, KECCAK_NULL_RLP};
use util::{ToPretty, U256, H256, Address};
use rlp::PayloadInfo;
use ethcore::service::ClientService;
use ethcore::client::{Mode, DatabaseCompactionProfile, VMType, BlockImportError, BlockChainClient, BlockId};
@@ -639,13 +640,13 @@ fn execute_export_state(cmd: ExportState) -> Result<(), String> {
out.write_fmt(format_args!("\n\"0x{}\": {{\"balance\": \"{:x}\", \"nonce\": \"{:x}\"", account.hex(), balance, client.nonce(&account, at).unwrap_or_else(U256::zero))).expect("Write error");
let code = client.code(&account, at).unwrap_or(None).unwrap_or_else(Vec::new);
if !code.is_empty() {
out.write_fmt(format_args!(", \"code_hash\": \"0x{}\"", code.sha3().hex())).expect("Write error");
out.write_fmt(format_args!(", \"code_hash\": \"0x{}\"", keccak(&code).hex())).expect("Write error");
if cmd.code {
out.write_fmt(format_args!(", \"code\": \"{}\"", code.to_hex())).expect("Write error");
}
}
let storage_root = client.storage_root(&account, at).unwrap_or(::util::SHA3_NULL_RLP);
if storage_root != ::util::SHA3_NULL_RLP {
let storage_root = client.storage_root(&account, at).unwrap_or(KECCAK_NULL_RLP);
if storage_root != KECCAK_NULL_RLP {
out.write_fmt(format_args!(", \"storage_root\": \"0x{}\"", storage_root.hex())).expect("Write error");
if cmd.storage {
out.write_fmt(format_args!(", \"storage\": {{")).expect("Write error");

View File

@@ -22,7 +22,8 @@ use std::collections::BTreeMap;
use std::cmp::max;
use std::str::FromStr;
use cli::{Args, ArgsError};
use util::{Hashable, H256, U256, Bytes, version_data, Address};
use hash::keccak;
use util::{H256, U256, Bytes, version_data, Address};
use util::journaldb::Algorithm;
use util::Colour;
use ethsync::{NetworkConfiguration, is_valid_node_url};
@@ -506,7 +507,7 @@ impl Configuration {
io_path: self.directories().db,
listen_addr: self.stratum_interface(),
port: self.args.flag_ports_shift + self.args.flag_stratum_port,
secret: self.args.flag_stratum_secret.as_ref().map(|s| s.parse::<H256>().unwrap_or_else(|_| s.sha3())),
secret: self.args.flag_stratum_secret.as_ref().map(|s| s.parse::<H256>().unwrap_or_else(|_| keccak(s))),
}))
} else { Ok(None) }
}
@@ -729,7 +730,7 @@ impl Configuration {
ret.listen_address = Some(format!("{}", listen));
ret.public_address = public.map(|p| format!("{}", p));
ret.use_secret = match self.args.flag_node_key.as_ref()
.map(|s| s.parse::<Secret>().or_else(|_| Secret::from_unsafe_slice(&s.sha3())).map_err(|e| format!("Invalid key: {:?}", e))
.map(|s| s.parse::<Secret>().or_else(|_| Secret::from_unsafe_slice(&keccak(s))).map_err(|e| format!("Invalid key: {:?}", e))
) {
None => None,
Some(Ok(key)) => Some(key),

View File

@@ -70,6 +70,7 @@ extern crate parity_whisper;
extern crate path;
extern crate rpc_cli;
extern crate node_filter;
extern crate hash;
#[macro_use]
extern crate log as rlog;
@@ -130,7 +131,7 @@ use std::collections::HashMap;
use std::io::{self as stdio, BufReader, Read, Write};
use std::fs::{remove_file, metadata, File, create_dir_all};
use std::path::PathBuf;
use util::sha3::sha3;
use hash::keccak_buffer;
use cli::Args;
use configuration::{Cmd, Execute, Configuration};
use deprecated::find_deprecated;
@@ -140,7 +141,7 @@ use dir::default_hypervisor_path;
fn print_hash_of(maybe_file: Option<String>) -> Result<String, String> {
if let Some(file) = maybe_file {
let mut f = BufReader::new(File::open(&file).map_err(|_| "Unable to open file".to_owned())?);
let hash = sha3(&mut f).map_err(|_| "Unable to read from file".to_owned())?;
let hash = keccak_buffer(&mut f).map_err(|_| "Unable to read from file".to_owned())?;
Ok(hash.hex())
} else {
Err("Streaming from standard input not yet supported. Specify a file.".to_owned())

View File

@@ -20,6 +20,7 @@ use std::time::Duration;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use hash::keccak;
use ethcore::snapshot::{Progress, RestorationStatus, SnapshotService as SS};
use ethcore::snapshot::io::{SnapshotReader, PackedReader, PackedWriter};
use ethcore::snapshot::service::Service as SnapshotService;
@@ -65,8 +66,6 @@ pub struct SnapshotCommand {
// helper for reading chunks from arbitrary reader and feeding them into the
// service.
fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R, recover: bool) -> Result<(), String> {
use util::sha3::Hashable;
let manifest = reader.manifest();
info!("Restoring to block #{} (0x{:?})", manifest.block_number, manifest.block_hash);
@@ -95,7 +94,7 @@ fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R,
let chunk = reader.chunk(state_hash)
.map_err(|e| format!("Encountered error while reading chunk {:?}: {}", state_hash, e))?;
let hash = chunk.sha3();
let hash = keccak(&chunk);
if hash != state_hash {
return Err(format!("Mismatched chunk hash. Expected {:?}, got {:?}", state_hash, hash));
}
@@ -112,7 +111,7 @@ fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R,
let chunk = reader.chunk(block_hash)
.map_err(|e| format!("Encountered error while reading chunk {:?}: {}", block_hash, e))?;
let hash = chunk.sha3();
let hash = keccak(&chunk);
if hash != block_hash {
return Err(format!("Mismatched chunk hash. Expected {:?}, got {:?}", block_hash, hash));
}