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

Add whitelist generation script #12

Merged
merged 1 commit into from
Feb 8, 2024
Merged
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: 2 additions & 3 deletions indexer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { appType } from "./utils/envs";
import { indexer } from "./indexer";
import { viewRefresher } from "./viewRefresher";
import { indexerApp, viewRefresherApp, generator } from "./utils/const";
import { whitelistGenerator } from "./whitelistGenerator";

import { generateWhitelistMintGenerations } from "./utils/generateWhitelistMintGenerations";
logger.info("Starting.");

AppDataSource.initialize().then(async () => {
Expand All @@ -17,7 +16,7 @@ AppDataSource.initialize().then(async () => {
} else if (appType === viewRefresherApp) {
await viewRefresher()
} else if(appType === generator) {
await whitelistGenerator();
await generateWhitelistMintGenerations();
}
} catch (e) {
logger.error(e, "App failed.");
Expand Down
2 changes: 2 additions & 0 deletions indexer/src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { IsNull, Not } from "typeorm";
import assert from "assert";
import { eventNameMap } from "./utils/const";
// import { saveWhitelistProofsFromFileToDB } from "./utils/saveWhitelistProofsFromFileToDB";

type ReturnedTransactionStatus = {
tx_status: string;
Expand Down Expand Up @@ -274,6 +275,7 @@ const updatePendingMints = async () => {

const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
export const indexer = async () => {
// saveWhitelistProofsFromFileToDB();
try {
while (true) {
await pullEvents();
Expand Down
2 changes: 1 addition & 1 deletion indexer/src/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Mints } from "../entity/mints";
import { Whitelist } from "../entity/whitelist";

// Uncomment below in local development
import 'dotenv/config'
// import 'dotenv/config'

// We need to store bigints in jsonb column, typeorm doesn't support that.
// Transformers in typeorm run _before_ typeorm's JSON.stringify run, so it is problematic
Expand Down
33 changes: 33 additions & 0 deletions indexer/src/utils/generateWhitelistMintGenerations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import fs from "fs";
import { AppDataSource } from "./db";

export const generateWhitelistMintGenerations = async () => {
const infinite = await AppDataSource.query(`
SELECT "transactionOwner", "gameGeneration", "gameState", "createdAt"
FROM "public"."infinite"
WHERE "transactionType" = 'game_evolved'
ORDER BY "gameGeneration" ASC
`);

// @ts-ignore
const processedData = infinite.reduce((acc, row) => {
acc[row.gameGeneration] = {
user_id: row.transactionOwner,
game_state: row.gameState,
timestamp: Math.floor(row.createdAt.getTime() / 1000), // Convert to Unix seconds
};
return acc;
}, {});

// Convert to JSON string with pretty formatting
const jsonData = JSON.stringify(processedData, null, 2);

// Write to a file
fs.writeFile("gol2-whitelist.json", jsonData, (err) => {
if (err) {
console.error("Error writing file:", err);
return;
}
console.log("Successfully wrote to gol2-whitelist.json");
});
};
25 changes: 0 additions & 25 deletions indexer/src/utils/parser.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import fs from 'fs/promises'
import { Whitelist } from "./entity/whitelist";
import { AppDataSource } from './utils/db';
import { Whitelist } from "../entity/whitelist";
import { AppDataSource } from './db';
import { exit } from 'process';

export const whitelistGenerator = async () => {
console.log("Starting whitelist generator.");
const filename = "whitelist.json";

export const saveWhitelistProofsFromFileToDB = async () => {
console.log(`Retrieving whitelist proofs from "${filename}" file.`);
const dataRaw = await fs.readFile("whitelist.json", "utf8");
const data = JSON.parse(dataRaw);

Expand Down