Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-kiwis-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ensrainbow": patch
---

feat: add CSV conversion command to ensrainbow CLI
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
feat: add CSV conversion command to ensrainbow CLI
feat: add CSV conversion command to ensrainbow CLI to convert rainbow tables from CSV format to ensrainbow format

4 changes: 3 additions & 1 deletion apps/ensrainbow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"validate:lite": "tsx src/cli.ts validate --lite",
"purge": "tsx src/cli.ts purge",
"convert": "tsx src/cli.ts convert",
"convert-csv": "tsx src/cli.ts convert-csv",
"test": "vitest",
"test:coverage": "vitest --coverage",
"lint": "biome check --write .",
Expand All @@ -38,7 +39,8 @@
"progress": "^2.0.3",
"protobufjs": "^7.4.0",
"viem": "catalog:",
"yargs": "^17.7.2"
"yargs": "^17.7.2",
"@fast-csv/parse": "^5.0.0"
},
"devDependencies": {
"@ensnode/shared-configs": "workspace:*",
Expand Down
69 changes: 67 additions & 2 deletions apps/ensrainbow/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from "@ensnode/ensnode-sdk";

import { convertCommand } from "@/commands/convert-command";
import { convertCsvCommand } from "@/commands/convert-csv-command";
// import { ingestCommand } from "@/commands/ingest-command";
import { ingestProtobufCommand } from "@/commands/ingest-protobuf-command";
import { purgeCommand } from "@/commands/purge-command";
Expand Down Expand Up @@ -61,6 +62,16 @@ interface ConvertArgs {
"label-set-version": LabelSetVersion;
}

interface ConvertCsvArgs {
"input-file": string;
"output-file": string;
"label-set-id": LabelSetId;
"label-set-version": LabelSetVersion;
"progress-interval"?: number;
"existing-db-path"?: string;
silent?: boolean;
}

export interface CLIOptions {
exitProcess?: boolean;
}
Expand Down Expand Up @@ -184,7 +195,7 @@ export function createCLI(options: CLIOptions = {}) {
)
.command(
"convert",
"Convert rainbow tables from SQL dump to protobuf format",
"Convert rainbow tables from SQL dump to ensrainbow format",
(yargs: Argv) => {
return yargs
.option("input-file", {
Expand All @@ -194,7 +205,7 @@ export function createCLI(options: CLIOptions = {}) {
})
.option("output-file", {
type: "string",
description: "Path to the output protobuf file",
description: "Path to the output ensrainbow file",
default: join(process.cwd(), "rainbow-records.ensrainbow"),
})
.option("label-set-id", {
Expand All @@ -219,6 +230,60 @@ export function createCLI(options: CLIOptions = {}) {
});
},
)
.command(
"convert-csv",
"Convert rainbow tables from CSV format to ensrainbow format",
(yargs: Argv) => {
return yargs
.option("input-file", {
type: "string",
description: "Path to the CSV input file",
demandOption: true,
})
.option("output-file", {
type: "string",
description: "Path to the output ensrainbow file",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
description: "Path to the output ensrainbow file",
description: "Path to where the resulting ensrainbow file will be output",

default: join(process.cwd(), "rainbow-records.ensrainbow"),
})
.option("label-set-id", {
type: "string",
description: "Label set id for the rainbow record collection",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
description: "Label set id for the rainbow record collection",
description: "Label set id for the generated ensrainbow file",

demandOption: true,
})
.coerce("label-set-id", buildLabelSetId)
.option("label-set-version", {
type: "number",
description: "Label set version for the rainbow record collection",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
description: "Label set version for the rainbow record collection",
description: "Label set version for the generated ensrainbow file",

demandOption: true,
})
.coerce("label-set-version", buildLabelSetVersion)
.option("progress-interval", {
type: "number",
description: "Number of records to process before logging progress",
default: 50000,
})
.option("existing-db-path", {
type: "string",
description: "Path to existing ENSRainbow database to filter out existing labels",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
description: "Path to existing ENSRainbow database to filter out existing labels",
description: "Path to existing ENSRainbow database to filter out existing labels from the generated ensrainbow file",

})
.option("silent", {
type: "boolean",
description: "Disable progress bar (useful for scripts)",
default: false,
});
},
async (argv: ArgumentsCamelCase<ConvertCsvArgs>) => {
await convertCsvCommand({
inputFile: argv["input-file"],
outputFile: argv["output-file"],
labelSetId: argv["label-set-id"],
labelSetVersion: argv["label-set-version"],
progressInterval: argv["progress-interval"],
existingDbPath: argv["existing-db-path"],
silent: argv["silent"],
});
},
)
.demandCommand(1, "You must specify a command")
.fail((msg, err, yargs) => {
if (process.env.VITEST) {
Expand Down
Loading