def get_test_ask(self): askDict = { "model": "QmaRmbJtyfMDBfkDETTPAxKUUcSqZKXWwFKKoZ318nrPku", "objective": "Qmb3H3tHZ1QutcrLq7WEtQWbEWjA11aPqVmeatMSrmFXvE", "token": self.test_token, "cost": 0, "lighthouse": self.lighthouse_address, "validator": "0x0000000000000000000000000000000000000000", "validatorFee": 0, "deadline": 9999999 } ask = Demand() model_mh = Multihash() model_mh.multihash = askDict['model'] objective_mh = Multihash() objective_mh.multihash = askDict['objective'] ask.model = model_mh ask.objective = objective_mh ask.token = askDict['token'] ask.cost = askDict['cost'] ask.lighthouse = askDict['lighthouse'] ask.validator = askDict['validator'] ask.validatorFee = askDict['validatorFee'] ask.deadline = askDict['deadline'] return ask
def create_demand(fields: dict) -> Demand: rospy.loginfo("Creating an demand...") demand = Demand() demand.model = Multihash(fields["model"]["multihash"]) demand.objective = Multihash(fields["objective"]["multihash"]) demand.token = Address(fields["token"]["address"]) demand.cost = UInt256(fields["cost"]["uint256"]) demand.lighthouse = Address(fields["lighthouse"]["address"]) demand.validator = Address(fields["validator"]["address"]) demand.validatorFee = UInt256(fields["validatorFee"]["uint256"]) demand.deadline = UInt256(fields["deadline"]["uint256"]) rospy.loginfo(demand) return demand
def dict2demand(m): msg = Demand() msg.model.multihash = m['model'] msg.objective.multihash = m['objective'] msg.token.address = m['token'] msg.cost.uint256 = str(m['cost']) msg.lighthouse.address = m['lighthouse'] msg.validator.address = m['validator'] msg.validatorFee.uint256 = str(m['validatorFee']) msg.deadline.uint256 = str(m['deadline']) msg.sender.address = m['sender'] msg.nonce.uint256 = str(m['nonce']) if m['signature']: msg.signature = unhexlify(m['signature'].encode('utf-8')) return msg
def make_demand(self, objective: Multihash, cost: UInt256): rospy.loginfo('Making demand...') demand = Demand() demand.model = Multihash() demand.model.multihash = self.MODEL demand.objective = objective demand.token = Address() demand.token.address = self.TOKEN demand.cost = cost demand.lighthouse = Address() demand.lighthouse.address = self.LIGHTHOUSE demand.validator = Address() demand.validator.address = '0x0000000000000000000000000000000000000000' demand.validatorFee = UInt256() demand.validatorFee.uint256 = '0' demand.deadline = self.get_deadline() self.signing_demand.publish(demand) rospy.loginfo(demand)
def getValidAsk(): a = Demand() model = Multihash() model.multihash = validAskDict['model'] objective = Multihash() objective.multihash = validAskDict['objective'] a.model = model a.objective = objective a.token = validAskDict['token'] a.cost = validAskDict['cost'] a.lighthouse = validAskDict['lighthouse'] a.validator = validAskDict['validator'] a.validatorFee = validAskDict['validatorFee'] a.deadline = validAskDict['deadline'] a.nonce = unhexlify(validAskDict['nonce'].encode('utf-8')) a.signature = unhexlify(validAskDict['signature'].encode('utf-8')) return a
def dict2ask(m): msg = Demand() model_mh = Multihash() model_mh.multihash = m['model'] objective_mh = Multihash() objective_mh.multihash = m['objective'] msg.model = model_mh msg.objective = objective_mh msg.token = m['token'] msg.cost = m['cost'] msg.lighthouse = m['lighthouse'] msg.validator = m['validator'] msg.validatorFee = m['validatorFee'] msg.deadline = m['deadline'] msg.nonce = unhexlify(m['nonce'].encode('utf-8')) msg.signature = unhexlify(m['signature'].encode('utf-8')) return msg
def getValidAsk(): a = Demand() a.model = Multihash() a.model.multihash = validAskDict['model'] a.objective = Multihash() a.objective.multihash = validAskDict['objective'] a.token = Address() a.token.address = validAskDict['token'] a.cost = UInt256() a.cost.uint256 = str(validAskDict['cost']) a.lighthouse = Address() a.lighthouse.address = validAskDict['lighthouse'] a.validator = Address() a.validator.address = validAskDict['validator'] a.validatorFee = UInt256() a.validatorFee.uint256 = str(validAskDict['validatorFee']) a.deadline = UInt256() a.deadline.uint256 = str(validAskDict['deadline']) a.sender = Address() a.sender.address = validAskDict['sender'] a.signature = unhexlify(validAskDict['signature'].encode('utf-8')) return a
rospy.loginfo('Node launched') model = MODEL or input('Model IPFS hash: ') objective = OBJECTIVE or input('Objective IPFS hash: ') token = TOKEN or input('Token: ') price = PRICE or input('Price: ') lifetime = LIFETIME or input('Demand lifetime: ') deadline = str( rospy.ServiceProxy('/eth/current_block', BlockNumber)().number + int(lifetime)) rospy.loginfo('Making demand...') # Demand message consists of the following fields demand = Demand() demand.model = Multihash() demand.model.multihash = model demand.objective = Multihash() demand.objective.multihash = objective demand.lighthouse = Address() demand.lighthouse.address = '0xD40AC7F1e5401e03D00F5aeC1779D8e5Af4CF9f1' demand.token = Address() demand.token.address = token demand.cost = UInt256() demand.cost.uint256 = str(price) demand.validatorFee = UInt256() demand.validatorFee.uint256 = '0' demand.validator = Address() demand.validator.address = '0x0000000000000000000000000000000000000000' demand.deadline = UInt256()
def make_demand(objective: str, cost: int) -> Demand: rospy.loginfo('Making demand...') demand = Demand() demand.model = Multihash(MODEL) demand.objective = Multihash(objective) demand.token = Address(TOKEN) demand.cost = UInt256(str(cost)) demand.lighthouse = Address(LIGHTHOUSE) demand.validator = Address(VALIDATOR) demand.validatorFee = UInt256('0') demand.deadline = UInt256() demand.deadline.uint256 = make_deadline() demand.nonce = UInt256('0') rospy.loginfo(demand) return demand
def dict2ask(m): msg = Demand() msg.model = Multihash() msg.model.multihash = m['model'] msg.objective = Multihash() msg.objective.multihash = m['objective'] msg.token = Address() msg.token.address = m['token'] msg.cost = UInt256() msg.cost.uint256 = str(m['cost']) msg.lighthouse = Address() msg.lighthouse.address = m['lighthouse'] msg.validator = Address() msg.validator.address = m['validator'] msg.validatorFee = UInt256() msg.validatorFee.uint256 = str(m['validatorFee']) msg.deadline = UInt256() msg.deadline.uint256 = str(m['deadline']) msg.sender = Address() msg.sender.address = m['sender'] msg.signature = unhexlify(m['signature'].encode('utf-8')) return msg