From 8ab66595d00006521dc9055ff28d2a1bcbd8e466 Mon Sep 17 00:00:00 2001 From: AlexandruPislariu Date: Mon, 14 Feb 2022 16:14:37 +0200 Subject: [PATCH 1/2] scroll transactions with timestamp --- src/families/elrond/api/apiCalls.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/families/elrond/api/apiCalls.ts b/src/families/elrond/api/apiCalls.ts index 69599b40ae..f00b283baf 100644 --- a/src/families/elrond/api/apiCalls.ts +++ b/src/families/elrond/api/apiCalls.ts @@ -103,20 +103,22 @@ export default class ElrondApi { async getHistory(addr: string, startAt: number) { const { data: transactionsCount } = await network({ method: "GET", - url: `${this.API_URL}/transactions/count?condition=should&sender=${addr}&receiver=${addr}&after=${startAt}`, + url: `${this.API_URL}/accounts/${addr}/transactions/count?after=${startAt}`, }); let allTransactions: any[] = []; let from = 0; + let before = Math.floor(Date.now() / 1000); while (from <= transactionsCount) { const { data: transactions } = await network({ method: "GET", - url: `${this.API_URL}/transactions?condition=should&sender=${addr}&receiver=${addr}&after=${startAt}&from=${from}&size=${TRANSACTIONS_SIZE}`, + url: `${this.API_URL}/accounts/${addr}/transactions?before=${before}&after=${startAt}&size=${TRANSACTIONS_SIZE}`, }); allTransactions = [...allTransactions, ...transactions]; from = from + TRANSACTIONS_SIZE; + before = transactions.slice(-1).timestamp; } return allTransactions; From b2f61ccdd809aeb435bce83eb7721f0ffb505b00 Mon Sep 17 00:00:00 2001 From: AlexandruPislariu Date: Mon, 14 Feb 2022 16:15:00 +0200 Subject: [PATCH 2/2] incremental sync based on timestamp --- src/families/elrond/js-synchronisation.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/families/elrond/js-synchronisation.ts b/src/families/elrond/js-synchronisation.ts index 5fdd19a53e..f84b92d72b 100644 --- a/src/families/elrond/js-synchronisation.ts +++ b/src/families/elrond/js-synchronisation.ts @@ -14,8 +14,11 @@ const getAccountShape: GetAccountShape = async (info) => { derivationMode, }); const oldOperations = initialAccount?.operations || []; - // Needed for incremental synchronisation - const startAt = 0; + let lastOperationTimestamp = 0; + if (oldOperations.length) { + lastOperationTimestamp = Math.floor(oldOperations[0].date.getTime() / 1000); + } + const startAt = lastOperationTimestamp + 1; // get the current account balance state depending your api implementation const { blockHeight, balance, nonce } = await getAccount(address);