def normalize_filter_params(from_block, to_block, address, topics): yield from_block yield to_block if address is None: yield address elif is_address(address): yield to_canonical_address(address) elif is_list_like(address): yield tuple( to_canonical_address(item) for item in address ) else: raise TypeError("Address is not in a recognized format: {0}".format(address)) if topics is None: yield topics elif is_valid_topic_array(topics): yield tuple( normalize_topic_list(item) if is_list_like(item) else normalize_topic(item) for item in topics ) else: raise TypeError("Topics are not in a recognized format: {0}".format(address))
def normalize_exec(exec_params: Dict[str, Any]) -> Dict[str, Any]: return { 'origin': to_canonical_address(exec_params['origin']), 'address': to_canonical_address(exec_params['address']), 'caller': to_canonical_address(exec_params['caller']), 'value': to_int(exec_params['value']), 'data': decode_hex(exec_params['data']), 'gas': to_int(exec_params['gas']), 'gasPrice': to_int(exec_params['gasPrice']), }
def normalize_block_header(header: Dict[str, Any]) -> Dict[str, Any]: normalized_header = { 'bloom': big_endian_to_int(decode_hex(header['bloom'])), 'coinbase': to_canonical_address(header['coinbase']), 'difficulty': to_int(header['difficulty']), 'extraData': decode_hex(header['extraData']), 'gasLimit': to_int(header['gasLimit']), 'gasUsed': to_int(header['gasUsed']), 'hash': decode_hex(header['hash']), 'mixHash': decode_hex(header['mixHash']), 'nonce': decode_hex(header['nonce']), 'number': to_int(header['number']), 'parentHash': decode_hex(header['parentHash']), 'receiptTrie': decode_hex(header['receiptTrie']), 'stateRoot': decode_hex(header['stateRoot']), 'timestamp': to_int(header['timestamp']), 'transactionsTrie': decode_hex(header['transactionsTrie']), 'uncleHash': decode_hex(header['uncleHash']), } if 'blocknumber' in header: normalized_header['blocknumber'] = to_int(header['blocknumber']) if 'chainname' in header: normalized_header['chainname'] = header['chainname'] if 'chainnetwork' in header: normalized_header['chainnetwork'] = header['chainnetwork'] return normalized_header
def encode_intended_validator(validator_address: Union[Address, str], primitive: bytes = None, *, hexstr: str = None, text: str = None) -> SignableMessage: """ Encode a message using the "intended validator" approach (ie~ version 0) defined in EIP-191_. Supply the message as exactly one of these three arguments: bytes as a primitive, a hex string, or a unicode string. .. WARNING:: Note that this code has not gone through an external audit. Also, watch for updates to the format, as the EIP is still in DRAFT. :param validator_address: which on-chain contract is capable of validating this message, provided as a checksummed address or in native bytes. :param primitive: the binary message to be signed :type primitive: bytes or int :param str hexstr: the message encoded as hex :param str text: the message as a series of unicode characters (a normal Py3 str) :returns: The EIP-191 encoded message, ready for signing .. _EIP-191: https://eips.ethereum.org/EIPS/eip-191 """ if not is_valid_address(validator_address): raise ValidationError( f"Cannot encode message with 'Validator Address': {validator_address}. " "It must be a checksum address, or an address converted to bytes.") message_bytes = to_bytes(primitive, hexstr=hexstr, text=text) return SignableMessage( HexBytes(b'\x00'), # version 0, as defined in EIP-191 to_canonical_address(validator_address), message_bytes, )
def normalize_account_state(account_state: FixtureAccountState) -> AccountState: return { to_canonical_address(address): { 'balance': to_int(state['balance']), 'code': decode_hex(state['code']), 'nonce': to_int(state['nonce']), 'storage': { to_int(slot): big_endian_to_int(decode_hex(value)) for slot, value in state['storage'].items() }, } for address, state in account_state.items() }
def normalize_callcreates(callcreates: Sequence[Dict[str, Any]]) -> List[Dict[str, Any]]: return [ { 'data': decode_hex(created_call['data']), 'destination': ( to_canonical_address(created_call['destination']) if created_call['destination'] else CREATE_CONTRACT_ADDRESS ), 'gasLimit': to_int(created_call['gasLimit']), 'value': to_int(created_call['value']), } for created_call in callcreates ]
def normalize_to_address(value: AnyStr) -> Address: if value: return to_canonical_address(value) else: return CREATE_CONTRACT_ADDRESS