dawsbot / eth-labels

📃 A public dataset of crypto addresses labeled
https://eth-labels-production.up.railway.app/swagger
MIT License
198 stars 30 forks source link

Implement `loadAllAccountsFromFilesystem()` #81

Closed dawsbot closed 4 months ago

dawsbot commented 5 months ago

We want a function which is callable synchronously (no await needed). that loads up ALL accounts from data/*/*/accounts.json.

The data type we are trying to load up can be called Array<AccountDBRow>.

An AccountDBRow is like the type AccountRow which is already in the db, but with a few extra keys. You can define the the like this:

type AccountDBRow = {
  chainId: number;
  address: string;
  label: string;
  nameTag?: string;
}

Steps

  1. Add all chainIds to "scanConfig" (this will allow us to "decode" the filepaths like etherscan/* to have the chainId instead
  2. Traverse the filesystem to generate this array. 2.1 Use globby to get all account filepaths: https://github.com/sindresorhus/globby 2.2 Use fs.readFileSync to load all of those files into memory & generate that AccountDBRow type

Expected outcome

const allAccounts = loadAllAccountsFromFilesystem();