Skip to content

Commit

Permalink
Init heights saving function for identity scan, #960
Browse files Browse the repository at this point in the history
  • Loading branch information
wliyongfeng committed Sep 26, 2024
1 parent e9aaf24 commit 256333d
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions backend/packages/identity-scan/src/scripts/known/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const { peopleChainName } = require("../../scan/common/consts");
const {
mongo: {
known: { saveKnownHeights },
},
} = require("@osn/scan-common");

async function saveHeightsCommon(col) {
const items = await col.find({}).toArray();
const heights = [];
const peopleChainHeights = [];

for (const item of items) {
if (item.indexer) {
const { chain, blockHeight } = item.indexer;
if (peopleChainName === chain) {
peopleChainHeights.push(blockHeight);
} else {
heights.push(blockHeight);
}
}

if (item.timeline) {
for (const timelineItem of item.timeline || []) {
if (timelineItem.indexer) {
const { chain, blockHeight } = item.indexer;
if (peopleChainName === chain) {
peopleChainHeights.push(blockHeight);
} else {
heights.push(blockHeight);
}
}
}
}
}

const uniqueHeights = [...new Set(heights)];
await saveKnownHeights(uniqueHeights);

const uniquePeopleChainHeights = [...new Set(peopleChainHeights)];
console.log(uniquePeopleChainHeights);
// todo: save people chain heights
}

0 comments on commit 256333d

Please sign in to comment.