diff --git a/crates/chainio/txmanager/src/simple_tx_manager.rs b/crates/chainio/txmanager/src/simple_tx_manager.rs index fc224d24..7ef58a4f 100644 --- a/crates/chainio/txmanager/src/simple_tx_manager.rs +++ b/crates/chainio/txmanager/src/simple_tx_manager.rs @@ -4,7 +4,7 @@ use alloy_primitives::Address; use alloy_provider::{PendingTransactionBuilder, Provider, ProviderBuilder, RootProvider}; use alloy_rpc_types_eth::{TransactionInput, TransactionReceipt, TransactionRequest}; use alloy_signer_local::PrivateKeySigner; -use eigen_logging::{logger::Logger, tracing_logger::TracingLogger}; +use eigen_logging::logger::SharedLogger; use eigen_signer::signer::Config; use k256::ecdsa::SigningKey; use reqwest::Url; @@ -29,14 +29,14 @@ pub enum TxManagerError { InvalidUrlError, } -pub struct SimpleTxManager<'log> { - logger: &'log TracingLogger, +pub struct SimpleTxManager { + logger: SharedLogger, gas_limit_multiplier: f64, private_key: String, provider: RootProvider, } -impl<'log> SimpleTxManager<'log> { +impl SimpleTxManager { /// Creates a new SimpleTxManager. /// /// # Arguments @@ -54,13 +54,13 @@ impl<'log> SimpleTxManager<'log> { /// /// - If the URL is invalid. pub fn new( - logger: &'log TracingLogger, + logger: SharedLogger, gas_limit_multiplier: f64, private_key: &str, rpc_url: &str, - ) -> Result, TxManagerError> { + ) -> Result { let url = Url::parse(rpc_url) - .inspect_err(|err| logger.error("Failed to parse url", &[err])) + .inspect_err(|err| logger.error("Failed to parse url", &err.to_string())) .map_err(|_| TxManagerError::InvalidUrlError)?; let provider = ProviderBuilder::new().on_http(url); Ok(SimpleTxManager { @@ -82,7 +82,10 @@ impl<'log> SimpleTxManager<'log> { /// - If the private key is invalid. pub fn get_address(&self) -> Result { let private_key_signing_key = SigningKey::from_slice(self.private_key.as_bytes()) - .inspect_err(|err| self.logger.error("Failed to parse private key", &[err])) + .inspect_err(|err| { + self.logger + .error("Failed to parse private key", &err.to_string()) + }) .map_err(|_| TxManagerError::AddressError)?; Ok(Address::from_private_key(&private_key_signing_key)) } @@ -94,7 +97,10 @@ impl<'log> SimpleTxManager<'log> { fn create_local_signer(&self) -> Result { let config = Config::PrivateKey(self.private_key.clone()); Config::signer_from_config(config) - .inspect_err(|err| self.logger.error("Failed to create signer", &[err])) + .inspect_err(|err| { + self.logger + .error("Failed to create signer", &err.to_string()) + }) .map_err(|_| TxManagerError::SignerError) } @@ -115,12 +121,12 @@ impl<'log> SimpleTxManager<'log> { tx: &mut TransactionRequest, ) -> Result { // Estimating gas and nonce - self.logger.debug("Estimating gas and nonce", &[()]); + self.logger.debug("Estimating gas and nonce", ""); - let tx = self - .estimate_gas_and_nonce(tx) - .await - .inspect_err(|err| self.logger.error("Failed to estimate gas", &[err]))?; + let tx = self.estimate_gas_and_nonce(tx).await.inspect_err(|err| { + self.logger + .error("Failed to estimate gas", &err.to_string()) + })?; let signer = self.create_local_signer()?; let wallet = EthereumWallet::from(signer); @@ -130,7 +136,7 @@ impl<'log> SimpleTxManager<'log> { .await .inspect_err(|err| { self.logger - .error("Failed to build and sign transaction", &[err]) + .error("Failed to build and sign transaction", &err.to_string()) }) .map_err(|_| TxManagerError::SendTxError)?; @@ -139,12 +145,13 @@ impl<'log> SimpleTxManager<'log> { .provider .send_transaction(signed_tx.into()) .await - .inspect_err(|err| self.logger.error("Failed to get receipt", &[err])) + .inspect_err(|err| self.logger.error("Failed to get receipt", &err.to_string())) .map_err(|_| TxManagerError::SendTxError)?; - self.logger - .debug("Transaction sent. Pending transaction: ", &[&pending_tx]); - + self.logger.debug( + "Transaction sent. Pending transaction: ", + &pending_tx.tx_hash().to_string(), + ); // wait for the transaction to be mined SimpleTxManager::wait_for_receipt(self, pending_tx).await } @@ -173,7 +180,7 @@ impl<'log> SimpleTxManager<'log> { let gas_tip_cap = self.provider.get_max_priority_fee_per_gas().await .inspect_err(|err| self.logger.info("eth_maxPriorityFeePerGas is unsupported by current backend, using fallback gasTipCap", - &[err])) + &err.to_string())) .unwrap_or(FALLBACK_GAS_TIP_CAP); let header = self @@ -184,10 +191,7 @@ impl<'log> SimpleTxManager<'log> { .flatten() .map(|block| block.header) .ok_or(TxManagerError::SendTxError) - .inspect_err(|_| { - self.logger - .error("Failed to get latest block header", &[()]) - })?; + .inspect_err(|_| self.logger.error("Failed to get latest block header", ""))?; // 2*baseFee + gas_tip_cap makes sure that the tx remains includeable for 6 consecutive 100% full blocks. // see https://www.blocknative.com/blog/eip-1559-fees @@ -260,7 +264,7 @@ impl<'log> SimpleTxManager<'log> { pending_tx .get_receipt() .await - .inspect_err(|err| self.logger.error("Failed to get receipt", &[err])) + .inspect_err(|err| self.logger.error("Failed to get receipt", &err.to_string())) .map_err(|_| TxManagerError::WaitForReceiptError) } }