Merge branch 'main' into fix/disapearingAdminExt
This commit is contained in:
commit
728ab517f5
|
@ -1,15 +1,15 @@
|
||||||
import datetime
|
|
||||||
import json
|
import json
|
||||||
from typing import Any, Dict, List, Optional
|
import datetime
|
||||||
from urllib.parse import urlparse
|
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
from typing import List, Optional, Dict, Any
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from lnbits import bolt11
|
from lnbits import bolt11
|
||||||
from lnbits.db import COCKROACH, POSTGRES, Connection
|
from lnbits.db import Connection, POSTGRES, COCKROACH
|
||||||
from lnbits.settings import DEFAULT_WALLET_NAME, LNBITS_ADMIN_USERS
|
from lnbits.settings import DEFAULT_WALLET_NAME, LNBITS_ADMIN_USERS
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
from .models import BalanceCheck, Payment, User, Wallet
|
from .models import User, Wallet, Payment, BalanceCheck
|
||||||
|
|
||||||
# accounts
|
# accounts
|
||||||
# --------
|
# --------
|
||||||
|
@ -53,7 +53,6 @@ async def get_user(user_id: str, conn: Optional[Connection] = None) -> Optional[
|
||||||
""",
|
""",
|
||||||
(user_id,),
|
(user_id,),
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@ from lnbits.core.models import User
|
||||||
from lnbits.decorators import check_user_exists
|
from lnbits.decorators import check_user_exists
|
||||||
from lnbits.helpers import template_renderer, url_for
|
from lnbits.helpers import template_renderer, url_for
|
||||||
from lnbits.settings import (
|
from lnbits.settings import (
|
||||||
LNBITS_ADMIN_USERS,
|
|
||||||
LNBITS_ALLOWED_USERS,
|
LNBITS_ALLOWED_USERS,
|
||||||
|
LNBITS_ADMIN_USERS,
|
||||||
LNBITS_SITE_TITLE,
|
LNBITS_SITE_TITLE,
|
||||||
SERVICE_FEE,
|
SERVICE_FEE,
|
||||||
)
|
)
|
||||||
|
@ -118,6 +118,8 @@ async def wallet(
|
||||||
return template_renderer().TemplateResponse(
|
return template_renderer().TemplateResponse(
|
||||||
"error.html", {"request": request, "err": "User not authorized."}
|
"error.html", {"request": request, "err": "User not authorized."}
|
||||||
)
|
)
|
||||||
|
if LNBITS_ADMIN_USERS and user_id in LNBITS_ADMIN_USERS:
|
||||||
|
user.admin = True
|
||||||
if not wallet_id:
|
if not wallet_id:
|
||||||
if user.wallets and not wallet_name:
|
if user.wallets and not wallet_name:
|
||||||
wallet = user.wallets[0]
|
wallet = user.wallets[0]
|
||||||
|
|
|
@ -30,6 +30,6 @@ from .views import * # noqa
|
||||||
from .views_api import * # noqa
|
from .views_api import * # noqa
|
||||||
|
|
||||||
|
|
||||||
def lnticket_start():
|
def livestream_start():
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
|
loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from mmap import MAP_DENYWRITE
|
# from mmap import MAP_DENYWRITE
|
||||||
|
|
||||||
from fastapi.param_functions import Depends
|
from fastapi.param_functions import Depends
|
||||||
from fastapi.params import Query
|
from fastapi.params import Query
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
from http import HTTPStatus
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
from starlette.exceptions import HTTPException
|
||||||
|
|
||||||
from lnbits.core import db as core_db
|
from lnbits.core import db as core_db
|
||||||
from lnbits.core.models import Payment
|
|
||||||
from lnbits.tasks import register_invoice_listener
|
|
||||||
from lnbits.core.views.api import api_wallet
|
|
||||||
from lnbits.core.crud import get_wallet
|
from lnbits.core.crud import get_wallet
|
||||||
from lnbits.core.views.api import api_payment, api_payments_decode, pay_invoice
|
from lnbits.core.models import Payment
|
||||||
|
from lnbits.core.services import pay_invoice
|
||||||
|
from lnbits.core.views.api import api_payments_decode
|
||||||
|
from lnbits.tasks import register_invoice_listener
|
||||||
|
|
||||||
from .crud import get_lnurlpayout, get_lnurlpayout_from_wallet
|
from .crud import get_lnurlpayout_from_wallet
|
||||||
|
|
||||||
|
|
||||||
async def wait_for_paid_invoices():
|
async def wait_for_paid_invoices():
|
||||||
|
@ -25,16 +27,16 @@ async def on_invoice_paid(payment: Payment) -> None:
|
||||||
try:
|
try:
|
||||||
# Check its got a payout associated with it
|
# Check its got a payout associated with it
|
||||||
lnurlpayout_link = await get_lnurlpayout_from_wallet(payment.wallet_id)
|
lnurlpayout_link = await get_lnurlpayout_from_wallet(payment.wallet_id)
|
||||||
|
print("LNURLpayout", lnurlpayout_link)
|
||||||
if lnurlpayout_link:
|
if lnurlpayout_link:
|
||||||
|
|
||||||
# Check the wallet balance is more than the threshold
|
# Check the wallet balance is more than the threshold
|
||||||
|
|
||||||
wallet = await get_wallet(lnurlpayout_link.wallet)
|
wallet = await get_wallet(lnurlpayout_link.wallet)
|
||||||
if wallet.balance < lnurlpayout_link.threshold + (
|
threshold = lnurlpayout_link.threshold + (lnurlpayout_link.threshold * 0.02)
|
||||||
lnurlpayout_link.threshold * 0.02
|
|
||||||
):
|
|
||||||
return
|
|
||||||
|
|
||||||
|
if wallet.balance < threshold:
|
||||||
|
return
|
||||||
# Get the invoice from the LNURL to pay
|
# Get the invoice from the LNURL to pay
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
try:
|
try:
|
||||||
|
@ -43,6 +45,7 @@ async def on_invoice_paid(payment: Payment) -> None:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.FORBIDDEN, detail="LNURL broken"
|
status_code=HTTPStatus.FORBIDDEN, detail="LNURL broken"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = await client.get(str(url["domain"]), timeout=40)
|
r = await client.get(str(url["domain"]), timeout=40)
|
||||||
res = r.json()
|
res = r.json()
|
||||||
|
@ -56,6 +59,12 @@ async def on_invoice_paid(payment: Payment) -> None:
|
||||||
timeout=40,
|
timeout=40,
|
||||||
)
|
)
|
||||||
res = r.json()
|
res = r.json()
|
||||||
|
|
||||||
|
if hasattr(res, "status") and res["status"] == "ERROR":
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.FORBIDDEN,
|
||||||
|
detail=res["reason"],
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
await pay_invoice(
|
await pay_invoice(
|
||||||
wallet_id=payment.wallet_id,
|
wallet_id=payment.wallet_id,
|
||||||
|
@ -65,7 +74,9 @@ async def on_invoice_paid(payment: Payment) -> None:
|
||||||
return
|
return
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
except:
|
|
||||||
|
except Exception as e:
|
||||||
|
print("ERROR", str(e))
|
||||||
return
|
return
|
||||||
except (httpx.ConnectError, httpx.RequestError):
|
except (httpx.ConnectError, httpx.RequestError):
|
||||||
return
|
return
|
||||||
|
|
|
@ -4,7 +4,8 @@ from fastapi import Query
|
||||||
from fastapi.params import Depends
|
from fastapi.params import Depends
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
|
|
||||||
from lnbits.core.crud import get_user, get_payments
|
from lnbits.core.crud import get_payments, get_user
|
||||||
|
from lnbits.core.models import Payment
|
||||||
from lnbits.core.services import create_invoice
|
from lnbits.core.services import create_invoice
|
||||||
from lnbits.core.views.api import api_payment, api_payments_decode
|
from lnbits.core.views.api import api_payment, api_payments_decode
|
||||||
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
|
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
|
||||||
|
@ -14,10 +15,10 @@ from .crud import (
|
||||||
create_lnurlpayout,
|
create_lnurlpayout,
|
||||||
delete_lnurlpayout,
|
delete_lnurlpayout,
|
||||||
get_lnurlpayout,
|
get_lnurlpayout,
|
||||||
get_lnurlpayouts,
|
|
||||||
get_lnurlpayout_from_wallet,
|
get_lnurlpayout_from_wallet,
|
||||||
|
get_lnurlpayouts,
|
||||||
)
|
)
|
||||||
from .models import lnurlpayout, CreateLnurlPayoutData
|
from .models import CreateLnurlPayoutData, lnurlpayout
|
||||||
from .tasks import on_invoice_paid
|
from .tasks import on_invoice_paid
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,14 +88,24 @@ async def api_lnurlpayout_check(
|
||||||
lnurlpayout_id: str, wallet: WalletTypeInfo = Depends(get_key_type)
|
lnurlpayout_id: str, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||||
):
|
):
|
||||||
lnurlpayout = await get_lnurlpayout(lnurlpayout_id)
|
lnurlpayout = await get_lnurlpayout(lnurlpayout_id)
|
||||||
payments = await get_payments(
|
## THIS
|
||||||
wallet_id=lnurlpayout.wallet,
|
mock_payment = Payment(
|
||||||
complete=True,
|
checking_id="mock",
|
||||||
pending=False,
|
pending=False,
|
||||||
outgoing=True,
|
amount=1,
|
||||||
incoming=True,
|
fee=1,
|
||||||
|
time=0000,
|
||||||
|
bolt11="mock",
|
||||||
|
preimage="mock",
|
||||||
|
payment_hash="mock",
|
||||||
|
wallet_id=lnurlpayout.wallet,
|
||||||
)
|
)
|
||||||
result = await on_invoice_paid(payments[0])
|
## INSTEAD OF THIS
|
||||||
|
# payments = await get_payments(
|
||||||
|
# wallet_id=lnurlpayout.wallet, complete=True, pending=False, outgoing=True, incoming=True
|
||||||
|
# )
|
||||||
|
|
||||||
|
result = await on_invoice_paid(mock_payment)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
<code>[<withdraw_link_object>, ...]</code>
|
<code>[<withdraw_link_object>, ...]</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X GET {{ request.base_url }}api/v1/links -H "X-Api-Key: {{
|
>curl -X GET {{ request.base_url }}withdraw/api/v1/links -H "X-Api-Key: {{
|
||||||
user.wallets[0].inkey }}"
|
user.wallets[0].inkey }}"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
@ -49,7 +49,7 @@
|
||||||
<code>{"lnurl": <string>}</code>
|
<code>{"lnurl": <string>}</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X GET {{ request.base_url }}api/v1/links/<withdraw_id> -H
|
>curl -X GET {{ request.base_url }}withdraw/api/v1/links/<withdraw_id> -H
|
||||||
"X-Api-Key: {{ user.wallets[0].inkey }}"
|
"X-Api-Key: {{ user.wallets[0].inkey }}"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
@ -78,7 +78,7 @@
|
||||||
<code>{"lnurl": <string>}</code>
|
<code>{"lnurl": <string>}</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X POST {{ request.base_url }}api/v1/links -d '{"title":
|
>curl -X POST {{ request.base_url }}withdraw/api/v1/links -d '{"title":
|
||||||
<string>, "min_withdrawable": <integer>,
|
<string>, "min_withdrawable": <integer>,
|
||||||
"max_withdrawable": <integer>, "uses": <integer>,
|
"max_withdrawable": <integer>, "uses": <integer>,
|
||||||
"wait_time": <integer>, "is_unique": <boolean>}' -H
|
"wait_time": <integer>, "is_unique": <boolean>}' -H
|
||||||
|
@ -114,7 +114,7 @@
|
||||||
<code>{"lnurl": <string>}</code>
|
<code>{"lnurl": <string>}</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X PUT {{ request.base_url }}api/v1/links/<withdraw_id> -d
|
>curl -X PUT {{ request.base_url }}withdraw/api/v1/links/<withdraw_id> -d
|
||||||
'{"title": <string>, "min_withdrawable": <integer>,
|
'{"title": <string>, "min_withdrawable": <integer>,
|
||||||
"max_withdrawable": <integer>, "uses": <integer>,
|
"max_withdrawable": <integer>, "uses": <integer>,
|
||||||
"wait_time": <integer>, "is_unique": <boolean>}' -H
|
"wait_time": <integer>, "is_unique": <boolean>}' -H
|
||||||
|
@ -142,7 +142,7 @@
|
||||||
<code></code>
|
<code></code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X DELETE {{ request.base_url }}api/v1/links/<withdraw_id>
|
>curl -X DELETE {{ request.base_url }}withdraw/api/v1/links/<withdraw_id>
|
||||||
-H "X-Api-Key: {{ user.wallets[0].adminkey }}"
|
-H "X-Api-Key: {{ user.wallets[0].adminkey }}"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
@ -170,7 +170,7 @@
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X GET {{ request.base_url
|
>curl -X GET {{ request.base_url
|
||||||
}}api/v1/links/<the_hash>/<lnurl_id> -H "X-Api-Key: {{
|
}}withdraw/api/v1/links/<the_hash>/<lnurl_id> -H "X-Api-Key: {{
|
||||||
user.wallets[0].inkey }}"
|
user.wallets[0].inkey }}"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
@ -191,7 +191,7 @@
|
||||||
>
|
>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X GET {{ request.base_url }}/withdraw/img/<lnurl_id>"
|
>curl -X GET {{ request.base_url }}withdraw/img/<lnurl_id>"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user