mirror of
https://github.com/lnbits/lnbits.git
synced 2025-07-07 14:00:38 +02:00
fix: phoenixd wallet description field supports lnurlp (#2514)
* Fix for phoenixd and lnurlp nostr usage - Support description, restricted to 128 characters - Support descriptionHash Co-authored-by: Pavol Rusnak <pavol@rusnak.io> Co-authored-by: Vic <vic@example.com>
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import base64
|
import base64
|
||||||
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from typing import AsyncGenerator, Dict, Optional
|
from typing import AsyncGenerator, Dict, Optional
|
||||||
@ -17,7 +18,6 @@ from .base import (
|
|||||||
PaymentStatus,
|
PaymentStatus,
|
||||||
PaymentSuccessStatus,
|
PaymentSuccessStatus,
|
||||||
StatusResponse,
|
StatusResponse,
|
||||||
UnsupportedError,
|
|
||||||
Wallet,
|
Wallet,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -87,17 +87,28 @@ class PhoenixdWallet(Wallet):
|
|||||||
unhashed_description: Optional[bytes] = None,
|
unhashed_description: Optional[bytes] = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> InvoiceResponse:
|
) -> InvoiceResponse:
|
||||||
if description_hash or unhashed_description:
|
|
||||||
raise UnsupportedError("description_hash")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
msats_amount = amount
|
msats_amount = amount
|
||||||
data: Dict = {
|
data: Dict = {
|
||||||
"amountSat": f"{msats_amount}",
|
"amountSat": f"{msats_amount}",
|
||||||
"description": memo,
|
|
||||||
"externalId": "",
|
"externalId": "",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Either 'description' (string) or 'descriptionHash' must be supplied
|
||||||
|
# PhoenixD description limited to 128 characters
|
||||||
|
if description_hash:
|
||||||
|
data["descriptionHash"] = description_hash.hex()
|
||||||
|
else:
|
||||||
|
desc = memo
|
||||||
|
if desc is None and unhashed_description:
|
||||||
|
desc = unhashed_description.decode()
|
||||||
|
desc = desc or ""
|
||||||
|
if len(desc) > 128:
|
||||||
|
data["descriptionHash"] = hashlib.sha256(desc.encode()).hexdigest()
|
||||||
|
else:
|
||||||
|
data["description"] = desc
|
||||||
|
|
||||||
r = await self.client.post(
|
r = await self.client.post(
|
||||||
"/createinvoice",
|
"/createinvoice",
|
||||||
data=data,
|
data=data,
|
||||||
|
Reference in New Issue
Block a user