feat: create unsafe real invoice
This commit is contained in:
@@ -35,6 +35,8 @@ class KvListResponse(BaseModel):
|
|||||||
class CreateInvoiceRequest(BaseModel):
|
class CreateInvoiceRequest(BaseModel):
|
||||||
wallet_id: str = Field(..., min_length=1, max_length=128)
|
wallet_id: str = Field(..., min_length=1, max_length=128)
|
||||||
amount_sat: int = Field(..., gt=0)
|
amount_sat: int = Field(..., gt=0)
|
||||||
|
# todo: bridge for extensions to select currencies
|
||||||
|
currency: str | None = Field(..., min_length=1, max_length=8)
|
||||||
memo: str = Field(..., max_length=512)
|
memo: str = Field(..., max_length=512)
|
||||||
tag: str = Field(..., min_length=1, max_length=64)
|
tag: str = Field(..., min_length=1, max_length=64)
|
||||||
extra: dict[str, str] = Field(default_factory=dict)
|
extra: dict[str, str] = Field(default_factory=dict)
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import hashlib
|
|
||||||
import secrets
|
|
||||||
import time
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from .api import ExtensionAPI
|
from .api import ExtensionAPI
|
||||||
from .models import (
|
from .models import (
|
||||||
CreateInvoiceRequest,
|
CreateInvoiceRequest,
|
||||||
@@ -70,16 +69,22 @@ class InMemoryExtensionAPI(ExtensionAPI):
|
|||||||
if self.wallet_id and request.wallet_id != self.wallet_id:
|
if self.wallet_id and request.wallet_id != self.wallet_id:
|
||||||
raise PermissionError("Extension cannot create invoices for this wallet.")
|
raise PermissionError("Extension cannot create invoices for this wallet.")
|
||||||
|
|
||||||
entropy = secrets.token_urlsafe(16)
|
from lnbits.core.models.payments import CreateInvoice
|
||||||
invoice_seed = (
|
from lnbits.core.services.payments import create_payment_request
|
||||||
f"{self.extension_id}:{request.wallet_id}:{request.amount_sat}:"
|
# todo: security stuff here
|
||||||
f"{request.memo}:{time.time_ns()}:{entropy}"
|
payment = await create_payment_request(
|
||||||
|
request.wallet_id,
|
||||||
|
CreateInvoice(
|
||||||
|
amount=request.amount_sat,
|
||||||
|
unit=request.currency or "sat",
|
||||||
|
memo=request.memo,
|
||||||
|
extra=request.extra,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
payment_hash = hashlib.sha256(invoice_seed.encode()).hexdigest()
|
|
||||||
return CreateInvoiceResponse(
|
return CreateInvoiceResponse(
|
||||||
payment_hash=payment_hash,
|
payment_hash=payment.payment_hash,
|
||||||
payment_request=f"lnbits-prototype-invoice:{payment_hash}",
|
payment_request=payment.payment_request or payment.bolt11,
|
||||||
checking_id=f"{self.extension_id}:{payment_hash}",
|
checking_id=payment.checking_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def wallet_list_user_wallets(
|
async def wallet_list_user_wallets(
|
||||||
|
|||||||
Reference in New Issue
Block a user