Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Combine label files in new combined.json #44

Merged
merged 5 commits into from
Mar 27, 2024
Merged

Conversation

kylewandishin
Copy link
Collaborator

@kylewandishin kylewandishin commented Mar 26, 2024

Closes #27

Copy link
Owner

@dawsbot dawsbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good start, but the code might be fragile as we expand what data is saved to the filesystem

files.forEach((file) => {
if (
file.endsWith(".json") &&
(file === "tokens.json" || file === "accounts.json")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this agnostic for all files in the directory. If we ever add support for blocks or txs, this method will not combine:

https://github.com/dawsbot/evm-labels/blob/53b4dfa63daf99c1159da3d539296df798294311/scripts/AnyscanPuller.ts#L82-L85

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will replace with endswith(".json") and file!=="combine.json"

(file === "tokens.json" || file === "accounts.json")
) {
const filePath: string = path.join(dataDir, file);
const data: Buffer = fs.readFileSync(filePath);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change this to instead use the FileSystem class we have in the codebase, you don't need to use fs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will work on that now

) {
const filePath: string = path.join(dataDir, file);
const data: Buffer = fs.readFileSync(filePath);
const jsonData: Array<{ address: string }> = JSON.parse(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can any of these Arrays be replaced with ReadonlyArray?

}

function runCombine() {
fs.readdir(dataFolderPath, (err, files) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be done Sync and the fs logic also moved into the FileSystem class

import path from "path";
import { FileUtilities } from "./FileSystem/FileSystem";

const fs = new FileUtilities(import.meta.url);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you instantiate a class called FileUtilities, it's best practice to call it fileUtilities.

By calling it "fs", it is difficult to know as a future developer if we're using the fs module from node.js

const providers = fs.readDir(dataFolderPath);
providers.forEach((provider) => {
const providerPath: string = path.join(dataFolderPath, provider);
if (!provider.includes(".")) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does a provider include a "."? What is a "provider"? I'm not sure if we want to ship this with that variable name. Maybe a comment could help here

const fs = new FileUtilities(import.meta.url);

function combineFiles(dataDir: string) {
const files: ReadonlyArray<string> = fs.readDir(dataDir);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a type-assertion here, what I might prefer here is for fs.readDir to return a ReadonlyArray<string>. Is that possible instead or in-addition?

@dawsbot dawsbot changed the title added combine.json for each label for each provider. progresses #27 ✨ Combine address files Mar 27, 2024
@dawsbot dawsbot changed the title ✨ Combine address files ✨ Combine label files in new combined.json Mar 27, 2024
@dawsbot dawsbot merged commit 6dee432 into v1 Mar 27, 2024
@dawsbot dawsbot deleted the feature-combine-data branch March 27, 2024 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create merging script and run on all
2 participants