def get_test_bid(self): bidDict = { "model": "QmaRmbJtyfMDBfkDETTPAxKUUcSqZKXWwFKKoZ318nrPku", "objective": "Qmb3H3tHZ1QutcrLq7WEtQWbEWjA11aPqVmeatMSrmFXvE", "token": self.test_token, "cost": 0, "validator": '0x0000000000000000000000000000000000000000', "lighthouse": self.lighthouse_address, "lighthouseFee": 0, "deadline": 9999999 } bid = Offer() model_mh = Multihash() model_mh.multihash = bidDict['model'] objective_mh = Multihash() objective_mh.multihash = bidDict['objective'] bid.model = model_mh bid.objective = objective_mh bid.token = bidDict['token'] bid.cost = bidDict['cost'] bid.validator = bidDict['validator'] bid.lighthouse = bidDict['lighthouse'] bid.lighthouseFee = bidDict['lighthouseFee'] bid.deadline = bidDict['deadline'] return bid
def send_offer(self, demand: Demand, price: UInt256): offer = Offer() offer.model = Multihash(self.MODEL) offer.objective = demand.objective offer.token = Address(self.TOKEN) offer.cost = price offer.lighthouse = demand.lighthouse offer.validator = demand.validator offer.lighthouseFee = UInt256("0") offer.deadline = self.make_deadline() self.signing_offer.publish(offer) rospy.loginfo(offer)
def create_offer(fields: dict) -> Offer: rospy.loginfo("Creating an offer...") offer = Offer() offer.model = Multihash(fields["model"]["multihash"]) offer.objective = Multihash(fields["objective"]["multihash"]) offer.token = Address(fields["token"]["address"]) offer.cost = UInt256(fields["cost"]["uint256"]) offer.lighthouse = Address(fields["lighthouse"]["address"]) offer.validator = Address(fields["validator"]["address"]) offer.lighthouseFee = UInt256(fields["lighthouseFee"]["uint256"]) offer.deadline = UInt256(fields["deadline"]["uint256"]) rospy.loginfo(offer) return offer
def make_offer(self, demand: Demand): rospy.loginfo('Making offer...') offer = Offer() offer.model = Multihash(self.MODEL) offer.objective = demand.objective offer.token = demand.token offer.cost = demand.cost offer.lighthouse = demand.lighthouse offer.validator = demand.validator offer.lighthouseFee = UInt256("0") offer.deadline = UInt256() offer.deadline.uint256 = self.make_deadline() self.signing_offer.publish(offer) rospy.loginfo(offer)
def dict2offer(m): msg = Offer() msg.model.multihash = m['model'] msg.objective.multihash = m['objective'] msg.token.address = m['token'] msg.cost.uint256 = str(m['cost']) msg.validator.address = m['validator'] msg.lighthouse.address = m['lighthouse'] msg.lighthouseFee.uint256 = str(m['lighthouseFee']) 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_bid(self, incoming_ask): rospy.loginfo('Making bid...') bid = Offer() bid.model = self.model bid.objective = incoming_ask.objective bid.token = self.token bid.cost = incoming_ask.cost bid.lighthouseFee = 0 bid.deadline = self.web3.eth.getBlock('latest').number + self.bid_lifetime self.signing_bid_pub.publish(bid)
def make_offer(self, incoming): rospy.loginfo('Making offer...') offer = Offer() offer.model = incoming.model offer.objective = incoming.objective offer.token = incoming.token offer.cost = incoming.cost offer.lighthouse = Address() offer.lighthouse.address = rospy.get_param('~lighthouse') offer.validator = incoming.validator offer.lighthouseFee = UInt256() offer.lighthouseFee.uint256 = '0' offer.deadline = UInt256() offer.deadline.uint256 = self.make_deadline() self.signing_offer.publish(offer) rospy.loginfo(offer)
def getValidBid(): b = Offer() model = Multihash() model.multihash = validBidDict['model'] objective = Multihash() objective.multihash = validBidDict['objective'] b.model = model b.objective = objective b.token = validBidDict['token'] b.cost = validBidDict['cost'] b.validator = validBidDict['validator'] b.lighthouse = validBidDict['lighthouse'] b.lighthouseFee = validBidDict['lighthouseFee'] b.deadline = validBidDict['deadline'] b.nonce = unhexlify(validBidDict['nonce'].encode('utf-8')) b.signature = unhexlify(validBidDict['signature'].encode('utf-8')) return b
def dict2bid(m): msg = Offer() 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.validator = m['validator'] msg.lighthouse = m['lighthouse'] msg.lighthouseFee = m['lighthouseFee'] msg.deadline = m['deadline'] msg.nonce = unhexlify(m['nonce'].encode('utf-8')) msg.signature = unhexlify(m['signature'].encode('utf-8')) return msg
def getValidBid(): b = Offer() b.model = Multihash() b.model.multihash = validBidDict['model'] b.objective = Multihash() b.objective.multihash = validBidDict['objective'] b.token = Address() b.token.address = validBidDict['token'] b.cost = UInt256() b.cost.uint256 = str(validBidDict['cost']) b.validator = Address() b.validator.address = validBidDict['validator'] b.lighthouse = Address() b.lighthouse.address = validBidDict['lighthouse'] b.lighthouseFee = UInt256() b.lighthouseFee.uint256 = str(validBidDict['lighthouseFee']) b.deadline = UInt256() b.deadline.uint256 = str(validBidDict['deadline']) b.sender = Address() b.sender.address = validAskDict['sender'] b.signature = unhexlify(validBidDict['signature'].encode('utf-8')) return b