当前位置: 首页>>代码示例>>Python>>正文


Python Contract.add_purchase_info方法代码示例

本文整理汇总了Python中market.contracts.Contract.add_purchase_info方法的典型用法代码示例。如果您正苦于以下问题:Python Contract.add_purchase_info方法的具体用法?Python Contract.add_purchase_info怎么用?Python Contract.add_purchase_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在market.contracts.Contract的用法示例。


在下文中一共展示了Contract.add_purchase_info方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: purchase_contract

# 需要导入模块: from market.contracts import Contract [as 别名]
# 或者: from market.contracts.Contract import add_purchase_info [as 别名]
    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_contract_id().encode("hex"),
                            },
                            indent=4,
                        )
                    )
                    request.finish()
                else:
                    request.write(json.dumps({"success": False, "reason": "seller 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["ship_to"][0] if "ship_to" in request.args else None,
                request.args["address"][0] if "address" in request.args else None,
                request.args["city"][0] if "city" in request.args else None,
                request.args["state"][0] if "state" in request.args else None,
                request.args["postal_code"][0] if "postal_code" in request.args else None,
                request.args["country"][0] 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()

            seller_guid = unhexlify(c.contract["vendor_offer"]["listing"]["id"]["guid"])
            self.kserver.resolve(seller_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
开发者ID:HiroIshikawa,项目名称:OpenBazaar-Server,代码行数:58,代码来源:restapi.py


注:本文中的market.contracts.Contract.add_purchase_info方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。