def normalize_address(ens, address): if address: if is_ens_name(address): validate_name_has_address(ens, address) else: validate_address(address) return address
def construct_event_filter_params(event_abi, contract_address=None, argument_filters=None, topics=None, fromBlock=None, toBlock=None, address=None): filter_params = {} topic_set = construct_event_topic_set(event_abi, argument_filters) if topics is not None: if len(topic_set) > 1: raise TypeError( "Merging the topics argument with topics generated " "from argument_filters is not supported.") topic_set = topics if len(topic_set) == 1 and is_list_like(topic_set[0]): filter_params['topics'] = topic_set[0] else: filter_params['topics'] = topic_set if address and contract_address: if is_list_like(address): filter_params['address'] = address + [contract_address] elif is_string(address): filter_params['address'] = [address, contract_address] else: raise ValueError( "Unsupported type for `address` parameter: {0}".format(type(address)) ) elif address: filter_params['address'] = address elif contract_address: filter_params['address'] = contract_address if 'address' not in filter_params: pass elif is_list_like(filter_params['address']): for addr in filter_params['address']: validate_address(addr) else: validate_address(filter_params['address']) if fromBlock is not None: filter_params['fromBlock'] = fromBlock if toBlock is not None: filter_params['toBlock'] = toBlock data_filters_set = construct_event_data_set(event_abi, argument_filters) return data_filters_set, filter_params
def fromAddress(address): """ This method should be used to create an iban object from ethereum address @method fromAddress @param {String} address @return {Iban} the IBAN object """ validate_address(address) address_as_integer = int(address, 16) address_as_base36 = baseN(address_as_integer, 36) padded = pad_left_hex(address_as_base36, 15) return Iban.fromBban(padded.upper())
def validate_attr_dict(self, attr_dict: Dict[str, str]) -> None: """ Validates that ContractType keys in attr_dict reference existing manifest ContractTypes. """ attr_dict_names = list(attr_dict.keys()) if not self.unlinked_references and not self.linked_references: raise BytecodeLinkingError( "Unable to validate attr dict, this contract has no linked/unlinked references." ) unlinked_refs = self.unlinked_references or ({}, ) linked_refs = self.linked_references or ({}, ) all_link_refs = unlinked_refs + linked_refs all_link_names = [ref["name"] for ref in all_link_refs if ref] if set(attr_dict_names) != set(all_link_names): raise BytecodeLinkingError( "All link references must be defined when calling " "`link_bytecode` on a contract factory.") for address in attr_dict.values(): validate_address(address)
def _deployment( contract_instance: str, contract_type: str, deployment_bytecode: Dict[str, Any], runtime_bytecode: Dict[str, Any], compiler: Dict[str, Any], block_uri: URI, address: HexStr, tx: HexStr, block: HexStr, manifest: Manifest, ) -> Manifest: validate_address(address) if not is_BIP122_block_uri(block_uri): raise ManifestBuildingError(f"{block_uri} is not a valid BIP122 URI.") if tx: if not is_string(tx) and not is_hex(tx): raise ManifestBuildingError( f"Transaction hash: {tx} is not a valid hexstring" ) if block: if not is_string(block) and not is_hex(block): raise ManifestBuildingError(f"Block hash: {block} is not a valid hexstring") # todo: validate db, rb and compiler are properly formatted dicts deployment_data = _build_deployments_object( contract_type, deployment_bytecode, runtime_bytecode, compiler, address, tx, block, manifest, ) return assoc_in( manifest, ["deployments", block_uri, contract_instance], deployment_data )
def abi_address_to_hex(type_str, data): if type_str == 'address': validate_address(data) if is_binary_address(data): return type_str, to_checksum_address(data)
def normalize_address_no_ens(address: ChecksumAddress) -> ChecksumAddress: if address: validate_address(address) return address
def abi_address_to_hex(type_str: TypeStr, data: Any) -> Optional[Tuple[TypeStr, ChecksumAddress]]: if type_str == 'address': validate_address(data) if is_binary_address(data): return type_str, to_checksum_address(data) return None
def abi_address_to_hex(abi_type, data): if abi_type == 'address': validate_address(data) if is_binary_address(data): return abi_type, to_checksum_address(data)