From 92cb381c67fb90412034135c17737cf7c7f190f5 Mon Sep 17 00:00:00 2001 From: Miguel Oliveira Date: Mon, 29 Jul 2024 17:37:34 -0300 Subject: [PATCH 1/6] replace type, change type of result and add type in mod.rs --- crates/eips/src/eip2930.rs | 13 ++++++++----- crates/provider/src/provider/trait.rs | 5 ++--- crates/rpc-types-eth/src/transaction/mod.rs | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/eips/src/eip2930.rs b/crates/eips/src/eip2930.rs index 2686d7bf8ec..fabaed9af03 100644 --- a/crates/eips/src/eip2930.rs +++ b/crates/eips/src/eip2930.rs @@ -130,15 +130,17 @@ impl AccessList { } } -/// Access list with gas used appended. +/// `AccessListResult` for handling errors from `eth_createAccessList` #[derive(Clone, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] -pub struct AccessListWithGasUsed { +pub struct AccessListResult { /// List with accounts accessed during transaction. pub access_list: AccessList, /// Estimated gas used with access list. pub gas_used: U256, + /// Optional error message if the transaction failed. + #[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "Option::is_none"))] + pub error: Option, } #[cfg(all(test, feature = "serde"))] @@ -158,15 +160,16 @@ mod tests { #[test] fn access_list_with_gas_used() { - let list = AccessListWithGasUsed { + let list = AccessListResult { access_list: AccessList(vec![ AccessListItem { address: Address::ZERO, storage_keys: vec![B256::ZERO] }, AccessListItem { address: Address::ZERO, storage_keys: vec![B256::ZERO] }, ]), gas_used: U256::from(100), + error: None, }; let json = serde_json::to_string(&list).unwrap(); - let list2 = serde_json::from_str::(&json).unwrap(); + let list2 = serde_json::from_str(&json).unwrap(); assert_eq!(list, list2); } } diff --git a/crates/provider/src/provider/trait.rs b/crates/provider/src/provider/trait.rs index 6af73c6744b..0c05f651121 100644 --- a/crates/provider/src/provider/trait.rs +++ b/crates/provider/src/provider/trait.rs @@ -15,8 +15,7 @@ use alloy_primitives::{ }; use alloy_rpc_client::{ClientRef, PollerBuilder, RpcCall, WeakClient}; use alloy_rpc_types_eth::{ - AccessListWithGasUsed, Block, BlockId, BlockNumberOrTag, EIP1186AccountProofResponse, - FeeHistory, Filter, FilterChanges, Log, SyncStatus, + AccessListResult, Block, BlockId, BlockNumberOrTag, EIP1186AccountProofResponse, FeeHistory, Filter, FilterChanges, Log, SyncStatus }; use alloy_transport::{BoxTransport, Transport, TransportErrorKind, TransportResult}; use serde_json::value::RawValue; @@ -163,7 +162,7 @@ pub trait Provider: fn create_access_list<'a>( &self, request: &'a N::TransactionRequest, - ) -> RpcWithBlock { + ) -> RpcWithBlock { RpcWithBlock::new(self.weak_client(), "eth_createAccessList", request) } diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index 40f00c9f78d..c81ecf414e7 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize}; pub use alloy_consensus::BlobTransactionSidecar; pub use alloy_eips::{ - eip2930::{AccessList, AccessListItem, AccessListWithGasUsed}, + eip2930::{AccessList, AccessListItem, AccessListResult}, eip7702::Authorization, }; From e9e89b51bac77751bd6ac43f944d8c75970d5e51 Mon Sep 17 00:00:00 2001 From: Miguel Oliveira Date: Tue, 30 Jul 2024 10:26:26 -0300 Subject: [PATCH 2/6] add new methods --- crates/eips/src/eip2930.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/eips/src/eip2930.rs b/crates/eips/src/eip2930.rs index fabaed9af03..dfd01f724fe 100644 --- a/crates/eips/src/eip2930.rs +++ b/crates/eips/src/eip2930.rs @@ -130,6 +130,18 @@ impl AccessList { } } +/// Access list with gas used appended. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +pub struct AccessListWithGasUsed { + /// List with accounts accessed during transaction. + pub access_list: AccessList, + /// Estimated gas used with access list. + pub gas_used: U256, +} + + /// `AccessListResult` for handling errors from `eth_createAccessList` #[derive(Clone, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -143,6 +155,17 @@ pub struct AccessListResult { pub error: Option, } +impl AccessListResult { + pub fn ensure_ok(self) -> Result { + unimplemented!() + } + + #[inline] + pub fn is_err(&self) -> bool { + self.error.is_some() + } +} + #[cfg(all(test, feature = "serde"))] mod tests { use super::*; From 93c58717c10196317ab1d08962e92caea2cf4309 Mon Sep 17 00:00:00 2001 From: Miguel Oliveira Date: Wed, 31 Jul 2024 08:54:07 -0300 Subject: [PATCH 3/6] add docs and impl --- crates/eips/src/eip2930.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/eips/src/eip2930.rs b/crates/eips/src/eip2930.rs index dfd01f724fe..01e9f7f3f62 100644 --- a/crates/eips/src/eip2930.rs +++ b/crates/eips/src/eip2930.rs @@ -141,10 +141,10 @@ pub struct AccessListWithGasUsed { pub gas_used: U256, } - /// `AccessListResult` for handling errors from `eth_createAccessList` #[derive(Clone, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct AccessListResult { /// List with accounts accessed during transaction. pub access_list: AccessList, @@ -156,10 +156,17 @@ pub struct AccessListResult { } impl AccessListResult { + /// Ensures the result is OK, returning `AccessListWithGasUsed` if so, or an error message if not. pub fn ensure_ok(self) -> Result { - unimplemented!() + match self.error { + Some(err) => Err(err), + None => { + Ok(AccessListWithGasUsed { access_list: self.access_list, gas_used: self.gas_used }) + } + } } + /// Checks if there is an error in the result. #[inline] pub fn is_err(&self) -> bool { self.error.is_some() From 214ea509efa6123d830cc984d5e1b5b13e7dda08 Mon Sep 17 00:00:00 2001 From: Miguel Oliveira Date: Wed, 31 Jul 2024 08:55:38 -0300 Subject: [PATCH 4/6] docs linking --- crates/eips/src/eip2930.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eips/src/eip2930.rs b/crates/eips/src/eip2930.rs index 01e9f7f3f62..c6995a21fae 100644 --- a/crates/eips/src/eip2930.rs +++ b/crates/eips/src/eip2930.rs @@ -156,7 +156,7 @@ pub struct AccessListResult { } impl AccessListResult { - /// Ensures the result is OK, returning `AccessListWithGasUsed` if so, or an error message if not. + /// Ensures the result is OK, returning [`AccessListWithGasUsed`] if so, or an error message if not. pub fn ensure_ok(self) -> Result { match self.error { Some(err) => Err(err), From 6ea3a24649755c712f553c26e6c50654711fc4cb Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 1 Aug 2024 18:58:21 +0200 Subject: [PATCH 5/6] clippy --- crates/eips/src/eip2930.rs | 8 ++++++-- crates/provider/src/provider/trait.rs | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/eips/src/eip2930.rs b/crates/eips/src/eip2930.rs index c6995a21fae..182cb37b10c 100644 --- a/crates/eips/src/eip2930.rs +++ b/crates/eips/src/eip2930.rs @@ -3,7 +3,10 @@ //! [EIP-2930]: https://eips.ethereum.org/EIPS/eip-2930 #[cfg(not(feature = "std"))] -use alloc::vec::Vec; +use alloc::{ + vec::Vec, + string::String +}; use alloy_primitives::{Address, B256, U256}; use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper}; @@ -156,7 +159,8 @@ pub struct AccessListResult { } impl AccessListResult { - /// Ensures the result is OK, returning [`AccessListWithGasUsed`] if so, or an error message if not. + /// Ensures the result is OK, returning [`AccessListWithGasUsed`] if so, or an error message if + /// not. pub fn ensure_ok(self) -> Result { match self.error { Some(err) => Err(err), diff --git a/crates/provider/src/provider/trait.rs b/crates/provider/src/provider/trait.rs index 0c05f651121..b90fc0ffbd7 100644 --- a/crates/provider/src/provider/trait.rs +++ b/crates/provider/src/provider/trait.rs @@ -15,7 +15,8 @@ use alloy_primitives::{ }; use alloy_rpc_client::{ClientRef, PollerBuilder, RpcCall, WeakClient}; use alloy_rpc_types_eth::{ - AccessListResult, Block, BlockId, BlockNumberOrTag, EIP1186AccountProofResponse, FeeHistory, Filter, FilterChanges, Log, SyncStatus + AccessListResult, Block, BlockId, BlockNumberOrTag, EIP1186AccountProofResponse, FeeHistory, + Filter, FilterChanges, Log, SyncStatus, }; use alloy_transport::{BoxTransport, Transport, TransportErrorKind, TransportResult}; use serde_json::value::RawValue; From 02c84a0071db0744b9990b657616a2eac1997455 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 1 Aug 2024 18:59:30 +0200 Subject: [PATCH 6/6] rustmft --- crates/eips/src/eip2930.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/eips/src/eip2930.rs b/crates/eips/src/eip2930.rs index 182cb37b10c..e215eec9e04 100644 --- a/crates/eips/src/eip2930.rs +++ b/crates/eips/src/eip2930.rs @@ -3,10 +3,7 @@ //! [EIP-2930]: https://eips.ethereum.org/EIPS/eip-2930 #[cfg(not(feature = "std"))] -use alloc::{ - vec::Vec, - string::String -}; +use alloc::{string::String, vec::Vec}; use alloy_primitives::{Address, B256, U256}; use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper}; @@ -172,7 +169,7 @@ impl AccessListResult { /// Checks if there is an error in the result. #[inline] - pub fn is_err(&self) -> bool { + pub const fn is_err(&self) -> bool { self.error.is_some() } }