This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
idiomatic changes to PodState #10834
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,7 @@ | |
|
||
//! State of all accounts in the system expressed in Plain Old Data. | ||
|
||
use std::fmt; | ||
use std::collections::BTreeMap; | ||
use itertools::Itertools; | ||
use ethereum_types::{H256, Address}; | ||
use triehash::sec_trie_root; | ||
use pod_account::{self, PodAccount}; | ||
|
@@ -30,12 +28,6 @@ use ethjson; | |
pub struct PodState(BTreeMap<Address, PodAccount>); | ||
|
||
impl PodState { | ||
/// Contruct a new object from the `m`. | ||
pub fn new() -> PodState { Default::default() } | ||
|
||
/// Contruct a new object from the `m`. | ||
pub fn from(m: BTreeMap<Address, PodAccount>) -> PodState { PodState(m) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved to a trait implementation |
||
|
||
/// Get the underlying map. | ||
pub fn get(&self) -> &BTreeMap<Address, PodAccount> { &self.0 } | ||
|
||
|
@@ -65,31 +57,28 @@ impl From<ethjson::spec::State> for PodState { | |
} | ||
} | ||
|
||
impl fmt::Display for PodState { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
for (add, acc) in &self.0 { | ||
writeln!(f, "{} => {}", add, acc)?; | ||
} | ||
Ok(()) | ||
impl From<BTreeMap<Address, PodAccount>> for PodState { | ||
fn from(s: BTreeMap<Address, PodAccount>) -> Self { | ||
PodState(s) | ||
} | ||
} | ||
|
||
/// Calculate and return diff between `pre` state and `post` state. | ||
pub fn diff_pod(pre: &PodState, post: &PodState) -> StateDiff { | ||
StateDiff { | ||
raw: pre.get().keys() | ||
.merge(post.get().keys()) | ||
.filter_map(|acc| pod_account::diff_pod(pre.get().get(acc), post.get().get(acc)).map(|d| (acc.clone(), d))) | ||
raw: pre.0.keys() | ||
.chain(post.0.keys()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
.filter_map(|acc| pod_account::diff_pod(pre.0.get(acc), post.0.get(acc)).map(|d| (*acc, d))) | ||
.collect() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use std::collections::BTreeMap; | ||
use types::state_diff::*; | ||
use types::account_diff::*; | ||
use pod_account::PodAccount; | ||
use types::account_diff::{AccountDiff, Diff}; | ||
use types::state_diff::StateDiff; | ||
use super::{PodState, Address}; | ||
|
||
#[test] | ||
|
@@ -102,15 +91,15 @@ mod test { | |
storage: map![], | ||
} | ||
]); | ||
assert_eq!(super::diff_pod(&a, &PodState::new()), StateDiff { raw: map![ | ||
assert_eq!(super::diff_pod(&a, &PodState::default()), StateDiff { raw: map![ | ||
Address::from_low_u64_be(1) => AccountDiff{ | ||
balance: Diff::Died(69.into()), | ||
nonce: Diff::Died(0.into()), | ||
code: Diff::Died(vec![]), | ||
storage: map![], | ||
} | ||
]}); | ||
assert_eq!(super::diff_pod(&PodState::new(), &a), StateDiff{ raw: map![ | ||
assert_eq!(super::diff_pod(&PodState::default(), &a), StateDiff{ raw: map![ | ||
Address::from_low_u64_be(1) => AccountDiff{ | ||
balance: Diff::Born(69.into()), | ||
nonce: Diff::Born(0.into()), | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Display
was never used