Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Increment nonce to #468

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion brownie/network/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,34 @@ def estimate_gas(self, to: "Accounts" = None, amount: int = 0, data: str = None)
return CONFIG.active_network["settings"]["reverting_tx_gas_limit"]
raise

def increase_nonce_to(self, new_nonce: int) -> int:
"""Increases the nonce of this account by performing empty transactions.

Args:
new_nonce: The target nonce of the account. Must be greater or equal to current nonce.

Returns:
The nonce of the account after it has been increased."""

if self.nonce > new_nonce:
raise ValueError(
f"Current nonce of {self.nonce} is HIGHER than desired nonce of {new_nonce}. "
f"Nonce can not be decreased."
)

while self.nonce < new_nonce:
self.transfer(Accounts()[0], 0, silent=True)

return self.nonce

def transfer(
self,
to: "Accounts" = None,
amount: int = 0,
gas_limit: Optional[int] = None,
gas_price: Optional[int] = None,
data: str = None,
silent: bool = False,
) -> "TransactionReceipt":
"""
Broadcast a transaction from this account.
Expand All @@ -327,6 +348,7 @@ def transfer(
gas_limit: Gas limit of the transaction.
gas_price: Gas price of the transaction.
data: Hexstring of data to include in transaction.
silent: toggles console verbosity.

Returns:
TransactionReceipt object
Expand All @@ -351,7 +373,7 @@ def transfer(
if rpc.is_active():
rpc._add_to_undo_buffer(self.transfer, (to, amount, gas_limit, gas_price, data), {})

return TransactionReceipt(txid, self, revert_data=revert_data)
return TransactionReceipt(txid, self, silent=silent, revert_data=revert_data)


class Account(_PrivateKeyAccount):
Expand Down