fix(nwc): implement lookupInvoice for CLNRest and LndHub
CLNRest defined no lookupInvoice, so BackendUtils.call returned false and every NWC lookup failed. LndHub inherited LND's /v1/invoice route, which LndHub does not serve. CLN now uses listinvoices filtered by payment hash, LndHub searches the user's invoice list.
This commit is contained in:
@@ -266,6 +266,22 @@ export default class CLNRest {
|
||||
return this.postRequest('/v1/withdraw', request);
|
||||
};
|
||||
getMyNodeInfo = () => this.postRequest('/v1/getinfo');
|
||||
// listinvoices filters natively by payment hash, and unlike the SQL query
|
||||
// used by getInvoices it is not restricted to paid invoices
|
||||
lookupInvoice = (data: any) =>
|
||||
this.postRequest('/v1/listinvoices', {
|
||||
payment_hash: data.r_hash
|
||||
}).then((response: any) => {
|
||||
const invoice = response?.invoices?.[0];
|
||||
if (!invoice) {
|
||||
throw new Error(
|
||||
localeString(
|
||||
'stores.NostrWalletConnectStore.error.invoiceNotFound'
|
||||
)
|
||||
);
|
||||
}
|
||||
return invoice;
|
||||
});
|
||||
getInvoices = (data?: any) =>
|
||||
this.postRequest('/v1/sql', {
|
||||
query: `SELECT label, bolt11, bolt12, payment_hash, amount_msat, status, amount_received_msat, paid_at, payment_preimage, description, expires_at FROM invoices ORDER BY created_index DESC LIMIT ${
|
||||
|
||||
@@ -4,6 +4,7 @@ import LND from './LND';
|
||||
import LoginRequest from './../models/LoginRequest';
|
||||
import Base64Utils from './../utils/Base64Utils';
|
||||
import Bolt11Utils from './../utils/Bolt11Utils';
|
||||
import { localeString } from './../utils/LocaleUtils';
|
||||
import { Hash as sha256Hash } from 'fast-sha256';
|
||||
import { ecdsaSignDERHex } from '../utils/SigningUtils';
|
||||
|
||||
@@ -40,6 +41,23 @@ export default class LndHub extends LND {
|
||||
this.getRequest('/getuserinvoices').then((data: any) => ({
|
||||
invoices: data
|
||||
}));
|
||||
// Overrides LND's /v1/invoice/{r_hash}, a route LndHub does not serve.
|
||||
// LndHub has no per-invoice endpoint returning details — /checkpayment only
|
||||
// answers paid/unpaid — so the user's invoice list is searched by hash.
|
||||
lookupInvoice = (data: any) =>
|
||||
this.getRequest('/getuserinvoices').then((invoices: any) => {
|
||||
const invoice = (invoices || []).find(
|
||||
(userInvoice: any) => userInvoice.payment_hash === data.r_hash
|
||||
);
|
||||
if (!invoice) {
|
||||
throw new Error(
|
||||
localeString(
|
||||
'stores.NostrWalletConnectStore.error.invoiceNotFound'
|
||||
)
|
||||
);
|
||||
}
|
||||
return invoice;
|
||||
});
|
||||
|
||||
createInvoice = (data: any) =>
|
||||
this.postRequest('/addinvoice', {
|
||||
|
||||
Reference in New Issue
Block a user