def loopUntil_NewContract(query_intervall = 0.1): """ Wait for new smart contract to be deployed. Continuously polls file "FILE_CONTRACT_ADDRESS". Returns when overwritten file has different address or new filedate. N.B.: It actually happens that same Ethereum contract address is created again, if blockchain is deleted, and everything restarted. So: Check filedate too. """ address, _ = loadFromDisk() when = os.path.getmtime(FILE_CONTRACT_ADDRESS) print ("(filedate %d) last contract address: %s" %(when, address)) while(True): time.sleep(query_intervall) # checks whether a new contract has been deployed # because then a new address has been saved to file: newAddress, _ = loadFromDisk() newWhen = os.path.getmtime(FILE_CONTRACT_ADDRESS) if (newAddress != address or newWhen != when): print ("(filedate %d) new contract address: %s" %(newWhen, newAddress)) break return
def test_saveTo_and_loadFromDisk(): try: # try to preserve the original file content, if it exists: address, abi = deploy.loadFromDisk() except FileNotFoundError: # otherwise use dummy data address = "0x95368440Aa0b1E90201942085e03eEccDb3dB3E1" abi = ABI answer = deploy.saveToDisk(address, abi) assert answer == None address2, abi2 = deploy.loadFromDisk() assert address == address2 assert abi == abi2
def initialize_fromAddress(): """ initialise contract object from address, stored in disk file by deploy.py """ contractAddress, abi = loadFromDisk() myContract = w3.eth.contract(address=contractAddress, abi=abi) return myContract