From ddc26859071ba6dc508ae765f8f95a6eafdae1de Mon Sep 17 00:00:00 2001 From: Anukul Pandey Date: Tue, 18 Nov 2025 17:49:13 +0530 Subject: [PATCH 1/4] feat: logs --- src/processor.ts | 52 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/processor.ts b/src/processor.ts index 074dfa9..72e6f99 100644 --- a/src/processor.ts +++ b/src/processor.ts @@ -108,108 +108,155 @@ processor.run(database, async (ctx_) => { }); const processBatch = async (batch: Block[]) => { + console.log("[processBatch] function called") //remove-this-later // Push data from previous batch if (newBlockData) { + console.log("new block detected") //remove-this-later if (firebaseDB) firebaseDB.notifyBlock(newBlockData); if (emitterIO) emitterIO.notifyBlock(newBlockData); if (pusher) pusher.notifyBlock(newBlockData); + console.log("emitted the new block") //remove-this-later } // Initialize global variables in first batch if (isFirstBatch) { + console.log("is this the first batch?") //remove-this-later const reefVerifiedContract_ = await ctx.store.get(VerifiedContract, REEF_CONTRACT_ADDRESS); + console.log("reef verified contract instance fetched") //remove-this-later if (reefVerifiedContract_) { + console.log("is reef verified contract") //remove-this-later reefVerifiedContract = reefVerifiedContract_; } else { + console.log("no reef verified contract in db") //remove-this-later throw new Error('REEF verified contract not found in the database'); } const emptyAccount_ = await ctx.store.get(Account, "0x"); + console.log("get empty account instance") //remove-this-later if (emptyAccount_) { emptyAccount = emptyAccount_; } else { + console.log("empty account not found") //remove-this-later throw new Error('Empty account not found in the database'); } const emptyExtrinsic_ = await ctx.store.get(Extrinsic, "-1"); + console.log("get empty extrinsic") //remove-this-later if (emptyExtrinsic_) { emptyExtrinsic = emptyExtrinsic_; } else { + console.log("empty extrinsic not found") //remove-this-later throw new Error('Empty extrinsic not found in the database'); } + isFirstBatch = false; } // Initialize managers const blockManager: BlockManager = new BlockManager(); + console.log("1/10 block manager init") //remove-this-later const extrinsicManager: ExtrinsicManager = new ExtrinsicManager(); + console.log("2/10 extrinsic manager init") //remove-this-later const eventManager: EventManager = new EventManager(); + console.log("3/10 event manager init") //remove-this-later const contractManager: ContractManager = new ContractManager(); + console.log("4/10 contract manager init") //remove-this-later const evmEventManager: EvmEventManager = new EvmEventManager(); + console.log("5/10 evm event manager init") //remove-this-later const tokenHolderManager: TokenHolderManager = new TokenHolderManager(); + console.log("6/10 token holder manager init") //remove-this-later const stakingManager: StakingManager = new StakingManager(); + console.log("7/10 staking manager init") //remove-this-later const stakingElectionManager: StakingElectionManager = new StakingElectionManager(); + console.log("8/10 staking election manager init") //remove-this-later const transferManager: TransferManager = new TransferManager(tokenHolderManager); + console.log("9/10 transfer manager init") //remove-this-later const accountManager = new AccountManager(tokenHolderManager, transferManager); + console.log("10/10 account manager init") //remove-this-later if (batch.length > 1) ctx.log.debug(`Batch size: ${batch.length}`); + console.log("batch size ",batch.length) //remove-this-later // Process blocks for (const block of batch) { + console.log("block processing started") //remove-this-later if (!headReached && ctx.blocks[0].header.height > 1 && ctx.isHead && block.header.height === ctx.blocks[ctx.blocks.length - 1].header.height) { headReached = true; await updateFromHead(block.header); } + console.log("processing block") //remove-this-later blockManager.process(block.header); + console.log("processed block") //remove-this-later ctx.log.debug(`Processing block ${block.header.height}`); for (const event of block.events) { if (event.phase === "Initialization" && (event.name === 'Staking.StakingElection' || event.name === 'Staking.StakersElected') ) { - await stakingElectionManager.process(event); + console.log("staking process start") //remove-this-later + await stakingElectionManager.process(event); + console.log("staking process end") //remove-this-later } else if (event.phase === "ApplyExtrinsic") { const signedData = await extrinsicManager.process(event); eventManager.process(event); + console.log("end") //remove-this-later switch (event.name) { case 'EVM.Log': + console.log("evm.log process start") //remove-this-later await evmEventManager.process(event, signedData, transferManager, accountManager, ctx.store); + console.log("end") //remove-this-later break; case 'EVM.Created': + console.log("evm.created process start") //remove-this-later await contractManager.process(event); + console.log("end") //remove-this-later break; case 'EVM.ExecutedFailed': + console.log("evm.executedfailed process start") //remove-this-later await evmEventManager.process(event, signedData, transferManager, accountManager); + console.log("end") //remove-this-later break; case 'EvmAccounts.ClaimAccount': + console.log("evmaccounts.claimaccount process start") //remove-this-later const addressClaimer = hexToNativeAddress(event.args[0]); await accountManager.process(addressClaimer, block.header, true, true); + console.log("end") //remove-this-later break; case 'Balances.Endowed': + console.log("balances.endowed process start") //remove-this-later const addressEndowed = hexToNativeAddress(event.args[0]); await accountManager.process(addressEndowed, block.header); + console.log("end") //remove-this-later break; case 'Balances.Reserved': + console.log("balances process start") //remove-this-later const addressReserved = hexToNativeAddress(event.args[0]); await accountManager.process(addressReserved, block.header); + console.log("end") //remove-this-later break; case 'Balances.Transfer': + console.log("balances transfer process start") //remove-this-later await transferManager.process(event, accountManager, reefVerifiedContract, signedData, true); + console.log("end") //remove-this-later break; case 'Staking.Rewarded': + console.log("staking process start") //remove-this-later await stakingManager.process(event, accountManager); + console.log("end") //remove-this-later break; case 'System.KilledAccount': + console.log("system.killedAccount process start") //remove-this-later const address = hexToNativeAddress(event.args); await accountManager.process(address, block.header, false); + console.log("end") //remove-this-later break; } } @@ -237,14 +284,17 @@ const processBatch = async (batch: Block[]) => { .filter(t => t.token.type === 'ERC20' && t.signerAddress !== '') .map(t => t.signerAddress as string) .filter((value, index, array) => array.indexOf(value) === index); + console.log("updatedErc20Accounts parsed") //remove-this-later const updatedErc721Accounts = Array.from(tokenHolderManager.tokenHoldersData.values()) .filter(t => t.token.type === 'ERC721' && t.signerAddress !== '') .map(t => t.signerAddress as string) .filter((value, index, array) => array.indexOf(value) === index); + console.log("updatedErc721Accounts parsed") //remove-this-later const updatedErc1155Accounts = Array.from(tokenHolderManager.tokenHoldersData.values()) .filter(t => t.token.type === 'ERC1155' && t.signerAddress !== '') .map(t => t.signerAddress as string) .filter((value, index, array) => array.indexOf(value) === index); + console.log("updatedErc1155Accounts parsed") //remove-this-later newBlockData = { blockHeight: lastBlockHeader.height, From 3804712fff71dd0facd9e84d5f87f9b0d3b24f75 Mon Sep 17 00:00:00 2001 From: Anukul Pandey Date: Thu, 20 Nov 2025 22:00:59 +0530 Subject: [PATCH 2/4] undo hiraw commits --- db/migrations/1706784285253-Data.js | 4 ++-- db/migrations/1706784285254-Data.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/migrations/1706784285253-Data.js b/db/migrations/1706784285253-Data.js index 7d74cfa..a5d8b4d 100644 --- a/db/migrations/1706784285253-Data.js +++ b/db/migrations/1706784285253-Data.js @@ -89,7 +89,7 @@ module.exports = class Data1706784285253 { await db.query(`ALTER TABLE "contract" ADD CONSTRAINT "FK_5474bf708e87b70509781ed759b" FOREIGN KEY ("extrinsic_id") REFERENCES "extrinsic"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) await db.query(`ALTER TABLE "contract" ADD CONSTRAINT "FK_c36378dd820dcbc9e74e71fe24d" FOREIGN KEY ("signer_id") REFERENCES "account"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) await db.query(`ALTER TABLE "extrinsic" ADD CONSTRAINT "FK_a3b99daba1259dab0dd040d4f74" FOREIGN KEY ("block_id") REFERENCES "block"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "verified_contract" ADD CONSTRAINT "FK_70c992c058f4f82d658a2cd899c" FOREIGN KEY ("contract_id") REFERENCES "contract"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + // await db.query(`ALTER TABLE "verified_contract" ADD CONSTRAINT "FK_70c992c058f4f82d658a2cd899c" FOREIGN KEY ("contract_id") REFERENCES "contract"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_0751309c66e97eac9ef11493623" FOREIGN KEY ("to_id") REFERENCES "account"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_76bdfed1a7eb27c6d8ecbb73496" FOREIGN KEY ("from_id") REFERENCES "account"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_b27b1150b8a7af68424540613c7" FOREIGN KEY ("token_id") REFERENCES "verified_contract"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) @@ -422,7 +422,7 @@ module.exports = class Data1706784285253 { await db.query(`ALTER TABLE "contract" DROP CONSTRAINT "FK_5474bf708e87b70509781ed759b"`) await db.query(`ALTER TABLE "contract" DROP CONSTRAINT "FK_c36378dd820dcbc9e74e71fe24d"`) await db.query(`ALTER TABLE "extrinsic" DROP CONSTRAINT "FK_a3b99daba1259dab0dd040d4f74"`) - await db.query(`ALTER TABLE "verified_contract" DROP CONSTRAINT "FK_70c992c058f4f82d658a2cd899c"`) + // await db.query(`ALTER TABLE "verified_contract" DROP CONSTRAINT "FK_70c992c058f4f82d658a2cd899c"`) await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_0751309c66e97eac9ef11493623"`) await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_76bdfed1a7eb27c6d8ecbb73496"`) await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_b27b1150b8a7af68424540613c7"`) diff --git a/db/migrations/1706784285254-Data.js b/db/migrations/1706784285254-Data.js index cecf6fb..8782c43 100644 --- a/db/migrations/1706784285254-Data.js +++ b/db/migrations/1706784285254-Data.js @@ -6,7 +6,7 @@ module.exports = class Data1706784285254 { // Script inserted manually. Modifies the foreign key constraint on the verified_contract table to delete // the verified contract when the contract is deleted. // ************************************************************************************************************* - await db.query(`ALTER TABLE "verified_contract" DROP CONSTRAINT "FK_70c992c058f4f82d658a2cd899c";`); - await db.query(`ALTER TABLE "verified_contract" ADD CONSTRAINT "FK_70c992c058f4f82d658a2cd899c" FOREIGN KEY ("contract_id") REFERENCES "contract"("id") ON DELETE CASCADE ON UPDATE NO ACTION`) + // await db.query(`ALTER TABLE "verified_contract" DROP CONSTRAINT "FK_70c992c058f4f82d658a2cd899c";`); + // await db.query(`ALTER TABLE "verified_contract" ADD CONSTRAINT "FK_70c992c058f4f82d658a2cd899c" FOREIGN KEY ("contract_id") REFERENCES "contract"("id") ON DELETE CASCADE ON UPDATE NO ACTION`) } } From b8daad057b4180ab18dfe1aed2ff6c7159ea24b6 Mon Sep 17 00:00:00 2001 From: Anukul Pandey Date: Fri, 21 Nov 2025 14:28:34 +0530 Subject: [PATCH 3/4] feat: reverted changes --- db/migrations/1706784285253-Data.js | 4 ++-- db/migrations/1706784285254-Data.js | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/db/migrations/1706784285253-Data.js b/db/migrations/1706784285253-Data.js index a5d8b4d..7d74cfa 100644 --- a/db/migrations/1706784285253-Data.js +++ b/db/migrations/1706784285253-Data.js @@ -89,7 +89,7 @@ module.exports = class Data1706784285253 { await db.query(`ALTER TABLE "contract" ADD CONSTRAINT "FK_5474bf708e87b70509781ed759b" FOREIGN KEY ("extrinsic_id") REFERENCES "extrinsic"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) await db.query(`ALTER TABLE "contract" ADD CONSTRAINT "FK_c36378dd820dcbc9e74e71fe24d" FOREIGN KEY ("signer_id") REFERENCES "account"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) await db.query(`ALTER TABLE "extrinsic" ADD CONSTRAINT "FK_a3b99daba1259dab0dd040d4f74" FOREIGN KEY ("block_id") REFERENCES "block"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - // await db.query(`ALTER TABLE "verified_contract" ADD CONSTRAINT "FK_70c992c058f4f82d658a2cd899c" FOREIGN KEY ("contract_id") REFERENCES "contract"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await db.query(`ALTER TABLE "verified_contract" ADD CONSTRAINT "FK_70c992c058f4f82d658a2cd899c" FOREIGN KEY ("contract_id") REFERENCES "contract"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_0751309c66e97eac9ef11493623" FOREIGN KEY ("to_id") REFERENCES "account"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_76bdfed1a7eb27c6d8ecbb73496" FOREIGN KEY ("from_id") REFERENCES "account"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_b27b1150b8a7af68424540613c7" FOREIGN KEY ("token_id") REFERENCES "verified_contract"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) @@ -422,7 +422,7 @@ module.exports = class Data1706784285253 { await db.query(`ALTER TABLE "contract" DROP CONSTRAINT "FK_5474bf708e87b70509781ed759b"`) await db.query(`ALTER TABLE "contract" DROP CONSTRAINT "FK_c36378dd820dcbc9e74e71fe24d"`) await db.query(`ALTER TABLE "extrinsic" DROP CONSTRAINT "FK_a3b99daba1259dab0dd040d4f74"`) - // await db.query(`ALTER TABLE "verified_contract" DROP CONSTRAINT "FK_70c992c058f4f82d658a2cd899c"`) + await db.query(`ALTER TABLE "verified_contract" DROP CONSTRAINT "FK_70c992c058f4f82d658a2cd899c"`) await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_0751309c66e97eac9ef11493623"`) await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_76bdfed1a7eb27c6d8ecbb73496"`) await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_b27b1150b8a7af68424540613c7"`) diff --git a/db/migrations/1706784285254-Data.js b/db/migrations/1706784285254-Data.js index 8782c43..fdb9963 100644 --- a/db/migrations/1706784285254-Data.js +++ b/db/migrations/1706784285254-Data.js @@ -6,7 +6,10 @@ module.exports = class Data1706784285254 { // Script inserted manually. Modifies the foreign key constraint on the verified_contract table to delete // the verified contract when the contract is deleted. // ************************************************************************************************************* - // await db.query(`ALTER TABLE "verified_contract" DROP CONSTRAINT "FK_70c992c058f4f82d658a2cd899c";`); - // await db.query(`ALTER TABLE "verified_contract" ADD CONSTRAINT "FK_70c992c058f4f82d658a2cd899c" FOREIGN KEY ("contract_id") REFERENCES "contract"("id") ON DELETE CASCADE ON UPDATE NO ACTION`) + + // condition by anukul to avoid errors if the constraint does not exist + await db.query(`DO $$ BEGIN IF EXISTS (SELECT 1 FROM information_schema.table_constraints WHERE constraint_name='FK_70c992c058f4f82d658a2cd899c' AND table_name='verified_contract') THEN ALTER TABLE "verified_contract" DROP CONSTRAINT "FK_70c992c058f4f82d658a2cd899c"; END IF; END $$;`); + + await db.query(`ALTER TABLE "verified_contract" ADD CONSTRAINT "FK_70c992c058f4f82d658a2cd899c" FOREIGN KEY ("contract_id") REFERENCES "contract"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); } } From d05d31abd71519276a29dbcf9f7ddeee5a401eac Mon Sep 17 00:00:00 2001 From: Anukul Pandey Date: Fri, 21 Nov 2025 19:19:28 +0530 Subject: [PATCH 4/4] feat: catched FK_70c992c058f4f82d658a2cd899c migration --- db/migrations/1706784285254-Data.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/db/migrations/1706784285254-Data.js b/db/migrations/1706784285254-Data.js index fdb9963..1a17113 100644 --- a/db/migrations/1706784285254-Data.js +++ b/db/migrations/1706784285254-Data.js @@ -6,10 +6,21 @@ module.exports = class Data1706784285254 { // Script inserted manually. Modifies the foreign key constraint on the verified_contract table to delete // the verified contract when the contract is deleted. // ************************************************************************************************************* + try { + await db.query(` + ALTER TABLE "verified_contract" + DROP CONSTRAINT IF EXISTS "FK_70c992c058f4f82d658a2cd899c"; + `); + } catch (error) { + console.log("Catched FK_70c992c058f4f82d658a2cd899c error:", error); + } + - // condition by anukul to avoid errors if the constraint does not exist - await db.query(`DO $$ BEGIN IF EXISTS (SELECT 1 FROM information_schema.table_constraints WHERE constraint_name='FK_70c992c058f4f82d658a2cd899c' AND table_name='verified_contract') THEN ALTER TABLE "verified_contract" DROP CONSTRAINT "FK_70c992c058f4f82d658a2cd899c"; END IF; END $$;`); - - await db.query(`ALTER TABLE "verified_contract" ADD CONSTRAINT "FK_70c992c058f4f82d658a2cd899c" FOREIGN KEY ("contract_id") REFERENCES "contract"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await db.query(` + ALTER TABLE "verified_contract" + ADD CONSTRAINT "FK_70c992c058f4f82d658a2cd899c" + FOREIGN KEY ("contract_id") REFERENCES "contract"("id") + ON DELETE CASCADE ON UPDATE NO ACTION; + `); } }