Skip to content

Commit

Permalink
Add convenience method on Tx
Browse files Browse the repository at this point in the history
  • Loading branch information
gnpar committed Dec 4, 2024
1 parent aad91f8 commit 723d791
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/ethproto/aa_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 723d791

Please sign in to comment.