@POST('^/api/v1/purchase_contract')
    @authenticated
    def purchase_contract(self, request):
        try:
            def handle_response(resp, contract):
                if resp:
                    contract.await_funding(self.mserver.protocol.get_notification_listener(),
                                           self.protocol.blockchain, resp)
                    request.write(json.dumps({"success": True, "payment_address": payment[0],
                                              "amount": payment[1],
                                              "order_id": c.get_order_id()},
                                             indent=4))
                    request.finish()
                else:
                    request.write(json.dumps({"success": False, "reason": "vendor rejected contract"}, indent=4))
                    request.finish()
            options = None
            if "options" in request.args:
                options = {}
                for option in request.args["options"]:
                    options[option] = request.args[option][0]
            c = Contract(self.db, hash_value=unhexlify(request.args["id"][0]), testnet=self.protocol.testnet)
            payment = c.\
                add_purchase_info(int(request.args["quantity"][0]),
                                  request.args["refund_address"][0],
                                  request.args["ship_to"][0].decode("utf8")
                                  if "ship_to" in request.args else None,
                                  request.args["address"][0].decode("utf8")
                                  if "address" in request.args else None,
                                  request.args["city"][0].decode("utf8")
                                  if "city" in request.args else None,
                                  request.args["state"][0].decode("utf8")
                                  if "state" in request.args else None,
                                  request.args["postal_code"][0].decode("utf8")
                                  if request.args in "postal_code" else None,
                                  request.args["country"][0].decode("utf8")
                                  if "country" in request.args else None,
                                  request.args["moderator"][0] if "moderator" in request.args else None,
                                  options)

            def get_node(node):
                if node is not None:
                    self.mserver.purchase(node, c).addCallback(handle_response, c)
                else:
                    request.write(json.dumps({"success": False, "reason": "unable to reach vendor"}, indent=4))
                    request.finish()
            vendor_guid = unhexlify(c.contract["vendor_offer"]["listing"]["id"]["guid"])
            self.kserver.resolve(vendor_guid).addCallback(get_node)
            return server.NOT_DONE_YET
        except Exception, e:
            request.write(json.dumps({"success": False, "reason": e.message}, indent=4))
            request.finish()
            return server.NOT_DONE_YET
dataset/ETHPy150Open OpenBazaar/OpenBazaar-Server/api/restapi.py/OpenBazaarAPI.purchase_contract/swapped operands of `in`