コード例 #1
0
    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)
コード例 #2
0
ファイル: contract.py プロジェクト: euri10/web3.py
    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)
コード例 #3
0
ファイル: contract.py プロジェクト: XertroV/web3.py
 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)
コード例 #4
0
ファイル: contract.py プロジェクト: vitaly-am/web3.py
 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)
コード例 #5
0
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))
コード例 #6
0
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
コード例 #7
0
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
コード例 #8
0
ファイル: contracts.py プロジェクト: 4gn3s/populus
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
コード例 #9
0
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))