Adding manual check

This commit is contained in:
benarc 2021-12-17 12:15:33 +00:00
parent 22440492d9
commit 331a383223
7 changed files with 50 additions and 17 deletions

View File

@ -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)

View File

@ -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
);

View File

@ -11,5 +11,6 @@ class lnurlpayout(BaseModel):
id: str
title: str
wallet: str
admin_key: str
lnurlpay: str
threshold: str

View File

@ -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:

View File

@ -20,8 +20,8 @@
<code>[&lt;lnurlpayout_object&gt;, ...]</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:
&lt;invoice_key&gt;"
>curl -X GET {{ request.base_url }}lnurlpayout/api/v1/lnurlpayouts -H
"X-Api-Key: &lt;invoice_key&gt;"
</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":
&lt;string&gt;, "currency": &lt;string&gt;}' -H "Content-type:
application/json" -H "X-Api-Key: &lt;admin_key&gt;"
>curl -X POST {{ request.base_url }}lnurlpayout/api/v1/lnurlpayouts -d
'{"name": &lt;string&gt;, "currency": &lt;string&gt;}' -H
"Content-type: application/json" -H "X-Api-Key: &lt;admin_key&gt;"
</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/&lt;lnurlpayout_id&gt; -H "X-Api-Key:
&lt;admin_key&gt;"
}}lnurlpayout/api/v1/lnurlpayouts/&lt;lnurlpayout_id&gt; -H
"X-Api-Key: &lt;admin_key&gt;"
</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/&lt;lnurlpayout_id&gt;</code
>
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
<code>{"X-Api-Key": &lt;invoice_key&gt;}</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>[&lt;lnurlpayout_object&gt;, ...]</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/&lt;lnurlpayout_id&gt; -H
"X-Api-Key: &lt;invoice_key&gt;"
</code>
</q-card-section>
</q-card>

View File

@ -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'},
{

View File

@ -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