Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

rlp as separate crate #2034

Merged
merged 5 commits into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ethcore-ipc-nano = { path = "ipc/nano" }
ethcore-ipc = { path = "ipc/rpc" }
ethcore-ipc-hypervisor = { path = "ipc/hypervisor" }
ethcore-logger = { path = "logger" }
rlp = { path = "util/rlp" }
json-ipc-server = { git = "https://github.com/ethcore/json-ipc-server.git" }
ethcore-dapps = { path = "dapps", optional = true }
clippy = { version = "0.0.85", optional = true}
Expand Down
1 change: 1 addition & 0 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ethcore-ipc = { path = "../ipc/rpc" }
ethstore = { path = "../ethstore" }
ethkey = { path = "../ethkey" }
ethcore-ipc-nano = { path = "../ipc/nano" }
rlp = { path = "../util/rlp" }
rand = "0.3"

[dependencies.hyper]
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/account_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

//! DB backend wrapper for Account trie
use util::*;
use rlp::NULL_RLP;

static NULL_RLP_STATIC: [u8; 1] = [0x80; 1];

Expand Down
1 change: 1 addition & 0 deletions ethcore/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use state::*;
use verification::PreverifiedBlock;
use trace::FlatTrace;
use factory::Factories;
use rlp::*;

/// A block, encoded as it is on the block chain.
#[derive(Default, Debug, Clone, PartialEq)]
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use bloomchain as bc;
use util::*;
use rlp::*;
use header::*;
use super::extras::*;
use transaction::*;
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/blockchain/extras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use bloomchain;
use util::*;
use rlp::*;
use header::BlockNumber;
use receipt::Receipt;
use db::Key;
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/blockchain/generator/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +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 util::rlp::*;
use rlp::*;
use util::{H256, H2048};
use util::bytes::Bytes;
use header::Header;
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/blooms/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use bloomchain as bc;
use util::rlp::*;
use rlp::*;
use util::HeapSizeOf;
use basic_types::LogBloom;

Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/blooms/bloom_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use bloomchain::group as bc;
use util::rlp::*;
use rlp::*;
use util::HeapSizeOf;
use super::Bloom;

Expand Down
11 changes: 6 additions & 5 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ use std::time::{Instant};
use time::precise_time_ns;

// util
use util::{journaldb, rlp, Bytes, View, PerfTimer, Itertools, Mutex, RwLock};
use util::journaldb::JournalDB;
use util::rlp::{UntrustedRlp};
use util::{Bytes, PerfTimer, Itertools, Mutex, RwLock};
use util::journaldb::{self, JournalDB};
use util::{U256, H256, Address, H2048, Uint};
use util::sha3::*;
use util::TrieFactory;
use util::kvdb::*;

// other
Expand Down Expand Up @@ -63,9 +63,10 @@ use trace;
use trace::FlatTransactionTraces;
use evm::Factory as EvmFactory;
use miner::{Miner, MinerService};
use util::TrieFactory;
use snapshot::{self, io as snapshot_io};
use factory::Factories;
use rlp::{View, UntrustedRlp};


// re-export
pub use types::blockchain_info::BlockChainInfo;
Expand Down Expand Up @@ -877,7 +878,7 @@ impl BlockChainClient for Client {
}

fn block_receipts(&self, hash: &H256) -> Option<Bytes> {
self.chain.block_receipts(hash).map(|receipts| rlp::encode(&receipts).to_vec())
self.chain.block_receipts(hash).map(|receipts| ::rlp::encode(&receipts).to_vec())
}

fn import_block(&self, bytes: Bytes) -> Result<H256, BlockImportError> {
Expand Down
11 changes: 6 additions & 5 deletions ethcore/src/client/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrder};
use util::*;
use rlp::*;
use ethkey::{Generator, Random};
use devtools::*;
use transaction::{Transaction, LocalizedTransaction, SignedTransaction, Action};
Expand Down Expand Up @@ -204,7 +205,7 @@ impl TestBlockChainClient {
txs.append(&signed_tx);
txs.out()
},
_ => rlp::EMPTY_LIST_RLP.to_vec()
_ => ::rlp::EMPTY_LIST_RLP.to_vec()
};

let mut rlp = RlpStream::new_list(3);
Expand All @@ -222,8 +223,8 @@ impl TestBlockChainClient {
header.set_extra_data(b"This extra data is way too long to be considered valid".to_vec());
let mut rlp = RlpStream::new_list(3);
rlp.append(&header);
rlp.append_raw(&rlp::NULL_RLP, 1);
rlp.append_raw(&rlp::NULL_RLP, 1);
rlp.append_raw(&::rlp::NULL_RLP, 1);
rlp.append_raw(&::rlp::NULL_RLP, 1);
self.blocks.write().insert(hash, rlp.out());
}

Expand All @@ -234,8 +235,8 @@ impl TestBlockChainClient {
header.set_parent_hash(H256::from(42));
let mut rlp = RlpStream::new_list(3);
rlp.append(&header);
rlp.append_raw(&rlp::NULL_RLP, 1);
rlp.append_raw(&rlp::NULL_RLP, 1);
rlp.append_raw(&::rlp::NULL_RLP, 1);
rlp.append_raw(&::rlp::NULL_RLP, 1);
self.blocks.write().insert(hash, rlp.out());
}

Expand Down
21 changes: 11 additions & 10 deletions ethcore/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use std::ops::Deref;
use std::hash::Hash;
use std::collections::HashMap;
use util::{DBTransaction, Database, RwLock};
use util::rlp::{encode, Encodable, decode, Decodable};

use rlp;

// database columns
/// Column for State
Expand Down Expand Up @@ -83,12 +84,12 @@ pub trait Key<T> {
/// Should be used to write value into database.
pub trait Writable {
/// Writes the value into the database.
fn write<T, R>(&mut self, col: Option<u32>, key: &Key<T, Target = R>, value: &T) where T: Encodable, R: Deref<Target = [u8]>;
fn write<T, R>(&mut self, col: Option<u32>, key: &Key<T, Target = R>, value: &T) where T: rlp::Encodable, R: Deref<Target = [u8]>;

/// Writes the value into the database and updates the cache.
fn write_with_cache<K, T, R>(&mut self, col: Option<u32>, cache: &mut Cache<K, T>, key: K, value: T, policy: CacheUpdatePolicy) where
K: Key<T, Target = R> + Hash + Eq,
T: Encodable,
T: rlp::Encodable,
R: Deref<Target = [u8]> {
self.write(col, &key, &value);
match policy {
Expand All @@ -104,7 +105,7 @@ pub trait Writable {
/// Writes the values into the database and updates the cache.
fn extend_with_cache<K, T, R>(&mut self, col: Option<u32>, cache: &mut Cache<K, T>, values: HashMap<K, T>, policy: CacheUpdatePolicy) where
K: Key<T, Target = R> + Hash + Eq,
T: Encodable,
T: rlp::Encodable,
R: Deref<Target = [u8]> {
match policy {
CacheUpdatePolicy::Overwrite => {
Expand All @@ -127,13 +128,13 @@ pub trait Writable {
pub trait Readable {
/// Returns value for given key.
fn read<T, R>(&self, col: Option<u32>, key: &Key<T, Target = R>) -> Option<T> where
T: Decodable,
T: rlp::Decodable,
R: Deref<Target = [u8]>;

/// Returns value for given key either in cache or in database.
fn read_with_cache<K, T, C>(&self, col: Option<u32>, cache: &RwLock<C>, key: &K) -> Option<T> where
K: Key<T> + Eq + Hash + Clone,
T: Clone + Decodable,
T: Clone + rlp::Decodable,
C: Cache<K, T> {
{
let read = cache.read();
Expand Down Expand Up @@ -169,17 +170,17 @@ pub trait Readable {
}

impl Writable for DBTransaction {
fn write<T, R>(&mut self, col: Option<u32>, key: &Key<T, Target = R>, value: &T) where T: Encodable, R: Deref<Target = [u8]> {
self.put(col, &key.key(), &encode(value));
fn write<T, R>(&mut self, col: Option<u32>, key: &Key<T, Target = R>, value: &T) where T: rlp::Encodable, R: Deref<Target = [u8]> {
self.put(col, &key.key(), &rlp::encode(value));
}
}

impl Readable for Database {
fn read<T, R>(&self, col: Option<u32>, key: &Key<T, Target = R>) -> Option<T> where T: Decodable, R: Deref<Target = [u8]> {
fn read<T, R>(&self, col: Option<u32>, key: &Key<T, Target = R>) -> Option<T> where T: rlp::Decodable, R: Deref<Target = [u8]> {
let result = self.get(col, &key.key());

match result {
Ok(option) => option.map(|v| decode(&v)),
Ok(option) => option.map(|v| rlp::decode(&v)),
Err(err) => {
panic!("db get failed, key: {:?}, err: {:?}", &key.key() as &[u8], err);
}
Expand Down
8 changes: 5 additions & 3 deletions ethcore/src/engines/basic_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Engine for BasicAuthority {
let message = header.bare_hash();
// account should be pernamently unlocked, otherwise sealing will fail
if let Ok(signature) = ap.sign(*block.header().author(), message) {
return Some(vec![encode(&(&*signature as &[u8])).to_vec()]);
return Some(vec![::rlp::encode(&(&*signature as &[u8])).to_vec()]);
} else {
trace!(target: "basicauthority", "generate_seal: FAIL: accounts secret key unavailable");
}
Expand All @@ -131,6 +131,8 @@ impl Engine for BasicAuthority {
}

fn verify_block_unordered(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
use rlp::{UntrustedRlp, View};

// check the signature is legit.
let sig = try!(UntrustedRlp::new(&header.seal()[0]).as_val::<H520>());
let signer = public_to_address(&try!(recover(&sig.into(), &header.bare_hash())));
Expand Down Expand Up @@ -172,7 +174,7 @@ impl Engine for BasicAuthority {
impl Header {
/// Get the none field of the header.
pub fn signature(&self) -> H520 {
decode(&self.seal()[0])
::rlp::decode(&self.seal()[0])
}
}

Expand Down Expand Up @@ -228,7 +230,7 @@ mod tests {
fn can_do_signature_verification_fail() {
let engine = new_test_authority().engine;
let mut header: Header = Header::default();
header.set_seal(vec![rlp::encode(&H520::default()).to_vec()]);
header.set_seal(vec![::rlp::encode(&H520::default()).to_vec()]);

let verify_result = engine.verify_block_unordered(&header, None);
assert!(verify_result.is_err());
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/engines/instant_seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ mod tests {

assert!(engine.verify_block_basic(&header, None).is_ok());

header.set_seal(vec![rlp::encode(&H520::default()).to_vec()]);
header.set_seal(vec![::rlp::encode(&H520::default()).to_vec()]);

assert!(engine.verify_block_unordered(&header, None).is_ok());
}
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ impl From<ExecutionError> for Error {
}
}

impl From<DecoderError> for Error {
fn from(err: DecoderError) -> Error {
impl From<::rlp::DecoderError> for Error {
fn from(err: ::rlp::DecoderError) -> Error {
Error::Util(UtilError::Decoder(err))
}
}
Expand Down
8 changes: 5 additions & 3 deletions ethcore/src/ethereum/ethash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use spec::CommonParams;
use engines::Engine;
use evm::Schedule;
use ethjson;
use rlp::{self, UntrustedRlp, View};

/// Ethash params.
#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -328,17 +329,17 @@ impl Ethash {
impl Header {
/// Get the none field of the header.
pub fn nonce(&self) -> H64 {
decode(&self.seal()[1])
rlp::decode(&self.seal()[1])
}

/// Get the mix hash field of the header.
pub fn mix_hash(&self) -> H256 {
decode(&self.seal()[0])
rlp::decode(&self.seal()[0])
}

/// Set the nonce and mix hash fields of the header.
pub fn set_nonce_and_mix_hash(&mut self, nonce: &H64, mix_hash: &H256) {
self.set_seal(vec![encode(mix_hash).to_vec(), encode(nonce).to_vec()]);
self.set_seal(vec![rlp::encode(mix_hash).to_vec(), rlp::encode(nonce).to_vec()]);
}
}

Expand All @@ -349,6 +350,7 @@ mod tests {
use tests::helpers::*;
use super::super::new_morden;
use super::Ethash;
use rlp;

#[test]
fn on_close_block() {
Expand Down
Loading