Skip to content

Commit

Permalink
Have get_receipt take a pending tx instead of creating shallow copies…
Browse files Browse the repository at this point in the history
… repeatedly - I don't believe it changes outside of this call.
  • Loading branch information
derekpierre committed Feb 20, 2024
1 parent 11fd15b commit e5298a8
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions atxm/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ def __handle_active_transaction(self) -> bool:
Returns True if the next queued transaction can be broadcasted right now.
"""

pending_tx = self._state.pending

# Outcome 1: the pending transaction is paused by strategies
if self.__pause:
self.log.warning(
Expand All @@ -227,7 +229,7 @@ def __handle_active_transaction(self) -> bool:
return False

try:
receipt = self.__get_receipt()
receipt = self.__get_receipt(pending_tx)

# Outcome 2: the pending transaction was reverted (final error)
except TransactionReverted:
Expand All @@ -241,10 +243,10 @@ def __handle_active_transaction(self) -> bool:
# Outcome 3: pending transaction is finalized (final success)
if receipt:
final_txhash = receipt["transactionHash"]
confirmations = self.__get_confirmations(tx=self._state.pending)
confirmations = self.__get_confirmations(tx=pending_tx)
self.log.info(
f"[finalized] Transaction #atx-{self._state.pending.id} has been finalized "
f"with {confirmations} confirmations txhash: {final_txhash.hex()}"
f"[finalized] Transaction #atx-{pending_tx.id} has been finalized "
f"with {confirmations} confirmation(s) txhash: {final_txhash.hex()}"
)
self._state.finalize_active_tx(receipt=receipt)
return True
Expand Down Expand Up @@ -364,7 +366,7 @@ def __broadcast(self) -> Optional[TxHash]:
# Monitoring
#

def __get_receipt(self) -> Optional[TxReceipt]:
def __get_receipt(self, pending_tx: PendingTx) -> Optional[TxReceipt]:
"""
Hits eth_getTransaction and eth_getTransactionReceipt
for the active pending txhash and checks if
Expand All @@ -374,11 +376,11 @@ def __get_receipt(self) -> Optional[TxReceipt]:
NOTE: Performs state changes
"""
try:
txdata = self.w3.eth.get_transaction(self._state.pending.txhash)
self._state.pending.data = txdata
txdata = self.w3.eth.get_transaction(pending_tx.txhash)
pending_tx.data = txdata
except TransactionNotFound:
self.log.error(
f"[error] Transaction {self._state.pending.txhash.hex()} not found"
f"[error] Transaction {pending_tx.txhash.hex()} not found"
)
return

Expand Down

0 comments on commit e5298a8

Please sign in to comment.