From 723d791b6c43d8dd13a257b19a8af0e6e146e77e Mon Sep 17 00:00:00 2001 From: GnP Date: Wed, 4 Dec 2024 18:05:09 -0300 Subject: [PATCH] Add convenience method on Tx --- src/ethproto/aa_bundler.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/ethproto/aa_bundler.py b/src/ethproto/aa_bundler.py index 689cb91..be5d5ab 100644 --- a/src/ethproto/aa_bundler.py +++ b/src/ethproto/aa_bundler.py @@ -14,6 +14,7 @@ from hexbytes import HexBytes from web3 import Web3 from web3.constants import ADDRESS_ZERO +from web3.types import TxParams from .contracts import RevertError @@ -94,6 +95,16 @@ class Tx: from_: HexAddress = ADDRESS_ZERO chain_id: int = None + @classmethod + def from_tx_params(cls, params: TxParams) -> "Tx": + return cls( + target=params["to"], + data=HexBytes(params["data"]), + value=params["value"], + from_=params.get("from", ADDRESS_ZERO), + chain_id=params.get("chainId", None), + ) + def as_execute_args(self): return [self.target, self.value, self.data] @@ -320,6 +331,14 @@ def __init__( self.base_gas_price_factor = base_gas_price_factor self.executor_pk = executor_pk + def __str__(self): + return ( + f"Bundler(type={self.bundler_type}, entrypoint={self.entrypoint}, nonce_mode={self.nonce_mode}" + f"fixed_nonce_key={self.fixed_nonce_key}, verification_gas_factor={self.verification_gas_factor}," + f"gas_limit_factor={self.gas_limit_factor}, priority_gas_price_factor={self.priority_gas_price_factor}," + f"base_gas_price_factor={self.base_gas_price_factor})" + ) + def get_nonce_and_key(self, tx: Tx, fetch=False): nonce_key = tx.nonce_key nonce = tx.nonce