Skip to content

Commit 77776f7

Browse files
authored
remove primitive_types dep (#783)
1 parent b69a6c0 commit 77776f7

File tree

9 files changed

+25
-41
lines changed

9 files changed

+25
-41
lines changed

chain-evm/Cargo.toml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,8 @@ hex = { version = "0.4", default-features = false, features = ["alloc"] }
2222
byte-slice-cast = { version = "1.0", default-features = false }
2323
thiserror = "1.0"
2424
quickcheck = { version = "0.9", optional = true }
25-
26-
[dependencies.evm]
27-
version = "0.34.0"
28-
29-
[dependencies.primitive-types]
30-
version = ">= 0.10, <= 0.11"
31-
features = ["rlp"]
32-
33-
[dependencies.ethereum-types]
34-
version = "0.13.1"
35-
features = ["rlp"]
25+
evm = { version = "0.34.0" }
26+
ethereum-types = { version = "0.13.1", features = ["rlp"] }
3627

3728
[dev-dependencies]
3829
rand = "0.7.3"

chain-evm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub use primitive_types;
1+
pub use ethereum_types;
22

33
pub mod machine;
44
mod precompiles;

chain-evm/src/machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
//! ## Handler <- EVM Context Handler
99
//! ## StackState<'config>
1010
//!
11+
use ethereum_types::{H160, H256, U256};
1112
use evm::{
1213
backend::{Backend, Basic},
1314
executor::stack::{Accessed, StackExecutor, StackState, StackSubstateMetadata},
1415
Context, ExitError, ExitFatal, ExitReason, ExitRevert, Transfer,
1516
};
16-
use primitive_types::{H160, H256, U256};
1717
use std::collections::{BTreeMap, BTreeSet};
1818

1919
use thiserror::Error;
@@ -133,7 +133,7 @@ pub trait EvmState {
133133
where
134134
F: FnOnce(Account) -> Option<Account>;
135135

136-
fn update_logs(&mut self, block_hash: H256, logs: Vec<Log>);
136+
fn update_logs(&mut self, block_hash: BlockHash, logs: Vec<Log>);
137137
}
138138

139139
struct VirtualMachineSubstate<'a> {

chain-evm/src/precompiles/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub use crate::Address;
2-
pub use primitive_types::{H160, H256, U256};
2+
pub use ethereum_types::{H160, H256, U256};
33
pub use std::collections::BTreeMap;
44
pub use std::marker::PhantomData;
55
pub use std::mem;

chain-evm/src/state/account.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use crate::{
22
state::{storage::Storage, trie::Trie, Error},
33
Address,
44
};
5-
6-
use primitive_types::U256;
5+
use ethereum_types::U256;
76

87
pub type Nonce = U256;
98

chain-evm/src/state/storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::state::trie::Trie;
22

3-
use primitive_types::H256;
3+
use ethereum_types::H256;
44

55
/// Representation of a storage key. Fixed-size uninterpreted hash type with 32 bytes (256 bits) size.
66
pub type Key = H256;

chain-evm/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::machine::test::TestEvmState;
22
use crate::machine::{transact_call, VirtualMachine};
33
use crate::{state::Account, Config};
4+
use ethereum_types::{H160, U256};
45
use evm_test_suite::{AccountState, BlockHeader, CallTransaction, NetworkType};
5-
use primitive_types::{H160, U256};
66
use std::collections::BTreeSet;
77

88
struct TestEvmLedger {

chain-impl-mockchain/src/evm/mod.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use chain_core::{
55
};
66
#[cfg(feature = "evm")]
77
use chain_evm::{
8-
primitive_types,
8+
ethereum_types::{H256, U256},
99
state::{ByteCode, Key},
1010
};
1111
use typed_bytes::ByteBuilder;
@@ -27,25 +27,25 @@ pub enum EvmTransaction {
2727
#[cfg(feature = "evm")]
2828
Create {
2929
caller: Address,
30-
value: primitive_types::U256,
30+
value: U256,
3131
init_code: ByteCode,
3232
gas_limit: u64,
3333
access_list: Vec<(Address, Vec<Key>)>,
3434
},
3535
#[cfg(feature = "evm")]
3636
Create2 {
3737
caller: Address,
38-
value: primitive_types::U256,
38+
value: U256,
3939
init_code: ByteCode,
40-
salt: primitive_types::H256,
40+
salt: H256,
4141
gas_limit: u64,
4242
access_list: Vec<(Address, Vec<Key>)>,
4343
},
4444
#[cfg(feature = "evm")]
4545
Call {
4646
caller: Address,
4747
address: Address,
48-
value: primitive_types::U256,
48+
value: U256,
4949
data: ByteCode,
5050
gas_limit: u64,
5151
access_list: Vec<(Address, Vec<Key>)>,
@@ -120,24 +120,21 @@ pub fn serialize_address<T>(bb: ByteBuilder<T>, caller: &Address) -> ByteBuilder
120120

121121
#[cfg(feature = "evm")]
122122
/// Serializes U256 types as fixed bytes.
123-
pub fn serialize_u256<T>(bb: ByteBuilder<T>, value: &primitive_types::U256) -> ByteBuilder<T> {
123+
pub fn serialize_u256<T>(bb: ByteBuilder<T>, value: &U256) -> ByteBuilder<T> {
124124
let mut value_bytes = [0u8; 32];
125125
value.to_big_endian(&mut value_bytes);
126126
bb.bytes(&value_bytes)
127127
}
128128

129129
#[cfg(feature = "evm")]
130130
/// Serializes H256 types as fixed bytes.
131-
pub fn serialize_h256<T>(bb: ByteBuilder<T>, value: &primitive_types::H256) -> ByteBuilder<T> {
131+
pub fn serialize_h256<T>(bb: ByteBuilder<T>, value: &H256) -> ByteBuilder<T> {
132132
bb.bytes(value.as_fixed_bytes())
133133
}
134134

135135
#[cfg(feature = "evm")]
136136
/// Serializes H256 types as fixed bytes.
137-
pub fn serialize_h256_list<T>(
138-
bb: ByteBuilder<T>,
139-
value: &[primitive_types::H256],
140-
) -> ByteBuilder<T> {
137+
pub fn serialize_h256_list<T>(bb: ByteBuilder<T>, value: &[H256]) -> ByteBuilder<T> {
141138
bb.u64(value.len() as u64)
142139
.fold(value.iter(), serialize_h256)
143140
}
@@ -174,13 +171,13 @@ fn read_address(codec: &mut Codec<&[u8]>) -> Result<Address, ReadError> {
174171
}
175172

176173
#[cfg(feature = "evm")]
177-
fn read_h256(codec: &mut Codec<&[u8]>) -> Result<primitive_types::H256, ReadError> {
178-
Ok(primitive_types::H256::from_slice(codec.get_slice(32)?))
174+
fn read_h256(codec: &mut Codec<&[u8]>) -> Result<H256, ReadError> {
175+
Ok(H256::from_slice(codec.get_slice(32)?))
179176
}
180177

181178
#[cfg(feature = "evm")]
182-
pub fn read_u256(codec: &mut Codec<&[u8]>) -> Result<primitive_types::U256, ReadError> {
183-
Ok(primitive_types::U256::from(codec.get_slice(32)?))
179+
pub fn read_u256(codec: &mut Codec<&[u8]>) -> Result<U256, ReadError> {
180+
Ok(U256::from(codec.get_slice(32)?))
184181
}
185182

186183
#[cfg(feature = "evm")]
@@ -304,7 +301,7 @@ impl Payload for EvmTransaction {
304301
#[cfg(all(any(test, feature = "property-test-api"), feature = "evm"))]
305302
mod test {
306303
use super::*;
307-
use chain_evm::primitive_types::{H160, H256};
304+
use chain_evm::ethereum_types::H160;
308305
use quickcheck::Arbitrary;
309306

310307
impl Arbitrary for EvmTransaction {

chain-impl-mockchain/src/ledger/evm.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use chain_evm::{
77
transact_call, transact_create, transact_create2, BlockHash, BlockNumber, BlockTimestamp,
88
Config, Environment, EvmState, Log, VirtualMachine,
99
},
10-
primitive_types::{H256, U256},
1110
state::{Account, AccountTrie, LogsState},
1211
Address,
1312
};
@@ -46,7 +45,7 @@ impl EvmState for super::Ledger {
4645
self.evm.accounts = self.evm.accounts.clone().modify_account(address, f);
4746
}
4847

49-
fn update_logs(&mut self, block_hash: H256, logs: Vec<Log>) {
48+
fn update_logs(&mut self, block_hash: BlockHash, logs: Vec<Log>) {
5049
self.evm.logs.put(block_hash, logs);
5150
}
5251
}
@@ -186,12 +185,10 @@ impl Ledger {
186185
pub(crate) fn stats(&self) -> String {
187186
let Ledger { accounts, .. } = self;
188187
let mut count = 0;
189-
let mut total = U256::zero();
190-
for (_, account) in accounts {
188+
for (_, _) in accounts {
191189
count += 1;
192-
total += account.balance.into();
193190
}
194-
format!("EVM accounts: #{} Total={:?}", count, total)
191+
format!("EVM accounts: #{}", count)
195192
}
196193

197194
pub(crate) fn info_eq(&self, other: &Self) -> String {

0 commit comments

Comments
 (0)