diff --git a/.gitignore b/.gitignore index 68729d6..f32e31a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .idea/ -.DS_Store \ No newline at end of file +.DS_Store diff --git a/acala/src/mappings/mappingHandlers.ts b/acala/src/mappings/mappingHandlers.ts index e70e9a0..2503c37 100644 --- a/acala/src/mappings/mappingHandlers.ts +++ b/acala/src/mappings/mappingHandlers.ts @@ -2,7 +2,7 @@ import { EventRecord } from "@polkadot/types/interfaces"; import { SubstrateExtrinsic, SubstrateBlock, SubstrateEvent } from "@subql/types"; import { SpecVersion, Event, Extrinsic, EvmLog, EvmTransaction } from "../types"; import acalaProcessor from '@subql/acala-evm-processor'; -import {hexDataSlice, stripZeros} from '@ethersproject/bytes'; +import { hexDataSlice, stripZeros } from '@ethersproject/bytes'; import { merge } from 'lodash'; let specVersion: SpecVersion; @@ -29,7 +29,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -92,10 +92,15 @@ function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, @@ -158,10 +163,10 @@ async function handleEvmTransaction(idx: number, tx: SubstrateExtrinsic): Promis } export function inputToFunctionSighash(input: string): string { - return hexDataSlice(input, 0, 4); + return hexDataSlice(input, 0, 4); } export function isZero(input: string): boolean { - return stripZeros(input).length === 0; + return stripZeros(input).length === 0; } diff --git a/aleph-zero/src/mappings/mappingHandlers.ts b/aleph-zero/src/mappings/mappingHandlers.ts index 6dc7d74..f79115f 100644 --- a/aleph-zero/src/mappings/mappingHandlers.ts +++ b/aleph-zero/src/mappings/mappingHandlers.ts @@ -71,10 +71,15 @@ function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, @@ -84,4 +89,4 @@ function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { events.findIndex((evt) => evt.event.method === "ExtrinsicSuccess") > -1, }; }); -} \ No newline at end of file +} diff --git a/altair/src/mappings/mappingHandlers.ts b/altair/src/mappings/mappingHandlers.ts index 22cccff..f19f314 100644 --- a/altair/src/mappings/mappingHandlers.ts +++ b/altair/src/mappings/mappingHandlers.ts @@ -11,8 +11,10 @@ export async function handleBlock(block: SubstrateBlock): Promise { // Check for updates to Spec Version if (!specVersion || specVersion.id !== block.specVersion.toString()) { - specVersion = new SpecVersion(block.specVersion.toString()); - specVersion.blockHeight = block.block.header.number.toBigInt(); + specVersion = SpecVersion.create({ + id: block.specVersion.toString(), + blockHeight: block.block.header.number.toBigInt(), + }); await specVersion.save(); } @@ -21,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -44,29 +46,36 @@ function handleEvent( eventIdx: number, event: EventRecord ): Event { - const newEvent = new Event(`${blockNumber}-${eventIdx}`); - newEvent.blockHeight = BigInt(blockNumber); - newEvent.module = event.event.section; - newEvent.event = event.event.method; - return newEvent; + return Event.create({ + id: `${blockNumber}-${eventIdx}`, + blockHeight: BigInt(blockNumber), + module: event.event.section, + event: event.event.method, + }); } function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { - const newExtrinsic = new Extrinsic(idx); - newExtrinsic.txHash = extrinsic.extrinsic.hash.toString(); - newExtrinsic.module = extrinsic.extrinsic.method.section; - newExtrinsic.call = extrinsic.extrinsic.method.method; - newExtrinsic.blockHeight = extrinsic.block.block.header.number.toBigInt(); - newExtrinsic.success = extrinsic.success; - newExtrinsic.isSigned = extrinsic.extrinsic.isSigned; - return newExtrinsic; + return Extrinsic.create({ + id: idx, + txHash: extrinsic.extrinsic.hash.toString(), + module: extrinsic.extrinsic.method.section, + call: extrinsic.extrinsic.method.method, + blockHeight: extrinsic.block.block.header.number.toBigInt(), + success: extrinsic.success, + isSigned: extrinsic.extrinsic.isSigned, + }); } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/automata/src/mappings/mappingHandlers.ts b/automata/src/mappings/mappingHandlers.ts index 22cccff..f19f314 100644 --- a/automata/src/mappings/mappingHandlers.ts +++ b/automata/src/mappings/mappingHandlers.ts @@ -11,8 +11,10 @@ export async function handleBlock(block: SubstrateBlock): Promise { // Check for updates to Spec Version if (!specVersion || specVersion.id !== block.specVersion.toString()) { - specVersion = new SpecVersion(block.specVersion.toString()); - specVersion.blockHeight = block.block.header.number.toBigInt(); + specVersion = SpecVersion.create({ + id: block.specVersion.toString(), + blockHeight: block.block.header.number.toBigInt(), + }); await specVersion.save(); } @@ -21,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -44,29 +46,36 @@ function handleEvent( eventIdx: number, event: EventRecord ): Event { - const newEvent = new Event(`${blockNumber}-${eventIdx}`); - newEvent.blockHeight = BigInt(blockNumber); - newEvent.module = event.event.section; - newEvent.event = event.event.method; - return newEvent; + return Event.create({ + id: `${blockNumber}-${eventIdx}`, + blockHeight: BigInt(blockNumber), + module: event.event.section, + event: event.event.method, + }); } function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { - const newExtrinsic = new Extrinsic(idx); - newExtrinsic.txHash = extrinsic.extrinsic.hash.toString(); - newExtrinsic.module = extrinsic.extrinsic.method.section; - newExtrinsic.call = extrinsic.extrinsic.method.method; - newExtrinsic.blockHeight = extrinsic.block.block.header.number.toBigInt(); - newExtrinsic.success = extrinsic.success; - newExtrinsic.isSigned = extrinsic.extrinsic.isSigned; - return newExtrinsic; + return Extrinsic.create({ + id: idx, + txHash: extrinsic.extrinsic.hash.toString(), + module: extrinsic.extrinsic.method.section, + call: extrinsic.extrinsic.method.method, + blockHeight: extrinsic.block.block.header.number.toBigInt(), + success: extrinsic.success, + isSigned: extrinsic.extrinsic.isSigned, + }); } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/basilisk/src/mappings/mappingHandlers.ts b/basilisk/src/mappings/mappingHandlers.ts index 22cccff..f19f314 100644 --- a/basilisk/src/mappings/mappingHandlers.ts +++ b/basilisk/src/mappings/mappingHandlers.ts @@ -11,8 +11,10 @@ export async function handleBlock(block: SubstrateBlock): Promise { // Check for updates to Spec Version if (!specVersion || specVersion.id !== block.specVersion.toString()) { - specVersion = new SpecVersion(block.specVersion.toString()); - specVersion.blockHeight = block.block.header.number.toBigInt(); + specVersion = SpecVersion.create({ + id: block.specVersion.toString(), + blockHeight: block.block.header.number.toBigInt(), + }); await specVersion.save(); } @@ -21,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -44,29 +46,36 @@ function handleEvent( eventIdx: number, event: EventRecord ): Event { - const newEvent = new Event(`${blockNumber}-${eventIdx}`); - newEvent.blockHeight = BigInt(blockNumber); - newEvent.module = event.event.section; - newEvent.event = event.event.method; - return newEvent; + return Event.create({ + id: `${blockNumber}-${eventIdx}`, + blockHeight: BigInt(blockNumber), + module: event.event.section, + event: event.event.method, + }); } function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { - const newExtrinsic = new Extrinsic(idx); - newExtrinsic.txHash = extrinsic.extrinsic.hash.toString(); - newExtrinsic.module = extrinsic.extrinsic.method.section; - newExtrinsic.call = extrinsic.extrinsic.method.method; - newExtrinsic.blockHeight = extrinsic.block.block.header.number.toBigInt(); - newExtrinsic.success = extrinsic.success; - newExtrinsic.isSigned = extrinsic.extrinsic.isSigned; - return newExtrinsic; + return Extrinsic.create({ + id: idx, + txHash: extrinsic.extrinsic.hash.toString(), + module: extrinsic.extrinsic.method.section, + call: extrinsic.extrinsic.method.method, + blockHeight: extrinsic.block.block.header.number.toBigInt(), + success: extrinsic.success, + isSigned: extrinsic.extrinsic.isSigned, + }); } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/bifrost-parachain/src/mappings/mappingHandlers.ts b/bifrost-parachain/src/mappings/mappingHandlers.ts index bcb2ed2..1116162 100644 --- a/bifrost-parachain/src/mappings/mappingHandlers.ts +++ b/bifrost-parachain/src/mappings/mappingHandlers.ts @@ -23,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -69,10 +69,15 @@ function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/bitcountry-pioneer/src/mappings/mappingHandlers.ts b/bitcountry-pioneer/src/mappings/mappingHandlers.ts index 22cccff..f19f314 100644 --- a/bitcountry-pioneer/src/mappings/mappingHandlers.ts +++ b/bitcountry-pioneer/src/mappings/mappingHandlers.ts @@ -11,8 +11,10 @@ export async function handleBlock(block: SubstrateBlock): Promise { // Check for updates to Spec Version if (!specVersion || specVersion.id !== block.specVersion.toString()) { - specVersion = new SpecVersion(block.specVersion.toString()); - specVersion.blockHeight = block.block.header.number.toBigInt(); + specVersion = SpecVersion.create({ + id: block.specVersion.toString(), + blockHeight: block.block.header.number.toBigInt(), + }); await specVersion.save(); } @@ -21,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -44,29 +46,36 @@ function handleEvent( eventIdx: number, event: EventRecord ): Event { - const newEvent = new Event(`${blockNumber}-${eventIdx}`); - newEvent.blockHeight = BigInt(blockNumber); - newEvent.module = event.event.section; - newEvent.event = event.event.method; - return newEvent; + return Event.create({ + id: `${blockNumber}-${eventIdx}`, + blockHeight: BigInt(blockNumber), + module: event.event.section, + event: event.event.method, + }); } function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { - const newExtrinsic = new Extrinsic(idx); - newExtrinsic.txHash = extrinsic.extrinsic.hash.toString(); - newExtrinsic.module = extrinsic.extrinsic.method.section; - newExtrinsic.call = extrinsic.extrinsic.method.method; - newExtrinsic.blockHeight = extrinsic.block.block.header.number.toBigInt(); - newExtrinsic.success = extrinsic.success; - newExtrinsic.isSigned = extrinsic.extrinsic.isSigned; - return newExtrinsic; + return Extrinsic.create({ + id: idx, + txHash: extrinsic.extrinsic.hash.toString(), + module: extrinsic.extrinsic.method.section, + call: extrinsic.extrinsic.method.method, + blockHeight: extrinsic.block.block.header.number.toBigInt(), + success: extrinsic.success, + isSigned: extrinsic.extrinsic.isSigned, + }); } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/calamari/src/mappings/mappingHandlers.ts b/calamari/src/mappings/mappingHandlers.ts index 04442b7..bef81f5 100644 --- a/calamari/src/mappings/mappingHandlers.ts +++ b/calamari/src/mappings/mappingHandlers.ts @@ -13,7 +13,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { if (!specVersion || specVersion.id !== block.specVersion.toString()) { specVersion = SpecVersion.create({ id: block.specVersion.toString(), - blockHeight: block.block.header.number.toBigInt() + blockHeight: block.block.header.number.toBigInt(), }); await specVersion.save(); } @@ -23,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -51,29 +51,34 @@ function handleEvent( ): Event { return Event.create({ id: `${blockNumber}-${eventIdx}`, - blockHeight : BigInt(blockNumber), - module : event.event.section, - event : event.event.method, + blockHeight: BigInt(blockNumber), + module: event.event.section, + event: event.event.method, }); } function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { return Extrinsic.create({ id: idx, - txHash : extrinsic.extrinsic.hash.toString(), - module : extrinsic.extrinsic.method.section, - call : extrinsic.extrinsic.method.method, - blockHeight : extrinsic.block.block.header.number.toBigInt(), - success : extrinsic.success, - isSigned : extrinsic.extrinsic.isSigned, + txHash: extrinsic.extrinsic.hash.toString(), + module: extrinsic.extrinsic.method.section, + call: extrinsic.extrinsic.method.method, + blockHeight: extrinsic.block.block.header.number.toBigInt(), + success: extrinsic.success, + isSigned: extrinsic.extrinsic.isSigned, }); } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/clover/src/mappings/mappingHandlers.ts b/clover/src/mappings/mappingHandlers.ts index 22cccff..f19f314 100644 --- a/clover/src/mappings/mappingHandlers.ts +++ b/clover/src/mappings/mappingHandlers.ts @@ -11,8 +11,10 @@ export async function handleBlock(block: SubstrateBlock): Promise { // Check for updates to Spec Version if (!specVersion || specVersion.id !== block.specVersion.toString()) { - specVersion = new SpecVersion(block.specVersion.toString()); - specVersion.blockHeight = block.block.header.number.toBigInt(); + specVersion = SpecVersion.create({ + id: block.specVersion.toString(), + blockHeight: block.block.header.number.toBigInt(), + }); await specVersion.save(); } @@ -21,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -44,29 +46,36 @@ function handleEvent( eventIdx: number, event: EventRecord ): Event { - const newEvent = new Event(`${blockNumber}-${eventIdx}`); - newEvent.blockHeight = BigInt(blockNumber); - newEvent.module = event.event.section; - newEvent.event = event.event.method; - return newEvent; + return Event.create({ + id: `${blockNumber}-${eventIdx}`, + blockHeight: BigInt(blockNumber), + module: event.event.section, + event: event.event.method, + }); } function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { - const newExtrinsic = new Extrinsic(idx); - newExtrinsic.txHash = extrinsic.extrinsic.hash.toString(); - newExtrinsic.module = extrinsic.extrinsic.method.section; - newExtrinsic.call = extrinsic.extrinsic.method.method; - newExtrinsic.blockHeight = extrinsic.block.block.header.number.toBigInt(); - newExtrinsic.success = extrinsic.success; - newExtrinsic.isSigned = extrinsic.extrinsic.isSigned; - return newExtrinsic; + return Extrinsic.create({ + id: idx, + txHash: extrinsic.extrinsic.hash.toString(), + module: extrinsic.extrinsic.method.section, + call: extrinsic.extrinsic.method.method, + blockHeight: extrinsic.block.block.header.number.toBigInt(), + success: extrinsic.success, + isSigned: extrinsic.extrinsic.isSigned, + }); } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/contextfree/src/mappings/mappingHandlers.ts b/contextfree/src/mappings/mappingHandlers.ts index 22cccff..f19f314 100644 --- a/contextfree/src/mappings/mappingHandlers.ts +++ b/contextfree/src/mappings/mappingHandlers.ts @@ -11,8 +11,10 @@ export async function handleBlock(block: SubstrateBlock): Promise { // Check for updates to Spec Version if (!specVersion || specVersion.id !== block.specVersion.toString()) { - specVersion = new SpecVersion(block.specVersion.toString()); - specVersion.blockHeight = block.block.header.number.toBigInt(); + specVersion = SpecVersion.create({ + id: block.specVersion.toString(), + blockHeight: block.block.header.number.toBigInt(), + }); await specVersion.save(); } @@ -21,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -44,29 +46,36 @@ function handleEvent( eventIdx: number, event: EventRecord ): Event { - const newEvent = new Event(`${blockNumber}-${eventIdx}`); - newEvent.blockHeight = BigInt(blockNumber); - newEvent.module = event.event.section; - newEvent.event = event.event.method; - return newEvent; + return Event.create({ + id: `${blockNumber}-${eventIdx}`, + blockHeight: BigInt(blockNumber), + module: event.event.section, + event: event.event.method, + }); } function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { - const newExtrinsic = new Extrinsic(idx); - newExtrinsic.txHash = extrinsic.extrinsic.hash.toString(); - newExtrinsic.module = extrinsic.extrinsic.method.section; - newExtrinsic.call = extrinsic.extrinsic.method.method; - newExtrinsic.blockHeight = extrinsic.block.block.header.number.toBigInt(); - newExtrinsic.success = extrinsic.success; - newExtrinsic.isSigned = extrinsic.extrinsic.isSigned; - return newExtrinsic; + return Extrinsic.create({ + id: idx, + txHash: extrinsic.extrinsic.hash.toString(), + module: extrinsic.extrinsic.method.section, + call: extrinsic.extrinsic.method.method, + blockHeight: extrinsic.block.block.header.number.toBigInt(), + success: extrinsic.success, + isSigned: extrinsic.extrinsic.isSigned, + }); } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/khala/src/mappings/mappingHandlers.ts b/khala/src/mappings/mappingHandlers.ts index 16c64f5..0728912 100644 --- a/khala/src/mappings/mappingHandlers.ts +++ b/khala/src/mappings/mappingHandlers.ts @@ -23,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -67,10 +67,15 @@ function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/kusama/project.yaml b/kusama/project.yaml index 4e6d3b1..874108f 100644 --- a/kusama/project.yaml +++ b/kusama/project.yaml @@ -3,23 +3,23 @@ name: SubQuery Dictionary - Kusama version: 1.0.0 runner: node: - name: '@subql/node' - version: '*' + name: "@subql/node" + version: "*" query: - name: '@subql/query' - version: '*' + name: "@subql/query" + version: "*" description: >- A SubQuery Dictionary Project that provides increased indexing speed to all projects -repository: 'https://github.com/subquery/subql-dictionary' +repository: "https://github.com/subquery/subql-dictionary" schema: file: ./schema.graphql network: - chainId: '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe' - endpoint: 'wss://kusama.api.onfinality.io/public-ws' + chainId: "0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe" + endpoint: "wss://kusama.api.onfinality.io/public-ws" dataSources: - kind: substrate/Runtime - startBlock: 1 + startBlock: 25845986 mapping: file: ./dist/index.js handlers: diff --git a/kusama/src/mappings/mappingHandlers.ts b/kusama/src/mappings/mappingHandlers.ts index 22cccff..f19f314 100644 --- a/kusama/src/mappings/mappingHandlers.ts +++ b/kusama/src/mappings/mappingHandlers.ts @@ -11,8 +11,10 @@ export async function handleBlock(block: SubstrateBlock): Promise { // Check for updates to Spec Version if (!specVersion || specVersion.id !== block.specVersion.toString()) { - specVersion = new SpecVersion(block.specVersion.toString()); - specVersion.blockHeight = block.block.header.number.toBigInt(); + specVersion = SpecVersion.create({ + id: block.specVersion.toString(), + blockHeight: block.block.header.number.toBigInt(), + }); await specVersion.save(); } @@ -21,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -44,29 +46,36 @@ function handleEvent( eventIdx: number, event: EventRecord ): Event { - const newEvent = new Event(`${blockNumber}-${eventIdx}`); - newEvent.blockHeight = BigInt(blockNumber); - newEvent.module = event.event.section; - newEvent.event = event.event.method; - return newEvent; + return Event.create({ + id: `${blockNumber}-${eventIdx}`, + blockHeight: BigInt(blockNumber), + module: event.event.section, + event: event.event.method, + }); } function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { - const newExtrinsic = new Extrinsic(idx); - newExtrinsic.txHash = extrinsic.extrinsic.hash.toString(); - newExtrinsic.module = extrinsic.extrinsic.method.section; - newExtrinsic.call = extrinsic.extrinsic.method.method; - newExtrinsic.blockHeight = extrinsic.block.block.header.number.toBigInt(); - newExtrinsic.success = extrinsic.success; - newExtrinsic.isSigned = extrinsic.extrinsic.isSigned; - return newExtrinsic; + return Extrinsic.create({ + id: idx, + txHash: extrinsic.extrinsic.hash.toString(), + module: extrinsic.extrinsic.method.section, + call: extrinsic.extrinsic.method.method, + blockHeight: extrinsic.block.block.header.number.toBigInt(), + success: extrinsic.success, + isSigned: extrinsic.extrinsic.isSigned, + }); } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/neumann/src/mappings/mappingHandlers.ts b/neumann/src/mappings/mappingHandlers.ts index 22cccff..f19f314 100644 --- a/neumann/src/mappings/mappingHandlers.ts +++ b/neumann/src/mappings/mappingHandlers.ts @@ -11,8 +11,10 @@ export async function handleBlock(block: SubstrateBlock): Promise { // Check for updates to Spec Version if (!specVersion || specVersion.id !== block.specVersion.toString()) { - specVersion = new SpecVersion(block.specVersion.toString()); - specVersion.blockHeight = block.block.header.number.toBigInt(); + specVersion = SpecVersion.create({ + id: block.specVersion.toString(), + blockHeight: block.block.header.number.toBigInt(), + }); await specVersion.save(); } @@ -21,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -44,29 +46,36 @@ function handleEvent( eventIdx: number, event: EventRecord ): Event { - const newEvent = new Event(`${blockNumber}-${eventIdx}`); - newEvent.blockHeight = BigInt(blockNumber); - newEvent.module = event.event.section; - newEvent.event = event.event.method; - return newEvent; + return Event.create({ + id: `${blockNumber}-${eventIdx}`, + blockHeight: BigInt(blockNumber), + module: event.event.section, + event: event.event.method, + }); } function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { - const newExtrinsic = new Extrinsic(idx); - newExtrinsic.txHash = extrinsic.extrinsic.hash.toString(); - newExtrinsic.module = extrinsic.extrinsic.method.section; - newExtrinsic.call = extrinsic.extrinsic.method.method; - newExtrinsic.blockHeight = extrinsic.block.block.header.number.toBigInt(); - newExtrinsic.success = extrinsic.success; - newExtrinsic.isSigned = extrinsic.extrinsic.isSigned; - return newExtrinsic; + return Extrinsic.create({ + id: idx, + txHash: extrinsic.extrinsic.hash.toString(), + module: extrinsic.extrinsic.method.section, + call: extrinsic.extrinsic.method.method, + blockHeight: extrinsic.block.block.header.number.toBigInt(), + success: extrinsic.success, + isSigned: extrinsic.extrinsic.isSigned, + }); } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/nodle-parachain/src/mappings/mappingHandlers.ts b/nodle-parachain/src/mappings/mappingHandlers.ts index 16c64f5..0728912 100644 --- a/nodle-parachain/src/mappings/mappingHandlers.ts +++ b/nodle-parachain/src/mappings/mappingHandlers.ts @@ -23,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -67,10 +67,15 @@ function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/parallel-heiko/src/mappings/mappingHandlers.ts b/parallel-heiko/src/mappings/mappingHandlers.ts index 22cccff..f19f314 100644 --- a/parallel-heiko/src/mappings/mappingHandlers.ts +++ b/parallel-heiko/src/mappings/mappingHandlers.ts @@ -11,8 +11,10 @@ export async function handleBlock(block: SubstrateBlock): Promise { // Check for updates to Spec Version if (!specVersion || specVersion.id !== block.specVersion.toString()) { - specVersion = new SpecVersion(block.specVersion.toString()); - specVersion.blockHeight = block.block.header.number.toBigInt(); + specVersion = SpecVersion.create({ + id: block.specVersion.toString(), + blockHeight: block.block.header.number.toBigInt(), + }); await specVersion.save(); } @@ -21,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -44,29 +46,36 @@ function handleEvent( eventIdx: number, event: EventRecord ): Event { - const newEvent = new Event(`${blockNumber}-${eventIdx}`); - newEvent.blockHeight = BigInt(blockNumber); - newEvent.module = event.event.section; - newEvent.event = event.event.method; - return newEvent; + return Event.create({ + id: `${blockNumber}-${eventIdx}`, + blockHeight: BigInt(blockNumber), + module: event.event.section, + event: event.event.method, + }); } function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { - const newExtrinsic = new Extrinsic(idx); - newExtrinsic.txHash = extrinsic.extrinsic.hash.toString(); - newExtrinsic.module = extrinsic.extrinsic.method.section; - newExtrinsic.call = extrinsic.extrinsic.method.method; - newExtrinsic.blockHeight = extrinsic.block.block.header.number.toBigInt(); - newExtrinsic.success = extrinsic.success; - newExtrinsic.isSigned = extrinsic.extrinsic.isSigned; - return newExtrinsic; + return Extrinsic.create({ + id: idx, + txHash: extrinsic.extrinsic.hash.toString(), + module: extrinsic.extrinsic.method.section, + call: extrinsic.extrinsic.method.method, + blockHeight: extrinsic.block.block.header.number.toBigInt(), + success: extrinsic.success, + isSigned: extrinsic.extrinsic.isSigned, + }); } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/parallel/src/mappings/mappingHandlers.ts b/parallel/src/mappings/mappingHandlers.ts index e0077fe..1352be6 100644 --- a/parallel/src/mappings/mappingHandlers.ts +++ b/parallel/src/mappings/mappingHandlers.ts @@ -13,7 +13,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { if (!specVersion || specVersion.id !== block.specVersion.toString()) { specVersion = SpecVersion.create({ id: block.specVersion.toString(), - blockHeight: block.block.header.number.toBigInt() + blockHeight: block.block.header.number.toBigInt(), }); await specVersion.save(); } @@ -23,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -52,28 +52,33 @@ function handleEvent( return Event.create({ id: `${blockNumber}-${eventIdx}`, blockHeight: BigInt(blockNumber), - module : event.event.section, - event : event.event.method + module: event.event.section, + event: event.event.method }); } function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { return Extrinsic.create({ id: idx, - txHash : extrinsic.extrinsic.hash.toString(), - module : extrinsic.extrinsic.method.section, - call : extrinsic.extrinsic.method.method, - blockHeight : extrinsic.block.block.header.number.toBigInt(), - success : extrinsic.success, - isSigned : extrinsic.extrinsic.isSigned, + txHash: extrinsic.extrinsic.hash.toString(), + module: extrinsic.extrinsic.method.section, + call: extrinsic.extrinsic.method.method, + blockHeight: extrinsic.block.block.header.number.toBigInt(), + success: extrinsic.success, + isSigned: extrinsic.extrinsic.isSigned, }); } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/polkadex/src/mappings/mappingHandlers.ts b/polkadex/src/mappings/mappingHandlers.ts index cd0bcae..4e59332 100644 --- a/polkadex/src/mappings/mappingHandlers.ts +++ b/polkadex/src/mappings/mappingHandlers.ts @@ -68,10 +68,15 @@ function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, @@ -81,4 +86,4 @@ function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { events.findIndex((evt) => evt.event.method === "ExtrinsicSuccess") > -1, }; }); -} \ No newline at end of file +} diff --git a/polkadot/src/mappings/mappingHandlers.ts b/polkadot/src/mappings/mappingHandlers.ts index ca0b625..a22fba1 100644 --- a/polkadot/src/mappings/mappingHandlers.ts +++ b/polkadot/src/mappings/mappingHandlers.ts @@ -2,6 +2,12 @@ import { EventRecord } from "@polkadot/types/interfaces"; import { SubstrateExtrinsic, SubstrateBlock } from "@subql/types"; import { SpecVersion, Event, Extrinsic } from "../types"; + +// Make BigInt json serializable, note this doesn't go from string -> BigInt when parsing +(BigInt.prototype as any).toJSON = function () { + return `${this.toString()}n`; +}; + let specVersion: SpecVersion; export async function handleBlock(block: SubstrateBlock): Promise { // Initialise Spec Version @@ -11,7 +17,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { // Check for updates to Spec Version if (!specVersion || specVersion.id !== block.specVersion.toString()) { - specVersion = new SpecVersion(block.specVersion.toString(),block.block.header.number.toBigInt()); + specVersion = new SpecVersion(block.specVersion.toString(), block.block.header.number.toBigInt()); await specVersion.save(); } @@ -20,7 +26,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -43,28 +49,36 @@ function handleEvent( eventIdx: number, event: EventRecord ): Event { - const newEvent = new Event(`${blockNumber}-${eventIdx}`,event.event.section,event.event.method,BigInt(blockNumber)); - return newEvent; + return Event.create({ + id: `${blockNumber}-${eventIdx}`, + blockHeight: BigInt(blockNumber), + module: event.event.section, + event: event.event.method, + }); } function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { - const newExtrinsic = new Extrinsic( - idx, - extrinsic.extrinsic.hash.toString(), - extrinsic.extrinsic.method.section, - extrinsic.extrinsic.method.method, - extrinsic.block.block.header.number.toBigInt(), - extrinsic.success, - extrinsic.extrinsic.isSigned - ); - return newExtrinsic; + return Extrinsic.create({ + id: idx, + txHash: extrinsic.extrinsic.hash.toString(), + module: extrinsic.extrinsic.method.section, + call: extrinsic.extrinsic.method.method, + blockHeight: extrinsic.block.block.header.number.toBigInt(), + success: extrinsic.success, + isSigned: extrinsic.extrinsic.isSigned, + }); } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record); return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/quartz/src/mappings/mappingHandlers.ts b/quartz/src/mappings/mappingHandlers.ts index 22cccff..f19f314 100644 --- a/quartz/src/mappings/mappingHandlers.ts +++ b/quartz/src/mappings/mappingHandlers.ts @@ -11,8 +11,10 @@ export async function handleBlock(block: SubstrateBlock): Promise { // Check for updates to Spec Version if (!specVersion || specVersion.id !== block.specVersion.toString()) { - specVersion = new SpecVersion(block.specVersion.toString()); - specVersion.blockHeight = block.block.header.number.toBigInt(); + specVersion = SpecVersion.create({ + id: block.specVersion.toString(), + blockHeight: block.block.header.number.toBigInt(), + }); await specVersion.save(); } @@ -21,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -44,29 +46,36 @@ function handleEvent( eventIdx: number, event: EventRecord ): Event { - const newEvent = new Event(`${blockNumber}-${eventIdx}`); - newEvent.blockHeight = BigInt(blockNumber); - newEvent.module = event.event.section; - newEvent.event = event.event.method; - return newEvent; + return Event.create({ + id: `${blockNumber}-${eventIdx}`, + blockHeight: BigInt(blockNumber), + module: event.event.section, + event: event.event.method, + }); } function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { - const newExtrinsic = new Extrinsic(idx); - newExtrinsic.txHash = extrinsic.extrinsic.hash.toString(); - newExtrinsic.module = extrinsic.extrinsic.method.section; - newExtrinsic.call = extrinsic.extrinsic.method.method; - newExtrinsic.blockHeight = extrinsic.block.block.header.number.toBigInt(); - newExtrinsic.success = extrinsic.success; - newExtrinsic.isSigned = extrinsic.extrinsic.isSigned; - return newExtrinsic; + return Extrinsic.create({ + id: idx, + txHash: extrinsic.extrinsic.hash.toString(), + module: extrinsic.extrinsic.method.section, + call: extrinsic.extrinsic.method.method, + blockHeight: extrinsic.block.block.header.number.toBigInt(), + success: extrinsic.success, + isSigned: extrinsic.extrinsic.isSigned, + }); } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/statemine/src/mappings/mappingHandlers.ts b/statemine/src/mappings/mappingHandlers.ts index 22cccff..f19f314 100644 --- a/statemine/src/mappings/mappingHandlers.ts +++ b/statemine/src/mappings/mappingHandlers.ts @@ -11,8 +11,10 @@ export async function handleBlock(block: SubstrateBlock): Promise { // Check for updates to Spec Version if (!specVersion || specVersion.id !== block.specVersion.toString()) { - specVersion = new SpecVersion(block.specVersion.toString()); - specVersion.blockHeight = block.block.header.number.toBigInt(); + specVersion = SpecVersion.create({ + id: block.specVersion.toString(), + blockHeight: block.block.header.number.toBigInt(), + }); await specVersion.save(); } @@ -21,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -44,29 +46,36 @@ function handleEvent( eventIdx: number, event: EventRecord ): Event { - const newEvent = new Event(`${blockNumber}-${eventIdx}`); - newEvent.blockHeight = BigInt(blockNumber); - newEvent.module = event.event.section; - newEvent.event = event.event.method; - return newEvent; + return Event.create({ + id: `${blockNumber}-${eventIdx}`, + blockHeight: BigInt(blockNumber), + module: event.event.section, + event: event.event.method, + }); } function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { - const newExtrinsic = new Extrinsic(idx); - newExtrinsic.txHash = extrinsic.extrinsic.hash.toString(); - newExtrinsic.module = extrinsic.extrinsic.method.section; - newExtrinsic.call = extrinsic.extrinsic.method.method; - newExtrinsic.blockHeight = extrinsic.block.block.header.number.toBigInt(); - newExtrinsic.success = extrinsic.success; - newExtrinsic.isSigned = extrinsic.extrinsic.isSigned; - return newExtrinsic; + return Extrinsic.create({ + id: idx, + txHash: extrinsic.extrinsic.hash.toString(), + module: extrinsic.extrinsic.method.section, + call: extrinsic.extrinsic.method.method, + blockHeight: extrinsic.block.block.header.number.toBigInt(), + success: extrinsic.success, + isSigned: extrinsic.extrinsic.isSigned, + }); } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/statemint/src/mappings/mappingHandlers.ts b/statemint/src/mappings/mappingHandlers.ts index 188f8cf..ca1f12b 100644 --- a/statemint/src/mappings/mappingHandlers.ts +++ b/statemint/src/mappings/mappingHandlers.ts @@ -23,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -50,30 +50,35 @@ function handleEvent( event: EventRecord ): Event { return Event.create({ - id :`${blockNumber}-${eventIdx}`, - blockHeight : BigInt(blockNumber), - module : event.event.section, - event : event.event.method, + id: `${blockNumber}-${eventIdx}`, + blockHeight: BigInt(blockNumber), + module: event.event.section, + event: event.event.method, }); } function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { return Extrinsic.create({ id: idx, - txHash : extrinsic.extrinsic.hash.toString(), - module : extrinsic.extrinsic.method.section, - call : extrinsic.extrinsic.method.method, - blockHeight : extrinsic.block.block.header.number.toBigInt(), - success : extrinsic.success, - isSigned : extrinsic.extrinsic.isSigned, + txHash: extrinsic.extrinsic.hash.toString(), + module: extrinsic.extrinsic.method.section, + call: extrinsic.extrinsic.method.method, + blockHeight: extrinsic.block.block.header.number.toBigInt(), + success: extrinsic.success, + isSigned: extrinsic.extrinsic.isSigned, }); } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/turing/src/mappings/mappingHandlers.ts b/turing/src/mappings/mappingHandlers.ts index cd0bcae..4e59332 100644 --- a/turing/src/mappings/mappingHandlers.ts +++ b/turing/src/mappings/mappingHandlers.ts @@ -68,10 +68,15 @@ function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, @@ -81,4 +86,4 @@ function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { events.findIndex((evt) => evt.event.method === "ExtrinsicSuccess") > -1, }; }); -} \ No newline at end of file +} diff --git a/westend/src/mappings/mappingHandlers.ts b/westend/src/mappings/mappingHandlers.ts index 16c64f5..6f7a2aa 100644 --- a/westend/src/mappings/mappingHandlers.ts +++ b/westend/src/mappings/mappingHandlers.ts @@ -23,7 +23,7 @@ export async function handleBlock(block: SubstrateBlock): Promise { .filter( (evt) => !(evt.event.section === "system" && - evt.event.method === "ExtrinsicSuccess") + evt.event.method === "ExtrinsicSuccess") ) .map((evt, idx) => handleEvent(block.block.header.number.toString(), idx, evt) @@ -67,10 +67,15 @@ function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record); return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, diff --git a/zeitgeist/src/mappings/mappingHandlers.ts b/zeitgeist/src/mappings/mappingHandlers.ts index cd0bcae..4e59332 100644 --- a/zeitgeist/src/mappings/mappingHandlers.ts +++ b/zeitgeist/src/mappings/mappingHandlers.ts @@ -68,10 +68,15 @@ function handleCall(idx: string, extrinsic: SubstrateExtrinsic): Extrinsic { } function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { + const groupedEvents = wrappedBlock.events.reduce((acc, evt) => { + if (evt.phase.isApplyExtrinsic) { + acc[evt.phase.asApplyExtrinsic.toNumber()] ??= []; + acc[evt.phase.asApplyExtrinsic.toNumber()].push(evt); + } + return acc; + }, {} as Record) return wrappedBlock.block.extrinsics.map((extrinsic, idx) => { - const events = wrappedBlock.events.filter( - ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(idx) - ); + const events = groupedEvents[idx]; return { idx, extrinsic, @@ -81,4 +86,4 @@ function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] { events.findIndex((evt) => evt.event.method === "ExtrinsicSuccess") > -1, }; }); -} \ No newline at end of file +}