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

Commit 6efb928

Browse files
authored
Merge pull request #486 from cpacia/master
1.0 upgrades
2 parents 681ce34 + 97a1a4d commit 6efb928

File tree

6 files changed

+94
-49
lines changed

6 files changed

+94
-49
lines changed

api/restapi.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ def parse_listings(listings):
233233
"nsfw": l.nsfw,
234234
"origin": str(CountryCode.Name(l.origin)),
235235
"ships_to": [],
236-
"last_modified": l.last_modified
236+
"last_modified": l.last_modified,
237+
"pinned": l.pinned,
238+
"hidden": l.hidden
237239
}
238240
if l.contract_type != 0:
239241
listing_json["contract_type"] = str(objects.Listings.ContractType.Name(l.contract_type))
@@ -549,6 +551,9 @@ def set_contract(self, request):
549551
else:
550552
c = Contract(self.db, testnet=self.protocol.testnet)
551553
c.create(
554+
str_to_bool(request.args["pinned"][0]) if "pinned" in request.args else False,
555+
int(request.args["max_quantity"][0]) if "max_quantity" in request.args else 999999,
556+
str_to_bool(request.args["hidden"][0]) if "hidden" in request.args else False,
552557
str(request.args["expiration_date"][0]),
553558
request.args["metadata_category"][0],
554559
request.args["title"][0].decode("utf8"),
@@ -705,7 +710,9 @@ def handle_response(resp, contract):
705710
request.args["country"][0].decode("utf8")
706711
if "country" in request.args else None,
707712
request.args["moderator"][0] if "moderator" in request.args else None,
708-
options)
713+
options,
714+
request.args["alternate_contact"][0].decode("utf8")
715+
if "alternate_contact" in request.args else None)
709716

710717
def get_node(node):
711718
if node is not None:

market/contracts.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

market/protocol.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ def rpc_get_listings(self, sender):
113113
l.ParseFromString(self.db.listings.get_proto())
114114
l.handle = p.handle
115115
l.avatar_hash = p.avatar_hash
116+
for listing in l.listing:
117+
if listing.hidden:
118+
l.listing.remove(listing)
116119
return [l.SerializeToString(), self.signing_key.sign(l.SerializeToString())[:64]]
117120
except Exception:
118121
self.log.warning("could not find any listings in the database")

net/dos.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__author__ = 'chris'
22

33
from log import Logger
4-
from protos.message import Command, PING, STUN, STORE, INV, VALUES, GET_LISTINGS, FOLLOW, UNFOLLOW
4+
from protos.message import Command, FOLLOW, UNFOLLOW
55
from twisted.internet import reactor, task
66

77
RECONNECTIONS = 100

protos/objects.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ message Listings {
123123
string handle = 11;
124124
ContractType contract_type = 12;
125125
uint64 last_modified = 13;
126+
bool pinned = 14;
127+
bool hidden = 15;
126128
}
127129

128130
enum ContractType {

0 commit comments

Comments
 (0)