def __init__(self, address: str, owner: Optional[AccountsType] = None, tx: TransactionReceiptType = None) -> None: address = _resolve_address(address) self.bytecode = web3.eth.getCode(address).hex()[2:] if not self.bytecode: raise ContractNotFound(f"No contract deployed at {address}") self._owner = owner self.tx = tx self.address = address _add_deployment_topics(address, self.abi) fn_names = [i["name"] for i in self.abi if i["type"] == "function"] for abi in [i for i in self.abi if i["type"] == "function"]: name = f"{self._name}.{abi['name']}" sig = build_function_signature(abi) natspec: Dict = {} if self._build.get("natspec"): natspec = self._build["natspec"]["methods"].get(sig, {}) if fn_names.count(abi["name"]) == 1: fn = _get_method_object(address, abi, name, owner, natspec) self._check_and_set(abi["name"], fn) continue # special logic to handle function overloading if not hasattr(self, abi["name"]): overloaded = OverloadedMethod(address, name, owner) self._check_and_set(abi["name"], overloaded) getattr(self, abi["name"])._add_fn(abi, natspec)
def decode_input(self, calldata: Union[str, bytes]) -> Tuple[str, Any]: """ Decode input calldata for this contract. Arguments --------- calldata : str | bytes Calldata for a call to this contract Returns ------- str Signature of the function that was called Any Decoded input arguments """ if not isinstance(calldata, HexBytes): calldata = HexBytes(calldata) abi = next( (i for i in self.abi if i["type"] == "function" and build_function_selector(i) == calldata[:4].hex()), None, ) if abi is None: raise ValueError( "Four byte selector does not match the ABI for this contract") function_sig = build_function_signature(abi) types_list = get_type_strings(abi["inputs"]) result = eth_abi.decode_abi(types_list, calldata[4:]) input_args = format_input(abi, result) return function_sig, input_args
def __init__( self, web3: 'AsyncWeb3', address: Address, abi: Dict, ) -> None: self.web3 = web3 self._address = address self.abi = abi self.signature = build_function_selector(abi) self._input_sig = build_function_signature(abi)
def __init__( self, address: str, abi: Dict, name: str, owner: Optional[AccountsType], natspec: Optional[Dict] = None, ) -> None: self._address = address self._name = name self.abi = abi self._owner = owner self.signature = build_function_selector(abi) self._input_sig = build_function_signature(abi) self.natspec = natspec or {}