def getValidRes():
    r = Result()
    result = Multihash()
    result.multihash = validResDict['result']
    r.liability = validResDict['liability']
    r.result = result
    r.success = validResDict['success']
    r.signature = unhexlify(validResDict['signature'].encode('utf-8'))
    return r
def dict2res(m):
    msg = Result()

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

    msg.liability = m['liability']
    msg.result = result_mh
    msg.success = m['success']
    msg.signature = unhexlify(m['signature'].encode('utf-8'))
    return msg
Exemplo n.º 3
0
    def finish(self, success):
        self.__recorder.stop()

        ipfs_response = self.ipfs_client.add(self.__liability_result_file)
        try:
            self.liability.result = ipfs_response['Hash']
        except TypeError:
            rospy.logwarn('IPFS add proceeding error: %s',
                          ipfs_response[1]['Message'])
            self.liability.result = ipfs_response[0]['Hash']

        result_msg = Result()

        result_mh = Multihash()
        result_mh.multihash = self.liability.result

        result_msg.liability = self.liability.address
        result_msg.result = result_mh
        result_msg.success = success
        return result_msg
Exemplo n.º 4
0
    def liability_read(self, address):
        '''
            Read liability from blockchain to message.
        '''
        c = self.web3.eth.contract(address, abi=self.liability_abi)
        msg = Liability()

        model_mh = Multihash()
        model_mh.multihash = multihash.decode(
            c.call().model()).encode('base58').decode()

        objective_mh = Multihash()
        objective_mh.multihash = multihash.decode(
            c.call().objective()).encode('base58').decode()

        msg.address = address
        msg.model = model_mh
        msg.objective = objective_mh
        msg.promisee = c.call().promisee()
        msg.promisor = c.call().promisor()
        msg.lighthouse = c.call().lighthouse()
        msg.token = c.call().token()
        msg.cost = c.call().cost()
        msg.validator = c.call().validator()
        msg.validatorFee = c.call().validatorFee()
        rospy.logdebug('New liability readed: %s', msg)
        return msg
    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 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 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 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 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