Skip to content

Commit

Permalink
fix: improve console output for blocking replaced tx's
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Nov 18, 2020
1 parent 9c5ad7e commit f2efb90
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions brownie/network/gas/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _update_loop() -> None:
gas_price = gas_strategy.update_gas_price(tx.gas_price, height - initial)
if gas_price is not None:
try:
tx = tx.replace(gas_price=gas_price, silent=True)
tx = tx.replace(gas_price=gas_price)
latest = web3.eth.blockNumber
except ValueError:
pass
Expand All @@ -152,7 +152,7 @@ def _update_loop() -> None:
gas_price = gas_strategy.update_gas_price(tx.gas_price, time.time() - initial)
if gas_price is not None:
try:
tx = tx.replace(gas_price=gas_price, silent=True)
tx = tx.replace(gas_price=gas_price)
latest = time.time()
except ValueError:
pass
Expand Down
22 changes: 11 additions & 11 deletions brownie/network/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __init__(
if isinstance(txid, bytes):
txid = HexBytes(txid).hex()
if not self._silent:
print(f"Transaction sent: {color('bright blue')}{txid}{color}")
print(f"\rTransaction sent: {color('bright blue')}{txid}{color}")

# this event is set once the transaction is confirmed or dropped
# it is used to waiting during blocking transaction actions
Expand Down Expand Up @@ -327,7 +327,7 @@ def wait(self, required_confs: int) -> None:
return
time.sleep(1)

self._await_confirmation(tx, required_confs)
self._await_confirmation(tx["blockNumber"], required_confs)

def _raise_if_reverted(self, exc: Any) -> None:
if self.status or CONFIG.mode == "console":
Expand Down Expand Up @@ -369,22 +369,22 @@ def _await_transaction(self, required_confs: int, is_blocking: bool) -> None:

# await confirmation of tx in a separate thread which is blocking if required_confs > 0
confirm_thread = threading.Thread(
target=self._await_confirmation, args=(tx, required_confs), daemon=True
target=self._await_confirmation, args=(tx["blockNumber"], required_confs), daemon=True
)
confirm_thread.start()
if is_blocking and required_confs > 0:
confirm_thread.join()

def _await_confirmation(self, tx: Dict, required_confs: int = 1) -> None:
if not tx["blockNumber"] and not self._silent and required_confs > 0:
def _await_confirmation(self, block_number: int = None, required_confs: int = 1) -> None:
block_number = block_number or self.block_number
if not block_number and not self._silent and required_confs > 0:
if required_confs == 1:
print("Waiting for confirmation...")
sys.stdout.write("\rWaiting for confirmation... ")
else:
sys.stdout.write(
f"\rRequired confirmations: {color('bright yellow')}0/"
f"{required_confs}{color}"
f"\rRequired confirmations: {color('bright yellow')}0/{required_confs}{color}"
)
sys.stdout.flush()
sys.stdout.flush()

# await first confirmation
while True:
Expand Down Expand Up @@ -417,7 +417,7 @@ def _await_confirmation(self, tx: Dict, required_confs: int = 1) -> None:
# check if tx is still in mempool, this will raise otherwise
tx = web3.eth.getTransaction(self.txid)
self.block_number = None
return self._await_confirmation(tx, required_confs)
return self._await_confirmation(tx["blockNumber"], required_confs)
if required_confs - self.confirmations != remaining_confs:
remaining_confs = required_confs - self.confirmations
if not self._silent:
Expand Down Expand Up @@ -494,7 +494,7 @@ def _confirm_output(self) -> str:
if not self.status:
status = f"({color('bright red')}{self.revert_msg or 'reverted'}{color}) "
result = (
f" {self._full_name()} confirmed {status}- "
f"\r {self._full_name()} confirmed {status}- "
f"Block: {color('bright blue')}{self.block_number}{color} "
f"Gas used: {color('bright blue')}{self.gas_used}{color} "
f"({color('bright blue')}{self.gas_used / self.gas_limit:.2%}{color})"
Expand Down

0 comments on commit f2efb90

Please sign in to comment.