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

Commit 45f23d2

Browse files
committed
Catch exception saving duplicate messages
1 parent 80622e5 commit 45f23d2

File tree

5 files changed

+122
-14
lines changed

5 files changed

+122
-14
lines changed

api/restapi.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,9 @@ def set_contract(self, request):
558558
contract_id=request.args["contract_id"][0] if "contract_id" in request.args else None)
559559

560560
for keyword in request.args["keywords"]:
561-
self.kserver.set(digest(keyword.lower()), unhexlify(c.get_contract_id()),
562-
self.kserver.node.getProto().SerializeToString())
561+
if keyword != "":
562+
self.kserver.set(digest(keyword.lower()), unhexlify(c.get_contract_id()),
563+
self.kserver.node.getProto().SerializeToString())
563564
request.write(json.dumps({"success": True, "id": c.get_contract_id()}))
564565
request.finish()
565566
return server.NOT_DONE_YET

db/datastore.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -502,17 +502,20 @@ def save_message(self, guid, handle, pubkey, subject, message_type, message,
502502
"""
503503
Store message in database.
504504
"""
505-
conn = Database.connect_database(self.PATH)
506-
with conn:
507-
outgoing = 1 if is_outgoing else 0
508-
msgID = digest(message + str(timestamp)).encode("hex") if msg_id is None else msg_id
509-
cursor = conn.cursor()
510-
cursor.execute('''INSERT INTO messages(msgID, guid, handle, pubkey, subject,
511-
messageType, message, timestamp, avatarHash, signature, outgoing, read) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)''',
512-
(msgID, guid, handle, pubkey, subject, message_type,
513-
message, timestamp, avatar_hash, signature, outgoing, 0))
514-
conn.commit()
515-
conn.close()
505+
try:
506+
conn = Database.connect_database(self.PATH)
507+
with conn:
508+
outgoing = 1 if is_outgoing else 0
509+
msgID = digest(message + str(timestamp)).encode("hex") if msg_id is None else msg_id
510+
cursor = conn.cursor()
511+
cursor.execute('''INSERT INTO messages(msgID, guid, handle, pubkey, subject,
512+
messageType, message, timestamp, avatarHash, signature, outgoing, read) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)''',
513+
(msgID, guid, handle, pubkey, subject, message_type,
514+
message, timestamp, avatar_hash, signature, outgoing, 0))
515+
conn.commit()
516+
conn.close()
517+
except Exception:
518+
pass
516519

517520
def get_messages(self, guid, message_type):
518521
"""

dht/protocol.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ def handleCallResponse(self, result, node):
225225
"""
226226
if result[0]:
227227
if self.router.isNewNode(node):
228+
self.log.debug("Call response from new node, transferring key/values")
228229
reactor.callLater(1, self.transferKeyValues, node)
229230
self.router.addContact(node)
230231
else:

market/contracts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def create(self,
147147
"listing": {
148148
"contract_id": contract_id,
149149
"metadata": {
150-
"version": "0.1",
150+
"version": "1",
151151
"category": metadata_category.lower(),
152152
"category_sub": "fixed price"
153153
},

protos/contract.proto

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
Get the protobuf compiler:
3+
You will need to manually compile protobuf v3.0.0-beta-2
4+
https://github.com/google/protobuf/releases/tag/v3.0.0-beta-2
5+
6+
Compile with:
7+
cd path/to/protos/
8+
protoc --python_out=./ message.proto
9+
*/
10+
11+
/*
12+
The goal here is to move the contract serialization to protobuf from json
13+
and use the proto3 json serialization when saving to disk. This will be part
14+
of a larger refactor of the contracts module, hence this is not used yet.
15+
*/
16+
17+
18+
syntax = "proto3";
19+
20+
//This is the message structure for OpenBazaar messages going over the wire
21+
message Contract {
22+
VendorOffer vendor_offer = 1;
23+
BuyerOrder buyer_order = 2;
24+
VendorOrderConfirmation vendor_order_confirmation = 3;
25+
BuyerReceipt buyer_receipt = 4;
26+
DisputeResolution dispute_resolution = 5;
27+
}
28+
29+
message VendorOffer {
30+
Listing listing = 1;
31+
Signatures signatures = 2;
32+
33+
message Listing {
34+
string contract_id = 1;
35+
ID id = 2;
36+
Metadata metadata = 3;
37+
Item item = 4;
38+
Shipping shipping = 5;
39+
repeated Moderator moderators = 6;
40+
41+
message ID {
42+
string guid = 1;
43+
string blockchain_id = 2;
44+
Pubkeys pubkeys = 3;
45+
46+
message Pubkeys {
47+
string guid = 1;
48+
string bitcoin = 2;
49+
}
50+
}
51+
52+
message Metadata {
53+
string version = 1;
54+
Category category = 2;
55+
CategorySub category_sub = 3;
56+
Timestamp expiry = 4;
57+
58+
enum CategorySub {
59+
FIXED_PRICE = 0;
60+
AUCTION = 1;
61+
}
62+
63+
enum Category {
64+
PHYSICAL_GOOD = 0;
65+
DIGITAL_GOOD = 1;
66+
SERVICE = 2;
67+
}
68+
}
69+
70+
message Item {
71+
string title = 1;
72+
string description = 2;
73+
string process_time = 3;
74+
PPU price_per_unit = 4;
75+
bool nsfw = 5;
76+
repeated string keywords = 6;
77+
repeated image_hashes = 7;
78+
string SKU = 8;
79+
string condition = 9;
80+
repeated Options options = 10;
81+
}
82+
83+
message PPU {
84+
float bitcoin = 1;
85+
Fiat fiat = 2;
86+
87+
message Fiat {
88+
string currency_code = 1;
89+
float price = 2;
90+
}
91+
}
92+
93+
message Options {
94+
string x = 1;
95+
repeated string y = 2;
96+
}
97+
}
98+
}
99+
100+
message Signatures {
101+
bytes guid = 1;
102+
bytes bitcoin = 2;
103+
}

0 commit comments

Comments
 (0)