Merge branch 'master' of github.com:ethcore/parity into rpc

This commit is contained in:
debris
2016-01-27 13:04:40 +01:00
21 changed files with 228 additions and 109 deletions

View File

@@ -273,7 +273,9 @@ pub enum FromBytesError {
/// TODO [debris] Please document me
DataIsTooShort,
/// TODO [debris] Please document me
DataIsTooLong
DataIsTooLong,
/// Integer-representation is non-canonically prefixed with zero byte(s).
ZeroPrefixedInt,
}
impl StdError for FromBytesError {
@@ -310,6 +312,9 @@ macro_rules! impl_uint_from_bytes {
match bytes.len() {
0 => Ok(0),
l if l <= mem::size_of::<$to>() => {
if bytes[0] == 0 {
return Err(FromBytesError::ZeroPrefixedInt)
}
let mut res = 0 as $to;
for i in 0..l {
let shift = (l - 1 - i) * 8;
@@ -344,7 +349,9 @@ macro_rules! impl_uint_from_bytes {
($name: ident) => {
impl FromBytes for $name {
fn from_bytes(bytes: &[u8]) -> FromBytesResult<$name> {
if bytes.len() <= $name::SIZE {
if !bytes.is_empty() && bytes[0] == 0 {
Err(FromBytesError::ZeroPrefixedInt)
} else if bytes.len() <= $name::SIZE {
Ok($name::from(bytes))
} else {
Err(FromBytesError::DataIsTooLong)

View File

@@ -7,6 +7,8 @@ use bytes::FromBytesError;
pub enum DecoderError {
/// TODO [debris] Please document me
FromBytesError(FromBytesError),
/// Given data has additional bytes at the end of the valid RLP fragment.
RlpIsTooBig,
/// TODO [debris] Please document me
RlpIsTooShort,
/// TODO [debris] Please document me

View File

@@ -46,6 +46,9 @@ impl PayloadInfo {
value_len: value_len,
}
}
/// Total size of the RLP.
pub fn total(&self) -> usize { self.header_len + self.value_len }
}
/// Data-oriented view onto rlp-slice.

View File

@@ -25,6 +25,12 @@ impl<'db> SecTrieDBMut<'db> {
pub fn from_existing(db: &'db mut HashDB, root: &'db mut H256) -> Self {
SecTrieDBMut { raw: TrieDBMut::from_existing(db, root) }
}
/// Get the backing database.
pub fn db(&'db self) -> &'db HashDB { self.raw.db() }
/// Get the backing database.
pub fn db_mut(&'db mut self) -> &'db mut HashDB { self.raw.db_mut() }
}
impl<'db> Trie for SecTrieDBMut<'db> {

View File

@@ -87,6 +87,11 @@ impl<'db> TrieDBMut<'db> {
self.db
}
/// Get the backing database.
pub fn db_mut(&'db mut self) -> &'db mut HashDB {
self.db
}
/// Determine all the keys in the backing database that belong to the trie.
pub fn keys(&self) -> Vec<H256> {
let mut ret: Vec<H256> = Vec::new();