Beispiel #1
0
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)
Beispiel #2
0
def check_auth(token, nonce, sig, body):
    invoice = Invoice.from_token(db.session, token)
    if not invoice:
        return False, "not found", None
    res, reason = check_hmac_auth(invoice, nonce, sig, body)
    if not res:
        return False, reason, None
    # update invoice nonce
    db.session.commit()
    return True, "", invoice
Beispiel #3
0
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)
Beispiel #4
0
def invoice():
    error = None
    qrcode_svg = None
    url = None
    token = request.args.get("token")
    invoice = Invoice.from_token(db.session, token)
    if not invoice:
        return abort(404)
    order = bronze_order_status(invoice)
    if not order:
        return abort(400)
    if order["status"] == Invoice.STATUS_EXPIRED:
        error = "invoice expired"
        return render_template("invoice.html",
                               invoice=invoice,
                               order=order,
                               error=error)
    if request.method == "POST":
        if order["status"] == Invoice.STATUS_CREATED:
            res = bronze_order_accept(invoice)
            if res:
                order = res
    if order["status"] == Invoice.STATUS_READY:
        # watch address
        logger.info("watching address %s for %s" %
                    (order["paymentAddress"], token))
        aw.watch(order["paymentAddress"], token)
        # prepare template
        invoice_id = order["invoiceId"]
        payment_address = order["paymentAddress"]
        attachment = json.dumps(dict(InvoiceId=invoice_id))
        url = "waves://{}?asset={}&amount={}&attachment={}".format(
            payment_address, app.config["ASSET_ID"], invoice.amount_zap,
            attachment)
        qrcode_svg = qrcode_svg_create(url)
        # change links to match zap app :/
        url = "zap" + url[5:]
    #TODO: other statuses..
    return render_template("invoice.html",
                           invoice=invoice,
                           order=order,
                           error=error,
                           qrcode_svg=qrcode_svg,
                           url=url)
Beispiel #5
0
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)