def build_initcode(*, contract_bytecode, contract_abi=[], constructor_args=[]): constructor_abi = get_constructor_abi(contract_abi) # The initcode is the bytecode with the encoded arguments appended if constructor_abi: return encode_abi( web3=Web3(), abi=constructor_abi, arguments=constructor_args, data=contract_bytecode, ) else: return contract_bytecode
def _encode_data_in_transaction(self, *args, **kwargs): constructor_abi = get_constructor_abi(self.abi) if constructor_abi: if not args: args = tuple() if not kwargs: kwargs = {} arguments = merge_args_and_kwargs(constructor_abi, args, kwargs) data = add_0x_prefix( encode_abi(self.web3, constructor_abi, arguments, data=self.bytecode) ) else: data = to_hex(self.bytecode) return data
def encode_constructor_arguments(web3: Web3, constructor_function: ContractConstructor, *constructor_args, **constructor_kwargs) -> HexStr: """ Takes a web3 constructor function and the arguments passed to it, and produces an encoding hex string of the constructor arguments, following the standard ABI encoding conventions. If there's no constructor, it returns None. """ constructor_abi = get_constructor_abi(constructor_function.abi) if constructor_abi: arguments = merge_args_and_kwargs(constructor_abi, constructor_args, constructor_kwargs) data = encode_abi(web3, constructor_abi, arguments) else: data = None return data
def _encode_data_in_transaction(self, *args, **kwargs): constructor_abi = get_constructor_abi(self.abi) if constructor_abi: if not args: args = tuple() if not kwargs: kwargs = {} arguments = merge_args_and_kwargs(constructor_abi, args, kwargs) data = add_0x_prefix( encode_abi(self.web3, constructor_abi, arguments, data=self.bytecode) ) else: data = to_hex(self.bytecode) return data
def _encode_constructor_data(cls, args=None, kwargs=None): constructor_abi = get_constructor_abi(cls.abi) if constructor_abi: if args is None: args = tuple() if kwargs is None: kwargs = {} arguments = merge_args_and_kwargs(constructor_abi, args, kwargs) deploy_data = add_0x_prefix( encode_abi(cls.web3, constructor_abi, arguments, data=cls.bytecode) ) else: deploy_data = to_hex(cls.bytecode) return deploy_data
def _encode_constructor_data(cls, args=None, kwargs=None): constructor_abi = get_constructor_abi(cls.abi) if constructor_abi: if args is None: args = tuple() if kwargs is None: kwargs = {} arguments = merge_args_and_kwargs(constructor_abi, args, kwargs) deploy_data = add_0x_prefix( encode_abi(cls.web3, constructor_abi, arguments, data=cls.bytecode) ) else: deploy_data = to_hex(cls.bytecode) return deploy_data
def _encode_constructor_data(cls, args=None, kwargs=None): constructor_abi = get_constructor_abi(cls.abi) if constructor_abi: if args is None: args = tuple() if kwargs is None: kwargs = {} arguments = merge_args_and_kwargs(constructor_abi, args, kwargs) deploy_data = add_0x_prefix( encode_abi(cls.web3, constructor_abi, arguments, data=cls.bytecode) ) else: if args is not None or kwargs is not None: msg = "Constructor args were provided, but no constructor function was provided." raise TypeError(msg) deploy_data = to_hex(cls.bytecode) return deploy_data
def parse_args_to_matching_types_for_constructor(args, contract_abi): """Parses a list of commandline arguments to the abi matching python types""" constructor_abi = get_constructor_abi(contract_abi) if constructor_abi: return parse_args_to_matching_types_for_function(args, constructor_abi) return []