예제 #1
0
    def get(self, uuid):
        k1 = request.args.get("k1")
        invoice = request.args.get("pr")

        db_entry = LnurlModel.find_by_uuid(uuid)
        if not db_entry:
            return {"status": "ERROR", "reason": "Lnurl not found."}, 404

        if db_entry.invoice_bech32:
            return {
                "status": "ERROR",
                "reason": "Invoice already submitted."
            }, 404

        if k1 != db_entry.k1:
            return {"status": "ERROR", "reason": "K1 does not match."}, 404

        db_entry.invoice_bech32 = invoice
        result = db_entry.invoice_amount_validation()
        if result == True:
            try:
                db_entry.save_to_db()
            except:
                return {
                    "message": "An error occured inserting into the database"
                }, 500
            return {"status": "OK"}, 200
        else:
            return result
예제 #2
0
    def get(self, uuid):
        # db_entry = LnurlModel.find_by_uuid(uuid)
        # if not db_entry:
        #     return {"status": "ERROR", "reason": "Lnurl not found."}, 404

        invoice = ""
        while not invoice:
            invoice = LnurlModel.find_by_uuid(uuid).invoice_bech32
            time.sleep(1)
        return {"invoice": invoice}, 200
예제 #3
0
    def post(self):
        data = self.parser.parse_args()

        lnurl = LnurlModel(**data)
        callback_url = lnurl.lnurl_string + "/await-invoice"

        try:
            lnurl.save_to_db()
        except:
            return {
                "message": "An error occured inserting into the database"
            }, 500

        return (
            {
                "lnurl": "lightning:" + lnurl.lnurl_bech32(),
                "callback": callback_url
            },
            201,
        )
예제 #4
0
    def get(self, uuid):
        db_entry = LnurlModel.find_by_uuid(uuid)
        if not db_entry:
            return {"status": "ERROR", "reason": "Lnurl not found."}, 404

        invoice = ""
        timeout = time.time() + 300

        while not invoice and (time.time() < timeout):
            invoice = LnurlModel.find_by_uuid(uuid).invoice_bech32
            time.sleep(1)

        if invoice:
            return {"invoice": invoice}, 200
        else:
            return (
                {
                    "status": "ERROR",
                    "reason": "Timed out after 300 seconds. Please try again.",
                },
                504,
            )
예제 #5
0
    def get(self, uuid):
        k1 = request.args.get("k1")
        invoice = request.args.get("pr")

        db_entry = LnurlModel.find_by_uuid(uuid)
        if not db_entry:
            return {"status": "ERROR", "reason": "Lnurl not found."}, 404

        if k1 != db_entry.k1:
            return {"status": "ERROR", "reason": "K1 not found"}, 404

        db_entry.invoice_bech32 = invoice
        if db_entry.validate_invoice():
            try:
                db_entry.save_to_db()
            except:
                {
                    "message": "An error occured inserting into the database"
                }, 500
            return {"status": "OK"}, 200
        return {"status": "ERROR", "reason": "Invalid lightning invoice"}, 400
예제 #6
0
 def get(self, uuid):
     db_entry = LnurlModel.find_by_uuid(uuid)
     if db_entry:
         response = LnurlModel.lnurl_withdraw_response(db_entry)
         return response.dict(), 200
     return {"status": "ERROR", "reason": "Lnurl not found"}, 404