mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-22 06:42:53 +02:00
Adding manual check
This commit is contained in:
parent
22440492d9
commit
331a383223
@ -6,14 +6,14 @@ from . import db
|
|||||||
from .models import lnurlpayout, CreateLnurlPayoutData
|
from .models import lnurlpayout, CreateLnurlPayoutData
|
||||||
|
|
||||||
|
|
||||||
async def create_lnurlpayout(wallet_id: str, data: CreateLnurlPayoutData) -> lnurlpayout:
|
async def create_lnurlpayout(wallet_id: str, admin_key: str, data: CreateLnurlPayoutData) -> lnurlpayout:
|
||||||
lnurlpayout_id = urlsafe_short_hash()
|
lnurlpayout_id = urlsafe_short_hash()
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO lnurlpayout.lnurlpayouts (id, title, wallet, lnurlpay, threshold)
|
INSERT INTO lnurlpayout.lnurlpayouts (id, title, wallet, admin_key, lnurlpay, threshold)
|
||||||
VALUES (?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(lnurlpayout_id, data.title, wallet_id, data.lnurlpay, data.threshold),
|
(lnurlpayout_id, data.title, wallet_id, admin_key, data.lnurlpay, data.threshold),
|
||||||
)
|
)
|
||||||
|
|
||||||
lnurlpayout = await get_lnurlpayout(lnurlpayout_id)
|
lnurlpayout = await get_lnurlpayout(lnurlpayout_id)
|
||||||
|
@ -8,6 +8,7 @@ async def m001_initial(db):
|
|||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
title TEXT NOT NULL,
|
title TEXT NOT NULL,
|
||||||
wallet TEXT NOT NULL,
|
wallet TEXT NOT NULL,
|
||||||
|
admin_key TEXT NOT NULL,
|
||||||
lnurlpay TEXT NOT NULL,
|
lnurlpay TEXT NOT NULL,
|
||||||
threshold INT NOT NULL
|
threshold INT NOT NULL
|
||||||
);
|
);
|
||||||
|
@ -11,5 +11,6 @@ class lnurlpayout(BaseModel):
|
|||||||
id: str
|
id: str
|
||||||
title: str
|
title: str
|
||||||
wallet: str
|
wallet: str
|
||||||
|
admin_key: str
|
||||||
lnurlpay: str
|
lnurlpay: str
|
||||||
threshold: str
|
threshold: str
|
||||||
|
@ -25,10 +25,13 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||||||
lnurlpayout_link = await get_lnurlpayout_from_wallet(payment.wallet_id)
|
lnurlpayout_link = await get_lnurlpayout_from_wallet(payment.wallet_id)
|
||||||
print(lnurlpayout_link)
|
print(lnurlpayout_link)
|
||||||
if lnurlpayout_link:
|
if lnurlpayout_link:
|
||||||
|
print("poo11")
|
||||||
# Check the wallet balance is more than the threshold
|
# Check the wallet balance is more than the threshold
|
||||||
wallet = await api_wallet(payment.wallet_id)
|
wallet = await api_wallet(lnurlpayout_link.admin_key)
|
||||||
|
print("poo1")
|
||||||
if wallet.balance + (wallet.balance/100*2) < lnurlpayout_link.threshold:
|
if wallet.balance + (wallet.balance/100*2) < lnurlpayout_link.threshold:
|
||||||
return
|
return
|
||||||
|
print("poo2")
|
||||||
# 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:
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
<code>[<lnurlpayout_object>, ...]</code>
|
<code>[<lnurlpayout_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/lnurlpayouts -H "X-Api-Key:
|
>curl -X GET {{ request.base_url }}lnurlpayout/api/v1/lnurlpayouts -H
|
||||||
<invoice_key>"
|
"X-Api-Key: <invoice_key>"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
@ -53,9 +53,9 @@
|
|||||||
>
|
>
|
||||||
<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/lnurlpayouts -d '{"name":
|
>curl -X POST {{ request.base_url }}lnurlpayout/api/v1/lnurlpayouts -d
|
||||||
<string>, "currency": <string>}' -H "Content-type:
|
'{"name": <string>, "currency": <string>}' -H
|
||||||
application/json" -H "X-Api-Key: <admin_key>"
|
"Content-type: application/json" -H "X-Api-Key: <admin_key>"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
@ -66,7 +66,6 @@
|
|||||||
dense
|
dense
|
||||||
expand-separator
|
expand-separator
|
||||||
label="Delete a lnurlpayout"
|
label="Delete a lnurlpayout"
|
||||||
class="q-pb-md"
|
|
||||||
>
|
>
|
||||||
<q-card>
|
<q-card>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
@ -81,8 +80,37 @@
|
|||||||
<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
|
>curl -X DELETE {{ request.base_url
|
||||||
}}api/v1/lnurlpayouts/<lnurlpayout_id> -H "X-Api-Key:
|
}}lnurlpayout/api/v1/lnurlpayouts/<lnurlpayout_id> -H
|
||||||
<admin_key>"
|
"X-Api-Key: <admin_key>"
|
||||||
|
</code>
|
||||||
|
</q-card-section>
|
||||||
|
</q-card>
|
||||||
|
</q-expansion-item>
|
||||||
|
<q-expansion-item
|
||||||
|
group="api"
|
||||||
|
dense
|
||||||
|
expand-separator
|
||||||
|
label="Check lnurlpayout"
|
||||||
|
class="q-pb-md"
|
||||||
|
>
|
||||||
|
<q-card>
|
||||||
|
<q-card-section>
|
||||||
|
<code
|
||||||
|
><span class="text-blue">GET</span>
|
||||||
|
/lnurlpayout/api/v1/lnurlpayouts/<lnurlpayout_id></code
|
||||||
|
>
|
||||||
|
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
|
||||||
|
<code>{"X-Api-Key": <invoice_key>}</code><br />
|
||||||
|
<h5 class="text-caption q-mt-sm q-mb-none">Body (application/json)</h5>
|
||||||
|
<h5 class="text-caption q-mt-sm q-mb-none">
|
||||||
|
Returns 200 OK (application/json)
|
||||||
|
</h5>
|
||||||
|
<code>[<lnurlpayout_object>, ...]</code>
|
||||||
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
|
<code
|
||||||
|
>curl -X GET {{ request.base_url
|
||||||
|
}}lnurlpayout/api/v1/lnurlpayouts/<lnurlpayout_id> -H
|
||||||
|
"X-Api-Key: <invoice_key>"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
@ -157,6 +157,7 @@
|
|||||||
lnurlpayouts: [],
|
lnurlpayouts: [],
|
||||||
lnurlpayoutsTable: {
|
lnurlpayoutsTable: {
|
||||||
columns: [
|
columns: [
|
||||||
|
{name: 'id', align: 'left', label: 'ID', field: 'id'},
|
||||||
{name: 'title', align: 'left', label: 'Title', field: 'title'},
|
{name: 'title', align: 'left', label: 'Title', field: 'title'},
|
||||||
{name: 'wallet', align: 'left', label: 'Wallet', field: 'wallet'},
|
{name: 'wallet', align: 'left', label: 'Wallet', field: 'wallet'},
|
||||||
{
|
{
|
||||||
|
@ -39,7 +39,7 @@ async def api_lnurlpayout_create(
|
|||||||
if str(url["domain"])[0:4] != "http":
|
if str(url["domain"])[0:4] != "http":
|
||||||
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Not valid LNURL")
|
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Not valid LNURL")
|
||||||
return
|
return
|
||||||
lnurlpayout = await create_lnurlpayout(wallet_id=wallet.wallet.id, data=data)
|
lnurlpayout = await create_lnurlpayout(wallet_id=wallet.wallet.id, admin_key=wallet.admin_key, data=data)
|
||||||
if not lnurlpayout:
|
if not lnurlpayout:
|
||||||
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Failed to save LNURLPayout")
|
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Failed to save LNURLPayout")
|
||||||
return
|
return
|
||||||
@ -67,10 +67,9 @@ 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 = get_payments(
|
payments = await get_payments(
|
||||||
wallet_id=lnurlpayout.wallet_id, complete=True, pending=False, outgoing=True, incoming=True
|
wallet_id=lnurlpayout.wallet, complete=True, pending=False, outgoing=True, incoming=True
|
||||||
)
|
)
|
||||||
print(payments[0])
|
print(payments[0])
|
||||||
result = on_invoice_paid(payments[0].id)
|
result = await on_invoice_paid(payments[0])
|
||||||
wallet_ids = [wallet.wallet.id]
|
|
||||||
return
|
return
|
Loading…
x
Reference in New Issue
Block a user