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

Commit

Permalink
Merge pull request #1192 from rphmeier/x_macros
Browse files Browse the repository at this point in the history
expunge x! and xx! from the codebase
  • Loading branch information
arkpar committed Jun 1, 2016
2 parents 3dd642a + bbb858b commit e743972
Show file tree
Hide file tree
Showing 24 changed files with 368 additions and 362 deletions.
18 changes: 9 additions & 9 deletions ethcore/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ mod tests {
let mut db = MemoryDB::new();
let mut db = AccountDBMut::new(&mut db, &Address::new());
let rlp = {
let mut a = Account::new_contract(x!(69), x!(0));
let mut a = Account::new_contract(69.into(), 0.into());
a.set_storage(H256::from(&U256::from(0x00u64)), H256::from(&U256::from(0x1234u64)));
a.commit_storage(&mut db);
a.init_code(vec![]);
Expand All @@ -281,7 +281,7 @@ mod tests {
let mut db = AccountDBMut::new(&mut db, &Address::new());

let rlp = {
let mut a = Account::new_contract(x!(69), x!(0));
let mut a = Account::new_contract(69.into(), 0.into());
a.init_code(vec![0x55, 0x44, 0xffu8]);
a.commit_code(&mut db);
a.rlp()
Expand All @@ -296,32 +296,32 @@ mod tests {

#[test]
fn commit_storage() {
let mut a = Account::new_contract(x!(69), x!(0));
let mut a = Account::new_contract(69.into(), 0.into());
let mut db = MemoryDB::new();
let mut db = AccountDBMut::new(&mut db, &Address::new());
a.set_storage(x!(0), x!(0x1234));
a.set_storage(0.into(), 0x1234.into());
assert_eq!(a.storage_root(), None);
a.commit_storage(&mut db);
assert_eq!(a.storage_root().unwrap().hex(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2");
}

#[test]
fn commit_remove_commit_storage() {
let mut a = Account::new_contract(x!(69), x!(0));
let mut a = Account::new_contract(69.into(), 0.into());
let mut db = MemoryDB::new();
let mut db = AccountDBMut::new(&mut db, &Address::new());
a.set_storage(x!(0), x!(0x1234));
a.set_storage(0.into(), 0x1234.into());
a.commit_storage(&mut db);
a.set_storage(x!(1), x!(0x1234));
a.set_storage(1.into(), 0x1234.into());
a.commit_storage(&mut db);
a.set_storage(x!(1), x!(0));
a.set_storage(1.into(), 0.into());
a.commit_storage(&mut db);
assert_eq!(a.storage_root().unwrap().hex(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2");
}

#[test]
fn commit_code() {
let mut a = Account::new_contract(x!(69), x!(0));
let mut a = Account::new_contract(69.into(), 0.into());
let mut db = MemoryDB::new();
let mut db = AccountDBMut::new(&mut db, &Address::new());
a.init_code(vec![0x55, 0x44, 0xffu8]);
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/account_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'db> AccountDB<'db> {
pub fn new(db: &'db HashDB, address: &Address) -> AccountDB<'db> {
AccountDB {
db: db,
address: x!(address),
address: address.into(),
}
}
}
Expand Down Expand Up @@ -67,7 +67,7 @@ impl<'db> AccountDBMut<'db> {
pub fn new(db: &'db mut HashDB, address: &Address) -> AccountDBMut<'db> {
AccountDBMut {
db: db,
address: x!(address),
address: address.into(),
}
}

Expand Down
14 changes: 7 additions & 7 deletions ethcore/src/basic_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ impl Engine for BasicAuthority {
let gas_limit = parent.gas_limit;
let bound_divisor = self.our_params.gas_limit_bound_divisor;
if gas_limit < gas_floor_target {
min(gas_floor_target, gas_limit + gas_limit / bound_divisor - x!(1))
min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into())
} else {
max(gas_floor_target, gas_limit - gas_limit / bound_divisor + x!(1))
max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into())
}
};
header.note_dirty();
Expand Down Expand Up @@ -211,12 +211,12 @@ mod tests {
let engine = new_test_authority().engine;
let schedule = engine.schedule(&EnvInfo {
number: 10000000,
author: x!(0),
author: 0.into(),
timestamp: 0,
difficulty: x!(0),
difficulty: 0.into(),
last_hashes: vec![],
gas_used: x!(0),
gas_limit: x!(0)
gas_used: 0.into(),
gas_limit: 0.into()
});

assert!(schedule.stack_limit > 0);
Expand Down Expand Up @@ -278,7 +278,7 @@ mod tests {
spec.ensure_db_good(db.as_hashdb_mut());
let last_hashes = vec![genesis_header.hash()];
let vm_factory = Default::default();
let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, addr.clone(), x!(3141562), vec![]);
let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, addr.clone(), 3141562.into(), vec![]);
let b = b.close_and_lock();
let seal = engine.generate_seal(b.block(), Some(&tap)).unwrap();

Expand Down
8 changes: 4 additions & 4 deletions ethcore/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ pub fn enact(header: &Header, transactions: &[SignedTransaction], uncles: &[Head
}
}

let mut b = OpenBlock::new(engine, vm_factory, tracing, db, parent, last_hashes, header.author().clone(), x!(3141562), header.extra_data().clone());
let mut b = OpenBlock::new(engine, vm_factory, tracing, db, parent, last_hashes, header.author().clone(), 3141562.into(), header.extra_data().clone());
b.set_difficulty(*header.difficulty());
b.set_gas_limit(*header.gas_limit());
b.set_timestamp(header.timestamp());
Expand Down Expand Up @@ -514,7 +514,7 @@ mod tests {
spec.ensure_db_good(db.as_hashdb_mut());
let last_hashes = vec![genesis_header.hash()];
let vm_factory = Default::default();
let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, Address::zero(), x!(3141562), vec![]);
let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, Address::zero(), 3141562.into(), vec![]);
let b = b.close_and_lock();
let _ = b.seal(engine.deref(), vec![]);
}
Expand All @@ -530,7 +530,7 @@ mod tests {
let mut db = db_result.take();
spec.ensure_db_good(db.as_hashdb_mut());
let vm_factory = Default::default();
let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, vec![genesis_header.hash()], Address::zero(), x!(3141562), vec![]).close_and_lock().seal(engine.deref(), vec![]).unwrap();
let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, vec![genesis_header.hash()], Address::zero(), 3141562.into(), vec![]).close_and_lock().seal(engine.deref(), vec![]).unwrap();
let orig_bytes = b.rlp_bytes();
let orig_db = b.drain();

Expand All @@ -557,7 +557,7 @@ mod tests {
let mut db = db_result.take();
spec.ensure_db_good(db.as_hashdb_mut());
let vm_factory = Default::default();
let mut open_block = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, vec![genesis_header.hash()], Address::zero(), x!(3141562), vec![]);
let mut open_block = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, vec![genesis_header.hash()], Address::zero(), 3141562.into(), vec![]);
let mut uncle1_header = Header::new();
uncle1_header.extra_data = b"uncle1".to_vec();
let mut uncle2_header = Header::new();
Expand Down
6 changes: 3 additions & 3 deletions ethcore/src/block_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,17 @@ impl BlockQueue {
let h = header.hash();
{
if self.processing.read().unwrap().contains(&h) {
return Err(x!(ImportError::AlreadyQueued));
return Err(ImportError::AlreadyQueued.into());
}

let mut bad = self.verification.bad.lock().unwrap();
if bad.contains(&h) {
return Err(x!(ImportError::KnownBad));
return Err(ImportError::KnownBad.into());
}

if bad.contains(&header.parent_hash) {
bad.insert(h.clone());
return Err(x!(ImportError::KnownBad));
return Err(ImportError::KnownBad.into());
}
}

Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,10 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
{
let header = BlockView::new(&bytes).header_view();
if self.chain.is_known(&header.sha3()) {
return Err(x!(ImportError::AlreadyInChain));
return Err(ImportError::AlreadyInChain.into());
}
if self.block_status(BlockID::Hash(header.parent_hash())) == BlockStatus::Unknown {
return Err(x!(BlockError::UnknownParent(header.parent_hash())));
return Err(BlockError::UnknownParent(header.parent_hash()).into());
}
}
self.block_queue.import_block(bytes)
Expand Down
14 changes: 7 additions & 7 deletions ethcore/src/env_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ impl Default for EnvInfo {
number: 0,
author: Address::new(),
timestamp: 0,
difficulty: x!(0),
gas_limit: x!(0),
difficulty: 0.into(),
gas_limit: 0.into(),
last_hashes: vec![],
gas_used: x!(0),
gas_used: 0.into(),
}
}
}
Expand Down Expand Up @@ -92,15 +92,15 @@ mod tests {

assert_eq!(env_info.number, 1112339);
assert_eq!(env_info.author, Address::from_str("000000f00000000f000000000000f00000000f00").unwrap());
assert_eq!(env_info.gas_limit, x!(40000));
assert_eq!(env_info.difficulty, x!(50000));
assert_eq!(env_info.gas_used, x!(0));
assert_eq!(env_info.gas_limit, 40000.into());
assert_eq!(env_info.difficulty, 50000.into());
assert_eq!(env_info.gas_used, 0.into());
}

#[test]
fn it_can_be_created_as_default() {
let default_env_info = EnvInfo::default();

assert_eq!(default_env_info.difficulty, x!(0));
assert_eq!(default_env_info.difficulty, 0.into());
}
}
28 changes: 14 additions & 14 deletions ethcore/src/ethereum/ethash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ impl Engine for Ethash {
let gas_limit = parent.gas_limit;
let bound_divisor = self.ethash_params.gas_limit_bound_divisor;
if gas_limit < gas_floor_target {
min(gas_floor_target, gas_limit + gas_limit / bound_divisor - x!(1))
min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into())
} else {
max(gas_floor_target, gas_limit - gas_limit / bound_divisor + x!(1) + (header.gas_used * x!(6) / x!(5)) / bound_divisor)
max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into() + (header.gas_used * 6.into() / 5.into()) / bound_divisor)
}
};
header.note_dirty();
Expand Down Expand Up @@ -255,12 +255,12 @@ impl Ethash {

/// Convert an Ethash boundary to its original difficulty. Basically just `f(x) = 2^256 / x`.
pub fn boundary_to_difficulty(boundary: &H256) -> U256 {
U256::from((U512::one() << 256) / x!(U256::from(boundary.as_slice())))
U256::from((U512::one() << 256) / U256::from(boundary.as_slice()).into())
}

/// Convert an Ethash difficulty to the target boundary. Basically just `f(x) = 2^256 / x`.
pub fn difficulty_to_boundary(difficulty: &U256) -> H256 {
x!(U256::from((U512::one() << 256) / x!(difficulty)))
U256::from((U512::one() << 256) / difficulty.into()).into()
}

fn to_ethash(hash: H256) -> EH256 {
Expand Down Expand Up @@ -308,7 +308,7 @@ mod tests {
spec.ensure_db_good(db.as_hashdb_mut());
let last_hashes = vec![genesis_header.hash()];
let vm_factory = Default::default();
let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, Address::zero(), x!(3141562), vec![]);
let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, Address::zero(), 3141562.into(), vec![]);
let b = b.close();
assert_eq!(b.state().balance(&Address::zero()), U256::from_str("4563918244f40000").unwrap());
}
Expand All @@ -323,7 +323,7 @@ mod tests {
spec.ensure_db_good(db.as_hashdb_mut());
let last_hashes = vec![genesis_header.hash()];
let vm_factory = Default::default();
let mut b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, Address::zero(), x!(3141562), vec![]);
let mut b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, Address::zero(), 3141562.into(), vec![]);
let mut uncle = Header::new();
let uncle_author = address_from_hex("ef2d6d194084c2de36e0dabfce45d046b37d1106");
uncle.author = uncle_author.clone();
Expand All @@ -346,24 +346,24 @@ mod tests {
let engine = new_morden().engine;
let schedule = engine.schedule(&EnvInfo {
number: 10000000,
author: x!(0),
author: 0.into(),
timestamp: 0,
difficulty: x!(0),
difficulty: 0.into(),
last_hashes: vec![],
gas_used: x!(0),
gas_limit: x!(0)
gas_used: 0.into(),
gas_limit: 0.into()
});

assert!(schedule.stack_limit > 0);

let schedule = engine.schedule(&EnvInfo {
number: 100,
author: x!(0),
author: 0.into(),
timestamp: 0,
difficulty: x!(0),
difficulty: 0.into(),
last_hashes: vec![],
gas_used: x!(0),
gas_limit: x!(0)
gas_used: 0.into(),
gas_limit: 0.into()
});

assert!(!schedule.have_delegate_call);
Expand Down
20 changes: 10 additions & 10 deletions ethcore/src/executive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ impl<'a> Executive<'a> {
let refunds_bound = sstore_refunds + suicide_refunds;

// real ammount to refund
let gas_left_prerefund = match result { Ok(x) => x, _ => x!(0) };
let gas_left_prerefund = match result { Ok(x) => x, _ => 0.into() };
let refunded = cmp::min(refunds_bound, (t.gas - gas_left_prerefund) / U256::from(2));
let gas_left = gas_left_prerefund + refunded;

Expand Down Expand Up @@ -588,10 +588,10 @@ mod tests {
let expected_trace = vec![ Trace {
depth: 0,
action: trace::Action::Call(trace::Call {
from: x!("cd1722f3947def4cf144679da39c4c32bdc35681"),
to: x!("b010143a42d5980c7e5ef0e4a4416dc098a4fed3"),
value: x!(100),
gas: x!(100000),
from: "cd1722f3947def4cf144679da39c4c32bdc35681".into(),
to: "b010143a42d5980c7e5ef0e4a4416dc098a4fed3".into(),
value: 100.into(),
gas: 100000.into(),
input: vec![],
}),
result: trace::Res::Call(trace::CallResult {
Expand All @@ -601,9 +601,9 @@ mod tests {
subs: vec![Trace {
depth: 1,
action: trace::Action::Create(trace::Create {
from: x!("b010143a42d5980c7e5ef0e4a4416dc098a4fed3"),
value: x!(23),
gas: x!(67979),
from: "b010143a42d5980c7e5ef0e4a4416dc098a4fed3".into(),
value: 23.into(),
gas: 67979.into(),
init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85]
}),
result: trace::Res::Create(trace::CreateResult {
Expand Down Expand Up @@ -642,7 +642,7 @@ mod tests {
params.origin = sender.clone();
params.gas = U256::from(100_000);
params.code = Some(code.clone());
params.value = ActionValue::Transfer(x!(100));
params.value = ActionValue::Transfer(100.into());
let mut state_result = get_temp_state();
let mut state = state_result.reference_mut();
state.add_balance(&sender, &U256::from(100));
Expand All @@ -660,7 +660,7 @@ mod tests {
depth: 0,
action: trace::Action::Create(trace::Create {
from: params.sender,
value: x!(100),
value: 100.into(),
gas: params.gas,
init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85],
}),
Expand Down
8 changes: 4 additions & 4 deletions ethcore/src/externalities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ mod tests {
fn get_test_env_info() -> EnvInfo {
EnvInfo {
number: 100,
author: x!(0),
author: 0.into(),
timestamp: 0,
difficulty: x!(0),
difficulty: 0.into(),
last_hashes: vec![],
gas_used: x!(0),
gas_limit: x!(0)
gas_used: 0.into(),
gas_limit: 0.into()
}
}

Expand Down
Loading

0 comments on commit e743972

Please sign in to comment.