mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-19 03:57:29 +02:00
wos debugging
lnurl debug text identifier text try1 try2 debugging more debug ... .... hard code indentifier . more hard code . trying revert remove identifier adding identifier...again . stupid return text instead of json htmlresponse on more spin . added tag revert to JSON return . ditch lnurl lib . .. .. clean prints
This commit is contained in:
@@ -5,6 +5,7 @@ from urllib.parse import urlparse
|
|||||||
|
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
|
from starlette.responses import HTMLResponse
|
||||||
|
|
||||||
from lnbits import bolt11
|
from lnbits import bolt11
|
||||||
|
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
|
import json
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
@@ -9,6 +10,7 @@ from lnurl import ( # type: ignore
|
|||||||
LnurlPayResponse,
|
LnurlPayResponse,
|
||||||
)
|
)
|
||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
|
from starlette.responses import HTMLResponse
|
||||||
|
|
||||||
from . import lnaddress_ext
|
from . import lnaddress_ext
|
||||||
from .crud import get_address, get_address_by_username, get_domain
|
from .crud import get_address, get_address_by_username, get_domain
|
||||||
@@ -28,20 +30,22 @@ async def lnurl_response(username: str, domain: str, request: Request):
|
|||||||
if now > expiration:
|
if now > expiration:
|
||||||
return LnurlErrorResponse(reason="Address has expired.").dict()
|
return LnurlErrorResponse(reason="Address has expired.").dict()
|
||||||
|
|
||||||
resp = LnurlPayResponse(
|
resp = {
|
||||||
callback=request.url_for("lnaddress.lnurl_callback", address_id=address.id),
|
"tag": "payRequest",
|
||||||
min_sendable=1000,
|
"callback": request.url_for("lnaddress.lnurl_callback", address_id=address.id),
|
||||||
max_sendable=1000000000,
|
"metadata": await address.lnurlpay_metadata(domain=domain),
|
||||||
metadata=await address.lnurlpay_metadata(),
|
"minSendable": 1000,
|
||||||
)
|
"maxSendable": 1000000000,
|
||||||
|
}
|
||||||
|
|
||||||
return resp.dict()
|
print("RESP", resp)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
@lnaddress_ext.get("/lnurl/cb/{address_id}", name="lnaddress.lnurl_callback")
|
@lnaddress_ext.get("/lnurl/cb/{address_id}", name="lnaddress.lnurl_callback")
|
||||||
async def lnurl_callback(address_id, amount: int = Query(...)):
|
async def lnurl_callback(address_id, amount: int = Query(...)):
|
||||||
|
print("PING")
|
||||||
address = await get_address(address_id)
|
address = await get_address(address_id)
|
||||||
|
|
||||||
if not address:
|
if not address:
|
||||||
return LnurlErrorResponse(reason=f"Address not found").dict()
|
return LnurlErrorResponse(reason=f"Address not found").dict()
|
||||||
|
|
||||||
@@ -67,7 +71,7 @@ async def lnurl_callback(address_id, amount: int = Query(...)):
|
|||||||
"out": False,
|
"out": False,
|
||||||
"amount": int(amount_received / 1000),
|
"amount": int(amount_received / 1000),
|
||||||
"description_hash": hashlib.sha256(
|
"description_hash": hashlib.sha256(
|
||||||
(await address.lnurlpay_metadata()).encode("utf-8")
|
(await address.lnurlpay_metadata(domain=domain.domain)).encode("utf-8")
|
||||||
).hexdigest(),
|
).hexdigest(),
|
||||||
"extra": {"tag": f"Payment to {address.username}@{domain.domain}"},
|
"extra": {"tag": f"Payment to {address.username}@{domain.domain}"},
|
||||||
},
|
},
|
||||||
@@ -78,6 +82,7 @@ async def lnurl_callback(address_id, amount: int = Query(...)):
|
|||||||
except AssertionError as e:
|
except AssertionError as e:
|
||||||
return LnurlErrorResponse(reason="ERROR")
|
return LnurlErrorResponse(reason="ERROR")
|
||||||
|
|
||||||
resp = LnurlPayActionResponse(pr=r["payment_request"], routes=[])
|
# resp = LnurlPayActionResponse(pr=r["payment_request"], routes=[])
|
||||||
|
resp = {"pr": r["payment_request"], "routes": []}
|
||||||
|
|
||||||
return resp.dict()
|
return resp
|
||||||
|
@@ -3,7 +3,7 @@ from typing import Optional
|
|||||||
|
|
||||||
from fastapi.params import Query
|
from fastapi.params import Query
|
||||||
from lnurl.types import LnurlPayMetadata
|
from lnurl.types import LnurlPayMetadata
|
||||||
from pydantic.main import BaseModel # type: ignore
|
from pydantic.main import BaseModel
|
||||||
|
|
||||||
|
|
||||||
class CreateDomain(BaseModel):
|
class CreateDomain(BaseModel):
|
||||||
@@ -49,8 +49,9 @@ class Addresses(BaseModel):
|
|||||||
paid: bool
|
paid: bool
|
||||||
time: int
|
time: int
|
||||||
|
|
||||||
async def lnurlpay_metadata(self) -> LnurlPayMetadata:
|
async def lnurlpay_metadata(self, domain) -> LnurlPayMetadata:
|
||||||
text = f"Payment to {self.username}"
|
text = f"Payment to {self.username}"
|
||||||
metadata = [["text/plain", text]]
|
identifier = f"{self.username}@{domain}"
|
||||||
|
metadata = [["text/plain", text], ["text/identifier", identifier]]
|
||||||
|
|
||||||
return LnurlPayMetadata(json.dumps(metadata))
|
return LnurlPayMetadata(json.dumps(metadata))
|
||||||
|
@@ -47,7 +47,7 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||||||
|
|
||||||
await payment.set_pending(False)
|
await payment.set_pending(False)
|
||||||
await set_address_paid(payment_hash=payment.payment_hash)
|
await set_address_paid(payment_hash=payment.payment_hash)
|
||||||
await call_webhook_on_paid(payment.payment_hash)
|
await call_webhook_on_paid(payment_hash=payment.payment_hash)
|
||||||
|
|
||||||
elif "renew lnaddress" == payment.extra.get("tag"):
|
elif "renew lnaddress" == payment.extra.get("tag"):
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||||||
await set_address_renewed(
|
await set_address_renewed(
|
||||||
address_id=payment.extra["id"], duration=payment.extra["duration"]
|
address_id=payment.extra["id"], duration=payment.extra["duration"]
|
||||||
)
|
)
|
||||||
await call_webhook_on_paid(payment.payment_hash)
|
await call_webhook_on_paid(payment_hash=payment.payment_hash)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user