fix: lnurl_encoding error was not handled (#56)
This commit is contained in:
parent
6b11dec0cc
commit
b42fee99e5
6 changed files with 1047 additions and 750 deletions
39
models.py
39
models.py
|
|
@ -1,14 +1,6 @@
|
|||
from datetime import datetime
|
||||
|
||||
import shortuuid
|
||||
from fastapi import Query, Request
|
||||
from lnurl import (
|
||||
ClearnetUrl,
|
||||
Lnurl,
|
||||
LnurlWithdrawResponse,
|
||||
MilliSatoshi,
|
||||
)
|
||||
from lnurl import encode as lnurl_encode
|
||||
from fastapi import Query
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
|
|
@ -50,35 +42,6 @@ class WithdrawLink(BaseModel):
|
|||
def is_spent(self) -> bool:
|
||||
return self.used >= self.uses
|
||||
|
||||
def lnurl(self, req: Request) -> Lnurl:
|
||||
if self.is_unique:
|
||||
usescssv = self.usescsv.split(",")
|
||||
tohash = self.id + self.unique_hash + usescssv[self.number]
|
||||
multihash = shortuuid.uuid(name=tohash)
|
||||
url = str(
|
||||
req.url_for(
|
||||
"withdraw.api_lnurl_multi_response",
|
||||
unique_hash=self.unique_hash,
|
||||
id_unique_hash=multihash,
|
||||
)
|
||||
)
|
||||
else:
|
||||
url = str(
|
||||
req.url_for("withdraw.api_lnurl_response", unique_hash=self.unique_hash)
|
||||
)
|
||||
|
||||
return lnurl_encode(url)
|
||||
|
||||
def lnurl_response(self, req: Request) -> LnurlWithdrawResponse:
|
||||
url = req.url_for("withdraw.api_lnurl_callback", unique_hash=self.unique_hash)
|
||||
return LnurlWithdrawResponse(
|
||||
callback=ClearnetUrl(url, scheme="https"), # type: ignore
|
||||
k1=self.k1,
|
||||
minWithdrawable=MilliSatoshi(self.min_withdrawable * 1000),
|
||||
maxWithdrawable=MilliSatoshi(self.max_withdrawable * 1000),
|
||||
defaultDescription=self.title,
|
||||
)
|
||||
|
||||
|
||||
class HashCheck(BaseModel):
|
||||
hash: bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue