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

Commit dcd6f31

Browse files
committed
Add websocket notification for underfunded order
1 parent c88db80 commit dcd6f31

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

dht/storage.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,11 @@ def get_ttl(self, keyword, key):
148148
cursor = self.db.cursor()
149149
cursor.execute('''SELECT birthday FROM dht WHERE keyword=? AND id=?''', (keyword.encode("hex"), key,))
150150
return self.ttl - (time.time() - cursor.fetchall()[0][0])
151+
152+
def get_db_size(self):
153+
cursor = self.db.cursor()
154+
cursor.execute('''PRAGMA page_count;''')
155+
count = cursor.fetchone()[0]
156+
cursor.execute('''PRAGMA page_size;''')
157+
size = cursor.fetchone()[0]
158+
return count * size

market/contracts.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,16 +861,28 @@ def on_tx_received(self, address_version, address_hash, height, block_hash, tx):
861861

862862
# get the amount (in satoshi) the user is expected to pay
863863
amount_to_pay = int(float(self.contract["buyer_order"]["order"]["payment"]["amount"]) * 100000000)
864+
val = 0
864865
if tx not in self.received_txs: # make sure we aren't parsing the same tx twice.
865866
outpoints = transaction.check_for_funding(
866867
self.contract["buyer_order"]["order"]["payment"]["address"])
867868
if outpoints is not None:
868869
for outpoint in outpoints:
869870
self.amount_funded += outpoint["value"]
871+
val += outpoint["value"]
870872
self.received_txs.append(tx)
871873
self.outpoints.append(outpoint)
872874
if self.amount_funded >= amount_to_pay: # if fully funded
873875
self.payment_received()
876+
else:
877+
order_id = digest(json.dumps(self.contract, indent=4)).encode("hex")
878+
notification_json = {
879+
"notification": {
880+
"type": "partial payment",
881+
"amount": val,
882+
"order_id": order_id
883+
}
884+
}
885+
self.notification_listener.push_ws(notification_json)
874886

875887
except Exception as e:
876888
self.log.critical("Error processing bitcoin transaction: %s" % e.message)

market/listeners.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,6 @@ def notify(self, guid, handle, notif_type, order_id, title, image_hash):
108108
}
109109
}
110110
self.ws.push(json.dumps(sanitize_html(notification_json), indent=4))
111+
112+
def push_ws(self, json_obj):
113+
self.ws.push(json.dumps(sanitize_html(json_obj), indent=4))

openbazaard.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from twisted.python import log, logfile
3838
from txws import WebSocketFactory
3939

40-
4140
def run(*args):
4241
TESTNET = args[0]
4342
LOGLEVEL = args[1]

0 commit comments

Comments
 (0)