def initialize_scenario( validator_set_contract: Contract, transition_heights: Sequence[int] = None ) -> Tuple[List[ValidatorDefinitionRange], List[Union[Type[Contract], Contract]]]: _transition_heights: List[Union[int, None]] = ( list(transition_heights) if transition_heights is not None else []) w3 = validator_set_contract.web3 validator_definition_ranges = [] contracts: List[Union[Type[Contract], Contract]] = [] for enter_height, leave_height in sliding_window( 2, _transition_heights + [None]): deployment_tx_hash = validator_set_contract.constructor().transact() deployment_receipt: TxReceipt = w3.eth.waitForTransactionReceipt( deployment_tx_hash) contract = w3.eth.contract( address=deployment_receipt["contractAddress"], abi=validator_set_contract.abi, ) contracts.append(contract) validator_definition_ranges.append( ValidatorDefinitionRange( enter_height=enter_height, leave_height=leave_height, is_contract=True, contract_address=contracts[-1].address, validators=None, )) return validator_definition_ranges, contracts
def _deploy_proxy_factory_contract(ethereum_client: EthereumClient, deployer_account: LocalAccount, contract: Contract) -> EthereumTxSent: tx = contract.constructor().buildTransaction({'from': deployer_account.address}) tx_hash = ethereum_client.send_unsigned_transaction(tx, private_key=deployer_account.key) tx_receipt = ethereum_client.get_transaction_receipt(tx_hash, timeout=120) assert tx_receipt assert tx_receipt['status'] contract_address = tx_receipt['contractAddress'] logger.info("Deployed and initialized Proxy Factory Contract=%s by %s", contract_address, deployer_account.address) return EthereumTxSent(tx_hash, tx, contract_address)
def send_deployment_transaction(self, contract: Contract, args: List) -> str: txhash = None while txhash is None: try: txhash = contract.constructor(*args).transact(self.transaction) except ValueError as ex: # pylint: disable=E1126 if ex.args[0]["code"] == -32015: LOG.info(f"Deployment failed with {ex}. Retrying...") else: raise ex return txhash
def create_signed_contract_transaction( private_key: str, contract: Contract, func_name: str, args: List[Any] ): w3 = contract.web3 acct = w3.eth.account.privateKeyToAccount(private_key) if name == 'constructor': tx_data = contract.constructor(*args).buildTransaction({ 'from': acct.address, 'nonce': web3.eth.getTransactionCount(acct.address), 'gasPrice': web3.eth.gasPrice }) else: tx_data = contract.functions[func_name](*args).buildTransaction({ 'from': acct.address, 'nonce': web3.eth.getTransactionCount(acct.address), 'gasPrice': web3.eth.gasPrice }) signed_tx = acct.signTransaction(tx_data) return signed_tx.rawTransaction