1use crate::error::TxMgrError;
2pub mod error;
3use ethers::{
4 core::types::Address,
5 providers::{Http, Middleware, Provider},
6 types::{
7 transaction::{eip1559::Eip1559TransactionRequest, eip2718::TypedTransaction},
8 TransactionReceipt,
9 },
10};
11
12use eigensdk_client_wallet::{privatekey_wallet::PrivateKeyWallet, WalletTrait};
13use std::sync::Arc;
14
15pub struct TxManager;
16
17pub struct SimpleTxManager {
18 pub wallet: PrivateKeyWallet,
19 client: Provider<Http>,
20 sender: Address,
21}
22
23impl SimpleTxManager {
24 pub fn new(wallet: PrivateKeyWallet, client: Provider<Http>, sender: Address) -> Self {
25 SimpleTxManager {
26 wallet,
27 client,
28 sender,
29 }
30 }
31
32 pub async fn send(
33 &self,
34 tx: Eip1559TransactionRequest,
35 ) -> Result<TransactionReceipt, TxMgrError> {
36 let tx_id_result = self
37 .wallet
38 .send_transaction(TypedTransaction::Eip1559(tx))
39 .await;
40
41 match tx_id_result {
42 Ok(tx_id) => {
43 let provider = Arc::new(self.client.clone());
44 let receipt_result = provider.get_transaction_receipt(tx_id).await;
45
46 match receipt_result {
47 Ok(receipt) => {
48 if let Some(rece) = receipt {
49 Ok(rece)
50 } else {
51 return Err(TxMgrError::EmptyReceipt);
52 }
53 }
54 Err(_) => return Err(TxMgrError::GetTransactionReceipt),
55 }
56 }
57 Err(_) => return Err(TxMgrError::SendTransaction),
58 }
59 }
60}