aboutsummaryrefslogtreecommitdiff
path: root/src/transaction
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2022-05-31 21:18:36 +0200
committerNicholas Rodrigues Lordello <[email protected]>2022-05-31 21:18:36 +0200
commit7517ff3454a1d3c8811d1eb8d8be8cef23aba001 (patch)
treece673b61a89c06a5c26a0b980e27c3e53d3ce8aa /src/transaction
parentc5d2ec6c93a40af460e35d9171dd7966e97a0c75 (diff)
Hash more types
Diffstat (limited to 'src/transaction')
-rw-r--r--src/transaction/accesslist.rs12
-rw-r--r--src/transaction/eip1559.rs30
-rw-r--r--src/transaction/eip2930.rs27
-rw-r--r--src/transaction/legacy.rs22
4 files changed, 42 insertions, 49 deletions
diff --git a/src/transaction/accesslist.rs b/src/transaction/accesslist.rs
index 507b73e..0147350 100644
--- a/src/transaction/accesslist.rs
+++ b/src/transaction/accesslist.rs
@@ -1,7 +1,8 @@
//! Module with EIP-2930 access list type definition with RLP encoding and JSON
//! serialization implementation.
-use crate::{account::Address, serialization, transaction::rlp};
+use crate::{serialization, transaction::rlp};
+use ethaddr::Address;
use serde::Deserialize;
/// An Ethereum virtual machine storage slot.
@@ -36,6 +37,7 @@ impl AccessList {
#[cfg(test)]
mod tests {
use super::*;
+ use ethaddr::address;
use hex_literal::hex;
use serde_json::json;
@@ -55,7 +57,7 @@ mod tests {
.unwrap(),
AccessList(vec![
(
- Address(hex!("de0b295669a9fd93d5f28d9ec85e40f4cb697bae")),
+ address!("0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe"),
vec![
StorageSlot(hex!(
"0000000000000000000000000000000000000000000000000000000000000003"
@@ -66,7 +68,7 @@ mod tests {
]
),
(
- Address(hex!("bb9bc244d798123fde783fcc1c72d3bb8c189413")),
+ address!("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413"),
vec![]
)
]),
@@ -78,7 +80,7 @@ mod tests {
assert_eq!(
AccessList(vec![
(
- Address(hex!("de0b295669a9fd93d5f28d9ec85e40f4cb697bae")),
+ address!("0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe"),
vec![
StorageSlot(hex!(
"0000000000000000000000000000000000000000000000000000000000000003"
@@ -89,7 +91,7 @@ mod tests {
]
),
(
- Address(hex!("bb9bc244d798123fde783fcc1c72d3bb8c189413")),
+ address!("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413"),
vec![]
)
])
diff --git a/src/transaction/eip1559.rs b/src/transaction/eip1559.rs
index 765ce97..f93b931 100644
--- a/src/transaction/eip1559.rs
+++ b/src/transaction/eip1559.rs
@@ -1,11 +1,9 @@
//! EIp-1559 Ethereum transaction with base gas pricing type definition and RLP encoding.
use crate::{
- account::{Address, Signature},
- serialization,
- transaction::accesslist::AccessList,
- transaction::rlp,
+ account::Signature, serialization, transaction::accesslist::AccessList, transaction::rlp,
};
+use ethaddr::Address;
use ethnum::U256;
use serde::Deserialize;
@@ -13,28 +11,25 @@ use serde::Deserialize;
#[derive(Clone, Debug, Deserialize, PartialEq)]
pub struct Eip1559Transaction {
/// The chain ID for the transaction.
- #[serde(rename = "chainId")]
- #[serde(with = "serialization::u256")]
+ #[serde(rename = "chainId", with = "ethnum::serde::permissive")]
pub chain_id: U256,
/// The nonce for the transaction.
- #[serde(with = "serialization::u256")]
+ #[serde(with = "ethnum::serde::permissive")]
pub nonce: U256,
/// The maximum priority fee in Wei for the transaction.
- #[serde(rename = "maxPriorityFeePerGas")]
- #[serde(with = "serialization::u256")]
+ #[serde(rename = "maxPriorityFeePerGas", with = "ethnum::serde::permissive")]
pub max_priority_fee_per_gas: U256,
/// The maximum gas price in Wei for the transaction.
- #[serde(rename = "maxFeePerGas")]
- #[serde(with = "serialization::u256")]
+ #[serde(rename = "maxFeePerGas", with = "ethnum::serde::permissive")]
pub max_fee_per_gas: U256,
/// The gas limit for the transaction.
- #[serde(with = "serialization::u256")]
+ #[serde(with = "ethnum::serde::permissive")]
pub gas: U256,
/// The target address for the transaction. This can also be `None` to
/// indicate a contract creation transaction.
pub to: Option<Address>,
/// The amount of Ether to send with the transaction.
- #[serde(with = "serialization::u256")]
+ #[serde(with = "ethnum::serde::permissive")]
pub value: U256,
/// The calldata to use for the transaction.
#[serde(with = "serialization::bytes")]
@@ -81,6 +76,7 @@ impl Eip1559Transaction {
mod tests {
use super::*;
use crate::transaction::accesslist::StorageSlot;
+ use ethaddr::address;
use ethnum::AsU256 as _;
use hex_literal::hex;
use serde_json::json;
@@ -119,7 +115,7 @@ mod tests {
let deserialized = serde_json::from_value::<Eip1559Transaction>(tx).unwrap();
assert_eq!(
deserialized.to.unwrap(),
- Address(hex!("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef")),
+ address!("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF"),
);
assert_eq!(
deserialized.access_list,
@@ -136,7 +132,7 @@ mod tests {
max_priority_fee_per_gas: 28e9.as_u256(),
max_fee_per_gas: 42e9.as_u256(),
gas: 30_000.as_u256(),
- to: Some(Address(hex!("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"))),
+ to: Some(address!("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF")),
value: 13.37e18.as_u256(),
data: vec![],
access_list: AccessList::default(),
@@ -164,7 +160,7 @@ mod tests {
.to_vec(),
access_list: AccessList(vec![
(
- Address(hex!("1111111111111111111111111111111111111111")),
+ address!("0x1111111111111111111111111111111111111111"),
vec![
StorageSlot(hex!(
"a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0"
@@ -175,7 +171,7 @@ mod tests {
],
),
(
- Address(hex!("2222222222222222222222222222222222222222")),
+ address!("0x2222222222222222222222222222222222222222"),
vec![],
),
]),
diff --git a/src/transaction/eip2930.rs b/src/transaction/eip2930.rs
index 4a8bcf8..5cd0f02 100644
--- a/src/transaction/eip2930.rs
+++ b/src/transaction/eip2930.rs
@@ -1,11 +1,9 @@
//! EIp-2930 Ethereum transaction with access list type definition and RLP encoding.
use crate::{
- account::{Address, Signature},
- serialization,
- transaction::accesslist::AccessList,
- transaction::rlp,
+ account::Signature, serialization, transaction::accesslist::AccessList, transaction::rlp,
};
+use ethaddr::Address;
use ethnum::U256;
use serde::Deserialize;
@@ -13,24 +11,22 @@ use serde::Deserialize;
#[derive(Clone, Debug, Deserialize, PartialEq)]
pub struct Eip2930Transaction {
/// The chain ID for the transaction.
- #[serde(rename = "chainId")]
- #[serde(with = "serialization::u256")]
+ #[serde(rename = "chainId", with = "ethnum::serde::permissive")]
pub chain_id: U256,
/// The nonce for the transaction.
- #[serde(with = "serialization::u256")]
+ #[serde(with = "ethnum::serde::permissive")]
pub nonce: U256,
/// The gas price in Wei for the transaction.
- #[serde(rename = "gasPrice")]
- #[serde(with = "serialization::u256")]
+ #[serde(rename = "gasPrice", with = "ethnum::serde::permissive")]
pub gas_price: U256,
/// The gas limit for the transaction.
- #[serde(with = "serialization::u256")]
+ #[serde(with = "ethnum::serde::permissive")]
pub gas: U256,
/// The target address for the transaction. This can also be `None` to
/// indicate a contract creation transaction.
pub to: Option<Address>,
/// The amount of Ether to send with the transaction.
- #[serde(with = "serialization::u256")]
+ #[serde(with = "ethnum::serde::permissive")]
pub value: U256,
/// The calldata to use for the transaction.
#[serde(with = "serialization::bytes")]
@@ -75,6 +71,7 @@ impl Eip2930Transaction {
mod tests {
use super::*;
use crate::transaction::accesslist::StorageSlot;
+ use ethaddr::address;
use ethnum::AsU256 as _;
use hex_literal::hex;
use serde_json::json;
@@ -110,7 +107,7 @@ mod tests {
.unwrap()
.to
.unwrap(),
- Address(hex!("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef")),
+ address!("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF"),
);
}
@@ -122,7 +119,7 @@ mod tests {
nonce: 66.as_u256(),
gas_price: 42e9.as_u256(),
gas: 30_000.as_u256(),
- to: Some(Address(hex!("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"))),
+ to: Some(address!("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF")),
value: 13.37e18.as_u256(),
data: vec![],
access_list: AccessList::default(),
@@ -149,7 +146,7 @@ mod tests {
.to_vec(),
access_list: AccessList(vec![
(
- Address(hex!("1111111111111111111111111111111111111111")),
+ address!("0x1111111111111111111111111111111111111111"),
vec![
StorageSlot(hex!(
"a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0"
@@ -160,7 +157,7 @@ mod tests {
],
),
(
- Address(hex!("2222222222222222222222222222222222222222")),
+ address!("0x2222222222222222222222222222222222222222"),
vec![],
),
]),
diff --git a/src/transaction/legacy.rs b/src/transaction/legacy.rs
index 9e0f9bc..231d9f8 100644
--- a/src/transaction/legacy.rs
+++ b/src/transaction/legacy.rs
@@ -1,10 +1,7 @@
//! Legacy Ethereum transaction type definition and RLP encoding.
-use crate::{
- account::{Address, Signature},
- serialization,
- transaction::rlp,
-};
+use crate::{account::Signature, serialization, transaction::rlp};
+use ethaddr::Address;
use ethnum::U256;
use serde::Deserialize;
@@ -12,25 +9,25 @@ use serde::Deserialize;
#[derive(Clone, Debug, Deserialize, PartialEq)]
pub struct LegacyTransaction {
/// The nonce for the transaction.
- #[serde(with = "serialization::u256")]
+ #[serde(with = "ethnum::serde::permissive")]
pub nonce: U256,
/// The gas price in Wei for the transaction.
- #[serde(rename = "gasPrice", with = "serialization::u256")]
+ #[serde(rename = "gasPrice", with = "ethnum::serde::permissive")]
pub gas_price: U256,
/// The gas limit for the transaction.
- #[serde(with = "serialization::u256")]
+ #[serde(with = "ethnum::serde::permissive")]
pub gas: U256,
/// The target address for the transaction. This can also be `None` to
/// indicate a contract creation transaction.
pub to: Option<Address>,
/// The amount of Ether to send with the transaction.
- #[serde(with = "serialization::u256")]
+ #[serde(with = "ethnum::serde::permissive")]
pub value: U256,
/// The calldata to use for the transaction.
#[serde(with = "serialization::bytes")]
pub data: Vec<u8>,
/// Optional chain ID for the transaction.
- #[serde(default, rename = "chainId", with = "serialization::u256::option")]
+ #[serde(default, rename = "chainId", with = "serialization::numopt")]
pub chain_id: Option<U256>,
}
@@ -59,6 +56,7 @@ impl LegacyTransaction {
#[cfg(test)]
mod tests {
use super::*;
+ use ethaddr::address;
use ethnum::AsU256 as _;
use hex_literal::hex;
use serde_json::json;
@@ -92,7 +90,7 @@ mod tests {
.unwrap()
.to
.unwrap(),
- Address(hex!("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef")),
+ address!("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF"),
);
}
@@ -104,7 +102,7 @@ mod tests {
nonce: 66.as_u256(),
gas_price: 42e9.as_u256(),
gas: 30_000.as_u256(),
- to: Some(Address(hex!("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"))),
+ to: Some(address!("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF")),
value: 13.37e18.as_u256(),
data: vec![],
}