Skip to content

Commit

Permalink
change how we serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
Agustin Chiappe Berrini committed Sep 26, 2019
1 parent d1bc786 commit 0908b63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 56 deletions.
55 changes: 23 additions & 32 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 1 addition & 24 deletions world/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::ser::SerializeStruct;
pub mod pool;

/// Core data structure for interacting with the EVM
#[derive(Debug, Default, Clone, PartialEq)]
#[derive(Debug, Default, Deserialize, Clone, PartialEq, Serialize)]
pub struct Transaction {
/// Nonce
pub nonce: U256,
Expand All @@ -29,29 +29,6 @@ pub struct Transaction {
pub s: U256,
}

impl Serialize for Transaction {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut state = serializer.serialize_struct("Transaction", 9)?;
state.serialize_field("nonce", &self.nonce.as_u64())?;
state.serialize_field("gasPrice", &self.gas_price.as_u64())?;
state.serialize_field("startGas", &self.start_gas.as_u64())?;
if self.to.is_none() {
state.serialize_field("to", &0)?;
} else {
state.serialize_field("to", &self.value.as_u64())?;
}
state.serialize_field("value", &self.value.as_u64())?;
state.serialize_field("data", &self.data)?;
state.serialize_field("v", &self.v.as_u64())?;
state.serialize_field("r", &self.r.as_u64())?;
state.serialize_field("s", &self.s.as_u64())?;
state.end()
}
}

/// A valid transaction is one where:
/// (i) the signature is well-formed (ie. 0 <= v <= 3, 0 <= r < P, 0 <= s < N, 0 <= r < P - N if v >= 2),
/// and (ii) the sending account has enough funds to pay the fee and the value.
Expand Down

0 comments on commit 0908b63

Please sign in to comment.