-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init heights saving function for identity scan, #960
- Loading branch information
1 parent
e9aaf24
commit 256333d
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |