예제 #1
0
def dict2bid(m):
    msg = Offer()

    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.validator = Address()
    msg.validator.address = m['validator']

    msg.lighthouse = Address()
    msg.lighthouse.address = m['lighthouse']

    msg.lighthouseFee = UInt256()
    msg.lighthouseFee.uint256 = str(m['lighthouseFee'])

    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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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
예제 #5
0
def getValidRes():
    r = Result()
    r.liability = Address()
    r.liability.address = validResDict['liability']
    r.result = Multihash()
    r.result.multihash = validResDict['result']
    r.success = validResDict['success']
    r.signature = unhexlify(validResDict['signature'].encode('utf-8'))
    return r
예제 #6
0
 def __stop_player(msg):
     try:
         player_thread = self.player_threads.pop(msg.player_id)
         result_ipfs_address = player_thread.finish(msg.success)
         rospy.loginfo('Player %s stopped with %s', msg.player_id,
                       result_ipfs_address)
         return StopRosbagPlayerResponse(True, result_ipfs_address)
     except KeyError as e:
         rospy.logerr("Could not find player_id %s for stopping",
                      msg.player_id)
         return StopRosbagPlayerResponse(False, Multihash(''))
예제 #7
0
    def __ipfs_download(self, ipfs_hash: str) -> str:
        rospy.wait_for_service('/ipfs/get_file')
        download = rospy.ServiceProxy('/ipfs/get_file', IpfsDownloadFile)

        tmpfile = mkstemp()

        res = download(Multihash(ipfs_hash), Filepath(tmpfile[1]))
        if not res.success:
            raise Exception(res.error_msg)

        return tmpfile[1]
예제 #8
0
def dict2res(m):
    msg = Result()

    msg.liability = Address()
    msg.liability.address = m['liability']

    msg.result = Multihash()
    msg.result.multihash = m['result']

    msg.success = m['success']
    msg.signature = unhexlify(m['signature'].encode('utf-8'))
    return msg
예제 #9
0
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
예제 #10
0
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
예제 #11
0
    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)
예제 #12
0
    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)
예제 #13
0
    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)
예제 #14
0
    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()
    demand.deadline.uint256 = deadline