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:
benarc 2021-12-01 21:55:04 +00:00
parent f7eba156e7
commit 69a4583203
4 changed files with 25 additions and 18 deletions

View File

@ -5,6 +5,7 @@ from urllib.parse import urlparse
from fastapi import HTTPException
from starlette.requests import Request
from starlette.responses import HTMLResponse
from lnbits import bolt11

View File

@ -1,4 +1,5 @@
import hashlib
import json
from datetime import datetime, timedelta
import httpx
@ -9,6 +10,7 @@ from lnurl import ( # type: ignore
LnurlPayResponse,
)
from starlette.requests import Request
from starlette.responses import HTMLResponse
from . import lnaddress_ext
from .crud import get_address, get_address_by_username, get_domain
@ -28,27 +30,29 @@ async def lnurl_response(username: str, domain: str, request: Request):
if now > expiration:
return LnurlErrorResponse(reason="Address has expired.").dict()
resp = LnurlPayResponse(
callback=request.url_for("lnaddress.lnurl_callback", address_id=address.id),
min_sendable=1000,
max_sendable=1000000000,
metadata=await address.lnurlpay_metadata(),
)
resp = {
"tag": "payRequest",
"callback": request.url_for("lnaddress.lnurl_callback", address_id=address.id),
"metadata": await address.lnurlpay_metadata(domain=domain),
"minSendable": 1000,
"maxSendable": 1000000000,
}
return resp.dict()
print("RESP", resp)
return resp
@lnaddress_ext.get("/lnurl/cb/{address_id}", name="lnaddress.lnurl_callback")
async def lnurl_callback(address_id, amount: int = Query(...)):
print("PING")
address = await get_address(address_id)
if not address:
return LnurlErrorResponse(reason=f"Address not found").dict()
amount_received = amount
domain = await get_domain(address.domain)
base_url = (
address.wallet_endpoint[:-1]
if address.wallet_endpoint.endswith("/")
@ -67,7 +71,7 @@ async def lnurl_callback(address_id, amount: int = Query(...)):
"out": False,
"amount": int(amount_received / 1000),
"description_hash": hashlib.sha256(
(await address.lnurlpay_metadata()).encode("utf-8")
(await address.lnurlpay_metadata(domain=domain.domain)).encode("utf-8")
).hexdigest(),
"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:
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

View File

@ -3,7 +3,7 @@ from typing import Optional
from fastapi.params import Query
from lnurl.types import LnurlPayMetadata
from pydantic.main import BaseModel # type: ignore
from pydantic.main import BaseModel
class CreateDomain(BaseModel):
@ -49,8 +49,9 @@ class Addresses(BaseModel):
paid: bool
time: int
async def lnurlpay_metadata(self) -> LnurlPayMetadata:
async def lnurlpay_metadata(self, domain) -> LnurlPayMetadata:
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))

View File

@ -47,7 +47,7 @@ async def on_invoice_paid(payment: Payment) -> None:
await payment.set_pending(False)
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"):
@ -55,7 +55,7 @@ async def on_invoice_paid(payment: Payment) -> None:
await set_address_renewed(
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:
return