本文整理汇总了Python中market.contracts.Contract.validate_for_moderation方法的典型用法代码示例。如果您正苦于以下问题:Python Contract.validate_for_moderation方法的具体用法?Python Contract.validate_for_moderation怎么用?Python Contract.validate_for_moderation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类market.contracts.Contract
的用法示例。
在下文中一共展示了Contract.validate_for_moderation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_dispute
# 需要导入模块: from market.contracts import Contract [as 别名]
# 或者: from market.contracts.Contract import validate_for_moderation [as 别名]
def process_dispute(contract, db, message_listener, notification_listener, testnet):
"""
This function processes a dispute message received from another node. It checks the
contract to see if this a dispute for a purchase we made, a dispute for one of our
sales, or a new case if we are the moderator.
If it's a purchase or sale it will
update the order status to disputed and push a notification to the listener.
If it's a new case it will validate the contract, create a new case in the db,
and push a notification to the listener.
Args:
contract: a json contract of the current order state. Should have a "dispute"
object attached with dispute info.
db: a `Database` object.
message_listener: a `MessageListenerImpl` object.
notification_listener: a `NotificationListenerImpl` object.
testnet: `bool` of whether we're on testnet or not.
"""
tmp_contract = deepcopy(contract)
if "vendor_order_confirmation" in tmp_contract:
del tmp_contract["vendor_order_confirmation"]
if "buyer_receipt" in tmp_contract:
del tmp_contract["buyer_receipt"]
del tmp_contract["dispute"]
order_id = digest(json.dumps(tmp_contract, indent=4)).encode("hex")
own_guid = KeyChain(db).guid.encode("hex")
if contract["dispute"]["info"]["guid"] == contract["vendor_offer"]["listing"]["id"]["guid"]:
guid = unhexlify(contract["vendor_offer"]["listing"]["id"]["guid"])
public_key = unhexlify(contract["vendor_offer"]["listing"]["id"]["pubkeys"]["guid"])
if "blockchain_id" in contract["vendor_offer"]["listing"]["id"]:
handle = contract["vendor_offer"]["listing"]["id"]["blockchain_id"]
else:
handle = ""
proof_sig = None
elif contract["dispute"]["info"]["guid"] == contract["buyer_order"]["order"]["id"]["guid"]:
guid = unhexlify(contract["buyer_order"]["order"]["id"]["guid"])
public_key = unhexlify(contract["buyer_order"]["order"]["id"]["pubkeys"]["guid"])
if "blockchain_id" in contract["buyer_order"]["order"]["id"]:
handle = contract["buyer_order"]["order"]["id"]["blockchain_id"]
else:
handle = ""
proof_sig = contract["dispute"]["info"]["proof_sig"]
else:
raise Exception("Dispute guid not in contract")
verify_key = nacl.signing.VerifyKey(public_key)
verify_key.verify(json.dumps(contract["dispute"]["info"], indent=4),
base64.b64decode(contract["dispute"]["signature"]))
p = PlaintextMessage()
p.sender_guid = guid
p.handle = handle
p.pubkey = public_key
p.subject = str(order_id)
p.type = PlaintextMessage.Type.Value("DISPUTE_OPEN")
p.message = str(contract["dispute"]["info"]["claim"])
p.timestamp = int(time.time())
p.avatar_hash = unhexlify(str(contract["dispute"]["info"]["avatar_hash"]))
if db.purchases.get_purchase(order_id) is not None:
db.purchases.update_status(order_id, 4)
elif db.sales.get_sale(order_id) is not None:
db.sales.update_status(order_id, 4)
elif "moderators" in contract["vendor_offer"]["listing"]:
# TODO: make sure a case isn't already open in the db
is_selected = False
for moderator in contract["vendor_offer"]["listing"]["moderators"]:
if moderator["guid"] == own_guid and contract["buyer_order"]["order"]["moderator"] == own_guid:
is_selected = True
if not is_selected:
raise Exception("Not a moderator for this contract")
else:
if "blockchain_id" in contract["vendor_offer"]["listing"]["id"] and \
contract["vendor_offer"]["listing"]["id"]["blockchain_id"] != "":
vendor = contract["vendor_offer"]["listing"]["id"]["blockchain_id"]
else:
vendor = contract["vendor_offer"]["listing"]["id"]["guid"]
if "blockchain_id" in contract["buyer_order"]["order"]["id"] and \
contract["buyer_order"]["order"]["id"]["blockchain_id"] != "":
buyer = contract["buyer_order"]["order"]["id"]["blockchain_id"]
else:
buyer = contract["buyer_order"]["order"]["id"]["guid"]
c = Contract(db, contract=contract, testnet=testnet)
validation_failures = c.validate_for_moderation(proof_sig)
db.cases.new_case(order_id,
contract["vendor_offer"]["listing"]["item"]["title"],
time.time(),
contract["buyer_order"]["order"]["date"],
float(contract["buyer_order"]["order"]["payment"]["amount"]),
contract["vendor_offer"]["listing"]["item"]["image_hashes"][0],
buyer, vendor, json.dumps(validation_failures),
#.........这里部分代码省略.........