Merge branch 'master' into ethminer_crate

Conflicts:
	Cargo.toml
	rpc/Cargo.toml
	sync/Cargo.toml
This commit is contained in:
Tomasz Drwięga
2016-03-12 09:48:17 +01:00
28 changed files with 197 additions and 58 deletions

View File

@@ -131,9 +131,15 @@ impl AccountService {
}
}
impl Default for SecretStore {
fn default() -> Self {
SecretStore::new()
}
}
impl SecretStore {
/// new instance of Secret Store in default home directory
pub fn new() -> SecretStore {
pub fn new() -> Self {
let mut path = ::std::env::home_dir().expect("Failed to get home dir");
path.push(".parity");
path.push("keys");
@@ -142,7 +148,7 @@ impl SecretStore {
}
/// new instance of Secret Store in specific directory
pub fn new_in(path: &Path) -> SecretStore {
pub fn new_in(path: &Path) -> Self {
SecretStore {
directory: KeyDirectory::new(path),
unlocks: RwLock::new(HashMap::new()),
@@ -214,12 +220,12 @@ impl SecretStore {
/// Creates new account
pub fn new_account(&mut self, pass: &str) -> Result<Address, ::std::io::Error> {
let secret = H256::random();
let key_pair = crypto::KeyPair::create().expect("Error creating key-pair. Something wrong with crypto libraries?");
let address = Address::from(key_pair.public().sha3());
let key_id = H128::random();
self.insert(key_id.clone(), secret, pass);
self.insert(key_id.clone(), key_pair.secret().clone(), pass);
let mut key_file = self.directory.get(&key_id).expect("the key was just inserted");
let address = Address::random();
key_file.account = Some(address);
try!(self.directory.save(key_file));
Ok(address)
@@ -381,6 +387,7 @@ mod tests {
use super::*;
use devtools::*;
use common::*;
use crypto::KeyPair;
#[test]
fn can_insert() {
@@ -555,4 +562,15 @@ mod tests {
let accounts = sstore.accounts().unwrap();
assert_eq!(30, accounts.len());
}
#[test]
fn validate_generated_addresses() {
let temp = RandomTempPath::create_dir();
let mut sstore = SecretStore::new_test(&temp);
let addr = sstore.new_account("test").unwrap();
let _ok = sstore.unlock_account(&addr, "test").unwrap();
let secret = sstore.account_secret(&addr).unwrap();
let kp = KeyPair::from_secret(secret).unwrap();
assert_eq!(Address::from(kp.public().sha3()), addr);
}
}

View File

@@ -16,6 +16,7 @@
//! Key-Value store abstraction with RocksDB backend.
use std::default::Default;
use rocksdb::{DB, Writable, WriteBatch, IteratorMode, DBVector, DBIterator,
IndexType, Options, DBCompactionStyle, BlockBasedOptions, Direction};
@@ -24,6 +25,12 @@ pub struct DBTransaction {
batch: WriteBatch,
}
impl Default for DBTransaction {
fn default() -> Self {
DBTransaction::new()
}
}
impl DBTransaction {
/// Create new transaction.
pub fn new() -> DBTransaction {

View File

@@ -27,6 +27,8 @@
#![cfg_attr(feature="dev", allow(match_same_arms))]
// Keeps consistency (all lines with `.clone()`) and helpful when changing ref to non-ref.
#![cfg_attr(feature="dev", allow(clone_on_copy))]
// In most cases it expresses function flow better
#![cfg_attr(feature="dev", allow(if_not_else))]
//! Ethcore-util library
//!

View File

@@ -24,6 +24,7 @@ use hashdb::*;
use heapsize::*;
use std::mem;
use std::collections::HashMap;
use std::default::Default;
#[derive(Debug,Clone)]
/// Reference-counted memory-based HashDB implementation.
@@ -32,7 +33,7 @@ use std::collections::HashMap;
/// with `kill()`, check for existance with `exists()` and lookup a hash to derive
/// the data with `lookup()`. Clear with `clear()` and purge the portions of the data
/// that have no references with `purge()`.
///
///
/// # Example
/// ```rust
/// extern crate ethcore_util;
@@ -74,6 +75,12 @@ pub struct MemoryDB {
static_null_rlp: (Bytes, i32),
}
impl Default for MemoryDB {
fn default() -> Self {
MemoryDB::new()
}
}
impl MemoryDB {
/// Create a new instance of the memory DB.
pub fn new() -> MemoryDB {
@@ -133,7 +140,7 @@ impl MemoryDB {
/// Denote than an existing value has the given key. Used when a key gets removed without
/// a prior insert and thus has a negative reference with no value.
///
///
/// May safely be called even if the key's value is known, in which case it will be a no-op.
pub fn denote(&self, key: &H256, value: Bytes) -> &(Bytes, i32) {
if self.raw(key) == None {

View File

@@ -19,6 +19,7 @@ use std::net::SocketAddr;
use std::collections::{HashSet, HashMap, BTreeMap, VecDeque};
use std::mem;
use std::cmp;
use std::default::Default;
use mio::*;
use mio::udp::*;
use sha3::*;
@@ -62,8 +63,14 @@ struct NodeBucket {
nodes: VecDeque<BucketEntry>, //sorted by last active
}
impl Default for NodeBucket {
fn default() -> Self {
NodeBucket::new()
}
}
impl NodeBucket {
fn new() -> NodeBucket {
fn new() -> Self {
NodeBucket {
nodes: VecDeque::new()
}

View File

@@ -23,6 +23,7 @@ use std::ops::*;
use std::cmp::min;
use std::path::{Path, PathBuf};
use std::io::{Read, Write};
use std::default::Default;
use std::fs;
use mio::*;
use mio::tcp::*;
@@ -75,9 +76,15 @@ pub struct NetworkConfiguration {
pub ideal_peers: u32,
}
impl Default for NetworkConfiguration {
fn default() -> Self {
NetworkConfiguration::new()
}
}
impl NetworkConfiguration {
/// Create a new instance of default settings.
pub fn new() -> NetworkConfiguration {
pub fn new() -> Self {
NetworkConfiguration {
config_path: None,
listen_address: None,

View File

@@ -19,6 +19,7 @@
use std::thread;
use std::ops::DerefMut;
use std::sync::{Arc, Mutex};
use std::default::Default;
/// Thread-safe closure for handling possible panics
pub trait OnPanicListener: Send + Sync + 'static {
@@ -56,14 +57,20 @@ pub struct PanicHandler {
listeners: Mutex<Vec<Box<OnPanicListener>>>
}
impl Default for PanicHandler {
fn default() -> Self {
PanicHandler::new()
}
}
impl PanicHandler {
/// Creates new `PanicHandler` wrapped in `Arc`
pub fn new_in_arc() -> Arc<PanicHandler> {
pub fn new_in_arc() -> Arc<Self> {
Arc::new(Self::new())
}
/// Creates new `PanicHandler`
pub fn new() -> PanicHandler {
pub fn new() -> Self {
PanicHandler {
listeners: Mutex::new(vec![])
}

View File

@@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::ops::Deref;
use std::default::Default;
use elastic_array::*;
use rlp::bytes::{ToBytes, VecLike};
use rlp::{Stream, Encoder, Encodable};
@@ -44,6 +45,12 @@ pub struct RlpStream {
finished_list: bool,
}
impl Default for RlpStream {
fn default() -> Self {
RlpStream::new()
}
}
impl Stream for RlpStream {
fn new() -> Self {
RlpStream {
@@ -190,8 +197,14 @@ struct BasicEncoder {
bytes: ElasticArray1024<u8>,
}
impl Default for BasicEncoder {
fn default() -> Self {
BasicEncoder::new()
}
}
impl BasicEncoder {
fn new() -> BasicEncoder {
fn new() -> Self {
BasicEncoder { bytes: ElasticArray1024::new() }
}
@@ -222,7 +235,7 @@ impl Encoder for BasicEncoder {
// just 0
0 => self.bytes.push(0x80u8),
// byte is its own encoding if < 0x80
1 => {
1 => {
value.to_bytes(&mut self.bytes);
let len = self.bytes.len();
let last_byte = self.bytes[len - 1];

View File

@@ -16,6 +16,7 @@
//! A collection associating pair of keys (row and column) with a single value.
use std::default::Default;
use std::hash::Hash;
use std::collections::HashMap;
@@ -30,11 +31,21 @@ pub struct Table<Row, Col, Val>
map: HashMap<Row, HashMap<Col, Val>>,
}
impl<Row, Col, Val> Default for Table<Row, Col, Val>
where Row: Eq + Hash + Clone,
Col: Eq + Hash {
fn default() -> Self {
Table::new()
}
}
// There is default but clippy does not detect it?
#[allow(new_without_default)]
impl<Row, Col, Val> Table<Row, Col, Val>
where Row: Eq + Hash + Clone,
Col: Eq + Hash {
/// Creates new Table
pub fn new() -> Table<Row, Col, Val> {
pub fn new() -> Self {
Table {
map: HashMap::new(),
}

View File

@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::default::Default;
use sha3::*;
use hash::H256;
use bytes::*;
@@ -39,6 +40,12 @@ pub struct Score {
#[derive(Debug)]
pub struct Journal (Vec<Operation>);
impl Default for Journal {
fn default() -> Self {
Journal::new()
}
}
impl Journal {
/// Create a new, empty, object.
pub fn new() -> Journal { Journal(vec![]) }