-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: eth_sendRawTransactionConditional
- Loading branch information
Showing
27 changed files
with
883 additions
and
746 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use crate::bundler::SendBundleOp; | ||
use ethers::{ | ||
middleware::SignerMiddleware, | ||
providers::Middleware, | ||
signers::LocalWallet, | ||
types::{ | ||
transaction::{ | ||
conditional::{AccountStorage, ConditionalOptions}, | ||
eip2718::TypedTransaction, | ||
}, | ||
Address, H256, | ||
}, | ||
}; | ||
use silius_primitives::{simulation::StorageMap, Wallet}; | ||
use std::{collections::HashMap, sync::Arc, time::Duration}; | ||
use tracing::trace; | ||
|
||
/// A type alias for the Ethereum Conditional Signer client | ||
#[derive(Clone)] | ||
pub struct ConditionalClient<M>(pub SignerMiddleware<Arc<M>, LocalWallet>); | ||
|
||
#[async_trait::async_trait] | ||
impl<M> SendBundleOp for ConditionalClient<M> | ||
where | ||
M: Middleware + 'static, | ||
{ | ||
/// Send a bundle of [UserOperations](UserOperation) to the Ethereum execution client | ||
/// over conditional RPC method. | ||
/// | ||
/// # Arguments | ||
/// * `bundle` - Bundle of [UserOperations](UserOperation) | ||
/// * 'storage_map' - Storage map | ||
/// | ||
/// # Returns | ||
/// * `H256` - The transaction hash | ||
async fn send_bundle( | ||
&self, | ||
bundle: TypedTransaction, | ||
storage_map: StorageMap, | ||
) -> eyre::Result<H256> { | ||
trace!("Sending transaction to the conditional endpoint: {bundle:?}"); | ||
|
||
let mut known_accounts: HashMap<Address, AccountStorage> = HashMap::default(); | ||
|
||
for (k, v) in storage_map.root_hashes { | ||
known_accounts.insert(k, AccountStorage::RootHash(v)); | ||
} | ||
|
||
for (k, v) in storage_map.slots { | ||
known_accounts.insert(k, AccountStorage::SlotValues(v)); | ||
} | ||
|
||
let signed_tx = self.0.sign_transaction(bundle).await?; | ||
|
||
let tx = self | ||
.0 | ||
.send_raw_transaction_conditional( | ||
signed_tx, | ||
ConditionalOptions { known_accounts, ..Default::default() }, | ||
) | ||
.await? | ||
.interval(Duration::from_millis(75)); | ||
let tx_hash = tx.tx_hash(); | ||
|
||
let tx_receipt = tx.await?; | ||
|
||
trace!("Transaction receipt: {tx_receipt:?}"); | ||
|
||
Ok(tx_hash) | ||
} | ||
} | ||
|
||
impl<M> ConditionalClient<M> | ||
where | ||
M: Middleware + 'static, | ||
{ | ||
/// Create an Conditional client | ||
/// | ||
/// # Arguments | ||
/// * `eth_client` - Connection to the Ethereum execution client | ||
/// * `wallet` - A [Wallet](Wallet) instance | ||
/// | ||
/// # Returns | ||
/// * `ConditionalClient` - A [Ethereum Signer Middleware](ConditionalClient) | ||
pub fn new(eth_client: Arc<M>, wallet: Wallet) -> Self { | ||
let signer = SignerMiddleware::new(eth_client, wallet.signer); | ||
Self(signer) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.