@@ -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