Updating ethcore and ethjson crates to Rust Edition 2018 (#316)

* Migrating use crate::Type imports to Rust 2018 edition

* import name fixes

* fmt

* removing diff leftover

* catching up with latest developments on dev

* fmt

* removing another diff leftover
This commit is contained in:
Karim Agha
2021-03-12 14:55:49 +01:00
committed by GitHub
parent 48e7d6cee4
commit 29dc10c446
81 changed files with 467 additions and 346 deletions

View File

@@ -16,9 +16,8 @@
//! Blockchain test account deserializer.
use bytes::Bytes;
use crate::{bytes::Bytes, uint::Uint};
use std::collections::BTreeMap;
use uint::Uint;
/// Blockchain test account deserializer.
#[derive(Debug, PartialEq, Deserialize, Clone)]
@@ -35,7 +34,7 @@ pub struct Account {
#[cfg(test)]
mod tests {
use blockchain::account::Account;
use crate::blockchain::account::Account;
use serde_json;
#[test]

View File

@@ -16,8 +16,10 @@
//! Blockchain test block deserializer.
use blockchain::{header::Header, transaction::Transaction};
use bytes::Bytes;
use crate::{
blockchain::{header::Header, transaction::Transaction},
bytes::Bytes,
};
/// Blockchain test block deserializer.
#[derive(Debug, PartialEq, Deserialize)]
@@ -39,7 +41,7 @@ impl Block {
#[cfg(test)]
mod tests {
use blockchain::block::Block;
use crate::blockchain::block::Block;
use serde_json;
#[test]

View File

@@ -16,10 +16,12 @@
//! Blockchain deserialization.
use blockchain::{block::Block, header::Header, state::State};
use bytes::Bytes;
use hash::H256;
use spec::{Ethereum, ForkSpec, Genesis, Seal};
use crate::{
blockchain::{block::Block, header::Header, state::State},
bytes::Bytes,
hash::H256,
spec::{Ethereum, ForkSpec, Genesis, Seal},
};
/// Json Block test possible engine kind.
#[derive(Debug, PartialEq, Deserialize)]
@@ -93,7 +95,7 @@ impl BlockChain {
#[cfg(test)]
mod tests {
use blockchain::blockchain::BlockChain;
use crate::blockchain::blockchain::BlockChain;
use serde_json;
#[test]

View File

@@ -16,9 +16,11 @@
//! Blockchain test header deserializer.
use bytes::Bytes;
use hash::{Address, Bloom, H256, H64};
use uint::Uint;
use crate::{
bytes::Bytes,
hash::{Address, Bloom, H256, H64},
uint::Uint,
};
/// Blockchain test header deserializer.
#[derive(Debug, PartialEq, Deserialize)]
@@ -64,7 +66,7 @@ pub struct Header {
#[cfg(test)]
mod tests {
use blockchain::header::Header;
use crate::blockchain::header::Header;
use serde_json;
#[test]

View File

@@ -16,7 +16,7 @@
//! Blockchain test deserializer.
use blockchain::blockchain::BlockChain;
use crate::blockchain::blockchain::BlockChain;
use serde_json::{self, Error};
use std::{collections::BTreeMap, io::Read};

View File

@@ -16,9 +16,8 @@
//! Blockchain test transaction deserialization.
use bytes::Bytes;
use crate::{bytes::Bytes, uint::Uint};
use ethereum_types::{H160, H256};
use uint::Uint;
/// Blockchain test transaction deserialization.
#[derive(Debug, PartialEq, Deserialize)]
@@ -39,11 +38,11 @@ pub struct Transaction {
pub hash: Option<H256>,
}
pub type AccessList = Vec<AccessListItem>;
#[derive(Debug, PartialEq, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct AccessListItem {
pub address: H160,
pub storage_keys: Vec<H256>,
}
pub type AccessList = Vec<AccessListItem>;

View File

@@ -102,7 +102,7 @@ impl<'a> Visitor<'a> for BytesVisitor {
#[cfg(test)]
mod test {
use bytes::Bytes;
use crate::bytes::Bytes;
use serde_json;
#[test]

View File

@@ -112,8 +112,8 @@ impl_hash!(Bloom, Hash2048);
#[cfg(test)]
mod test {
use crate::hash::H256;
use ethereum_types;
use hash::H256;
use serde_json;
use std::str::FromStr;

View File

@@ -14,9 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
extern crate common_types as types;
extern crate ethereum_types;
extern crate parity_crypto as crypto;
pub use common_types as types;
pub use parity_crypto as crypto;
extern crate rustc_hex;
extern crate serde;
extern crate serde_json;

View File

@@ -1,4 +1,4 @@
use blockchain::block::Block;
use crate::blockchain::block::Block;
use serde_json::{self, Error};
use std::{collections::BTreeMap, io::Read};

View File

@@ -94,9 +94,8 @@ impl<T> Into<Option<T>> for MaybeEmpty<T> {
#[cfg(test)]
mod tests {
use crate::{hash::H256, maybe::MaybeEmpty};
use ethereum_types;
use hash::H256;
use maybe::MaybeEmpty;
use serde_json;
use std::str::FromStr;

View File

@@ -18,9 +18,7 @@
use std::collections::BTreeMap;
use bytes::Bytes;
use spec::builtin::BuiltinCompat;
use uint::Uint;
use crate::{bytes::Bytes, spec::builtin::BuiltinCompat, uint::Uint};
/// Spec account.
#[derive(Clone, Debug, PartialEq, Deserialize)]
@@ -53,12 +51,10 @@ impl Account {
#[cfg(test)]
mod tests {
use bytes::Bytes;
use crate::{bytes::Bytes, spec::account::Account, uint::Uint};
use ethereum_types::U256;
use serde_json;
use spec::account::Account;
use std::collections::BTreeMap;
use uint::Uint;
#[test]
fn account_balance_missing_not_empty() {

View File

@@ -17,9 +17,7 @@
//! Authority params deserialization.
use super::{BlockReward, ValidatorSet};
use bytes::Bytes;
use hash::Address;
use uint::Uint;
use crate::{bytes::Bytes, hash::Address, uint::Uint};
/// Authority params deserialization.
#[derive(Debug, PartialEq, Deserialize)]
@@ -73,12 +71,14 @@ mod tests {
use std::collections::BTreeMap;
use super::BlockReward;
use crate::{
hash::Address,
spec::{authority_round::AuthorityRound, validator_set::ValidatorSet},
uint::Uint,
};
use ethereum_types::{H160, U256};
use hash::Address;
use serde_json;
use spec::{authority_round::AuthorityRound, validator_set::ValidatorSet};
use std::str::FromStr;
use uint::Uint;
#[test]
fn authority_round_deserialization() {

View File

@@ -17,7 +17,7 @@
//! Authority params deserialization.
use super::ValidatorSet;
use uint::Uint;
use crate::uint::Uint;
/// Authority params deserialization.
#[derive(Debug, PartialEq, Deserialize)]
@@ -40,12 +40,14 @@ pub struct BasicAuthority {
#[cfg(test)]
mod tests {
use crate::{
hash::Address,
spec::{basic_authority::BasicAuthority, validator_set::ValidatorSet},
uint::Uint,
};
use ethereum_types::{H160, U256};
use hash::Address;
use serde_json;
use spec::{basic_authority::BasicAuthority, validator_set::ValidatorSet};
use std::str::FromStr;
use uint::Uint;
#[test]
fn basic_authority_deserialization() {

View File

@@ -16,8 +16,8 @@
//! Spec builtin deserialization.
use crate::uint::Uint;
use std::collections::BTreeMap;
use uint::Uint;
/// Linear pricing.
#[derive(Debug, PartialEq, Deserialize, Clone)]

View File

@@ -40,8 +40,8 @@ pub enum Engine {
#[cfg(test)]
mod tests {
use crate::spec::Engine;
use serde_json;
use spec::Engine;
#[test]
fn engine_deserialization() {

View File

@@ -16,10 +16,12 @@
//! Ethash params deserialization.
use bytes::Bytes;
use hash::Address;
use crate::{
bytes::Bytes,
hash::Address,
uint::{self, Uint},
};
use std::collections::BTreeMap;
use uint::{self, Uint};
/// Deserializable doppelganger of block rewards for EthashParams
#[derive(Clone, Debug, PartialEq, Deserialize)]
@@ -105,12 +107,14 @@ pub struct Ethash {
#[cfg(test)]
mod tests {
use crate::{
hash::Address,
spec::ethash::{BlockReward, Ethash, EthashParams},
uint::Uint,
};
use ethereum_types::{H160, U256};
use hash::Address;
use serde_json;
use spec::ethash::{BlockReward, Ethash, EthashParams};
use std::str::FromStr;
use uint::Uint;
#[test]
fn ethash_deserialization() {

View File

@@ -16,10 +16,12 @@
//! Spec genesis deserialization.
use bytes::Bytes;
use hash::{Address, H256};
use spec::Seal;
use uint::{self, Uint};
use crate::{
bytes::Bytes,
hash::{Address, H256},
spec::Seal,
uint::{self, Uint},
};
/// Spec genesis.
#[derive(Debug, PartialEq, Deserialize)]
@@ -53,13 +55,15 @@ pub struct Genesis {
#[cfg(test)]
mod tests {
use bytes::Bytes;
use crate::{
bytes::Bytes,
hash::{Address, H256, H64},
spec::{genesis::Genesis, Ethereum, Seal},
uint::Uint,
};
use ethereum_types::{H160, H256 as Eth256, H64 as Eth64, U256};
use hash::{Address, H256, H64};
use serde_json;
use spec::{genesis::Genesis, Ethereum, Seal};
use std::str::FromStr;
use uint::Uint;
#[test]
fn genesis_deserialization() {

View File

@@ -16,7 +16,7 @@
//! Null engine params deserialization.
use uint::Uint;
use crate::uint::Uint;
/// Authority params deserialization.
#[derive(Debug, PartialEq, Deserialize)]
@@ -40,9 +40,9 @@ pub struct NullEngine {
#[cfg(test)]
mod tests {
use super::*;
use crate::uint::Uint;
use ethereum_types::U256;
use serde_json;
use uint::Uint;
#[test]
fn null_engine_deserialization() {

View File

@@ -16,9 +16,11 @@
//! Spec params deserialization.
use bytes::Bytes;
use hash::{Address, H256};
use uint::{self, Uint};
use crate::{
bytes::Bytes,
hash::{Address, H256},
uint::{self, Uint},
};
/// Spec params.
#[derive(Debug, PartialEq, Deserialize)]
@@ -146,10 +148,9 @@ pub struct Params {
#[cfg(test)]
mod tests {
use crate::{spec::params::Params, uint::Uint};
use ethereum_types::U256;
use serde_json;
use spec::params::Params;
use uint::Uint;
#[test]
fn params_deserialization() {

View File

@@ -16,9 +16,7 @@
//! Spec seal deserialization.
use bytes::Bytes;
use hash::*;
use uint::Uint;
use crate::{bytes::Bytes, hash::*, uint::Uint};
/// Ethereum seal.
#[derive(Debug, PartialEq, Deserialize)]
@@ -70,13 +68,15 @@ pub enum Seal {
#[cfg(test)]
mod tests {
use bytes::Bytes;
use crate::{
bytes::Bytes,
hash::*,
spec::{AuthorityRoundSeal, Ethereum, Seal, TendermintSeal},
uint::Uint,
};
use ethereum_types::{H256 as Eth256, H520 as Eth520, H64 as Eth64, U256};
use hash::*;
use serde_json;
use spec::{AuthorityRoundSeal, Ethereum, Seal, TendermintSeal};
use std::str::FromStr;
use uint::Uint;
#[test]
fn seal_deserialization() {

View File

@@ -16,8 +16,8 @@
//! Spec deserialization.
use crate::spec::{Engine, Genesis, Params, State};
use serde_json::{self, Error};
use spec::{Engine, Genesis, Params, State};
use std::io::Read;
/// Fork spec definition
@@ -73,8 +73,8 @@ impl Spec {
#[cfg(test)]
mod tests {
use crate::spec::spec::Spec;
use serde_json;
use spec::spec::Spec;
#[test]
fn should_error_on_unknown_fields() {

View File

@@ -16,9 +16,11 @@
//! Blockchain test state deserializer.
use bytes::Bytes;
use hash::Address;
use spec::{Account, Builtin};
use crate::{
bytes::Bytes,
hash::Address,
spec::{Account, Builtin},
};
use std::collections::BTreeMap;
/// Blockchain test state deserializer.

View File

@@ -16,9 +16,8 @@
//! Validator set deserialization.
use hash::Address;
use crate::{hash::Address, uint::Uint};
use std::collections::BTreeMap;
use uint::Uint;
/// Different ways of specifying validators.
#[derive(Debug, PartialEq, Deserialize)]
@@ -37,12 +36,10 @@ pub enum ValidatorSet {
#[cfg(test)]
mod tests {
use crate::{hash::Address, spec::validator_set::ValidatorSet, uint::Uint};
use ethereum_types::{H160, U256};
use hash::Address;
use serde_json;
use spec::validator_set::ValidatorSet;
use std::str::FromStr;
use uint::Uint;
#[test]
fn validator_set_deserialization() {

View File

@@ -15,8 +15,11 @@
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
//! State test log deserialization.
use bytes::Bytes;
use hash::{Address, Bloom, H256};
use crate::{
bytes::Bytes,
hash::{Address, Bloom, H256},
};
use common_types::log_entry::LogEntry;
/// State test log deserialization.
#[derive(Debug, PartialEq, Deserialize)]
@@ -33,8 +36,8 @@ pub struct Log {
#[cfg(test)]
mod tests {
use super::Log;
use serde_json;
use state::Log;
#[test]
fn log_deserialization() {
@@ -50,3 +53,13 @@ mod tests {
// TODO: validate all fields
}
}
impl From<Log> for LogEntry {
fn from(l: Log) -> Self {
LogEntry {
address: l.address.into(),
topics: l.topics.into_iter().map(Into::into).collect(),
data: l.data.into(),
}
}
}

View File

@@ -22,5 +22,4 @@ pub mod test;
pub mod transaction;
pub use self::{log::Log, state::State, test::Test, transaction::Transaction};
pub use blockchain::State as AccountState;
pub use vm::Env;
pub use crate::{blockchain::State as AccountState, vm::Env};

View File

@@ -16,9 +16,11 @@
//! State test deserialization.
use bytes::Bytes;
use hash::H256;
use state::{AccountState, Env, Log, Transaction};
use crate::{
bytes::Bytes,
hash::H256,
state::{AccountState, Env, Log, Transaction},
};
/// State test deserialization.
#[derive(Debug, PartialEq, Deserialize)]
@@ -45,8 +47,8 @@ pub struct State {
#[cfg(test)]
mod tests {
use super::State;
use serde_json;
use state::State;
#[test]
fn state_deserialization() {

View File

@@ -16,16 +16,22 @@
//! General test deserialization.
use bytes::Bytes;
use crypto::publickey::Secret;
use hash::{Address, H256};
use maybe::MaybeEmpty;
use crate::{
bytes::Bytes,
crypto::publickey::Secret,
hash::{Address, H256},
maybe::MaybeEmpty,
spec::ForkSpec,
state::{AccountState, Env},
uint::Uint,
};
use common_types::transaction::{
AccessListTx, Action, SignedTransaction, Transaction, TypedTransaction,
};
use serde_json::{self, Error};
use spec::ForkSpec;
use state::{AccountState, Env};
use std::{collections::BTreeMap, io::Read};
use types::transaction::{AccessListTx, Action, SignedTransaction, Transaction, TypedTransaction};
use uint::Uint;
use crate::blockchain::transaction::AccessList;

View File

@@ -16,10 +16,12 @@
//! State test transaction deserialization.
use bytes::Bytes;
use hash::{Address, H256};
use maybe::MaybeEmpty;
use uint::Uint;
use crate::{
bytes::Bytes,
hash::{Address, H256},
maybe::MaybeEmpty,
uint::Uint,
};
/// State test transaction deserialization.
#[derive(Debug, PartialEq, Deserialize)]
@@ -44,8 +46,8 @@ pub struct Transaction {
#[cfg(test)]
mod tests {
use super::Transaction;
use serde_json;
use state::Transaction;
#[test]
fn transaction_deserialization() {

View File

@@ -16,10 +16,9 @@
//! Additional test structures deserialization.
use hash::H256;
use crate::{hash::H256, uint::Uint};
use serde_json::{self, Error};
use std::{collections::BTreeMap, io::Read, path::PathBuf};
use uint::Uint;
/// Blockchain test header deserializer.
#[derive(Debug, PartialEq, Deserialize)]

View File

@@ -16,9 +16,9 @@
//! TransactionTest test deserializer.
use crate::transaction::TransactionTest;
use serde_json::{self, Error};
use std::{collections::BTreeMap, io::Read};
use transaction::TransactionTest;
/// TransactionTest test deserializer.
#[derive(Debug, Deserialize)]

View File

@@ -16,10 +16,12 @@
//! Transaction test transaction deserialization.
use bytes::Bytes;
use hash::Address;
use maybe::MaybeEmpty;
use uint::Uint;
use crate::{bytes::Bytes, hash::Address, maybe::MaybeEmpty, uint::Uint};
use common_types::transaction::{
signature, Action, SignatureComponents, Transaction as CoreTransaction, TypedTransaction,
UnverifiedTransaction,
};
use ethereum_types::H256;
/// Transaction test transaction deserialization.
#[derive(Debug, PartialEq, Deserialize)]
@@ -45,10 +47,37 @@ pub struct Transaction {
pub v: Uint,
}
impl From<Transaction> for UnverifiedTransaction {
fn from(t: Transaction) -> Self {
let to: Option<Address> = t.to.into();
UnverifiedTransaction {
unsigned: TypedTransaction::Legacy(CoreTransaction {
nonce: t.nonce.into(),
gas_price: t.gas_price.into(),
gas: t.gas_limit.into(),
action: match to {
Some(to) => Action::Call(to.into()),
None => Action::Create,
},
value: t.value.into(),
data: t.data.into(),
}),
chain_id: signature::extract_chain_id_from_legacy_v(t.v.into()),
signature: SignatureComponents {
r: t.r.into(),
s: t.s.into(),
standard_v: signature::extract_standard_v(t.v.into()),
},
hash: H256::zero(),
}
.compute_hash()
}
}
#[cfg(test)]
mod tests {
use super::Transaction;
use serde_json;
use transaction::Transaction;
#[test]
fn transaction_deserialization() {

View File

@@ -16,9 +16,11 @@
//! Transaction test deserialization.
use bytes::Bytes;
use hash::{Address, H256};
use spec::ForkSpec;
use crate::{
bytes::Bytes,
hash::{Address, H256},
spec::ForkSpec,
};
use std::collections::BTreeMap;
/// Transaction test deserialization.
@@ -42,8 +44,8 @@ pub struct PostState {
#[cfg(test)]
mod tests {
use super::TransactionTest;
use serde_json;
use transaction::TransactionTest;
#[test]
fn transaction_deserialization() {

View File

@@ -16,7 +16,7 @@
//! Trie test input deserialization.
use bytes::Bytes;
use crate::bytes::Bytes;
use serde::{
de::{Error as ErrorTrait, MapAccess, SeqAccess, Visitor},
Deserialize, Deserializer,
@@ -135,7 +135,7 @@ impl<'a> Visitor<'a> for InputVisitor {
#[cfg(test)]
mod tests {
use super::Input;
use bytes::Bytes;
use crate::bytes::Bytes;
use serde_json;
use std::collections::BTreeMap;

View File

@@ -16,9 +16,9 @@
//! TransactionTest test deserializer.
use crate::trie::Trie;
use serde_json::{self, Error};
use std::{collections::BTreeMap, io::Read};
use trie::Trie;
/// TransactionTest test deserializer.
#[derive(Debug, PartialEq, Deserialize)]

View File

@@ -16,8 +16,7 @@
//! Trie test deserialization.
use hash::H256;
use trie::Input;
use crate::{hash::H256, trie::Input};
/// Trie test deserialization.
#[derive(Debug, Deserialize, PartialEq)]

View File

@@ -148,9 +148,9 @@ where
#[cfg(test)]
mod test {
use crate::uint::Uint;
use ethereum_types::U256;
use serde_json;
use uint::Uint;
#[test]
fn uint_deserialization() {

View File

@@ -16,10 +16,7 @@
//! Vm call deserialization.
use bytes::Bytes;
use hash::Address;
use maybe::MaybeEmpty;
use uint::Uint;
use crate::{bytes::Bytes, hash::Address, maybe::MaybeEmpty, uint::Uint};
/// Vm call deserialization.
#[derive(Debug, PartialEq, Deserialize)]
@@ -37,13 +34,11 @@ pub struct Call {
#[cfg(test)]
mod tests {
use crate::{hash::Address, maybe::MaybeEmpty, uint::Uint, vm::Call};
use ethereum_types::{H160 as Hash160, U256};
use hash::Address;
use maybe::MaybeEmpty;
use serde_json;
use std::str::FromStr;
use uint::Uint;
use vm::Call;
#[test]
fn call_deserialization_empty_dest() {

View File

@@ -15,8 +15,7 @@
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
//! Vm environment.
use hash::Address;
use uint::Uint;
use crate::{hash::Address, uint::Uint};
/// Vm environment.
#[derive(Debug, PartialEq, Deserialize)]
@@ -40,8 +39,8 @@ pub struct Env {
#[cfg(test)]
mod tests {
use super::Env;
use serde_json;
use vm::Env;
#[test]
fn env_deserialization() {

View File

@@ -16,9 +16,9 @@
//! Vm test deserializer.
use crate::vm::Vm;
use serde_json::{self, Error};
use std::{collections::BTreeMap, io::Read};
use vm::Vm;
/// Vm test deserializer.
#[derive(Debug, PartialEq, Deserialize)]

View File

@@ -15,9 +15,7 @@
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
//! Executed transaction.
use bytes::Bytes;
use hash::Address;
use uint::Uint;
use crate::{bytes::Bytes, hash::Address, uint::Uint};
/// Executed transaction.
#[derive(Debug, PartialEq, Deserialize)]
@@ -44,8 +42,8 @@ pub struct Transaction {
#[cfg(test)]
mod tests {
use super::Transaction;
use serde_json;
use vm::Transaction;
#[test]
fn transaction_deserialization() {

View File

@@ -16,11 +16,13 @@
//! Vm execution env.
use blockchain::State;
use bytes::Bytes;
use hash::H256;
use uint::Uint;
use vm::{Call, Env, Transaction};
use crate::{
blockchain::State,
bytes::Bytes,
hash::H256,
uint::Uint,
vm::{Call, Env, Transaction},
};
/// Represents vm execution environment before and after execution of transaction.
#[derive(Debug, PartialEq, Deserialize)]
@@ -58,8 +60,8 @@ impl Vm {
#[cfg(test)]
mod tests {
use super::Vm;
use serde_json;
use vm::Vm;
#[test]
fn vm_deserialization() {