@POST('^/api/v1/contracts')
    @authenticated
    def set_contract(self, request):
        try:
            if "options" in request.args:
                options = {}
                for option in request.args["options"]:
                    options[option.decode("utf8")] = request.args[option.decode("utf8")]
            keywords = None
            if "keywords" in request.args:
                keywords = []
                for keyword in request.args["keywords"]:
                    keywords.append(keyword.decode("utf8"))
                if len(keywords) > 10:
                    raise Exception("Too many keywords")
            if "contract_id" in request.args:
                c = Contract(self.db, hash_value=unhexlify(request.args["contract_id"][0]),
                             testnet=self.protocol.testnet)
            else:
                c = Contract(self.db, testnet=self.protocol.testnet)
            c.create(
                str(request.args["expiration_date"][0]),
                request.args["metadata_category"][0],
                request.args["title"][0].decode("utf8"),
                request.args["description"][0].decode("utf8"),
                request.args["currency_code"][0],
                request.args["price"][0],
                request.args["process_time"][0].decode("utf8"),
                str_to_bool(request.args["nsfw"][0]),
                shipping_origin=request.args["shipping_origin"][0] if "shipping_origin" in request.args else None,
                shipping_regions=request.args["ships_to"] if "ships_to" in request.args else None,
                est_delivery_domestic=request.args["est_delivery_domestic"][0].decode("utf8")
                if "est_delivery_domestic" in request.args else None,
                est_delivery_international=request.args["est_delivery_international"][0].decode("utf8")
                if "est_delivery_international" in request.args else None,
                terms_conditions=request.args["terms_conditions"][0].decode("utf8")
                if request.args["terms_conditions"][0] is not "" else None,
                returns=request.args["returns"][0].decode("utf8")
                if request.args["returns"][0] is not "" else None,
                shipping_currency_code=request.args["shipping_currency_code"][0],
                shipping_domestic=request.args["shipping_domestic"][0],
                shipping_international=request.args["shipping_international"][0],
                keywords=keywords,
                category=request.args["category"][0].decode("utf8")
                if request.args["category"][0] is not "" else None,
                condition=request.args["condition"][0].decode("utf8")
                if request.args["condition"][0] is not "" else None,
                sku=request.args["sku"][0].decode("utf8") if request.args["sku"][0] is not "" else None,
                images=request.args["images"],
                free_shipping=str_to_bool(request.args["free_shipping"][0]),
                options=options if "options" in request.args else None,
                moderators=request.args["moderators"] if "moderators" in request.args else None,
                contract_id=request.args["contract_id"][0] if "contract_id" in request.args else None)

            for keyword in request.args["keywords"]:
                if keyword != "":
                    self.kserver.set(digest(keyword.lower()), unhexlify(c.get_contract_id()),
                                     self.kserver.node.getProto().SerializeToString())
            request.write(json.dumps({"success": True, "id": c.get_contract_id()}))
            request.finish()
            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.set_contract/original