mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-22 14:22:55 +01:00
lnurlp: support for floating point fiat values
This commit is contained in:
parent
77fbea25af
commit
b7008495b8
4 changed files with 16 additions and 11 deletions
|
@ -9,6 +9,12 @@ async def create_pay_link(data: CreatePayLinkData, wallet_id: str) -> PayLink:
|
|||
|
||||
returning = "" if db.type == SQLITE else "RETURNING ID"
|
||||
method = db.execute if db.type == SQLITE else db.fetchone
|
||||
# database only allows int4 entries for min and max. For fiat currencies,
|
||||
# we multiply by 100 to save the value in cents.
|
||||
if data.currency:
|
||||
data.min *= 100
|
||||
data.max *= 100
|
||||
|
||||
result = await (method)(
|
||||
f"""
|
||||
INSERT INTO lnurlp.pay_links (
|
||||
|
|
|
@ -29,11 +29,11 @@ async def api_lnurl_response(request: Request, link_id):
|
|||
status_code=HTTPStatus.NOT_FOUND, detail="Pay link does not exist."
|
||||
)
|
||||
|
||||
rate = await get_fiat_rate_satoshis(link.currency) if link.currency else 1
|
||||
rate = await get_fiat_rate_satoshis(link.currency) / 100 if link.currency else 1
|
||||
|
||||
resp = LnurlPayResponse(
|
||||
callback=request.url_for("lnurlp.api_lnurl_callback", link_id=link.id),
|
||||
min_sendable=math.ceil(link.min * rate) * 1000,
|
||||
min_sendable=round(link.min * rate) * 1000,
|
||||
max_sendable=round(link.max * rate) * 1000,
|
||||
metadata=link.lnurlpay_metadata,
|
||||
)
|
||||
|
|
|
@ -11,8 +11,8 @@ from pydantic import BaseModel
|
|||
|
||||
class CreatePayLinkData(BaseModel):
|
||||
description: str
|
||||
min: int = Query(0.01, ge=0.01)
|
||||
max: int = Query(0.01, ge=0.01)
|
||||
min: float = Query(1, ge=0.01)
|
||||
max: float = Query(1, ge=0.01)
|
||||
currency: str = Query(None)
|
||||
comment_chars: int = Query(0, ge=0, lt=800)
|
||||
webhook_url: str = Query(None)
|
||||
|
@ -24,7 +24,7 @@ class PayLink(BaseModel):
|
|||
id: int
|
||||
wallet: str
|
||||
description: str
|
||||
min: int
|
||||
min: float
|
||||
served_meta: int
|
||||
served_pr: int
|
||||
webhook_url: Optional[str]
|
||||
|
@ -32,11 +32,14 @@ class PayLink(BaseModel):
|
|||
success_url: Optional[str]
|
||||
currency: Optional[str]
|
||||
comment_chars: int
|
||||
max: int
|
||||
max: float
|
||||
|
||||
@classmethod
|
||||
def from_row(cls, row: Row) -> "PayLink":
|
||||
data = dict(row)
|
||||
if data["currency"]:
|
||||
data["min"] /= 100
|
||||
data["max"] /= 100
|
||||
return cls(**data)
|
||||
|
||||
def lnurl(self, req: Request) -> str:
|
||||
|
|
|
@ -76,10 +76,6 @@ async def api_link_create_or_update(
|
|||
link_id=None,
|
||||
wallet: WalletTypeInfo = Depends(get_key_type),
|
||||
):
|
||||
if data.min < 1:
|
||||
raise HTTPException(
|
||||
detail="Min must be more than 1.", status_code=HTTPStatus.BAD_REQUEST
|
||||
)
|
||||
|
||||
if data.min > data.max:
|
||||
raise HTTPException(
|
||||
|
@ -87,7 +83,7 @@ async def api_link_create_or_update(
|
|||
)
|
||||
|
||||
if data.currency == None and (
|
||||
round(data.min) != data.min or round(data.max) != data.max
|
||||
round(data.min) != data.min or round(data.max) != data.max or data.min < 1
|
||||
):
|
||||
raise HTTPException(
|
||||
detail="Must use full satoshis.", status_code=HTTPStatus.BAD_REQUEST
|
||||
|
|
Loading…
Add table
Reference in a new issue