fix: duplicate transactions (#356)

This commit is contained in:
Anthony Potdevin 2021-10-31 12:56:10 +01:00 committed by GitHub
parent 0ad780016f
commit 4815d86cbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 10 deletions

View file

@ -11,6 +11,10 @@ import {
LndObject,
} from 'server/types/ln-service.types';
// Limit the amount of transactions that are fetched
const FETCH_LIMIT = 50000;
const BATCH_SIZE = 250;
export const getNodeFromChannel = async (
lnd: {},
channelId: string,
@ -94,17 +98,15 @@ export const getPaymentsBetweenDates = async ({
lnd,
from,
until,
batch = 25,
}: {
lnd: LndObject | null;
from?: string;
until?: string;
batch?: number;
}) => {
const paymentList = await to<GetPaymentsType>(
getPayments({
lnd,
limit: batch,
limit: BATCH_SIZE,
})
);
@ -129,7 +131,7 @@ export const getPaymentsBetweenDates = async ({
return last && first;
};
if (isOutOf) {
if (isOutOf || paymentList.payments.length < BATCH_SIZE) {
return paymentList.payments.filter(filterArray);
}
@ -139,6 +141,11 @@ export const getPaymentsBetweenDates = async ({
let finished = false;
while (!finished) {
if (completePayments.length >= FETCH_LIMIT) {
finished = true;
break;
}
const newPayments = await to<GetPaymentsType>(
getPayments({
lnd,
@ -175,17 +182,15 @@ export const getInvoicesBetweenDates = async ({
lnd,
from,
until,
batch = 25,
}: {
lnd: LndObject | null;
from?: string;
until?: string;
batch?: number;
}) => {
const invoiceList = await to<GetInvoicesType>(
getInvoices({
lnd,
limit: batch,
limit: BATCH_SIZE,
})
);
@ -210,7 +215,7 @@ export const getInvoicesBetweenDates = async ({
return last && first;
};
if (isOutOf) {
if (isOutOf || invoiceList.invoices.length < BATCH_SIZE) {
return invoiceList.invoices.filter(filterArray);
}
@ -220,6 +225,11 @@ export const getInvoicesBetweenDates = async ({
let finished = false;
while (!finished) {
if (completeInvoices.length >= FETCH_LIMIT) {
finished = true;
break;
}
const newInvoices = await to<GetInvoicesType>(
getInvoices({
lnd,

View file

@ -31,7 +31,6 @@ export const transactionResolvers = {
lnd,
from: startDate,
until: endDate,
batch: 25,
});
const mappedPayments = payments.map(payment => ({
@ -47,7 +46,6 @@ export const transactionResolvers = {
lnd,
from: startDate,
until: endDate,
batch: 25,
});
const mappedInvoices = invoices.map(invoice => ({