diff --git a/indexer/src/index.ts b/indexer/src/index.ts index 20f1824..b2cab93 100644 --- a/indexer/src/index.ts +++ b/indexer/src/index.ts @@ -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 () => { @@ -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."); diff --git a/indexer/src/indexer.ts b/indexer/src/indexer.ts index 5fb98dd..d386dc4 100644 --- a/indexer/src/indexer.ts +++ b/indexer/src/indexer.ts @@ -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; @@ -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(); diff --git a/indexer/src/utils/db.ts b/indexer/src/utils/db.ts index 4d0a197..54bc266 100644 --- a/indexer/src/utils/db.ts +++ b/indexer/src/utils/db.ts @@ -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 diff --git a/indexer/src/utils/generateWhitelistMintGenerations.ts b/indexer/src/utils/generateWhitelistMintGenerations.ts new file mode 100644 index 0000000..6f5abc4 --- /dev/null +++ b/indexer/src/utils/generateWhitelistMintGenerations.ts @@ -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"); + }); +}; diff --git a/indexer/src/utils/parser.ts b/indexer/src/utils/parser.ts deleted file mode 100644 index ef78dcc..0000000 --- a/indexer/src/utils/parser.ts +++ /dev/null @@ -1,25 +0,0 @@ -const uint256Shift = BigInt("0x100000000000000000000000000000000"); - -const isObject = (value: any): boolean => { - return Object.prototype.toString.call(value) === '[object Object]' -} - -export const deserializeContent = (parsedEvent: any): any => { - const eventContent: { [key: string]: any } = {}; - for (const obj of Object.entries(parsedEvent)) { - const [key, value] = obj as any; - if ( - isObject(value) && - value?.hasOwnProperty("low") && - value?.hasOwnProperty("high") - ) { - // @ts-ignore - eventContent[key] = BigInt(value.low) + BigInt(value.high) * uint256Shift; - } else { - eventContent[key] = value; - } - } - - return eventContent; -}; - diff --git a/indexer/src/whitelistGenerator.ts b/indexer/src/utils/saveWhitelistProofsFromFileToDB.ts similarity index 74% rename from indexer/src/whitelistGenerator.ts rename to indexer/src/utils/saveWhitelistProofsFromFileToDB.ts index d8cc0a3..d586345 100644 --- a/indexer/src/whitelistGenerator.ts +++ b/indexer/src/utils/saveWhitelistProofsFromFileToDB.ts @@ -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);