Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AccessListResult type (EIP-2930) #1110

Merged
merged 7 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions crates/eips/src/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,31 @@ 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))]
pub struct AccessListResult {
mvares marked this conversation as resolved.
Show resolved Hide resolved
/// 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<String>,
}

impl AccessListResult {
pub fn ensure_ok(self) -> Result<AccessListWithGasUsed, String> {
unimplemented!()
mvares marked this conversation as resolved.
Show resolved Hide resolved
}

#[inline]
pub fn is_err(&self) -> bool {
mvares marked this conversation as resolved.
Show resolved Hide resolved
self.error.is_some()
}
}

#[cfg(all(test, feature = "serde"))]
mod tests {
use super::*;
Expand All @@ -158,15 +183,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::<AccessListWithGasUsed>(&json).unwrap();
let list2 = serde_json::from_str(&json).unwrap();
assert_eq!(list, list2);
}
}
5 changes: 2 additions & 3 deletions crates/provider/src/provider/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -163,7 +162,7 @@ pub trait Provider<T: Transport + Clone = BoxTransport, N: Network = Ethereum>:
fn create_access_list<'a>(
&self,
request: &'a N::TransactionRequest,
) -> RpcWithBlock<T, &'a N::TransactionRequest, AccessListWithGasUsed> {
) -> RpcWithBlock<T, &'a N::TransactionRequest, AccessListResult> {
RpcWithBlock::new(self.weak_client(), "eth_createAccessList", request)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rpc-types-eth/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
Loading