Skip to content

Commit

Permalink
properly resetting nonce when canceling the batch
Browse files Browse the repository at this point in the history
  • Loading branch information
nerfZael committed Apr 11, 2024
1 parent 7bf040a commit 32f66c9
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion autotx/utils/ethereum/SafeManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,14 @@ def send_tx_batch(self, txs: list[PreparedTx], require_approval: bool, safe_nonc

if response.lower() == "n" or response.lower() == "no":
print("Transactions not sent to your smart account (declined).")

self.reset_nonce(start_nonce)

return False
elif response.lower() != "y" and response.lower() != "yes":

self.reset_nonce(start_nonce)

return response
else:
print("Non-interactive mode enabled. Transactions will be sent to your smart account without approval.")
Expand All @@ -282,8 +288,14 @@ def send_tx_batch(self, txs: list[PreparedTx], require_approval: bool, safe_nonc

if response.lower() == "n" or response.lower() == "no":
print("Transactions not executed (declined).")

self.reset_nonce(start_nonce)

return False
elif response.lower() != "y" and response.lower() != "yes":

self.reset_nonce(start_nonce)

return response
else:
print("Non-interactive mode enabled. Transactions will be executed without approval.")
Expand Down Expand Up @@ -321,7 +333,7 @@ def balance_of(self, token_address: ETHAddress | None = None) -> float:

def nonce(self) -> int:
return self.safe.retrieve_nonce()

def gas_price(self) -> int:
return self.web3.eth.gas_price if self.gas_multiplier is None else int(self.web3.eth.gas_price * self.gas_multiplier)

Expand All @@ -335,6 +347,12 @@ def track_nonce(self, safe_nonce: Optional[int] = None) -> int:
else:
return safe_nonce

def reset_nonce(self, starting_safe_nonce: Optional[int] = None) -> int:
if starting_safe_nonce is None:
self.safe_nonce = None
else:
self.safe_nonce = starting_safe_nonce - 1 # -1 because it will be incremented in track_nonce

@staticmethod
def is_valid_safe(client: EthereumClient, address: ETHAddress) -> bool:
return is_valid_safe(client, address)

0 comments on commit 32f66c9

Please sign in to comment.