def get_messages(self, listener):
        # if the transport hasn't been initialized yet, wait a second
        if self.protocol.multiplexer is None or self.protocol.multiplexer.transport is None:
            return task.deferLater(reactor, 1, self.get_messages, listener)

        def parse_messages(messages):
            if messages is not None:
                self.log.info(len(messages) % "retrieved %s message(s) from the dht")
                for message in messages:
                    try:
                        value = objects.Value()
                        value.ParseFromString(message)
                        try:
                            box = Box(self.signing_key.to_curve25519_private_key(), PublicKey(value.valueKey))
                            ciphertext = value.serializedData
                            plaintext = box.decrypt(ciphertext).decode("zlib")
                            p = objects.PlaintextMessage()
                            p.ParseFromString(plaintext)
                            signature = p.signature
                            p.ClearField("signature")
                            verify_key = nacl.signing.VerifyKey(p.pubkey)
                            verify_key.verify(p.SerializeToString(), signature)
                            h = nacl.hash.sha512(p.pubkey)
                            pow_hash = h[40:]
                            if int(pow_hash[:6], 16) >= 50 or p.sender_guid.encode("hex") != h[:40]:
                                raise Exception('Invalid guid')
                            if p.type == objects.PlaintextMessage.Type.Value("ORDER_CONFIRMATION"):
                                c = Contract(self.db, hash_value=unhexlify(p.subject),
                                             testnet=self.protocol.multiplexer.testnet)
                                c.accept_order_confirmation(self.protocol.get_notification_listener(),
                                                            confirmation_json=p.message)
                            elif p.type == objects.PlaintextMessage.Type.Value("RECEIPT"):
                                c = Contract(self.db, hash_value=unhexlify(p.subject),
                                             testnet=self.protocol.multiplexer.testnet)
                                c.accept_receipt(self.protocol.get_notification_listener(),
                                                 self.protocol.multiplexer.blockchain,
                                                 receipt_json=p.message)
                            elif p.type == objects.PlaintextMessage.Type.Value("DISPUTE_OPEN"):
                                process_dispute(json.loads(p.message, object_pairs_hook=OrderedDict),
                                                self.db, self.protocol.get_message_listener(),
                                                self.protocol.get_notification_listener(),
                                                self.protocol.multiplexer.testnet)
                            elif p.type == objects.PlaintextMessage.Type.Value("DISPUTE_CLOSE"):
                                close_dispute(json.loads(p.message, object_pairs_hook=OrderedDict),
                                              self.db, self.protocol.get_message_listener(),
                                              self.protocol.get_notification_listener(),
                                              self.protocol.multiplexer.testnet)
                            elif p.type == objects.PlaintextMessage.Type.Value("REFUND"):
                                refund_json = json.loads(p.message, object_pairs_hook=OrderedDict)
                                c = Contract(self.db, hash_value=unhexlify(refund_json["refund"]["order_id"]),
                                             testnet=self.protocol.multiplexer.testnet)
                                c.process_refund(refund_json, self.protocol.multiplexer.blockchain,
                                                 self.protocol.get_notification_listener())
                            else:
                                listener.notify(p, signature)
                        except Exception:
                            pass
                        signature = self.signing_key.sign(value.valueKey)[:64]
                        self.kserver.delete(self.kserver.node.id, value.valueKey, signature)
                    except Exception:
                        pass
        self.kserver.get(self.kserver.node.id, False).addCallback(parse_messages)
dataset/ETHPy150Open OpenBazaar/OpenBazaar-Server/market/network.py/Server.get_messages/swapped operands of `%`