本文整理汇总了Python中market.contracts.Contract类的典型用法代码示例。如果您正苦于以下问题:Python Contract类的具体用法?Python Contract怎么用?Python Contract使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Contract类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_contract
def delete_contract(self, request):
if "id" in request.args:
c = Contract(hash_value=unhexlify(request.args["id"][0]))
for keyword in c.contract["vendor_offer"]["listing"]["item"]["keywords"]:
self.kserver.delete(keyword.lower(), c.get_contract_id(),
KeyChain().signing_key.sign(c.get_contract_id())[:64])
c.delete()
示例2: confirm_order
def confirm_order(self, request):
try:
def respond(success):
if success:
request.write(json.dumps({"success": True}))
request.finish()
else:
request.write(json.dumps({"success": False, "reason": "Failed to send order confirmation"}))
request.finish()
file_path = DATA_FOLDER + "store/contracts/in progress/" + request.args["id"][0] + ".json"
with open(file_path, 'r') as filename:
order = json.load(filename, object_pairs_hook=OrderedDict)
c = Contract(self.db, contract=order, testnet=self.protocol.testnet)
c.add_order_confirmation(self.protocol.blockchain,
request.args["payout_address"][0],
comments=request.args["comments"][0] if "comments" in request.args else None,
shipper=request.args["shipper"][0] if "shipper" in request.args else None,
tracking_number=request.args["tracking_number"][0]
if "tracking_number" in request.args else None,
est_delivery=request.args["est_delivery"][0]
if "est_delivery" in request.args else None,
url=request.args["url"][0] if "url" in request.args else None,
password=request.args["password"][0] if "password" in request.args else None)
guid = c.contract["buyer_order"]["order"]["id"]["guid"]
self.mserver.confirm_order(guid, c).addCallback(respond)
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
示例3: set_contract
def set_contract(self, request):
print request
c = Contract()
c.create(
str(request.args["expiration_date"][0]),
request.args["metadata_category"][0],
request.args["title"][0],
request.args["description"][0],
request.args["currency_code"][0],
request.args["price"][0],
request.args["process_time"][0],
True if "nsfw" in request.args else False,
request.args["shipping_origin"][0],
request.args["ships_to"],
est_delivery_domestic=request.args["est_delivery_domestic"][0],
est_delivery_international=request.args["est_delivery_international"][0],
shipping_currency_code=request.args["shipping_currency_code"][0],
shipping_domestic=request.args["shipping_domestic"][0],
shipping_international=request.args["shipping_international"][0],
keywords=request.args["keywords"] if "keywords" in request.args else None,
category=request.args["category"][0] if request.args["category"][0] is not "" else None,
condition=request.args["condition"][0] if request.args["condition"][0] is not "" else None,
sku=request.args["sku"][0] if request.args["sku"][0] is not "" else None,
images=request.args["images"],
free_shipping=True if "free_shipping" in request.args else False)
for keyword in request.args["keywords"]:
self.kserver.set(keyword.lower(), c.get_contract_id(), self.kserver.node.getProto().SerializeToString())
示例4: rpc_order
def rpc_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)
if c.verify(sender.signed_pubkey[64:]):
self.router.addContact(sender)
self.log.info("received an order from %s, waiting for payment..." % sender)
payment_address = c.contract["buyer_order"]["order"]["payment"]["address"]
chaincode = c.contract["buyer_order"]["order"]["payment"]["chaincode"]
masterkey_b = c.contract["buyer_order"]["order"]["id"]["pubkeys"]["bitcoin"]
buyer_key = derive_childkey(masterkey_b, chaincode)
amount = c.contract["buyer_order"]["order"]["payment"]["amount"]
listing_hash = c.contract["buyer_order"]["order"]["ref_hash"]
signature = self.signing_key.sign(
str(payment_address) + str(amount) + str(listing_hash) + str(buyer_key))[:64]
c.await_funding(self.get_notification_listener(), self.multiplexer.blockchain, signature, False)
return [signature]
else:
self.log.warning("received invalid order from %s" % sender)
return ["False"]
except Exception:
self.log.error("unable to decrypt order from %s" % sender)
return ["False"]
示例5: complete_order
def complete_order(self, request):
def respond(success):
if success:
request.write(json.dumps({"success": True}))
request.finish()
else:
request.write(json.dumps({"success": False, "reason": "Failed to send receipt to vendor"}))
request.finish()
file_path = DATA_FOLDER + "purchases/in progress/" + request.args["id"][0] + ".json"
with open(file_path, 'r') as filename:
order = json.load(filename, object_pairs_hook=OrderedDict)
c = Contract(self.db, contract=order, testnet=self.protocol.testnet)
c.add_receipt(True,
self.protocol.blockchain,
feedback=request.args["feedback"][0] if "feedback" in request.args else None,
quality=request.args["quality"][0] if "quality" in request.args else None,
description=request.args["description"][0] if "description" in request.args else None,
delivery_time=request.args["delivery_time"][0]
if "delivery_time" in request.args else None,
customer_service=request.args["customer_service"][0]
if "customer_service" in request.args else None,
review=request.args["review"][0] if "review" in request.args else "")
guid = c.contract["vendor_offer"]["listing"]["id"]["guid"]
self.mserver.complete_order(guid, c).addCallback(respond)
return server.NOT_DONE_YET
示例6: parse_messages
def parse_messages(messages):
if messages is not None:
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 hexlify(p.sender_guid) != h[:40]:
raise Exception('Invalid guid')
if p.type == objects.Plaintext_Message.Type.Value("ORDER_CONFIRMATION"):
c = Contract(self.db, hash_value=unhexlify(p.subject))
c.accept_order_confirmation(self.protocol.multiplexer.ws,
confirmation_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
示例7: rpc_order
def rpc_order(self, sender, pubkey, encrypted):
try:
box = Box(self.signing_key.to_curve25519_private_key(), PublicKey(pubkey))
order = box.decrypt(encrypted)
c = Contract(self.db, contract=json.loads(order, object_pairs_hook=OrderedDict),
testnet=self.multiplexer.testnet)
v = c.verify(sender.pubkey)
if v is True:
self.router.addContact(sender)
self.log.info("received an order from %s, waiting for payment..." % sender)
payment_address = c.contract["buyer_order"]["order"]["payment"]["address"]
chaincode = c.contract["buyer_order"]["order"]["payment"]["chaincode"]
masterkey_b = c.contract["buyer_order"]["order"]["id"]["pubkeys"]["bitcoin"]
buyer_key = derive_childkey(masterkey_b, chaincode)
amount = c.contract["buyer_order"]["order"]["payment"]["amount"]
listing_hash = c.contract["vendor_offer"]["listing"]["contract_id"]
signature = self.signing_key.sign(
str(payment_address) + str(amount) + str(listing_hash) + str(buyer_key))[:64]
c.await_funding(self.get_notification_listener(), self.multiplexer.blockchain, signature, False)
return [signature]
else:
self.log.warning("received invalid order from %s reason %s" % (sender, v))
return ["False"]
except Exception, e:
self.log.error("Exception (%s) occurred processing order from %s" % (e.message, sender))
return ["False"]
示例8: purchase_contract
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
示例9: set_contract
def set_contract(self, request):
try:
if "options" in request.args:
options = {}
for option in request.args["options"]:
options[option] = request.args[option]
c = Contract(self.db)
c.create(
str(request.args["expiration_date"][0]),
request.args["metadata_category"][0],
request.args["title"][0],
request.args["description"][0],
request.args["currency_code"][0],
request.args["price"][0],
request.args["process_time"][0],
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]
if "est_delivery_domestic" in request.args
else None,
est_delivery_international=request.args["est_delivery_international"][0]
if "est_delivery_international" in request.args
else None,
terms_conditions=request.args["terms_conditions"][0]
if request.args["terms_conditions"][0] is not ""
else None,
returns=request.args["returns"][0] 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=request.args["keywords"] if "keywords" in request.args else None,
category=request.args["category"][0] if request.args["category"][0] is not "" else None,
condition=request.args["condition"][0] if request.args["condition"][0] is not "" else None,
sku=request.args["sku"][0] 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,
)
for keyword in request.args["keywords"]:
self.kserver.set(
digest(keyword.lower()), c.get_contract_id(), self.kserver.node.getProto().SerializeToString()
)
request.write(json.dumps({"success": True, "id": c.get_contract_id().encode("hex")}))
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
示例10: rpc_refund
def rpc_refund(self, sender, pubkey, encrypted):
try:
box = Box(self.signing_key.to_curve25519_private_key(), PublicKey(pubkey))
refund = box.decrypt(encrypted)
refund_json = json.loads(refund, object_pairs_hook=OrderedDict)
c = Contract(self.db, hash_value=unhexlify(refund_json["refund"]["order_id"]),
testnet=self.multiplexer.testnet)
c.process_refund(refund_json, self.multiplexer.blockchain, self.get_notification_listener())
self.router.addContact(sender)
self.log.info("order %s refunded by vendor" % refund_json["refund"]["order_id"])
return ["True"]
except Exception, e:
self.log.error("unable to parse refund message from %s" % sender)
return [e.message]
示例11: rpc_complete_order
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"]
示例12: delete_contract
def delete_contract(self, request):
try:
if "id" in request.args:
c = Contract(self.db, hash_value=unhexlify(request.args["id"][0]))
for keyword in c.contract["vendor_offer"]["listing"]["item"]["keywords"]:
self.kserver.delete(keyword.lower(), c.get_contract_id(),
self.keychain.signing_key.sign(c.get_contract_id())[:64])
c.delete()
request.write(json.dumps({"success": True}))
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
示例13: rpc_order_confirmation
def rpc_order_confirmation(self, sender, pubkey, encrypted):
try:
box = Box(self.signing_key.to_curve25519_private_key(), PublicKey(pubkey))
order = box.decrypt(encrypted)
c = Contract(self.db, contract=json.loads(order, object_pairs_hook=OrderedDict),
testnet=self.multiplexer.testnet)
valid = c.accept_order_confirmation(self.get_notification_listener())
if valid is True:
self.router.addContact(sender)
self.log.info("received confirmation for order %s" % c.get_order_id())
return ["True"]
else:
self.log.warning("received invalid order confirmation from %s" % sender)
return [valid]
except Exception, e:
self.log.error("unable to decrypt order confirmation from %s" % sender)
return [str(e.message)]
示例14: rpc_order_confirmation
def rpc_order_confirmation(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_order_confirmation(self.multiplexer.ws)
if contract_id:
self.router.addContact(sender)
self.log.info("received confirmation for order %s" % contract_id)
return ["True"]
else:
self.log.warning("received invalid order confirmation from %s" % sender)
return ["False"]
except Exception:
self.log.error("unable to decrypt order confirmation from %s" % sender)
return ["False"]
示例15: delete_contract
def delete_contract(self, request):
try:
if "id" in request.args:
file_path = self.db.HashMap().get_file(request.args["id"][0])
with open(file_path, "r") as filename:
contract = json.load(filename, object_pairs_hook=OrderedDict)
c = Contract(self.db, contract=contract)
if "keywords" in c.contract["vendor_offer"]["listing"]["item"]:
for keyword in c.contract["vendor_offer"]["listing"]["item"]["keywords"]:
self.kserver.delete(
keyword.lower(),
c.get_contract_id(),
self.keychain.signing_key.sign(c.get_contract_id())[:64],
)
if "delete_images" in request.args:
c.delete(delete_images=True)
else:
c.delete()
request.write(json.dumps({"success": True}))
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