Adding manual check
This commit is contained in:
parent
22440492d9
commit
331a383223
|
@ -6,14 +6,14 @@ from . import db
|
|||
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()
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO lnurlpayout.lnurlpayouts (id, title, wallet, lnurlpay, threshold)
|
||||
INSERT INTO lnurlpayout.lnurlpayouts (id, title, wallet, admin_key, lnurlpay, threshold)
|
||||
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)
|
||||
|
|
|
@ -8,6 +8,7 @@ async def m001_initial(db):
|
|||
id TEXT PRIMARY KEY,
|
||||
title TEXT NOT NULL,
|
||||
wallet TEXT NOT NULL,
|
||||
admin_key TEXT NOT NULL,
|
||||
lnurlpay TEXT NOT NULL,
|
||||
threshold INT NOT NULL
|
||||
);
|
||||
|
|
|
@ -11,5 +11,6 @@ class lnurlpayout(BaseModel):
|
|||
id: str
|
||||
title: str
|
||||
wallet: str
|
||||
admin_key: str
|
||||
lnurlpay: 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)
|
||||
print(lnurlpayout_link)
|
||||
if lnurlpayout_link:
|
||||
print("poo11")
|
||||
# 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:
|
||||
return
|
||||
print("poo2")
|
||||
# Get the invoice from the LNURL to pay
|
||||
async with httpx.AsyncClient() as client:
|
||||
try:
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
<code>[<lnurlpayout_object>, ...]</code>
|
||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||
<code
|
||||
>curl -X GET {{ request.base_url }}api/v1/lnurlpayouts -H "X-Api-Key:
|
||||
<invoice_key>"
|
||||
>curl -X GET {{ request.base_url }}lnurlpayout/api/v1/lnurlpayouts -H
|
||||
"X-Api-Key: <invoice_key>"
|
||||
</code>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
|
@ -53,9 +53,9 @@
|
|||
>
|
||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||
<code
|
||||
>curl -X POST {{ request.base_url }}api/v1/lnurlpayouts -d '{"name":
|
||||
<string>, "currency": <string>}' -H "Content-type:
|
||||
application/json" -H "X-Api-Key: <admin_key>"
|
||||
>curl -X POST {{ request.base_url }}lnurlpayout/api/v1/lnurlpayouts -d
|
||||
'{"name": <string>, "currency": <string>}' -H
|
||||
"Content-type: application/json" -H "X-Api-Key: <admin_key>"
|
||||
</code>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
|
@ -66,7 +66,6 @@
|
|||
dense
|
||||
expand-separator
|
||||
label="Delete a lnurlpayout"
|
||||
class="q-pb-md"
|
||||
>
|
||||
<q-card>
|
||||
<q-card-section>
|
||||
|
@ -81,8 +80,37 @@
|
|||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||
<code
|
||||
>curl -X DELETE {{ request.base_url
|
||||
}}api/v1/lnurlpayouts/<lnurlpayout_id> -H "X-Api-Key:
|
||||
<admin_key>"
|
||||
}}lnurlpayout/api/v1/lnurlpayouts/<lnurlpayout_id> -H
|
||||
"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>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
|
|
|
@ -157,6 +157,7 @@
|
|||
lnurlpayouts: [],
|
||||
lnurlpayoutsTable: {
|
||||
columns: [
|
||||
{name: 'id', align: 'left', label: 'ID', field: 'id'},
|
||||
{name: 'title', align: 'left', label: 'Title', field: 'title'},
|
||||
{name: 'wallet', align: 'left', label: 'Wallet', field: 'wallet'},
|
||||
{
|
||||
|
|
|
@ -39,7 +39,7 @@ async def api_lnurlpayout_create(
|
|||
if str(url["domain"])[0:4] != "http":
|
||||
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Not valid LNURL")
|
||||
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:
|
||||
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Failed to save LNURLPayout")
|
||||
return
|
||||
|
@ -67,10 +67,9 @@ async def api_lnurlpayout_check(
|
|||
lnurlpayout_id: str, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||
):
|
||||
lnurlpayout = await get_lnurlpayout(lnurlpayout_id)
|
||||
payments = get_payments(
|
||||
wallet_id=lnurlpayout.wallet_id, complete=True, pending=False, outgoing=True, incoming=True
|
||||
payments = await get_payments(
|
||||
wallet_id=lnurlpayout.wallet, complete=True, pending=False, outgoing=True, incoming=True
|
||||
)
|
||||
print(payments[0])
|
||||
result = on_invoice_paid(payments[0].id)
|
||||
wallet_ids = [wallet.wallet.id]
|
||||
result = await on_invoice_paid(payments[0])
|
||||
return
|
Loading…
Reference in New Issue
Block a user