parent
92fd00f41e
commit
7200cfcbc9
@ -60,7 +60,7 @@ impl WriteCache {
|
|||||||
self.entries.insert(key, WriteCacheEntry::Remove);
|
self.entries.insert(key, WriteCacheEntry::Remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get(&self, key: &Vec<u8>) -> Option<Vec<u8>> {
|
fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
|
||||||
self.entries.get(key).and_then(
|
self.entries.get(key).and_then(
|
||||||
|vec_ref| match vec_ref {
|
|vec_ref| match vec_ref {
|
||||||
&WriteCacheEntry::Write(ref val) => Some(val.clone()),
|
&WriteCacheEntry::Write(ref val) => Some(val.clone()),
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
//! Blockchain block.
|
//! Blockchain block.
|
||||||
|
|
||||||
#![cfg_attr(feature="dev", allow(ptr_arg))] // Because of &LastHashes -> &Vec<_>
|
|
||||||
|
|
||||||
use common::*;
|
use common::*;
|
||||||
use engine::*;
|
use engine::*;
|
||||||
use state::*;
|
use state::*;
|
||||||
@ -76,11 +74,11 @@ pub struct BlockRefMut<'a> {
|
|||||||
/// Block header.
|
/// Block header.
|
||||||
pub header: &'a mut Header,
|
pub header: &'a mut Header,
|
||||||
/// Block transactions.
|
/// Block transactions.
|
||||||
pub transactions: &'a Vec<SignedTransaction>,
|
pub transactions: &'a [SignedTransaction],
|
||||||
/// Block uncles.
|
/// Block uncles.
|
||||||
pub uncles: &'a Vec<Header>,
|
pub uncles: &'a [Header],
|
||||||
/// Transaction receipts.
|
/// Transaction receipts.
|
||||||
pub receipts: &'a Vec<Receipt>,
|
pub receipts: &'a [Receipt],
|
||||||
/// State.
|
/// State.
|
||||||
pub state: &'a mut State,
|
pub state: &'a mut State,
|
||||||
/// Traces.
|
/// Traces.
|
||||||
@ -92,11 +90,11 @@ pub struct BlockRef<'a> {
|
|||||||
/// Block header.
|
/// Block header.
|
||||||
pub header: &'a Header,
|
pub header: &'a Header,
|
||||||
/// Block transactions.
|
/// Block transactions.
|
||||||
pub transactions: &'a Vec<SignedTransaction>,
|
pub transactions: &'a [SignedTransaction],
|
||||||
/// Block uncles.
|
/// Block uncles.
|
||||||
pub uncles: &'a Vec<Header>,
|
pub uncles: &'a [Header],
|
||||||
/// Transaction receipts.
|
/// Transaction receipts.
|
||||||
pub receipts: &'a Vec<Receipt>,
|
pub receipts: &'a [Receipt],
|
||||||
/// State.
|
/// State.
|
||||||
pub state: &'a State,
|
pub state: &'a State,
|
||||||
/// Traces.
|
/// Traces.
|
||||||
@ -152,16 +150,16 @@ pub trait IsBlock {
|
|||||||
fn state(&self) -> &State { &self.block().state }
|
fn state(&self) -> &State { &self.block().state }
|
||||||
|
|
||||||
/// Get all information on transactions in this block.
|
/// Get all information on transactions in this block.
|
||||||
fn transactions(&self) -> &Vec<SignedTransaction> { &self.block().base.transactions }
|
fn transactions(&self) -> &[SignedTransaction] { &self.block().base.transactions }
|
||||||
|
|
||||||
/// Get all information on receipts in this block.
|
/// Get all information on receipts in this block.
|
||||||
fn receipts(&self) -> &Vec<Receipt> { &self.block().receipts }
|
fn receipts(&self) -> &[Receipt] { &self.block().receipts }
|
||||||
|
|
||||||
/// Get all information concerning transaction tracing in this block.
|
/// Get all information concerning transaction tracing in this block.
|
||||||
fn traces(&self) -> &Option<Vec<Trace>> { &self.block().traces }
|
fn traces(&self) -> &Option<Vec<Trace>> { &self.block().traces }
|
||||||
|
|
||||||
/// Get all uncles in this block.
|
/// Get all uncles in this block.
|
||||||
fn uncles(&self) -> &Vec<Header> { &self.block().base.uncles }
|
fn uncles(&self) -> &[Header] { &self.block().base.uncles }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait for a object that has a state database.
|
/// Trait for a object that has a state database.
|
||||||
|
@ -426,7 +426,7 @@ impl Client {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Commit results
|
// Commit results
|
||||||
let receipts = block.receipts().clone();
|
let receipts = block.receipts().to_owned();
|
||||||
let traces = From::from(block.traces().clone().unwrap_or_else(Vec::new));
|
let traces = From::from(block.traces().clone().unwrap_or_else(Vec::new));
|
||||||
|
|
||||||
// CHECK! I *think* this is fine, even if the state_root is equal to another
|
// CHECK! I *think* this is fine, even if the state_root is equal to another
|
||||||
|
@ -143,7 +143,7 @@ impl Header {
|
|||||||
/// Get the difficulty field of the header.
|
/// Get the difficulty field of the header.
|
||||||
pub fn difficulty(&self) -> &U256 { &self.difficulty }
|
pub fn difficulty(&self) -> &U256 { &self.difficulty }
|
||||||
/// Get the seal field of the header.
|
/// Get the seal field of the header.
|
||||||
pub fn seal(&self) -> &Vec<Bytes> { &self.seal }
|
pub fn seal(&self) -> &[Bytes] { &self.seal }
|
||||||
|
|
||||||
// TODO: seal_at, set_seal_at &c.
|
// TODO: seal_at, set_seal_at &c.
|
||||||
|
|
||||||
|
@ -665,7 +665,7 @@ impl MinerService for Miner {
|
|||||||
};
|
};
|
||||||
match (&self.options.pending_set, sealing_set) {
|
match (&self.options.pending_set, sealing_set) {
|
||||||
(&PendingSet::AlwaysQueue, _) | (&PendingSet::SealingOrElseQueue, None) => queue.top_transactions(),
|
(&PendingSet::AlwaysQueue, _) | (&PendingSet::SealingOrElseQueue, None) => queue.top_transactions(),
|
||||||
(_, sealing) => sealing.map_or_else(Vec::new, |s| s.transactions().clone()),
|
(_, sealing) => sealing.map_or_else(Vec::new, |s| s.transactions().to_owned()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -702,7 +702,7 @@ impl MinerService for Miner {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|t| t.hash());
|
.map(|t| t.hash());
|
||||||
|
|
||||||
let receipts = pending.receipts().clone().into_iter();
|
let receipts = pending.receipts().iter().cloned();
|
||||||
|
|
||||||
hashes.zip(receipts).collect()
|
hashes.zip(receipts).collect()
|
||||||
},
|
},
|
||||||
|
@ -143,7 +143,7 @@ impl Spec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the known knodes of the network in enode format.
|
/// Get the known knodes of the network in enode format.
|
||||||
pub fn nodes(&self) -> &Vec<String> { &self.nodes }
|
pub fn nodes(&self) -> &[String] { &self.nodes }
|
||||||
|
|
||||||
/// Get the configured Network ID.
|
/// Get the configured Network ID.
|
||||||
pub fn network_id(&self) -> U256 { self.params.network_id }
|
pub fn network_id(&self) -> U256 { self.params.network_id }
|
||||||
|
@ -40,9 +40,9 @@ impl Into<Vec<u8>> for Bytes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for Bytes {
|
impl Deref for Bytes {
|
||||||
type Target = Vec<u8>;
|
type Target = [u8];
|
||||||
|
|
||||||
fn deref(&self) -> &Vec<u8> {
|
fn deref(&self) -> &[u8] {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,7 @@ impl Configuration {
|
|||||||
})
|
})
|
||||||
}).collect(),
|
}).collect(),
|
||||||
Some(_) => Vec::new(),
|
Some(_) => Vec::new(),
|
||||||
None => spec.nodes().clone(),
|
None => spec.nodes().to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,7 +508,7 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
|
|||||||
fn compilers(&self, params: Params) -> Result<Value, Error> {
|
fn compilers(&self, params: Params) -> Result<Value, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
match params {
|
match params {
|
||||||
Params::None => to_value(&vec![] as &Vec<String>),
|
Params::None => to_value(&(&[] as &[String])),
|
||||||
_ => Err(Error::invalid_params())
|
_ => Err(Error::invalid_params())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,11 @@ use std::str::FromStr;
|
|||||||
use jsonrpc_core::IoHandler;
|
use jsonrpc_core::IoHandler;
|
||||||
use util::H256;
|
use util::H256;
|
||||||
|
|
||||||
fn origin_is_allowed(self_origin: &str, header: Option<&Vec<u8>>) -> bool {
|
fn origin_is_allowed(self_origin: &str, header: Option<&[u8]>) -> bool {
|
||||||
match header {
|
match header {
|
||||||
None => false,
|
None => false,
|
||||||
Some(h) => {
|
Some(h) => {
|
||||||
let v = String::from_utf8(h.clone()).ok();
|
let v = String::from_utf8(h.to_owned()).ok();
|
||||||
match v {
|
match v {
|
||||||
Some(ref origin) if origin.starts_with("chrome-extension://") => true,
|
Some(ref origin) if origin.starts_with("chrome-extension://") => true,
|
||||||
Some(ref origin) if origin.starts_with(self_origin) => true,
|
Some(ref origin) if origin.starts_with(self_origin) => true,
|
||||||
@ -84,8 +84,8 @@ pub struct Session {
|
|||||||
|
|
||||||
impl ws::Handler for Session {
|
impl ws::Handler for Session {
|
||||||
fn on_request(&mut self, req: &ws::Request) -> ws::Result<(ws::Response)> {
|
fn on_request(&mut self, req: &ws::Request) -> ws::Result<(ws::Response)> {
|
||||||
let origin = req.header("origin").or_else(|| req.header("Origin"));
|
let origin = req.header("origin").or_else(|| req.header("Origin")).map(|x| &x[..]);
|
||||||
let host = req.header("host").or_else(|| req.header("Host"));
|
let host = req.header("host").or_else(|| req.header("Host")).map(|x| &x[..]);
|
||||||
|
|
||||||
// Check request origin and host header.
|
// Check request origin and host header.
|
||||||
if !origin_is_allowed(&self.self_origin, origin) && !(origin.is_none() && origin_is_allowed(&self.self_origin, host)) {
|
if !origin_is_allowed(&self.self_origin, origin) && !(origin.is_none() && origin_is_allowed(&self.self_origin, host)) {
|
||||||
|
@ -255,7 +255,7 @@ impl<T> FromRawBytes for T where T: FixedHash {
|
|||||||
Ordering::Equal => ()
|
Ordering::Equal => ()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut res: Self = unsafe { mem::uninitialized() };
|
let mut res = T::zero();
|
||||||
res.copy_raw(bytes);
|
res.copy_raw(bytes);
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
@ -271,7 +271,7 @@ macro_rules! sized_binary_map {
|
|||||||
::std::cmp::Ordering::Greater => return Err(FromBytesError::TooLong),
|
::std::cmp::Ordering::Greater => return Err(FromBytesError::TooLong),
|
||||||
::std::cmp::Ordering::Equal => ()
|
::std::cmp::Ordering::Equal => ()
|
||||||
};
|
};
|
||||||
let mut res: Self = unsafe { ::std::mem::uninitialized() };
|
let mut res: Self = 0;
|
||||||
res.copy_raw(bytes);
|
res.copy_raw(bytes);
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
@ -339,7 +339,7 @@ impl<T> FromRawBytesVariable for Vec<T> where T: FromRawBytes {
|
|||||||
impl<V1, T2> FromRawBytes for (V1, T2) where V1: FromRawBytesVariable, T2: FromRawBytes {
|
impl<V1, T2> FromRawBytes for (V1, T2) where V1: FromRawBytesVariable, T2: FromRawBytes {
|
||||||
fn from_bytes(bytes: &[u8]) -> Result<Self, FromBytesError> {
|
fn from_bytes(bytes: &[u8]) -> Result<Self, FromBytesError> {
|
||||||
let header = 8usize;
|
let header = 8usize;
|
||||||
let mut map: (u64, ) = unsafe { mem::uninitialized() };
|
let mut map: (u64, ) = (0,);
|
||||||
|
|
||||||
if bytes.len() < header { return Err(FromBytesError::NotLongEnough); }
|
if bytes.len() < header { return Err(FromBytesError::NotLongEnough); }
|
||||||
map.copy_raw(&bytes[0..header]);
|
map.copy_raw(&bytes[0..header]);
|
||||||
@ -358,7 +358,7 @@ impl<V1, V2, T3> FromRawBytes for (V1, V2, T3)
|
|||||||
{
|
{
|
||||||
fn from_bytes(bytes: &[u8]) -> Result<Self, FromBytesError> {
|
fn from_bytes(bytes: &[u8]) -> Result<Self, FromBytesError> {
|
||||||
let header = 16usize;
|
let header = 16usize;
|
||||||
let mut map: (u64, u64, ) = unsafe { mem::uninitialized() };
|
let mut map: (u64, u64, ) = (0, 0,);
|
||||||
|
|
||||||
if bytes.len() < header { return Err(FromBytesError::NotLongEnough); }
|
if bytes.len() < header { return Err(FromBytesError::NotLongEnough); }
|
||||||
map.copy_raw(&bytes[0..header]);
|
map.copy_raw(&bytes[0..header]);
|
||||||
@ -373,7 +373,7 @@ impl<V1, V2, T3> FromRawBytes for (V1, V2, T3)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, V1, T2> ToBytesWithMap for (&'a Vec<V1>, &'a T2) where V1: ToBytesWithMap, T2: ToBytesWithMap {
|
impl<'a, V1, X1, T2> ToBytesWithMap for (X1, &'a T2) where V1: ToBytesWithMap, X1: Deref<Target=[V1]>, T2: ToBytesWithMap {
|
||||||
fn to_bytes_map(&self) -> Vec<u8> {
|
fn to_bytes_map(&self) -> Vec<u8> {
|
||||||
let header = 8usize;
|
let header = 8usize;
|
||||||
let v1_size = mem::size_of::<V1>();
|
let v1_size = mem::size_of::<V1>();
|
||||||
@ -390,9 +390,9 @@ impl<'a, V1, T2> ToBytesWithMap for (&'a Vec<V1>, &'a T2) where V1: ToBytesWithM
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, V1, V2, T3> ToBytesWithMap for (&'a Vec<V1>, &'a Vec<V2>, &'a T3)
|
impl<'a, V1, X1, V2, X2, T3> ToBytesWithMap for (X1, X2, &'a T3)
|
||||||
where V1: ToBytesWithMap,
|
where V1: ToBytesWithMap, X1: Deref<Target=[V1]>,
|
||||||
V2: ToBytesWithMap,
|
V2: ToBytesWithMap, X2: Deref<Target=[V2]>,
|
||||||
T3: ToBytesWithMap
|
T3: ToBytesWithMap
|
||||||
{
|
{
|
||||||
fn to_bytes_map(&self) -> Vec<u8> {
|
fn to_bytes_map(&self) -> Vec<u8> {
|
||||||
@ -433,7 +433,7 @@ pub trait ToBytesWithMap {
|
|||||||
|
|
||||||
impl<T> ToBytesWithMap for T where T: FixedHash {
|
impl<T> ToBytesWithMap for T where T: FixedHash {
|
||||||
fn to_bytes_map(&self) -> Vec<u8> {
|
fn to_bytes_map(&self) -> Vec<u8> {
|
||||||
self.as_slice().to_vec()
|
self.as_slice().to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,7 +493,7 @@ fn populate_big_types() {
|
|||||||
fn raw_bytes_from_tuple() {
|
fn raw_bytes_from_tuple() {
|
||||||
type Tup = (Vec<u16>, u16);
|
type Tup = (Vec<u16>, u16);
|
||||||
|
|
||||||
let tup = (vec![1u16, 1u16, 1u16, 1u16], 10u16);
|
let tup: (&[u16], u16) = (&[1; 4], 10);
|
||||||
let bytes = vec![
|
let bytes = vec![
|
||||||
// map
|
// map
|
||||||
8u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
|
8u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
|
||||||
@ -505,18 +505,19 @@ fn raw_bytes_from_tuple() {
|
|||||||
// 10u16
|
// 10u16
|
||||||
10u8, 0u8];
|
10u8, 0u8];
|
||||||
|
|
||||||
let tup_from = Tup::from_bytes(&bytes).unwrap();
|
let (v, x) = Tup::from_bytes(&bytes).unwrap();
|
||||||
assert_eq!(tup, tup_from);
|
assert_eq!(tup, (&v[..], x));
|
||||||
|
let tup_from = (v, x);
|
||||||
|
|
||||||
let tup_to = (&tup_from.0, &tup_from.1);
|
let tup_to = (tup_from.0, &tup_from.1);
|
||||||
let bytes_to = tup_to.to_bytes_map();
|
let bytes_to = tup_to.to_bytes_map();
|
||||||
assert_eq!(bytes_to, bytes);
|
assert_eq!(bytes_to, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bytes_map_from_triple() {
|
fn bytes_map_from_triple() {
|
||||||
let data = (vec![2u16; 6], vec![6u32; 3], 12u64);
|
let data: (&[u16], &[u32], u64) = (&[2; 6], &[6; 3], 12u64);
|
||||||
let bytes_map = (&data.0, &data.1, &data.2).to_bytes_map();
|
let bytes_map = (data.0, data.1, &data.2).to_bytes_map();
|
||||||
assert_eq!(bytes_map, vec![
|
assert_eq!(bytes_map, vec![
|
||||||
// data map 2 x u64
|
// data map 2 x u64
|
||||||
12, 0, 0, 0, 0, 0, 0, 0,
|
12, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
@ -195,7 +195,7 @@ fn hash256rlp(input: &[(Vec<u8>, Vec<u8>)], pre_len: usize, stream: &mut RlpStre
|
|||||||
}
|
}
|
||||||
|
|
||||||
// take slices
|
// take slices
|
||||||
let key: &Vec<u8> = &input[0].0;
|
let key: &[u8] = &input[0].0;
|
||||||
let value: &[u8] = &input[0].1;
|
let value: &[u8] = &input[0].1;
|
||||||
|
|
||||||
// if the slice contains just one item, append the suffix of the key
|
// if the slice contains just one item, append the suffix of the key
|
||||||
|
@ -33,7 +33,7 @@ pub trait SharedPrefix <T> {
|
|||||||
fn shared_prefix_len(&self, elem: &[T]) -> usize;
|
fn shared_prefix_len(&self, elem: &[T]) -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <T> SharedPrefix<T> for Vec<T> where T: Eq {
|
impl<T> SharedPrefix<T> for [T] where T: Eq {
|
||||||
fn shared_prefix_len(&self, elem: &[T]) -> usize {
|
fn shared_prefix_len(&self, elem: &[T]) -> usize {
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
let len = cmp::min(self.len(), elem.len());
|
let len = cmp::min(self.len(), elem.len());
|
||||||
|
Loading…
Reference in New Issue
Block a user