@@ -94,6 +94,9 @@ def __init__(self, database, contract=None, hash_value=None, testnet=False):
9494 self .outpoints = []
9595
9696 def create (self ,
97+ pinned ,
98+ max_quantity ,
99+ hidden ,
97100 expiration_date ,
98101 metadata_category ,
99102 title ,
@@ -150,7 +153,10 @@ def create(self,
150153 "version" : "1" ,
151154 "category" : metadata_category .lower (),
152155 "category_sub" : "fixed price" ,
153- "last_modified" : int (time .time ())
156+ "last_modified" : int (time .time ()),
157+ "pinned" : pinned ,
158+ "max_quantity" : max_quantity ,
159+ "hidden" : hidden
154160 },
155161 "id" : {
156162 "guid" : self .keychain .guid .encode ("hex" ),
@@ -282,7 +288,8 @@ def add_purchase_info(self,
282288 postal_code = None ,
283289 country = None ,
284290 moderator = None ,
285- options = None ):
291+ options = None ,
292+ alternate_contact = None ):
286293 """
287294 Update the contract with the buyer's purchase information.
288295 """
@@ -297,6 +304,10 @@ def add_purchase_info(self,
297304 except AssertionError :
298305 raise Exception ("Invalid Bitcoin address" )
299306
307+ if "max_quantity" in self .contract ["vendor_offer" ]["listing" ]["metadata" ]:
308+ if quantity > int (self .contract ["vendor_offer" ]["listing" ]["metadata" ]["max_quantity" ]):
309+ raise Exception ("Quantity exceeds max quantity in listing" )
310+
300311 profile = Profile (self .db ).get ()
301312 order_json = {
302313 "buyer_order" : {
@@ -312,7 +323,8 @@ def add_purchase_info(self,
312323 }
313324 },
314325 "payment" : {},
315- "refund_address" : refund_address
326+ "refund_address" : refund_address ,
327+ "alternate_contact" : alternate_contact if alternate_contact is not None else ""
316328 }
317329 }
318330 }
@@ -1065,6 +1077,8 @@ def save(self):
10651077 elif self .contract ["vendor_offer" ]["listing" ]["metadata" ]["category" ].lower () == "service" :
10661078 data .contract_type = listings .SERVICE
10671079 data .last_modified = int (time .time ())
1080+ data .pinned = self .contract ["vendor_offer" ]["listing" ]["metadata" ]["pinned" ]
1081+ data .hidden = self .contract ["vendor_offer" ]["listing" ]["metadata" ]["hidden" ]
10681082
10691083 # save the mapping of the contract file path and contract hash in the database
10701084 self .db .filemap .insert (data .contract_hash .encode ("hex" ), file_path [len (DATA_FOLDER ):])
@@ -1179,8 +1193,13 @@ def verify(self, sender_key):
11791193 if not valid :
11801194 raise Exception ("Invalid Bitcoin signature" )
11811195
1182- # verify buyer included the correct bitcoin amount for payment
1196+ # verify the quantity does not exceed the max
11831197 quantity = int (self .contract ["buyer_order" ]["order" ]["quantity" ])
1198+ if "max_quantity" in self .contract ["vendor_offer" ]["listing" ]["metadata" ]:
1199+ if quantity > int (self .contract ["vendor_offer" ]["listing" ]["metadata" ]["max_quantity" ]):
1200+ raise Exception ("Buyer tried to purchase more than the max quantity" )
1201+
1202+ # verify buyer included the correct bitcoin amount for payment
11841203 price_json = self .contract ["vendor_offer" ]["listing" ]["item" ]["price_per_unit" ]
11851204 if "bitcoin" in price_json :
11861205 asking_price = float (price_json ["bitcoin" ]) * quantity
0 commit comments