Skip to content

Commit 93bc0f0

Browse files
committed
Remove Address::{new, zero} and use Address::default() instead
1 parent bbc8802 commit 93bc0f0

File tree

5 files changed

+19
-27
lines changed

5 files changed

+19
-27
lines changed

core/src/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ pub fn enact(
423423
parent: &Header,
424424
is_epoch_begin: bool,
425425
) -> Result<LockedBlock, Error> {
426-
let mut b = OpenBlock::new(engine, db, parent, Address::new(), vec![], is_epoch_begin)?;
426+
let mut b = OpenBlock::new(engine, db, parent, Address::default(), vec![], is_epoch_begin)?;
427427

428428
b.populate_from(header);
429429
b.push_parcels(parcels)?;
@@ -444,7 +444,7 @@ mod tests {
444444
let spec = Spec::new_test();
445445
let genesis_header = spec.genesis_header();
446446
let db = spec.ensure_genesis_state(get_temp_state_db()).unwrap();
447-
let b = OpenBlock::new(&*spec.engine, db, &genesis_header, Address::zero(), vec![], false).unwrap();
447+
let b = OpenBlock::new(&*spec.engine, db, &genesis_header, Address::default(), vec![], false).unwrap();
448448
let parent_parcels_root = genesis_header.parcels_root().clone();
449449
let parent_invoices_root = genesis_header.invoices_root().clone();
450450
let b = b.close_and_lock(parent_parcels_root, parent_invoices_root);

core/src/miner/sealing_queue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ mod tests {
9494
#[test]
9595
fn should_not_find_when_pushed() {
9696
let mut q = SealingQueue::new(QUEUE_SIZE);
97-
let b = create_closed_block(Address::zero());
97+
let b = create_closed_block(Address::default());
9898
let h = b.hash();
9999

100100
q.push(b);
@@ -105,7 +105,7 @@ mod tests {
105105
#[test]
106106
fn should_find_when_pushed_and_used() {
107107
let mut q = SealingQueue::new(QUEUE_SIZE);
108-
let b = create_closed_block(Address::zero());
108+
let b = create_closed_block(Address::default());
109109
let h = b.hash();
110110

111111
q.push(b);

core/src/spec/genesis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl From<cjson::spec::Genesis> for Genesis {
4848
Genesis {
4949
seal: From::from(g.seal),
5050
score: g.score.into(),
51-
author: g.author.map_or_else(Address::zero, Into::into),
51+
author: g.author.map_or_else(Address::default, Into::into),
5252
timestamp: g.timestamp.map_or(0, Into::into),
5353
parent_hash: g.parent_hash.map_or_else(H256::zero, Into::into),
5454
parcels_root: g.parcels_root.map_or_else(|| BLAKE_NULL_RLP.clone(), Into::into),

key/src/address.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ use super::{Error, Network};
3434
pub struct Address(H160);
3535

3636
impl Address {
37-
pub fn zero() -> Self {
38-
Address(H160::zero())
39-
}
40-
41-
pub fn new() -> Self {
42-
Address(H160::new())
43-
}
44-
4537
pub fn random() -> Self {
4638
Address(H160::random())
4739
}

state/src/impls/top_level.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ impl TopLevelState {
552552
ctrace!(STATE, "shard created({}, {:?})", shard_id, shard_root);
553553

554554
self.set_shard_root(shard_id, &BLAKE_NULL_RLP, &shard_root)?;
555-
self.set_shard_owner(shard_id, &Address::zero(), *fee_payer)?;
555+
self.set_shard_owner(shard_id, &Address::default(), *fee_payer)?;
556556
Ok(())
557557
}
558558

@@ -628,7 +628,7 @@ impl TopLevelState {
628628
}
629629

630630
fn require_shard<'a>(&'a self, shard_id: ShardId) -> TrieResult<RefMut<'a, Shard>> {
631-
let default = || Shard::new(BLAKE_NULL_RLP, Address::zero());
631+
let default = || Shard::new(BLAKE_NULL_RLP, Address::default());
632632
let db = TrieFactory::readonly(self.db.as_hashdb(), &self.root)?;
633633
let shard_address = ShardAddress::new(shard_id);
634634
let from_db = || self.db.get_cached_shard(&shard_address);
@@ -822,7 +822,7 @@ mod tests_state {
822822

823823
#[test]
824824
fn should_work_when_cloned() {
825-
let a = Address::zero();
825+
let a = Address::default();
826826

827827
let mut state = {
828828
let mut state = get_temp_state();
@@ -855,7 +855,7 @@ mod tests_state {
855855

856856
#[test]
857857
fn get_from_database() {
858-
let a = Address::zero();
858+
let a = Address::default();
859859
let (root, db) = {
860860
let mut state = get_temp_state();
861861
assert_eq!(Ok(()), state.inc_nonce(&a));
@@ -872,7 +872,7 @@ mod tests_state {
872872

873873
#[test]
874874
fn remove() {
875-
let a = Address::zero();
875+
let a = Address::default();
876876
let mut state = get_temp_state();
877877
assert_eq!(Ok(false), state.account_exists(&a));
878878
assert_eq!(Ok(false), state.account_exists_and_not_null(&a));
@@ -888,7 +888,7 @@ mod tests_state {
888888

889889
#[test]
890890
fn empty_account_is_not_created() {
891-
let a = Address::zero();
891+
let a = Address::default();
892892
let db = get_temp_state_db();
893893
let (root, db) = {
894894
let mut state = TopLevelState::new(db);
@@ -903,7 +903,7 @@ mod tests_state {
903903

904904
#[test]
905905
fn remove_from_database() {
906-
let a = Address::zero();
906+
let a = Address::default();
907907
let (root, db) = {
908908
let mut state = get_temp_state();
909909
assert_eq!(Ok(()), state.inc_nonce(&a));
@@ -932,7 +932,7 @@ mod tests_state {
932932
#[test]
933933
fn alter_balance() {
934934
let mut state = get_temp_state();
935-
let a = Address::zero();
935+
let a = Address::default();
936936
let b = 1u64.into();
937937
assert_eq!(Ok(()), state.add_balance(&a, &U256::from(69u64)));
938938
assert_eq!(Ok(69.into()), state.balance(&a));
@@ -953,7 +953,7 @@ mod tests_state {
953953
#[test]
954954
fn alter_nonce() {
955955
let mut state = get_temp_state();
956-
let a = Address::zero();
956+
let a = Address::default();
957957
assert_eq!(Ok(()), state.inc_nonce(&a));
958958
assert_eq!(Ok(1.into()), state.nonce(&a));
959959
assert_eq!(Ok(()), state.inc_nonce(&a));
@@ -969,7 +969,7 @@ mod tests_state {
969969
#[test]
970970
fn balance_nonce() {
971971
let mut state = get_temp_state();
972-
let a = Address::zero();
972+
let a = Address::default();
973973
assert_eq!(Ok(0.into()), state.balance(&a));
974974
assert_eq!(Ok(0.into()), state.nonce(&a));
975975
assert_eq!(Ok(()), state.commit());
@@ -980,7 +980,7 @@ mod tests_state {
980980
#[test]
981981
fn ensure_cached() {
982982
let mut state = get_temp_state();
983-
let a = Address::zero();
983+
let a = Address::default();
984984
state.require_account(&a).unwrap();
985985
assert_eq!(Ok(()), state.commit());
986986
assert_eq!(*state.root(), "db4046bb91a12a37cbfb0f09631aad96a97248423163eca791e19b430cc7fe4a".into());
@@ -989,7 +989,7 @@ mod tests_state {
989989
#[test]
990990
fn checkpoint_basic() {
991991
let mut state = get_temp_state();
992-
let a = Address::zero();
992+
let a = Address::default();
993993
state.create_checkpoint(0);
994994
assert_eq!(Ok(()), state.add_balance(&a, &U256::from(69u64)));
995995
assert_eq!(Ok(69.into()), state.balance(&a));
@@ -1005,7 +1005,7 @@ mod tests_state {
10051005
#[test]
10061006
fn checkpoint_nested() {
10071007
let mut state = get_temp_state();
1008-
let a = Address::zero();
1008+
let a = Address::default();
10091009
state.create_checkpoint(0);
10101010
assert_eq!(Ok(()), state.add_balance(&a, &U256::from(69u64)));
10111011
state.create_checkpoint(1);
@@ -1020,7 +1020,7 @@ mod tests_state {
10201020
#[test]
10211021
fn checkpoint_discard() {
10221022
let mut state = get_temp_state();
1023-
let a = Address::zero();
1023+
let a = Address::default();
10241024
state.create_checkpoint(0);
10251025
assert_eq!(Ok(()), state.add_balance(&a, &U256::from(69u64)));
10261026
state.create_checkpoint(1);

0 commit comments

Comments
 (0)