def tx_event(txn): txt = json.dumps(txn.to_json()) socketio.emit("tx", txt, json=True, room=txn.sender.email, namespace=NS) if txn.recipient and txn.recipient != txn.sender: socketio.emit("tx", txt, json=True, room=txn.recipient.email, namespace=NS)
def ws_invoices_timer_callback(): #logger.info("ws_invoices_timer_callback()..") for token in ws_invoices.keys(): #logger.info("ws_invoices_timer_callback: token: {}".format(token)) invoice = Invoice.from_token(db.session, token) if invoice: order = bronze_order_status(invoice) if order: socketio.emit("order_status", order["status"], room=token)
def test_claimcode(token): if not app.config["DEBUG"]: return abort(404) claim_code = ClaimCode.from_token(db.session, token) for api_key in ws_api_keys: print("sending claim code to %s" % api_key) socketio.emit("info", claim_code.to_json(), json=True, room=api_key) if claim_code: return jsonify(claim_code.to_json()) return abort(404)
def test_invoice(token): if not app.config["DEBUG"]: return abort(404) invoice = Invoice.from_token(db.session, token) if token in ws_invoices: logger.info("sending invoice update %s" % token) socketio.emit("info", invoice.to_json(), json=True, room=token) if invoice: return jsonify(invoice.to_json()) return abort(404)
def transfer_tx_callback(api_keys, txn): txt = json.dumps(txn) print("transfer_tx_callback: tx %s" % txt) for api_key in api_keys: print("sending 'tx' event to room %s" % api_key) socketio.emit("tx", txt, json=True, room=api_key) if not TxNotification.exists(db.session, txn["id"]): print("adding to tx notification table") api_key = ApiKey.from_token(db.session, api_key) txnoti = TxNotification(api_key.user, txn["id"]) db.session.add(txnoti) db.session.commit()
def transfer_tx_callback(tokens, tx): txt = json.dumps(tx) logger.info("transfer_tx_callback: tx %s" % txt) for token in tokens: invoice = Invoice.from_token(db.session, token) if invoice: order = bronze_order_status(invoice) if order: try: attachment = json.loads(tx["attachment"]) invoice_id = attachment["InvoiceId"] amount_zap = int(tx["amount"] * 100) if invoice_id == order[ "invoiceId"] and amount_zap >= invoice.amount_zap: logger.info("marking invoice (%s) as seen" % token) invoice.tx_seen = True db.session.add(invoice) db.session.commit() except: pass logger.info("sending 'tx' event to room %s" % token) socketio.emit("tx", txt, json=True, room=token)
def alert_claimed(claim_code): for apikey in claim_code.user.apikeys: socketio.emit("claimed", claim_code.to_json(), json=True, room=apikey.token)
def alert_invoice_update(invoice): socketio.emit("update", invoice.to_json(), json=True, room=invoice.token)