def _encode_abi(cls, abi, arguments, data=None): argument_types = get_abi_input_types(abi) if not check_if_arguments_can_be_encoded(abi, arguments, {}): raise TypeError( "One or more arguments could not be encoded to the necessary " "ABI type. Expected types are: {0}".format( ', '.join(argument_types), )) try: encoded_arguments = encode_abi( argument_types, force_obj_to_bytes(arguments), ) except EncodingError as e: raise TypeError( "One or more arguments could not be encoded to the necessary " "ABI type: {0}".format(str(e))) if data: return add_0x_prefix( force_bytes(remove_0x_prefix(data)) + force_bytes(remove_0x_prefix(encode_hex(encoded_arguments)))) else: return encode_hex(encoded_arguments)
def _encode_abi(cls, abi, arguments, data=None): argument_types = get_abi_input_types(abi) if not check_if_arguments_can_be_encoded(abi, arguments, {}): raise TypeError( "One or more arguments could not be encoded to the necessary " "ABI type. Expected types are: {0}".format( ', '.join(argument_types), ) ) try: encoded_arguments = encode_abi( argument_types, force_obj_to_bytes(arguments), ) except EncodingError as e: raise TypeError( "One or more arguments could not be encoded to the necessary " "ABI type: {0}".format(str(e)) ) if data: return add_0x_prefix( force_bytes(remove_0x_prefix(data)) + force_bytes(remove_0x_prefix(encode_hex(encoded_arguments))) ) else: return encode_hex(encoded_arguments)
def _encodeABI(cls, abi, arguments, data=None): arguent_types = get_abi_input_types(abi) encoded_arguments = encode_abi(arguent_types, force_obj_to_bytes(arguments)) if data: return add_0x_prefix( force_bytes(remove_0x_prefix(data)) + force_bytes(remove_0x_prefix(encode_hex(encoded_arguments))) ) else: return encode_hex(encoded_arguments)
def _encodeABI(cls, abi, arguments, data=None): arguent_types = get_abi_input_types(abi) encoded_arguments = encode_abi(arguent_types, force_obj_to_bytes(arguments)) if data: return add_0x_prefix( force_bytes(remove_0x_prefix(data)) + force_bytes(remove_0x_prefix(encode_hex(encoded_arguments)))) else: return encode_hex(encoded_arguments)
def test_contract_constructor_encoding_encoding( WithConstructorArgumentsContract): deploy_data = WithConstructorArgumentsContract._encode_constructor_data( [1234, 'abcd']) encoded_args = '0x00000000000000000000000000000000000000000000000000000000000004d26162636400000000000000000000000000000000000000000000000000000000' expected_ending = encode_hex( encode_abi(['uint256', 'bytes32'], [1234, b'abcd'])) assert expected_ending == encoded_args assert deploy_data.endswith(remove_0x_prefix(expected_ending))
def test_personal_importRawKey_as_hex_without_0x(web3, account_private_key, account_password, account_public_key): address = web3.personal.importRawKey( remove_0x_prefix(encode_32bytes(account_private_key)), account_password) # sanity check assert is_same_address(address, account_public_key) assert web3.personal.unlockAccount(address, account_password) is True
def link_bytecode(bytecode, **dependencies): """ Given the bytecode for a contract, and it's dependencies in the form of {contract_name: address} this functino returns the bytecode with all of the link references replaced with the dependency addresses. """ linker_fn = compose(*(functools.partial( make_link_regex(name).sub, remove_0x_prefix(address), ) for name, address in dependencies.items())) linked_bytecode = linker_fn(bytecode) return linked_bytecode
def link_bytecode(bytecode, **dependencies): """ Given the bytecode for a contract, and it's dependencies in the form of {contract_name: address} this functino returns the bytecode with all of the link references replaced with the dependency addresses. """ linker_fn = compose(*( functools.partial( make_link_regex(name).sub, remove_0x_prefix(address), ) for name, address in dependencies.items() )) linked_bytecode = linker_fn(bytecode) return linked_bytecode
def test_contract_constructor_encoding_encoding(WithConstructorArgumentsContract): deploy_data = WithConstructorArgumentsContract.encodeConstructorData([1234, 'abcd']) encoded_args = b'0x00000000000000000000000000000000000000000000000000000000000004d26162636400000000000000000000000000000000000000000000000000000000' expected_ending = encode_hex(encode_abi(['uint256', 'bytes32'], [1234, b'abcd'])) assert expected_ending == encoded_args assert deploy_data.endswith(remove_0x_prefix(expected_ending))