sending kinda working

This commit is contained in:
Arc
2026-02-13 16:58:56 +02:00
committed by Vlad Stan
parent 64e83e25dc
commit a59996d5d4
2 changed files with 22 additions and 5 deletions
+12 -2
View File
@@ -4,6 +4,7 @@ from typing import Any
import httpx
from loguru import logger
from bolt11 import decode as bolt11_decode
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
@@ -131,9 +132,18 @@ class LightsparkSparkWallet(Wallet):
async def pay_invoice(self, bolt11: str, fee_limit_msat: int) -> PaymentResponse:
try:
max_fee_sats = (int(fee_limit_msat) + 999) // 1000
payload = {"bolt11": bolt11, "max_fee_sats": max_fee_sats}
payment_hash = None
try:
payment_hash = bolt11_decode(bolt11).payment_hash
except Exception:
payment_hash = None
payload = {
"bolt11": bolt11,
"max_fee_sats": max_fee_sats,
"payment_hash": payment_hash,
}
res = await self._request("POST", "/v1/payments", payload)
checking_id = res.get("checking_id")
checking_id = payment_hash or res.get("checking_id")
if not checking_id:
raise SparkSidecarError(
"Spark sidecar payment response missing checking_id."
+10 -3
View File
@@ -17,6 +17,7 @@ if (!MNEMONIC) {
}
let walletPromise
const paymentHashToRequestId = new Map()
async function getWallet() {
if (!walletPromise) {
walletPromise = SparkWallet.initialize({
@@ -142,13 +143,17 @@ const server = http.createServer(async (req, res) => {
const amountSatsToSend = body.amount_sats
? Number(body.amount_sats)
: undefined
const paymentHash = body.payment_hash || null
const payment = await wallet.payLightningInvoice({
invoice: bolt11,
maxFeeSats,
amountSatsToSend
})
if (paymentHash && payment?.id) {
paymentHashToRequestId.set(paymentHash, payment.id)
}
return sendJson(res, 200, {
checking_id: payment.id,
checking_id: paymentHash || payment.id,
status: payment.status,
fee_msat: feeToMsat(payment.fee),
preimage: payment.paymentPreimage || null
@@ -172,12 +177,14 @@ const server = http.createServer(async (req, res) => {
if (parts.length === 3 && parts[0] === 'v1' && parts[1] === 'payments') {
const wallet = await getWallet()
const payment = await wallet.getLightningSendRequest(parts[2])
const requestedId = parts[2]
const lookupId = paymentHashToRequestId.get(requestedId) || requestedId
const payment = await wallet.getLightningSendRequest(lookupId)
if (!payment) {
return sendJson(res, 404, {error: 'Not found'})
}
return sendJson(res, 200, {
checking_id: payment.id,
checking_id: requestedId,
status: payment.status,
fee_msat: feeToMsat(payment.fee),
preimage: payment.paymentPreimage || null