예제 #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 sign_offer(msg):
     msg.sender = Address(self.__account.address)
     current_nonce = get_nonce_by_address(msg.sender)
     message_hash = robonomicsMessageUtils.offer_hash(msg, current_nonce)
     signed_hash = self.__account.signHash(defunct_hash_message(message_hash))
     msg.signature = signed_hash.signature
     rospy.loginfo('bidhash: %s signature: %s', binascii.hexlify(message_hash), binascii.hexlify(msg.signature))
     self.signed_offer.publish(msg)
예제 #5
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
예제 #6
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
예제 #7
0
 def liability_filter_thread():
     try:
         for entry in self.liability_filter.get_new_entries():
             liability_address = Address(entry['args']['liability'])
             self.liabilities_queue.push(liability_address)
             rospy.loginfo("New liability added to persistence queue: %s", liability_address)
     except Exception as e:
         rospy.logerr('listener liability filter exception: %s', e)
         self.create_liability_filter()
     Timer(self.poll_interval, liability_filter_thread).start()
예제 #8
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)
예제 #9
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
예제 #10
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)
예제 #11
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
예제 #12
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
예제 #13
0
    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)
예제 #14
0
    def __init__(self, bag, address, namespace=''):
        self.liability_address = Address(address)
        self.namespace = namespace
        self.pubs = {}
        self.start_timestamp = None

        self.__update_timestamp = rospy.Publisher(
            "persistence/update_timestamp",
            LiabilityExecutionTimestamp,
            queue_size=10)

        try:
            self.publisher = Thread(target=self.simple_publisher,
                                    daemon=True,
                                    args=(bag.read_messages(), ))
            rospy.logdebug('Player created for %s', bag.filename)
        except Exception as e:
            rospy.logerr('Player exception: %s', e)
예제 #15
0
        def sign_demand(msg):
            msg.sender = Address(self.__account.address)

            if messageValidator.isDemandFieldsCorrect(msg):
                msg = robonomicsMessageUtils.convert_msg_ens_names_to_addresses(
                    msg, web3=self.web3)
                current_nonce = get_nonce_by_address(msg.sender)
                message_hash = robonomicsMessageUtils.demand_hash(
                    msg, current_nonce)
                signed_hash = self.__account.signHash(
                    defunct_hash_message(message_hash))
                msg.signature = signed_hash.signature
                msg.nonce = UInt256(uint256=str(current_nonce.uint256))
                rospy.loginfo('askhash: %s signature: %s',
                              binascii.hexlify(message_hash),
                              binascii.hexlify(msg.signature))
                self.signed_demand.publish(msg)
            else:
                rospy.logerr(
                    "Signing demand error: msg %s is not valid Demand message",
                    msg)
예제 #16
0
    def __init__(self):
        rospy.init_node('blockchainization_agent')

        self.model = rospy.get_param('~model')
        self.token = rospy.get_param('~token')
        self.bid_lifetime = rospy.get_param('~bid_lifetime')
        self._web3 = Web3(HTTPProvider(rospy.get_param('~web3_http_provider')))

        rospy.loginfo('Connecting to ERC20 node...')
        rospy.wait_for_service('accounts')
        self.accounts = rospy.ServiceProxy('accounts',
                                           Accounts)(AccountsRequest())
        rospy.loginfo(str(self.accounts))  # agent's ethereum addresses

        if rospy.get_param('~approve', 'no') == 'yes':
            self.liability_factory = rospy.get_param('~liability_factory')
            rospy.loginfo('Making approvement to liabilities factory %s.',
                          self.liability_factory)
            rospy.wait_for_service('approve')
            msg = ApproveRequest(
                spender=Address(address=self.liability_factory),
                value=UInt256(
                    uint256=rospy.get_param('~approve_value', "10000")))
            tx = rospy.ServiceProxy('approve', Approve)(msg)
            rospy.loginfo('Approved on tx: %s.', tx)
        else:
            rospy.loginfo('Launching without approve on liabilities factory.')

        self._signing_bid = rospy.Publisher('liability/infochan/signing/bid',
                                            Bid,
                                            queue_size=128)

        def on_incoming_ask(incoming_ask):
            rospy.loginfo('Incoming ask: ' + str(incoming_ask))
            if incoming_ask.model == self.model and incoming_ask.token == self.token:
                rospy.loginfo('For my model and token.')
                self.make_bid(incoming_ask)
            else:
                rospy.loginfo('Not fits, skip.')

        rospy.Subscriber('liability/infochan/incoming/ask', Ask,
                         on_incoming_ask)

        rospy.Subscriber('/agent/objective/duration', Duration,
                         self.start_process)

        rospy.loginfo('Connecting to observer node...')
        rospy.wait_for_service('/observer/journals')
        self.get_journals = rospy.ServiceProxy('/observer/journals',
                                               GetJournals)

        self.result_topics = dict()
        self.result_topics['journals'] = rospy.Publisher('~result/journals',
                                                         String,
                                                         queue_size=1000)
        self.result_topics['sha256'] = rospy.Publisher('~result/sha256',
                                                       String,
                                                       queue_size=1000)

        rospy.loginfo('Connecting to liability node...')
        self.finish_allowed = False
        rospy.Service('~allow_finish', EmptySrv, self.allow_finish)
        rospy.wait_for_service('liability/finish')
        self._finish_liability = rospy.ServiceProxy('liability/finish',
                                                    EmptySrv)

        rospy.loginfo('Node ' + rospy.get_name() + ' started.')
예제 #17
0
# ROS
import rospy

# Robonomics communication
from robonomics_msgs.msg import Offer, Demand
from ethereum_common.msg import Address, UInt256
from ethereum_common.srv import Accounts, BlockNumber, Approve, ApproveRequest
from ipfs_common.msg import Multihash


if __name__ == '__main__':
    rospy.init_node('demand_publisher')
    rospy.loginfo('Launching...')

    rospy.wait_for_service('/eth/current_block')
    rospy.wait_for_service('/eth/accounts')
    rospy.wait_for_service('/eth/approve')

    accounts = rospy.ServiceProxy('/eth/accounts', Accounts)()
    rospy.loginfo(str(accounts)) # AIRA ethereum addresses

    # Building the request. Specify spender address (factory address) and amount of tokens
    # our own address is derived from robonomics_comm settings
    req = ApproveRequest(spender=Address(address='0x7e384AD1FE06747594a6102EE5b377b273DC1225'), value=UInt256(uint256='100000000000000000'))

    # calling the service
    approve = rospy.ServiceProxy('/eth/approve', Approve)(req)

    rospy.loginfo(approve)
    rospy.loginfo('Complete.')
예제 #18
0
    def __init__(self):
        rospy.init_node('agent')

        self.model = rospy.get_param('~model')
        self.token = rospy.get_param('~token')
        self.bid_lifetime = rospy.get_param('~bid_lifetime')
        self.web3 = Web3(HTTPProvider(rospy.get_param('~web3_http_provider')))

        rospy.wait_for_service('accounts')
        self.account = str(
            rospy.ServiceProxy('accounts', Accounts)(AccountsRequest()))
        rospy.loginfo('Account: ' + self.account)
        if rospy.get_param('~approve') == 'y':
            rospy.wait_for_service('approve')
            factory = Address(
                address="0x44CFBcb1Ca0d3df0925dDA3354E955d38d78ad6B")
            msg = ApproveRequest(spender=factory, value=UInt256(uint256="1"))
            tx = rospy.ServiceProxy('approve', Approve)(msg)
            rospy.loginfo('Approved in: ' + str(tx))

        self.signing_bid = rospy.Publisher('liability/infochan/signing/bid',
                                           Bid,
                                           queue_size=128)

        def on_incoming_ask(incoming_ask):
            rospy.loginfo('Incoming ask: ' + str(incoming_ask))
            if incoming_ask.model == self.model and incoming_ask.token == self.token:
                rospy.loginfo('For my model and token.')
                self.make_bid(incoming_ask)
            else:
                rospy.loginfo('Not fits, skip.')

        rospy.Subscriber('liability/infochan/incoming/ask', Ask,
                         on_incoming_ask)

        def on_email(msg):
            self.current_job['email'] = msg.data
            rospy.loginfo('Email: ' + msg.data)

        rospy.Subscriber('~objective/email', String, on_email)

        def on_droneid(msg):
            self.current_job['droneid'] = msg.data
            self.current_job['success'] = True
            rospy.loginfo('Drone ID: ' + msg.data)

        rospy.Subscriber('~objective/droneid', String, on_droneid)

        self.result_topics = dict()
        self.result_topics['droneid'] = rospy.Publisher('~result/droneid',
                                                        String,
                                                        queue_size=10)
        self.result_topics['email'] = rospy.Publisher('~result/email',
                                                      String,
                                                      queue_size=10)
        self.result_topics['success'] = rospy.Publisher('~result/success',
                                                        Bool,
                                                        queue_size=10)

        rospy.wait_for_service('liability/finish')
        self.finish = rospy.ServiceProxy('liability/finish', Empty)

        threading.Thread(target=self.process, daemon=True).start()
        rospy.loginfo('Node ' + rospy.get_name() + ' started.')
예제 #19
0
def strToAddress(s):
    return Address(s)
예제 #20
0
    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

    # We ask robonomics_comm to publish the demand message by publishing the message to the ros topic
    signing_demand.publish(demand)
    rospy.loginfo(demand)
예제 #21
0
# Standart, System and Third Party

# ROS
import rospy

# Robonomics communication
from robonomics_msgs.msg import Offer, Demand
from ethereum_common.msg import Address, UInt256
from ethereum_common.srv import Accounts, BlockNumber, Approve, ApproveRequest
from ipfs_common.msg import Multihash

if __name__ == '__main__':
    rospy.init_node('demand_publisher')
    rospy.loginfo('Launching...')

    rospy.wait_for_service('/eth/current_block')
    rospy.wait_for_service('/eth/accounts')
    rospy.wait_for_service('/eth/approve')

    accounts = rospy.ServiceProxy('/eth/accounts', Accounts)()
    rospy.loginfo(str(accounts))  # AIRA ethereum addresses

    req = ApproveRequest(
        spender=Address(address='0x7e384AD1FE06747594a6102EE5b377b273DC1225'),
        value=UInt256(uint256='100000000000000000'))
    approve = rospy.ServiceProxy('/eth/approve', Approve)(req)

    rospy.loginfo(approve)
    rospy.loginfo('Complete.')