Skip to content

Commit

Permalink
feat: add get_transaction_trace to provider (#602)
Browse files Browse the repository at this point in the history
* feat: add get_transaction_trace to provider

* refactor: raises_not_implemented to utils

* chore: bump evm-trace version

* refactor: pr feedback
  • Loading branch information
NotPeopling2day authored Mar 26, 2022
1 parent 74903af commit 45cbf43
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"click>=8.0.0",
"eth-account==0.5.7",
"ethpm-types>=0.1.0b7",
"evm-trace>=0.1.0.a2",
"hexbytes>=0.2.2,<1.0.0",
"packaging>=20.9,<21.0",
"pandas>=1.3.0,<2.0",
Expand Down
25 changes: 14 additions & 11 deletions src/ape/api/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from eth_typing import HexStr
from eth_utils import add_0x_prefix, keccak
from ethpm_types.abi import EventABI
from evm_trace import TraceFrame
from hexbytes import HexBytes
from pydantic import Field, validator
from web3 import Web3
Expand All @@ -32,17 +33,7 @@
)
from ape.logging import logger
from ape.types import AddressType, BlockID, ContractLog, SnapshotID
from ape.utils import BaseInterfaceModel, abstractmethod, cached_property


def raises_not_implemented(fn):
def inner(*args, **kwargs):
raise NotImplementedError(
f"Attempted to call method '{fn.__name__}' in 'ProviderAPI', "
f"which is only available in 'TestProviderAPI'."
)

return inner
from ape.utils import BaseInterfaceModel, abstractmethod, cached_property, raises_not_implemented


class BlockGasAPI(BaseInterfaceModel):
Expand Down Expand Up @@ -371,6 +362,18 @@ def unlock_account(self, address: AddressType) -> bool:
bool: ``True`` if successfully unlocked account and ``False`` otherwise.
"""

@raises_not_implemented
def get_transaction_trace(self, txn_hash: str) -> Iterator[TraceFrame]:
"""
Provide a detailed description of opcodes.
Args:
txn_hash (str): The hash of a transaction to trace.
Returns:
Iterator(EvmTrace): Transaction execution trace object.
"""

def prepare_transaction(self, txn: TransactionAPI) -> TransactionAPI:
"""
Set default values on the transaction.
Expand Down
14 changes: 14 additions & 0 deletions src/ape/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,19 @@ def json(self, *args, **kwargs) -> str:
return super().json(*args, **kwargs)


def raises_not_implemented(fn):
"""
Decorator for raising helpful not implemented error.
"""

def inner(*args, **kwargs):
raise NotImplementedError(
f"Attempted to call method '{fn.__qualname__}', method not supported."
)

return inner


__all__ = [
"abstractmethod",
"BaseInterfaceModel",
Expand All @@ -742,6 +755,7 @@ def json(self, *args, **kwargs) -> str:
"get_all_files_in_directory",
"injected_before_use",
"load_config",
"raises_not_implemented",
"singledispatchmethod",
"stream_response",
"to_address",
Expand Down

0 comments on commit 45cbf43

Please sign in to comment.