Skip to content

Commit

Permalink
sto blocktimes
Browse files Browse the repository at this point in the history
  • Loading branch information
waynebruce0x committed Jun 19, 2023
1 parent 69b6ee8 commit 811bb8c
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions adapters/balance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export async function latest(
return res;
}

let blockHeightsSto: { [timestamp: number]: BlockTime } = {};

export async function balance(
owners: string[],
target: string,
Expand Down Expand Up @@ -57,13 +59,23 @@ export async function balance(
currentTimestamp += INCOMPLETE_SECTION_STEP;
}

const blockHeights: BlockTime[] = await Promise.all(
allTimestamps.map((t: number) =>
getBlock2(chain, t).then((h: number | undefined) => ({
timestamp: t,
block: h == null ? -1 : h,
})),
),
await Promise.all(
allTimestamps.map(async (t: number) => {
if (blockHeightsSto[t]) {
console.log("saved");
return;
}
blockHeightsSto[t] = await getBlock2(chain, t).then(
(h: number | undefined) => ({
timestamp: t,
block: h == null ? -1 : h,
}),
);
}),
);

const blockHeights: BlockTime[] = allTimestamps.map(
(t: number) => blockHeightsSto[t],
);

let balances: any[] = [];
Expand Down

0 comments on commit 811bb8c

Please sign in to comment.