lnurlwithdraw
This commit is contained in:
parent
9b7fa96fa2
commit
39339469bb
7 changed files with 17 additions and 25 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
38
lnurl.py
38
lnurl.py
|
|
@ -6,10 +6,11 @@ from http import HTTPStatus
|
|||
from fastapi import Depends, Query, Request
|
||||
from . import myextension_ext
|
||||
from .crud import get_myextension
|
||||
from lnbits.core.services import create_invoice
|
||||
from lnbits.core.services import create_invoice, pay_invoice
|
||||
from loguru import logger
|
||||
from uuid import UUID
|
||||
from typing import Optional
|
||||
from .crud import update_myextension
|
||||
import shortuuid
|
||||
|
||||
#################################################
|
||||
########### A very simple LNURLpay ##############
|
||||
|
|
@ -91,17 +92,11 @@ async def api_lnurl_pay(
|
|||
myextension = await get_myextension(myextension_id)
|
||||
if not myextension:
|
||||
return {"status": "ERROR", "reason": "No myextension found"}
|
||||
k1 = UUID(myextension_id + str(myextension.ticker), version=4)
|
||||
data_to_update = {
|
||||
"ticker": myextension.ticker + 1
|
||||
}
|
||||
|
||||
await update_myextension(myextension_id=myextension_id, **data_to_update)
|
||||
|
||||
k1 = shortuuid.uuid(name=myextension.id + str(myextension.ticker))
|
||||
return {
|
||||
"callback": str(request.url_for("myextension.api_lnurl_withdraw_callback", myextension_id=myextension_id)),
|
||||
"maxSendable": myextension.lnurlwithdrawamount,
|
||||
"minSendable": myextension.lnurlwithdrawamount,
|
||||
"maxSendable": myextension.lnurlwithdrawamount * 1000,
|
||||
"minSendable": myextension.lnurlwithdrawamount * 1000,
|
||||
"k1": k1,
|
||||
"defaultDescription": myextension.name,
|
||||
"metadata":f"[[\"text/plain\", \"{myextension.name}\"]]",
|
||||
|
|
@ -109,7 +104,7 @@ async def api_lnurl_pay(
|
|||
}
|
||||
|
||||
@myextension_ext.get(
|
||||
"/api/v1/lnurl/pay/cb/{myextension_id}",
|
||||
"/api/v1/lnurl/withdraw/cb/{myextension_id}",
|
||||
status_code=HTTPStatus.OK,
|
||||
name="myextension.api_lnurl_withdraw_callback",
|
||||
)
|
||||
|
|
@ -126,18 +121,13 @@ async def api_lnurl_withdraw_cb(
|
|||
if not myextension:
|
||||
return {"status": "ERROR", "reason": "No myextension found"}
|
||||
|
||||
k1Check = UUID(myextension_id + str(myextension.ticker - 1), version=4)
|
||||
k1Check = shortuuid.uuid(name=myextension.id + str(myextension.ticker - 1))
|
||||
if k1Check != k1:
|
||||
return {"status": "ERROR", "reason": "Already spent"}
|
||||
try:
|
||||
await pay_invoice(
|
||||
wallet_id=tpos.wallet,
|
||||
payment_request=pr,
|
||||
max_sat=myextension.lnurlwithdrawamount * 1000,
|
||||
extra={"tag": "MyExtension", "myextensionId": myextension_id,}
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.BAD_REQUEST, detail=f"withdraw not working. {str(e)}"
|
||||
)
|
||||
await pay_invoice(
|
||||
wallet_id=myextension.wallet,
|
||||
payment_request=pr,
|
||||
max_sat=int(myextension.lnurlwithdrawamount * 1000),
|
||||
extra={"tag": "MyExtension", "myextensionId": myextension_id,}
|
||||
)
|
||||
return {"status": "OK"}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class CreateMyExtensionData(BaseModel):
|
|||
total: Optional[int]
|
||||
lnurlpayamount: Optional[int]
|
||||
lnurlwithdrawamount: Optional[int]
|
||||
ticker: Optional[int]
|
||||
|
||||
class MyExtension(BaseModel):
|
||||
id: str
|
||||
|
|
@ -25,6 +26,7 @@ class MyExtension(BaseModel):
|
|||
lnurlwithdrawamount: Optional[int]
|
||||
lnurlpay: Optional[str]
|
||||
lnurlwithdraw: Optional[str]
|
||||
ticker: Optional[int]
|
||||
|
||||
@classmethod
|
||||
def from_row(cls, row: Row) -> "MyExtension":
|
||||
|
|
|
|||
2
tasks.py
2
tasks.py
|
|
@ -3,7 +3,7 @@ import asyncio
|
|||
from loguru import logger
|
||||
|
||||
from lnbits.core.models import Payment
|
||||
from lnbits.core.services import create_invoice, pay_invoice, websocketUpdater
|
||||
from lnbits.core.services import create_invoice, websocketUpdater
|
||||
from lnbits.helpers import get_current_extension_name
|
||||
from lnbits.tasks import register_invoice_listener
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue