Skip to content
This repository was archived by the owner on Jul 15, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/families/elrond/api/apiCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/families/elrond/js-synchronisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down