Skip to content

Commit

Permalink
Merge pull request #2751 from kaloudis/activity-500
Browse files Browse the repository at this point in the history
 Activity: LND: limit to 500 invoices + payments
  • Loading branch information
kaloudis authored Jan 27, 2025
2 parents b1a3211 + f4a88dc commit be83aaa
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 37 deletions.
6 changes: 4 additions & 2 deletions backends/CLNRest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,11 @@ export default class CLNRest {
return this.postRequest('/v1/withdraw', request);
};
getMyNodeInfo = () => this.postRequest('/v1/getinfo');
getInvoices = () =>
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 WHERE status = 'paid' ORDER BY created_index DESC LIMIT 150;"
query: `SELECT label, bolt11, bolt12, payment_hash, amount_msat, status, amount_received_msat, paid_at, payment_preimage, description, expires_at FROM invoices WHERE status = 'paid' ORDER BY created_index DESC LIMIT ${
data?.limit ? data.limit : 150
};`
}).then((data: any) => {
const invoiceList: any[] = [];
data.rows.forEach((invoice: any) => {
Expand Down
6 changes: 5 additions & 1 deletion backends/LND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ export default class LND {
: undefined,
route_hints: data.route_hints
});
getPayments = (params?: { maxPayments?: number; reversed?: boolean }) =>
getPayments = (
params: { maxPayments?: number; reversed?: boolean } = {
maxPayments: 500
}
) =>
this.getRequest(
`/v1/payments?include_incomplete=true${
params?.maxPayments ? `&max_payments=${params.maxPayments}` : ''
Expand Down
19 changes: 13 additions & 6 deletions backends/LightningNodeConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,12 @@ export default class LightningNodeConnect {
await this.lnc.lnd.lightning
.getNetworkInfo({})
.then((data: lnrpc.NetworkInfo) => snakeize(data));
getInvoices = async () =>
getInvoices = async (data: any) =>
await this.lnc.lnd.lightning
.listInvoices({ reversed: true, num_max_invoices: 100 })
.listInvoices({
reversed: true,
num_max_invoices: data?.limit || 500
})
.then((data: lnrpc.ListInvoiceResponse) => snakeize(data));
createInvoice = async (data: any) =>
await this.lnc.lnd.lightning
Expand All @@ -173,10 +176,14 @@ export default class LightningNodeConnect {
route_hints: data.route_hints
})
.then((data: lnrpc.AddInvoiceResponse) => snakeize(data));
getPayments = async (params?: {
maxPayments?: number;
reversed?: boolean;
}) =>
getPayments = async (
params: {
maxPayments?: number;
reversed?: boolean;
} = {
maxPayments: 500
}
) =>
await this.lnc.lnd.lightning
.listPayments({
include_incomplete: true,
Expand Down
53 changes: 25 additions & 28 deletions views/Receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1013,36 +1013,33 @@ export default class Receive extends React.Component<
if (implementation === 'lndhub') {
if (rHash) {
this.lnInterval = setInterval(() => {
// only fetch the last 10 invoices
BackendUtils.getInvoices({ limit: 10 }).then(
(response: any) => {
const invoices = response.invoices;
for (let i = 0; i < invoices.length; i++) {
const result = new Invoice(invoices[i]);
if (
result.getFormattedRhash === rHash &&
result.ispaid &&
Number(result.amt) >= Number(value) &&
Number(result.amt) !== 0
) {
setWatchedInvoicePaid(result.amt);
if (orderId)
PosStore.recordPayment({
orderId,
orderTotal,
orderTip,
exchangeRate,
rate,
type: 'ln',
tx: result.payment_request,
preimage: result.r_preimage
});
this.clearIntervals();
break;
}
BackendUtils.getInvoices().then((response: any) => {
const invoices = response.invoices;
for (let i = 0; i < invoices.length; i++) {
const result = new Invoice(invoices[i]);
if (
result.getFormattedRhash === rHash &&
result.ispaid &&
Number(result.amt) >= Number(value) &&
Number(result.amt) !== 0
) {
setWatchedInvoicePaid(result.amt);
if (orderId)
PosStore.recordPayment({
orderId,
orderTotal,
orderTip,
exchangeRate,
rate,
type: 'ln',
tx: result.payment_request,
preimage: result.r_preimage
});
this.clearIntervals();
break;
}
}
);
});
}, 5000);
}
}
Expand Down

0 comments on commit be83aaa

Please sign in to comment.