def __init__(self, *args): rospy.init_node(NAME) super(TestSigner, self).__init__(*args) self._test_sign_ask_success = False self._test_sign_bid_success = False self._test_sign_res_success = False __keyfile = rospy.get_param('~keyfile') __keyfile_password_file = rospy.get_param('~keyfile_password_file') __keyfile_helper = eth_keyfile_helper.KeyfileHelper( __keyfile, keyfile_password_file=__keyfile_password_file) self.__account = __keyfile_helper.get_local_account_from_keyfile()
def __init__(self): ''' Market reporter initialisation. ''' rospy.init_node('robonomics_lighthouse') http_provider = HTTPProvider(rospy.get_param('~web3_http_provider')) ens = ENS(http_provider, addr=rospy.get_param('~ens_contract', None)) self.web3 = Web3(http_provider, ens=ens) # inject the poa compatibility middleware to the innermost layer self.web3.middleware_stack.inject(middleware.geth_poa_middleware, layer=0) ens.web3.middleware_stack.inject(middleware.geth_poa_middleware, layer=0) self.web3.middleware_stack.add(middleware.time_based_cache_middleware) self.web3.middleware_stack.add( middleware.latest_block_based_cache_middleware) self.web3.middleware_stack.add(middleware.simple_cache_middleware) self.liability_abi = json.loads(rospy.get_param('~liability_abi')) lighthouse_abi = json.loads(rospy.get_param('~lighthouse_abi')) lighthouse_contract = rospy.get_param('~lighthouse_contract') self.lighthouse = self.web3.eth.contract(lighthouse_contract, abi=lighthouse_abi) __keyfile = rospy.get_param('~keyfile') __keyfile_password_file = rospy.get_param('~keyfile_password_file') __keyfile_helper = eth_keyfile_helper.KeyfileHelper( __keyfile, keyfile_password_file=__keyfile_password_file) __account = __keyfile_helper.get_local_account_from_keyfile() self.account_address = __account.address rospy.Subscriber('infochan/incoming/result', Result, self.settle_result) rospy.Subscriber('deal', Deal, self.settle_deal) self.setupGasStrategy() self.createQuotaManager()
def __init__(self): ''' Robonomics liability node initialisation. ''' rospy.init_node('robonomics_liability_executor') self.recording_topics = list(filter(None, [x.strip() for x in rospy.get_param('~recording_topics').split(",")])) self.master_check_interval = rospy.get_param('~master_check_interval') __keyfile = rospy.get_param('~keyfile') __keyfile_password_file = rospy.get_param('~keyfile_password_file') __keyfile_helper = eth_keyfile_helper.KeyfileHelper(__keyfile, keyfile_password_file=__keyfile_password_file) self.__account = __keyfile_helper.get_local_account_from_keyfile() self.liability_execution_threads = {} # persistence publishers self.persistence_add = rospy.Publisher('persistence/add', Liability, queue_size=10) self.persistence_del = rospy.Publisher('persistence/del', Liability, queue_size=10) # persistence services self.persistence_get_liability_timestamp = rospy.ServiceProxy('persistence/get_liability_timestamp', PersistenceLiabilityTimestamp) self.read_libility_srv = rospy.ServiceProxy('read', ReadLiability) self.executions_work_directory = os.path.join(os.getcwd(), 'liabilities_executions') def incoming_liability(msg): if msg.promisor.address != self.__account.address: rospy.logwarn('Liability %s is not for me, SKIP.', msg.address) else: rospy.loginfo('Append %s to liability queue.', msg.address) self.persistence_add.publish(msg) self.liability_queue.put(msg) rospy.Subscriber('incoming', Liability, incoming_liability) def finish_liability(msg): liability_thread = self.liability_execution_threads.pop(msg.address.address) liability_msg = liability_thread.getLiabilityMsg() result_ipfs_address = liability_thread.finish(msg.success) result = Result() result.liability = liability_msg.address result.result = result_ipfs_address result.success = msg.success self.persistence_del.publish(liability_msg) self.complete.publish(liability_msg) self.result_topic.publish(result) rospy.loginfo('Liability %s finished with %s', liability_msg.address.address, result.result) return FinishLiabilityResponse() rospy.Service('finish', FinishLiability, finish_liability) def start_liability(msg): if msg.address.address not in self.liability_execution_threads: rospy.wait_for_service(self.read_libility_srv.resolved_name) read_liability_response = self.read_libility_srv(msg.address) if not read_liability_response.read: return StartLiabilityResponse(False, "Could not find {0} in ready liabilities or read them from chain for starting".format(msg.address.address)) try: self.persistence_add.publish(read_liability_response.liability) self._createLiabilityExceutionThread(read_liability_response.liability) except Exception as e: rospy.logerr("Failed to prepare liability {0} to execution with e: {1}".format(msg.address.address, e)) return StartLiabilityResponse(False, "Failed to prepare liability {0} to execution with e: {1}".format(msg.address.address, e)) liability_thread = self.liability_execution_threads[msg.address.address] try: liability_thread.start() rospy.loginfo('Liability %s started', liability_thread.getLiabilityMsg().address.address) except Exception as e: rospy.logerr("Can't start liability %s with %s", msg.address.address, e) return StartLiabilityResponse(False, "Can't start liability {0} with exception: {1}".format(msg.address.address, e)) return StartLiabilityResponse(True, "Liability {0} started".format(liability_thread.getLiabilityMsg().address.address)) rospy.Service('start', StartLiability, start_liability) def restart_liability(msg): try: liability_thread = self.liability_execution_threads.pop(msg.address.address) except KeyError as e: rospy.logerr("Could not find liability %s for restarting", msg.address.address) return StartLiabilityResponse(False, "Could not find liability {0} for restarting".format(msg.address.address)) liability = liability_thread.getLiabilityMsg() try: liability_thread.interrupt(delete_result=True) rospy.loginfo('Liability %s interrupted', liability.address.address) except Exception as e: rospy.logerr("Can't interrupt liability %s with %s", msg.address.address, e) return StartLiabilityResponse(False, "Can't interrupt liability {0} with exception: {1}".format(msg.address.address, e)) try: self._createLiabilityExceutionThread(liability) except Exception as e: return StartLiabilityResponse(False, "Can't initialize liability {0} execution thread with exception: {1}".format(msg.address.address, e)) return start_liability(msg) rospy.Service('restart', StartLiability, restart_liability) def resume_liability(msg): try: liability_thread = self.liability_execution_threads[msg.address.address] except KeyError as e: rospy.logerr("Could not find liability %s for resuming", msg.address.address) return StartLiabilityResponse(False, "Could not find liability {0} for resuming".format(msg.address.address)) try: rospy.wait_for_service(self.persistence_get_liability_timestamp.resolved_name) timestamp = self.persistence_get_liability_timestamp(liability_thread.getLiabilityMsg().address) rospy.logwarn("Getting %s timestamp for liability %s", timestamp.timestamp, msg.address.address) liability_thread.start(timestamp.timestamp) rospy.loginfo('Liability %s resumed', liability_thread.getLiabilityMsg().address.address) except Exception as e: rospy.logerr("Can't resume liability %s with %s", msg.address.address, e) return StartLiabilityResponse(False, "Can't resume liability {0} with exception: {1}".format(msg.address.address, e)) return StartLiabilityResponse(True, "Liability {0} resumed".format(liability_thread.getLiabilityMsg().address.address)) rospy.Service('resume', StartLiability, resume_liability) self.complete = rospy.Publisher('complete', Liability, queue_size=10) self.ready = rospy.Publisher('ready', Liability, queue_size=10) self.result_topic = rospy.Publisher('result', Result, queue_size=10)
def __init__(self): ''' Robonomics liability node initialisation. ''' rospy.init_node('robonomics_liability_executor') self.recording_topics = list( filter(None, [ x.strip() for x in rospy.get_param('~recording_topics').split(",") ])) self.master_check_interval = rospy.get_param('~master_check_interval') __keyfile = rospy.get_param('~keyfile') __keyfile_password_file = rospy.get_param('~keyfile_password_file') __keyfile_helper = eth_keyfile_helper.KeyfileHelper( __keyfile, keyfile_password_file=__keyfile_password_file) self.__account = __keyfile_helper.get_local_account_from_keyfile() ipfs_provider = urlparse( rospy.get_param('~ipfs_http_provider')).netloc.split(':') self.ipfs_client = ipfsapi.connect(ipfs_provider[0], int(ipfs_provider[1])) self.liability_execution_threads = {} def incoming_liability(msg): if msg.promisor != self.__account.address: rospy.logwarn('Liability %s is not for me, SKIP.', msg.address) else: rospy.loginfo('Append %s to liability queue.', msg.address) self.liability_queue.put(msg) rospy.Subscriber('incoming', Liability, incoming_liability) def finish_liability(msg): liability_thread = self.liability_execution_threads.pop( msg.address) liability_msg = liability_thread.getLiabilityMsg() result = liability_thread.finish(msg.success) self.complete.publish(liability_msg) self.result_topic.publish(result) rospy.loginfo('Liability %s finished with %s', liability_msg.address, result.result) return FinishLiabilityResponse() rospy.Service('finish', FinishLiability, finish_liability) def start_liability(msg): try: liability_thread = self.liability_execution_threads[ msg.address] except KeyError as e: rospy.logerr("Could not find liability %s for starting", msg.address) return StartLiabilityResponse( False, "Could not find liability {0} for starting".format( msg.address)) try: liability_thread.start() rospy.loginfo('Liability %s started', liability_thread.getLiabilityMsg().address) except Exception as e: rospy.logerr("Can't start liability %s with %s", msg.address, e) return StartLiabilityResponse( False, "Can't start liability {0} with exception: {1}".format( msg.address, e)) return StartLiabilityResponse( True, "Liability {0} started".format( liability_thread.getLiabilityMsg().address)) rospy.Service('start', StartLiability, start_liability) self.complete = rospy.Publisher('complete', Liability, queue_size=10) self.ready = rospy.Publisher('ready', Liability, queue_size=10) self.result_topic = rospy.Publisher('result', Result, queue_size=10)