Skip to content

Commit

Permalink
Merge pull request #674 from eth-brownie/fix-txreceipt-slots
Browse files Browse the repository at this point in the history
Meaningful error on failed trace
  • Loading branch information
iamdefinitelyahuman authored Jul 9, 2020
2 parents 5293642 + 98151b0 commit 603b669
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 43 deletions.
2 changes: 1 addition & 1 deletion brownie/network/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def at(

def _add_from_tx(self, tx: TransactionReceiptType) -> None:
tx._confirmed.wait()
if tx.status:
if tx.status and tx.contract_address is not None:
try:
self.at(tx.contract_address, tx.sender, tx)
except ContractNotFound:
Expand Down
61 changes: 19 additions & 42 deletions brownie/network/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def trace_property(fn: Callable) -> Any:
def wrapper(self: "TransactionReceipt") -> Any:
if self.status == -1:
return None
if self._trace_exc is not None:
raise self._trace_exc
return fn(self)

return wrapper
Expand Down Expand Up @@ -90,39 +92,6 @@ class TransactionReceipt:
revert_msg: Error string from reverted contract all
modified_state: Boolean, did this contract write to storage?"""

__slots__ = (
"_call_cost",
"_confirmed",
"_events",
"_internal_transfers",
"_modified_state",
"_new_contracts",
"_raw_trace",
"_return_value",
"_revert_msg",
"_revert_pc",
"_silent",
"_trace",
"_trace_origin",
"block_number",
"contract_address",
"contract_name",
"coverage_hash",
"fn_name",
"gas_limit",
"gas_price",
"gas_used",
"input",
"logs",
"nonce",
"receiver",
"sender",
"status",
"txid",
"txindex",
"value",
)

def __init__(
self,
txid: Union[str, bytes],
Expand Down Expand Up @@ -151,6 +120,8 @@ def __init__(
if not self._silent:
print(f"Transaction sent: {color('bright blue')}{txid}{color}")

# internal attributes
self._trace_exc = None
self._trace_origin = None
self._raw_trace = None
self._trace = None
Expand All @@ -163,9 +134,19 @@ def __init__(
self._internal_transfers = None
self._confirmed = threading.Event()

# attributes that cannot be set until the tx confirms
self.block_number = None
self.contract_address: Optional[str] = None
self.gas_used = None
self.logs = None
self.nonce = None
self.txindex = None

# attributes that can be set immediately
self.sender = sender
self.status = -1
self.txid = txid
self.contract_name = None
self.fn_name = name

if name and "." in name:
Expand Down Expand Up @@ -193,12 +174,6 @@ def __repr__(self) -> str:
def __hash__(self) -> int:
return hash(self.txid)

def __getattr__(self, attr: str) -> Any:
if attr not in self.__slots__:
raise AttributeError(f"'TransactionReceipt' object has no attribute '{attr}'")
if self.status == -1:
return None

@trace_property
def events(self) -> Optional[List]:
if not self.status:
Expand Down Expand Up @@ -329,7 +304,7 @@ def _await_confirmation(self, tx: Dict, required_confs: int = 1) -> None:
# await first confirmation
receipt = web3.eth.waitForTransactionReceipt(self.txid, timeout=None, poll_latency=0.5)

self.block_number: Optional[int] = receipt["blockNumber"]
self.block_number = receipt["blockNumber"]
# wait for more confirmations if required and handle uncle blocks
remaining_confs = required_confs
while remaining_confs > 0 and required_confs > 1:
Expand Down Expand Up @@ -444,8 +419,10 @@ def _get_trace(self) -> None:
raise RPCRequestError(msg) from None

if "error" in trace:
self.modified_state = None
raise RPCRequestError(trace["error"]["message"])
self._modified_state = None
self._trace_exc = RPCRequestError(trace["error"]["message"])
raise self._trace_exc

self._raw_trace = trace = trace["result"]["structLogs"]
if not trace:
self._modified_state = False
Expand Down

0 comments on commit 603b669

Please sign in to comment.