From 7a8110327b4072d0a6c376b4ca1ffba6b240a7cd Mon Sep 17 00:00:00 2001 From: tesseract <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Wed, 3 Jul 2024 16:14:56 -0700 Subject: [PATCH 01/12] Update request.rs --- .../rpc-types-eth/src/transaction/request.rs | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/rpc-types-eth/src/transaction/request.rs b/crates/rpc-types-eth/src/transaction/request.rs index c5ffd89d78e..9878658133a 100644 --- a/crates/rpc-types-eth/src/transaction/request.rs +++ b/crates/rpc-types-eth/src/transaction/request.rs @@ -7,8 +7,7 @@ use alloy_consensus::{ }; use alloy_primitives::{Address, Bytes, ChainId, TxKind, B256, U256}; use serde::{Deserialize, Serialize}; -use std::hash::Hash; - +use std::{collections::HashMap, hash::Hash}; /// Represents _all_ transaction requests to/from RPC. #[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -767,6 +766,34 @@ impl From for TransactionRequest { #[non_exhaustive] pub struct TransactionInputError; +/// Options for conditional raw transaction submissions. +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct ConditionalTxOptions { + /// The minimal block number at which the transaction can be included. + /// `None` indicates no minimum block number constraint. + pub block_number_min: Option, + /// The maximal block number at which the transaction can be included. + /// `None` indicates no maximum block number constraint. + pub block_number_max: Option, + /// The minimal timestamp at which the transaction can be included. + /// `None` indicates no minimum timestamp constraint. + pub timestamp_min: Option, + /// The maximal timestamp at which the transaction can be included. + /// `None` indicates no maximum timestamp constraint. + pub timestamp_max: Option, + /// A map of account addresses to their expected storage states. + /// Each account can have a specified storage root or explicit slot-value pairs. + pub known_accounts: HashMap, +} +/// Represents the expected state of an account for a transaction to be conditionally accepted. +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(untagged)] +pub enum KnownAccountState { + /// Expected storage root hash of the account. + StorageRoot(B256), + /// Explicit storage slots and their expected values. + Slots(HashMap), +} #[cfg(test)] mod tests { use super::*; From ae300f3e91b879869d73b6fc8715d150310cfbc1 Mon Sep 17 00:00:00 2001 From: tesseract <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Wed, 3 Jul 2024 16:16:59 -0700 Subject: [PATCH 02/12] Update trait.rs --- crates/provider/src/provider/trait.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/provider/src/provider/trait.rs b/crates/provider/src/provider/trait.rs index c9543249e61..6807190e996 100644 --- a/crates/provider/src/provider/trait.rs +++ b/crates/provider/src/provider/trait.rs @@ -14,8 +14,9 @@ use alloy_primitives::{ }; use alloy_rpc_client::{ClientRef, PollerBuilder, RpcCall, WeakClient}; use alloy_rpc_types_eth::{ - AccessListWithGasUsed, Block, BlockId, BlockNumberOrTag, BlockTransactionsKind, - EIP1186AccountProofResponse, FeeHistory, Filter, FilterChanges, Log, SyncStatus, + request::ConditionalTxOptions, AccessListWithGasUsed, Block, BlockId, BlockNumberOrTag, + BlockTransactionsKind, EIP1186AccountProofResponse, FeeHistory, Filter, FilterChanges, Log, + SyncStatus, }; use alloy_transport::{BoxTransport, Transport, TransportErrorKind, TransportResult}; use serde_json::value::RawValue; @@ -617,6 +618,21 @@ pub trait Provider: Ok(PendingTransactionBuilder::new(self.root(), tx_hash)) } + /// Submits a raw transaction with conditions that must be met at the point of inclusion. + async fn send_raw_transaction_conditional( + &self, + raw_tx: &[u8], + options: ConditionalTxOptions, + ) -> TransportResult> { + // Convert raw transaction to a hex string + let tx_hex = hex::encode_prefixed(&raw_tx); + + // Prepare and send the RPC request + let tx_hash = + self.client().request("eth_sendRawTransactionConditional", (tx_hex, options)).await?; + Ok(PendingTransactionBuilder::new(self.root(), tx_hash)) + } + /// Broadcasts a transaction to the network. /// /// Returns a [`PendingTransactionBuilder`] which can be used to configure From b0f7c4fa7b995dc9ca51f350b7f420c373eac840 Mon Sep 17 00:00:00 2001 From: tesseract <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Wed, 3 Jul 2024 16:22:40 -0700 Subject: [PATCH 03/12] clippy --- crates/provider/src/provider/trait.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/provider/src/provider/trait.rs b/crates/provider/src/provider/trait.rs index 6807190e996..278d797cc01 100644 --- a/crates/provider/src/provider/trait.rs +++ b/crates/provider/src/provider/trait.rs @@ -625,7 +625,7 @@ pub trait Provider: options: ConditionalTxOptions, ) -> TransportResult> { // Convert raw transaction to a hex string - let tx_hex = hex::encode_prefixed(&raw_tx); + let tx_hex = hex::encode_prefixed(raw_tx); // Prepare and send the RPC request let tx_hash = From b0ead3e24f744d7d8e7c595102763ec18e077a7f Mon Sep 17 00:00:00 2001 From: tesseract <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Thu, 4 Jul 2024 13:48:27 -0700 Subject: [PATCH 04/12] Update trait.rs --- crates/provider/src/provider/trait.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/crates/provider/src/provider/trait.rs b/crates/provider/src/provider/trait.rs index 278d797cc01..815efb62b09 100644 --- a/crates/provider/src/provider/trait.rs +++ b/crates/provider/src/provider/trait.rs @@ -618,21 +618,6 @@ pub trait Provider: Ok(PendingTransactionBuilder::new(self.root(), tx_hash)) } - /// Submits a raw transaction with conditions that must be met at the point of inclusion. - async fn send_raw_transaction_conditional( - &self, - raw_tx: &[u8], - options: ConditionalTxOptions, - ) -> TransportResult> { - // Convert raw transaction to a hex string - let tx_hex = hex::encode_prefixed(raw_tx); - - // Prepare and send the RPC request - let tx_hash = - self.client().request("eth_sendRawTransactionConditional", (tx_hex, options)).await?; - Ok(PendingTransactionBuilder::new(self.root(), tx_hash)) - } - /// Broadcasts a transaction to the network. /// /// Returns a [`PendingTransactionBuilder`] which can be used to configure From a9624024ccbd38a9770941088eb4122cd64b2e0f Mon Sep 17 00:00:00 2001 From: tesseract <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Thu, 4 Jul 2024 13:49:55 -0700 Subject: [PATCH 05/12] Update trait.rs --- crates/provider/src/provider/trait.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/provider/src/provider/trait.rs b/crates/provider/src/provider/trait.rs index 815efb62b09..c9543249e61 100644 --- a/crates/provider/src/provider/trait.rs +++ b/crates/provider/src/provider/trait.rs @@ -14,9 +14,8 @@ use alloy_primitives::{ }; use alloy_rpc_client::{ClientRef, PollerBuilder, RpcCall, WeakClient}; use alloy_rpc_types_eth::{ - request::ConditionalTxOptions, AccessListWithGasUsed, Block, BlockId, BlockNumberOrTag, - BlockTransactionsKind, EIP1186AccountProofResponse, FeeHistory, Filter, FilterChanges, Log, - SyncStatus, + AccessListWithGasUsed, Block, BlockId, BlockNumberOrTag, BlockTransactionsKind, + EIP1186AccountProofResponse, FeeHistory, Filter, FilterChanges, Log, SyncStatus, }; use alloy_transport::{BoxTransport, Transport, TransportErrorKind, TransportResult}; use serde_json::value::RawValue; From 6b45f2abd92fb4cb4950b58d0f239dbd64d82030 Mon Sep 17 00:00:00 2001 From: tesseract <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Thu, 4 Jul 2024 14:11:16 -0700 Subject: [PATCH 06/12] added reference and camelCase serde --- crates/rpc-types-eth/src/transaction/request.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/rpc-types-eth/src/transaction/request.rs b/crates/rpc-types-eth/src/transaction/request.rs index 9878658133a..7de8fc07065 100644 --- a/crates/rpc-types-eth/src/transaction/request.rs +++ b/crates/rpc-types-eth/src/transaction/request.rs @@ -767,7 +767,10 @@ impl From for TransactionRequest { pub struct TransactionInputError; /// Options for conditional raw transaction submissions. +// reference for the implementation https://notes.ethereum.org/@yoav/SkaX2lS9j# + #[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] pub struct ConditionalTxOptions { /// The minimal block number at which the transaction can be included. /// `None` indicates no minimum block number constraint. From 31ab4a167e2f1329c36e21ee7813343bb99f599f Mon Sep 17 00:00:00 2001 From: tesseract <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Fri, 5 Jul 2024 11:20:37 -0700 Subject: [PATCH 07/12] Update request.rs --- .../rpc-types-eth/src/transaction/request.rs | 33 +------------------ 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/crates/rpc-types-eth/src/transaction/request.rs b/crates/rpc-types-eth/src/transaction/request.rs index 7de8fc07065..154611f4eab 100644 --- a/crates/rpc-types-eth/src/transaction/request.rs +++ b/crates/rpc-types-eth/src/transaction/request.rs @@ -7,7 +7,7 @@ use alloy_consensus::{ }; use alloy_primitives::{Address, Bytes, ChainId, TxKind, B256, U256}; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, hash::Hash}; +use std::hash::Hash; /// Represents _all_ transaction requests to/from RPC. #[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -766,37 +766,6 @@ impl From for TransactionRequest { #[non_exhaustive] pub struct TransactionInputError; -/// Options for conditional raw transaction submissions. -// reference for the implementation https://notes.ethereum.org/@yoav/SkaX2lS9j# - -#[derive(Debug, Serialize, Deserialize, Clone)] -#[serde(rename_all = "camelCase")] -pub struct ConditionalTxOptions { - /// The minimal block number at which the transaction can be included. - /// `None` indicates no minimum block number constraint. - pub block_number_min: Option, - /// The maximal block number at which the transaction can be included. - /// `None` indicates no maximum block number constraint. - pub block_number_max: Option, - /// The minimal timestamp at which the transaction can be included. - /// `None` indicates no minimum timestamp constraint. - pub timestamp_min: Option, - /// The maximal timestamp at which the transaction can be included. - /// `None` indicates no maximum timestamp constraint. - pub timestamp_max: Option, - /// A map of account addresses to their expected storage states. - /// Each account can have a specified storage root or explicit slot-value pairs. - pub known_accounts: HashMap, -} -/// Represents the expected state of an account for a transaction to be conditionally accepted. -#[derive(Debug, Serialize, Deserialize, Clone)] -#[serde(untagged)] -pub enum KnownAccountState { - /// Expected storage root hash of the account. - StorageRoot(B256), - /// Explicit storage slots and their expected values. - Slots(HashMap), -} #[cfg(test)] mod tests { use super::*; From fbd94dafde6343def2d9519ff05a0b4806110c9a Mon Sep 17 00:00:00 2001 From: tesseract <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Fri, 5 Jul 2024 11:20:50 -0700 Subject: [PATCH 08/12] Update lib.rs --- crates/rpc-types-eth/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/rpc-types-eth/src/lib.rs b/crates/rpc-types-eth/src/lib.rs index 335066e97e9..3c01ff9843a 100644 --- a/crates/rpc-types-eth/src/lib.rs +++ b/crates/rpc-types-eth/src/lib.rs @@ -46,3 +46,6 @@ pub use transaction::*; mod work; pub use work::Work; + +/// This module provides implementations for EIP-4337. +pub mod eip4337; From a4b3029426327973b92f90d13ef263e8a5c1e91b Mon Sep 17 00:00:00 2001 From: tesseract <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Fri, 5 Jul 2024 11:21:08 -0700 Subject: [PATCH 09/12] Create eip4337.rs --- crates/rpc-types-eth/src/eip4337.rs | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 crates/rpc-types-eth/src/eip4337.rs diff --git a/crates/rpc-types-eth/src/eip4337.rs b/crates/rpc-types-eth/src/eip4337.rs new file mode 100644 index 00000000000..815716ba09f --- /dev/null +++ b/crates/rpc-types-eth/src/eip4337.rs @@ -0,0 +1,34 @@ +use alloy_primitives::{Address, B256, U256}; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; +/// Options for conditional raw transaction submissions. +// reference for the implementation https://notes.ethereum.org/@yoav/SkaX2lS9j# + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] +pub struct ConditionalTxOptions { + /// The minimal block number at which the transaction can be included. + /// `None` indicates no minimum block number constraint. + pub block_number_min: Option, + /// The maximal block number at which the transaction can be included. + /// `None` indicates no maximum block number constraint. + pub block_number_max: Option, + /// The minimal timestamp at which the transaction can be included. + /// `None` indicates no minimum timestamp constraint. + pub timestamp_min: Option, + /// The maximal timestamp at which the transaction can be included. + /// `None` indicates no maximum timestamp constraint. + pub timestamp_max: Option, + /// A map of account addresses to their expected storage states. + /// Each account can have a specified storage root or explicit slot-value pairs. + pub known_accounts: HashMap, +} +/// Represents the expected state of an account for a transaction to be conditionally accepted. +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(untagged)] +pub enum KnownAccountState { + /// Expected storage root hash of the account. + StorageRoot(B256), + /// Explicit storage slots and their expected values. + Slots(HashMap), +} From d371649b818158f8ab797ab89c04dbfe0c527f45 Mon Sep 17 00:00:00 2001 From: tesseract <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Fri, 5 Jul 2024 11:22:02 -0700 Subject: [PATCH 10/12] Update eip4337.rs --- crates/rpc-types-eth/src/eip4337.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/rpc-types-eth/src/eip4337.rs b/crates/rpc-types-eth/src/eip4337.rs index 815716ba09f..8e8d31dc122 100644 --- a/crates/rpc-types-eth/src/eip4337.rs +++ b/crates/rpc-types-eth/src/eip4337.rs @@ -1,4 +1,4 @@ -use alloy_primitives::{Address, B256, U256}; +use alloy_primitives::{Address, BlockNumber, B256, U256}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; /// Options for conditional raw transaction submissions. @@ -9,10 +9,10 @@ use std::collections::HashMap; pub struct ConditionalTxOptions { /// The minimal block number at which the transaction can be included. /// `None` indicates no minimum block number constraint. - pub block_number_min: Option, + pub block_number_min: Option, /// The maximal block number at which the transaction can be included. /// `None` indicates no maximum block number constraint. - pub block_number_max: Option, + pub block_number_max: Option, /// The minimal timestamp at which the transaction can be included. /// `None` indicates no minimum timestamp constraint. pub timestamp_min: Option, From e450826200fa33b6d6ba33c09d5c90b7ba0039bf Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 17 Jul 2024 01:09:44 +0200 Subject: [PATCH 11/12] fix serde --- crates/rpc-types-eth/src/eip4337.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/crates/rpc-types-eth/src/eip4337.rs b/crates/rpc-types-eth/src/eip4337.rs index 8e8d31dc122..d1339db73cb 100644 --- a/crates/rpc-types-eth/src/eip4337.rs +++ b/crates/rpc-types-eth/src/eip4337.rs @@ -1,34 +1,41 @@ use alloy_primitives::{Address, BlockNumber, B256, U256}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; -/// Options for conditional raw transaction submissions. -// reference for the implementation https://notes.ethereum.org/@yoav/SkaX2lS9j# -#[derive(Debug, Serialize, Deserialize, Clone)] +/// Options for conditional raw transaction submissions. +// reference for the implementation +// See also +#[derive(Debug, Serialize, Deserialize, Clone, Default)] #[serde(rename_all = "camelCase")] -pub struct ConditionalTxOptions { +pub struct ConditionalOptions { /// The minimal block number at which the transaction can be included. /// `None` indicates no minimum block number constraint. + #[serde(default, skip_serializing_if = "Option::is_none")] pub block_number_min: Option, /// The maximal block number at which the transaction can be included. /// `None` indicates no maximum block number constraint. + #[serde(default, skip_serializing_if = "Option::is_none")] pub block_number_max: Option, /// The minimal timestamp at which the transaction can be included. /// `None` indicates no minimum timestamp constraint. - pub timestamp_min: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub timestamp_min: Option, /// The maximal timestamp at which the transaction can be included. /// `None` indicates no maximum timestamp constraint. - pub timestamp_max: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub timestamp_max: Option, /// A map of account addresses to their expected storage states. /// Each account can have a specified storage root or explicit slot-value pairs. - pub known_accounts: HashMap, + #[serde(default)] + pub known_accounts: HashMap, } + /// Represents the expected state of an account for a transaction to be conditionally accepted. #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(untagged)] -pub enum KnownAccountState { +pub enum AccountStorage { /// Expected storage root hash of the account. - StorageRoot(B256), + RootHash(B256), /// Explicit storage slots and their expected values. Slots(HashMap), } From ca855f95ef0670b62b6b5d5e9aa21c89c074ab86 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 17 Jul 2024 01:11:50 +0200 Subject: [PATCH 12/12] reorder --- crates/rpc-types-eth/src/eip4337.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/rpc-types-eth/src/eip4337.rs b/crates/rpc-types-eth/src/eip4337.rs index d1339db73cb..0a43da2f44f 100644 --- a/crates/rpc-types-eth/src/eip4337.rs +++ b/crates/rpc-types-eth/src/eip4337.rs @@ -8,6 +8,10 @@ use std::collections::HashMap; #[derive(Debug, Serialize, Deserialize, Clone, Default)] #[serde(rename_all = "camelCase")] pub struct ConditionalOptions { + /// A map of account addresses to their expected storage states. + /// Each account can have a specified storage root or explicit slot-value pairs. + #[serde(default)] + pub known_accounts: HashMap, /// The minimal block number at which the transaction can be included. /// `None` indicates no minimum block number constraint. #[serde(default, skip_serializing_if = "Option::is_none")] @@ -24,10 +28,6 @@ pub struct ConditionalOptions { /// `None` indicates no maximum timestamp constraint. #[serde(default, skip_serializing_if = "Option::is_none")] pub timestamp_max: Option, - /// A map of account addresses to their expected storage states. - /// Each account can have a specified storage root or explicit slot-value pairs. - #[serde(default)] - pub known_accounts: HashMap, } /// Represents the expected state of an account for a transaction to be conditionally accepted.