Esempio n. 1
0
def api_lnurlfetch(parstr, urlstr, rand):
    """Returns LNURL json."""

    if not parstr:
        return jsonify({"status": "FALSE", "ERROR": "NO WALL ID"}), 200

    if not urlstr:
        return jsonify({"status": "FALSE", "ERROR": "NO URL"}), 200

    with open_ext_db("withdraw") as withdraw_ext_db:
        user_fau = withdraw_ext_db.fetchall(
            "SELECT * FROM withdraws WHERE uni = ?", (parstr, ))
        k1str = uuid.uuid4().hex
        withdraw_ext_db.execute(
            "UPDATE withdraws SET withdrawals = ? WHERE uni = ?", (
                k1str,
                parstr,
            ))

    res = LnurlWithdrawResponse(
        callback=url_for("withdraw.api_lnurlwithdraw",
                         _external=True,
                         rand=rand).replace("http://", "https://"),
        k1=k1str,
        min_withdrawable=user_fau[0][8] * 1000,
        max_withdrawable=user_fau[0][7] * 1000,
        default_description="LNbits LNURL withdraw",
    )

    return res.json(), 200
Esempio n. 2
0
 def lnurl_response(self):
     url = f"withdraw.lnurl_callback?unique_hash={self.unique_hash}"
     return LnurlWithdrawResponse(
         callback=url,
         k1=self.k1,
         min_withdrawable=self.min_withdrawable * 1000,
         max_withdrawable=self.max_withdrawable * 1000,
         default_description=self.title)
Esempio n. 3
0
 def lnurl_response(self) -> LnurlWithdrawResponse:
     url = url_for("withdraw.api_lnurl_callback",
                   unique_hash=self.unique_hash,
                   _external=True)
     return LnurlWithdrawResponse(
         callback=url,
         k1=self.k1,
         min_withdrawable=self.min_withdrawable * 1000,
         max_withdrawable=self.max_withdrawable * 1000,
         default_description=self.title,
     )
Esempio n. 4
0
    def lnurl_response(self) -> LnurlWithdrawResponse:
        scheme = "https" if FORCE_HTTPS else None

        url = url_for("withdraw.api_lnurl_callback", unique_hash=self.unique_hash, _external=True, _scheme=scheme)
        return LnurlWithdrawResponse(
            callback=url,
            k1=self.k1,
            min_withdrawable=self.min_withdrawable * 1000,
            max_withdrawable=self.max_withdrawable * 1000,
            default_description="#withdraw LNbits LNURL",
        )
Esempio n. 5
0
 def lnurl_response(self) -> LnurlWithdrawResponse:
     url = url_for(
         "satsdice.api_lnurlw_callback",
         unique_hash=self.unique_hash,
         _external=True,
     )
     return LnurlWithdrawResponse(
         callback=url,
         k1=self.k1,
         minWithdrawable=self.value * 1000,
         maxWithdrawable=self.value * 1000,
         default_description="Satsdice winnings!",
     )
Esempio n. 6
0
def lnurlwallet():
    lnurl = Lnurl(request.args.get("lightning"))
    r = requests.get(lnurl.url)
    if not r.ok:
        return redirect(url_for("home"))

    data = json.loads(r.text)
    if data.get("status") == "ERROR":
        return redirect(url_for("home"))

    withdraw_res = LnurlWithdrawResponse(**data)

    _, pay_hash, pay_req = WALLET.create_invoice(withdraw_res.max_sats,
                                                 "LNbits lnurl funding")

    r = requests.get(
        withdraw_res.callback.base,
        params={
            **withdraw_res.callback.query_params,
            **{
                "k1": withdraw_res.k1,
                "pr": pay_req
            }
        },
    )

    if not r.ok:
        return redirect(url_for("home"))
    data = json.loads(r.text)

    for i in range(10):
        r = WALLET.get_invoice_status(pay_hash).raw_response
        if not r.ok:
            continue

        data = r.json()
        break

    with open_db() as db:
        wallet_id = uuid.uuid4().hex
        user_id = uuid.uuid4().hex
        wallet_name = DEFAULT_USER_WALLET_NAME
        adminkey = uuid.uuid4().hex
        inkey = uuid.uuid4().hex

        db.execute("INSERT INTO accounts (id) VALUES (?)", (user_id, ))
        db.execute(
            "INSERT INTO wallets (id, name, user, adminkey, inkey) VALUES (?, ?, ?, ?, ?)",
            (wallet_id, wallet_name, user_id, adminkey, inkey),
        )
        db.execute(
            "INSERT INTO apipayments (payhash, amount, wallet, pending, memo) VALUES (?, ?, ?, 0, ?)",
            (
                pay_hash,
                withdraw_res.max_sats * 1000,
                wallet_id,
                "LNbits lnurl funding",
            ),
        )

    return redirect(url_for("wallet", usr=user_id, wal=wallet_id))