Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 17b50f6

Browse files
committed
Add max_quantity to contract
1 parent a57a00f commit 17b50f6

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

api/restapi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,8 @@ def set_contract(self, request):
550550
else:
551551
c = Contract(self.db, testnet=self.protocol.testnet)
552552
c.create(
553-
str_to_bool(request.args["pinned"][0]),
553+
str_to_bool(request.args["pinned"][0]) if "pinned" in request.args else False,
554+
int(request.args["max_quantity"][0]) if "max_quantity" in request.args else 999999,
554555
str(request.args["expiration_date"][0]),
555556
request.args["metadata_category"][0],
556557
request.args["title"][0].decode("utf8"),

market/contracts.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def __init__(self, database, contract=None, hash_value=None, testnet=False):
9595

9696
def create(self,
9797
pinned,
98+
max_quantity,
9899
expiration_date,
99100
metadata_category,
100101
title,
@@ -152,7 +153,8 @@ def create(self,
152153
"category": metadata_category.lower(),
153154
"category_sub": "fixed price",
154155
"last_modified": int(time.time()),
155-
"pinned": pinned
156+
"pinned": pinned,
157+
"max_quantity": max_quantity
156158
},
157159
"id": {
158160
"guid": self.keychain.guid.encode("hex"),
@@ -299,6 +301,10 @@ def add_purchase_info(self,
299301
except AssertionError:
300302
raise Exception("Invalid Bitcoin address")
301303

304+
if "max_quantity" in self.contract["vendor_offer"]["listing"]["metadata"]:
305+
if quantity > int(self.contract["vendor_offer"]["listing"]["metadata"]["max_quantity"]):
306+
raise Exception("Quantity exceeds max quantity in listing")
307+
302308
profile = Profile(self.db).get()
303309
order_json = {
304310
"buyer_order": {
@@ -1182,8 +1188,13 @@ def verify(self, sender_key):
11821188
if not valid:
11831189
raise Exception("Invalid Bitcoin signature")
11841190

1185-
# verify buyer included the correct bitcoin amount for payment
1191+
# verify the quantity does not exceed the max
11861192
quantity = int(self.contract["buyer_order"]["order"]["quantity"])
1193+
if "max_quantity" in self.contract["vendor_offer"]["listing"]["metadata"]:
1194+
if quantity > int(self.contract["vendor_offer"]["listing"]["metadata"]["max_quantity"]):
1195+
raise Exception("Buyer tried to purchase more than the max quantity")
1196+
1197+
# verify buyer included the correct bitcoin amount for payment
11871198
price_json = self.contract["vendor_offer"]["listing"]["item"]["price_per_unit"]
11881199
if "bitcoin" in price_json:
11891200
asking_price = float(price_json["bitcoin"]) * quantity

0 commit comments

Comments
 (0)