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

Expand call_trace #679

Merged
merged 15 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions brownie/_cli/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ def get_suggestion(self, buffer, document):
# object is a callable class instance
obj = obj.__call__

# ensure we aren't looking at a decorator
if hasattr(obj, "__wrapped__"):
obj = obj.__wrapped__

if hasattr(obj, "_autosuggest"):
inputs = obj._autosuggest()
else:
Expand Down
32 changes: 28 additions & 4 deletions brownie/network/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ def __init__(
self.abi = abi
self._owner = owner
self.signature = build_function_selector(abi)
self._input_sig = build_function_signature(abi)
self.natspec = natspec or {}

def __repr__(self) -> str:
Expand Down Expand Up @@ -986,6 +987,23 @@ def transact(self, *args: Tuple) -> TransactionReceiptType:
data=self.encode_input(*args),
)

def decode_input(self, hexstr: str) -> List:
"""
Decode input call data for this method.

Arguments
---------
hexstr : str
Hexstring of input call data

Returns
-------
Decoded values
"""
types_list = get_type_strings(self.abi["inputs"])
result = eth_abi.decode_abi(types_list, HexBytes(hexstr)[4:])
return format_input(self.abi, result)

def encode_input(self, *args: Tuple) -> str:
"""
Generate encoded ABI data to call the method with the given arguments.
Expand All @@ -1005,12 +1023,18 @@ def encode_input(self, *args: Tuple) -> str:
return self.signature + eth_abi.encode_abi(types_list, data).hex()

def decode_output(self, hexstr: str) -> Tuple:
"""Decodes hexstring data returned by this method.
"""
Decode hexstring data returned by this method.

Args:
hexstr: Hexstring of returned call data
Arguments
---------
hexstr : str
Hexstring of returned call data

Returns: Decoded values."""
Returns
-------
Decoded values
"""
types_list = get_type_strings(self.abi["outputs"])
result = eth_abi.decode_abi(types_list, HexBytes(hexstr))
result = format_output(self.abi, result)
Expand Down
Loading