本文整理汇总了Python中market.contracts.Contract.accept_receipt方法的典型用法代码示例。如果您正苦于以下问题:Python Contract.accept_receipt方法的具体用法?Python Contract.accept_receipt怎么用?Python Contract.accept_receipt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类market.contracts.Contract
的用法示例。
在下文中一共展示了Contract.accept_receipt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_messages
# 需要导入模块: from market.contracts import Contract [as 别名]
# 或者: from market.contracts.Contract import accept_receipt [as 别名]
def parse_messages(messages):
if messages is not None:
self.log.info("retrieved %s message(s) from the dht" % len(messages))
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,
)
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
示例2: parse_messages
# 需要导入模块: from market.contracts import Contract [as 别名]
# 或者: from market.contracts.Contract import accept_receipt [as 别名]
def parse_messages(messages):
if messages is not None:
self.log.info("retrieved %s message(s) from the dht" % len(messages))
for message in messages:
try:
value = objects.Value()
value.ParseFromString(message)
try:
box = Box(PrivateKey(self.signing_key.encode()), PublicKey(value.valueKey))
ciphertext = value.serializedData
plaintext = box.decrypt(ciphertext)
p = objects.Plaintext_Message()
p.ParseFromString(plaintext)
signature = p.signature
p.ClearField("signature")
verify_key = nacl.signing.VerifyKey(p.signed_pubkey[64:])
verify_key.verify(p.SerializeToString(), signature)
h = nacl.hash.sha512(p.signed_pubkey)
pow_hash = h[64:128]
if int(pow_hash[:6], 16) >= 50 or p.sender_guid.encode("hex") != h[:40]:
raise Exception('Invalid guid')
if p.type == objects.Plaintext_Message.Type.Value("ORDER_CONFIRMATION"):
c = Contract(self.db, hash_value=p.subject)
c.accept_order_confirmation(self.protocol.get_notification_listener(),
confirmation_json=p.message)
elif p.type == objects.Plaintext_Message.Type.Value("RECEIPT"):
c = Contract(self.db, hash_value=p.subject)
c.accept_receipt(self.protocol.get_notification_listener(),
self.protocol.multiplexer.blockchain,
receipt_json=p.message)
else:
listener.notify(p.sender_guid, p.encryption_pubkey, p.subject,
objects.Plaintext_Message.Type.Name(p.type), p.message)
except Exception:
pass
signature = self.signing_key.sign(value.valueKey)[:64]
self.kserver.delete(self.kserver.node.id, value.valueKey, signature)
except Exception:
pass
示例3: rpc_complete_order
# 需要导入模块: from market.contracts import Contract [as 别名]
# 或者: from market.contracts.Contract import accept_receipt [as 别名]
def rpc_complete_order(self, sender, pubkey, encrypted):
try:
box = Box(PrivateKey(self.signing_key.encode(nacl.encoding.RawEncoder)), PublicKey(pubkey))
order = box.decrypt(encrypted)
c = Contract(self.db, contract=json.loads(order, object_pairs_hook=OrderedDict),
testnet=self.multiplexer.testnet)
contract_id = c.accept_receipt(self.get_notification_listener(), self.multiplexer.blockchain)
self.router.addContact(sender)
self.log.info("received receipt for order %s" % contract_id)
return ["True"]
except Exception:
self.log.error("unable to parse receipt from %s" % sender)
return ["False"]
示例4: rpc_complete_order
# 需要导入模块: from market.contracts import Contract [as 别名]
# 或者: from market.contracts.Contract import accept_receipt [as 别名]
def rpc_complete_order(self, sender, pubkey, encrypted):
try:
box = Box(self.signing_key.to_curve25519_private_key(), PublicKey(pubkey))
order = box.decrypt(encrypted)
json.loads(order, object_pairs_hook=OrderedDict)
temp = Contract(self.db, contract=json.loads(order, object_pairs_hook=OrderedDict),
testnet=self.multiplexer.testnet)
c = Contract(self.db, hash_value=unhexlify(temp.get_order_id()),
testnet=self.multiplexer.testnet)
contract_id = c.accept_receipt(self.get_notification_listener(),
self.multiplexer.blockchain,
receipt_json=json.dumps(temp.contract["buyer_receipt"], indent=4))
self.router.addContact(sender)
self.log.info("received receipt for order %s" % contract_id)
return ["True"]
except Exception, e:
self.log.error("unable to parse receipt from %s" % sender)
return [e.message]
示例5: rpc_complete_order
# 需要导入模块: from market.contracts import Contract [as 别名]
# 或者: from market.contracts.Contract import accept_receipt [as 别名]
def rpc_complete_order(self, sender, pubkey, encrypted):
try:
box = Box(PrivateKey(self.signing_key.encode(nacl.encoding.RawEncoder)), PublicKey(pubkey))
order = box.decrypt(encrypted)
c = Contract(self.db, contract=json.loads(order, object_pairs_hook=OrderedDict),
testnet=self.multiplexer.testnet)
def handle_result(contract_id):
if contract_id:
self.router.addContact(sender)
self.log.info("Received receipt for order %s" % contract_id)
return ["True"]
else:
self.log.error("Received invalid receipt from %s" % sender)
return ["False"]
d = c.accept_receipt(self.multiplexer.ws, self.multiplexer.blockchain)
d.addCallback(handle_result)
except Exception:
self.log.error("Unable to decrypt order receipt from %s" % sender)
return ["False"]