def dump(): version = request.args.get('version', '1') contract_address = redis_store.get(f'contractAddress{version}').decode() contract_interface_abi = ast.literal_eval( redis_store.get(f'contractInterfaceAbi{version}').decode()) name_value = w3.eth.contract(address=contract_address, abi=contract_interface_abi, ContractFactoryClass=ConciseContract) file = request.args.get('file') if version == '1': return name_value_1.dump(name_value, file) elif version == '2': return name_value_2.dump(name_value, file)
def update(): version = request.args.get('version', '1') contract_address = redis_store.get(f'contractAddress{version}').decode() contract_interface_abi = ast.literal_eval( redis_store.get(f'contractInterfaceAbi{version}').decode()) name_value = w3.eth.contract(address=contract_address, abi=contract_interface_abi) if version == '1': name_value_1.update(name_value) elif version == '2': name_value_2.update(name_value) return 'ok'
def listener(): version = request.args.get('version', '1') if version == '1': return 'Not implemented, see version 2' contract_address = redis_store.get(f'contractAddress{version}').decode() contract_interface_abi = ast.literal_eval( redis_store.get(f'contractInterfaceAbi{version}').decode()) name_value = w3.eth.contract( address=contract_address, abi=contract_interface_abi, ) return name_value_2.listener(name_value)
def remove(): version = request.args.get('version', '1') contract_address = redis_store.get(f'contractAddress{version}').decode() contract_interface_abi = ast.literal_eval( redis_store.get(f'contractInterfaceAbi{version}').decode()) name_value = w3.eth.contract( address=contract_address, abi=contract_interface_abi, ) key = request.args.get('key') tx_hash = name_value.functions.remove(key).transact({'gas': 410_000}) w3.eth.waitForTransactionReceipt(tx_hash) return 'ok'
def get(): version = request.args.get('version', '1') contract_address = redis_store.get(f'contractAddress{version}').decode() contract_interface_abi = ast.literal_eval( redis_store.get(f'contractInterfaceAbi{version}').decode()) name_value = w3.eth.contract(address=contract_address, abi=contract_interface_abi, ContractFactoryClass=ConciseContract) key = request.args.get('key') value = name_value.get(key) if type(value) == str: return value value[-1] = datetime.fromtimestamp( (int(value[-1]) / 1_000_000_000)).strftime("%Y-%m-%d %H:%M:%S") return jsonify(dict(zip(('value', 'author', 'updated_date'), value)))