def __init__(self, web3_addr, contract_addr="", contract_abi=None, contract_bytecode=None, timeout=30): web3 = ServiceStart.startweb3(web3_addr) contract_abi = FileLoad.getabi(contract_abi) contract_bytecode = FileLoad.getbytecode(contract_bytecode) if contract_addr != "": self.handle = web3.eth.contract( Web3.toChecksumAddress(contract_addr), abi=contract_abi, bytecode=contract_bytecode) else: self.handle = web3.eth.contract(abi=contract_abi, bytecode=contract_bytecode) self.timeout = timeout self.web3 = web3 self.address = self.handle.address self.abi = self.handle.abi self.bytecode = self.handle.bytecode self.functions = self.handle.functions
def make_contract(owners, signature, rlped_txs, tx_count, ves, bytescode=None, bin_dir=isc_bin_dir): try: rlped_txs = HexBytes(rlped_txs) encoded_data = AbiEncoder.encodes( [ owners, [0, 0, 0], HexBytes(ETHSIGN_HEADER + bytes(str(len(rlped_txs)).encode(ENC)) + bytes(rlped_txs)).hex(), signature, keccak(ETHSIGN_HEADER + b'\x36\x35' + HexBytes(signature)), tx_count ], ['address[]', 'uint256[]', 'bytes', 'bytes', 'bytes32', 'uint256'] ) if bytescode is None: bytescode = FileLoad.getbytecode(bin_dir) ves.unlockself() tx_json = JsonRPC.eth_send_transaction({ 'from': ves.address, 'data': bytescode.decode(ENC) + encoded_data, 'gas': hex(8000000) }) # print(tx_json) response = JsonRPC.send(tx_json, rpc_host=ves.chain_host) rp_json = JsonRPC.eth_get_transaction_receipt(response['result']) except Exception as e: isc_log.debug('ISCBulidError: {}'.format(str(e))) raise e while True: try: response = JsonRPC.send(rp_json, rpc_host=ves.chain_host) if response['result'] is None: console_logger.info("Contract is deploying, please stand by") time.sleep(2) continue console_logger.info("got Transaction_result {}".format(response['result'])) block_number = response['result']['blockNumber'] contract_addr = response['result']['contractAddress'] cd_json = JsonRPC.eth_get_code(contract_addr, block_number) response = JsonRPC.send(cd_json, rpc_host=ves.chain_host) if response['result'] == '0x': raise IndexError("Contract deployment failed") return contract_addr except Exception as e: isc_log.debug('ISCBulidError: {exec}'.format(exec=str(e)), extra={"addr": ""}) raise e