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

Update all to us TS strict #54

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion acala/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//Exports all handler functions
import {atob} from 'abab';
if (!global.atob) {
global.atob = atob;
global.atob = atob as any;
}
export * from "./mappings/mappingHandlers";
import "@polkadot/api-augment";
30 changes: 17 additions & 13 deletions acala/src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { EventRecord } from "@polkadot/types/interfaces";
import { SubstrateExtrinsic, SubstrateBlock, SubstrateEvent } from "@subql/types";
import {SubstrateExtrinsic, SubstrateBlock, SubstrateEvent, SubstrateEventFilter} 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 { merge } from 'lodash';
import assert from "assert";

let specVersion: SpecVersion;
let specVersion: SpecVersion | undefined;
export async function handleBlock(block: SubstrateBlock): Promise<void> {
// Initialise Spec Version
if (!specVersion) {
Expand Down Expand Up @@ -37,7 +38,7 @@ export async function handleBlock(block: SubstrateBlock): Promise<void> {

const evmLogs: EvmLog[][] = []
for (const evt of wrappedEvents.filter(evt => {
const baseFilter = acalaProcessor.handlerProcessors['substrate/AcalaEvmEvent'].baseFilter[0];
const baseFilter = (acalaProcessor as any).handlerProcessors['substrate/AcalaEvmEvent'].baseFilter[0] as any as SubstrateEventFilter;
return evt.event.section === baseFilter.module && evt.event.method === baseFilter.method;
})) {
const logResult = await handleEvmLog(block.block.header.number.toString(), evt);
Expand All @@ -52,7 +53,7 @@ export async function handleBlock(block: SubstrateBlock): Promise<void> {
const evmTransactions: EvmTransaction[][] = [];

for (const ex of wrappedExtrinsics.filter(ex => {
const baseFilter = acalaProcessor.handlerProcessors['substrate/AcalaEvmCall'].baseFilter[0];
const baseFilter = (acalaProcessor as any).handlerProcessors['substrate/AcalaEvmCall'].baseFilter[0];
return ex.extrinsic.method.section === baseFilter.module && ex.extrinsic.method.method === baseFilter.method && ex.success;
})) {
const transactionResult = await handleEvmTransaction(ex.idx, ex);
Expand Down Expand Up @@ -156,15 +157,18 @@ async function handleEvmTransaction(idx: number, tx: SubstrateExtrinsic): Promis
api: api as any,
});

return calls.map((call, i) => EvmTransaction.create({
id: `${call.blockNumber}-${idx}-${i}`,
txHash: call.hash,
from: call.from,
to: call.to,
func: isZero(call.data) ? undefined : inputToFunctionSighash(call.data).toLowerCase(),
blockHeight: BigInt(call.blockNumber),
success: tx.success,
}));
return calls.map((call, i) => {
assert(call.blockNumber, 'No blockNumber in call')
return EvmTransaction.create({
id: `${call.blockNumber}-${idx}-${i}`,
txHash: call.hash,
from: call.from,
to: call.to,
func: isZero(call.data) ? undefined : inputToFunctionSighash(call.data).toLowerCase(),
blockHeight: BigInt(call.blockNumber),
success: tx.success,
})
});
}

export function inputToFunctionSighash(input: string): string {
Expand Down
8 changes: 5 additions & 3 deletions acala/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
"outDir": "dist",
"rootDir": "src",
"target": "es2017",
"strict": true,
},
"include": [
"src/**/*",
"node_modules/@subql/types/dist/global.d.ts"
]
}
"node_modules/@subql/types-core/dist/global.d.ts",
"node_modules/@subql/types/dist/global.d.ts",
],
}
7 changes: 4 additions & 3 deletions aleph-zero/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
"outDir": "dist",
"rootDir": "src",
"target": "es2017",
"strict": true
"strict": true,
},
"include": [
"src/**/*",
"node_modules/@subql/types/dist/global.d.ts"
]
"node_modules/@subql/types-core/dist/global.d.ts",
"node_modules/@subql/types/dist/global.d.ts",
],
}
38 changes: 21 additions & 17 deletions altair/src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EventRecord } from "@polkadot/types/interfaces";
import { SubstrateExtrinsic, SubstrateBlock } from "@subql/types";
import { SpecVersion, Event, Extrinsic } from "../types";

let specVersion: SpecVersion;
let specVersion: SpecVersion | undefined;
export async function handleBlock(block: SubstrateBlock): Promise<void> {
// Initialise Spec Version
if (!specVersion) {
Expand All @@ -11,8 +11,10 @@ export async function handleBlock(block: SubstrateBlock): Promise<void> {

// 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();
}

Expand Down Expand Up @@ -46,22 +48,24 @@ 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,
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(),
});
}

function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] {
Expand All @@ -78,4 +82,4 @@ function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] {
events.findIndex((evt) => evt.event.method === "ExtrinsicSuccess") > -1,
};
});
}
}
10 changes: 6 additions & 4 deletions altair/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
"module": "commonjs",
"outDir": "dist",
"rootDir": "src",
"target": "es2017"
"target": "es2017",
"strict": true,
},
"include": [
"src/**/*",
"node_modules/@subql/types/dist/global.d.ts"
]
}
"node_modules/@subql/types-core/dist/global.d.ts",
"node_modules/@subql/types/dist/global.d.ts",
],
}
7 changes: 4 additions & 3 deletions astar/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"include": [
"src/**/*",
"node_modules/@subql/types/dist/global.d.ts"
]
}
"node_modules/@subql/types-core/dist/global.d.ts",
"node_modules/@subql/types/dist/global.d.ts",
],
}
38 changes: 21 additions & 17 deletions automata/src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EventRecord } from "@polkadot/types/interfaces";
import { SubstrateExtrinsic, SubstrateBlock } from "@subql/types";
import { SpecVersion, Event, Extrinsic } from "../types";

let specVersion: SpecVersion;
let specVersion: SpecVersion | undefined;
export async function handleBlock(block: SubstrateBlock): Promise<void> {
// Initialise Spec Version
if (!specVersion) {
Expand All @@ -11,8 +11,10 @@ export async function handleBlock(block: SubstrateBlock): Promise<void> {

// 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();
}

Expand Down Expand Up @@ -47,22 +49,24 @@ 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,
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()
});
}

function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] {
Expand All @@ -79,4 +83,4 @@ function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] {
events.findIndex((evt) => evt.event.method === "ExtrinsicSuccess") > -1,
};
});
}
}
10 changes: 6 additions & 4 deletions automata/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
"module": "commonjs",
"outDir": "dist",
"rootDir": "src",
"target": "es2017"
"target": "es2017",
"strict": true,
},
"include": [
"src/**/*",
"node_modules/@subql/types/dist/global.d.ts"
]
}
"node_modules/@subql/types-core/dist/global.d.ts",
"node_modules/@subql/types/dist/global.d.ts",
],
}
38 changes: 21 additions & 17 deletions basilisk/src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EventRecord } from "@polkadot/types/interfaces";
import { SubstrateExtrinsic, SubstrateBlock } from "@subql/types";
import { SpecVersion, Event, Extrinsic } from "../types";

let specVersion: SpecVersion;
let specVersion: SpecVersion | undefined;
export async function handleBlock(block: SubstrateBlock): Promise<void> {
// Initialise Spec Version
if (!specVersion) {
Expand All @@ -11,8 +11,10 @@ export async function handleBlock(block: SubstrateBlock): Promise<void> {

// 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();
}

Expand Down Expand Up @@ -47,22 +49,24 @@ 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[] {
Expand All @@ -79,4 +83,4 @@ function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] {
events.findIndex((evt) => evt.event.method === "ExtrinsicSuccess") > -1,
};
});
}
}
10 changes: 6 additions & 4 deletions basilisk/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
"module": "commonjs",
"outDir": "dist",
"rootDir": "src",
"target": "es2017"
"target": "es2017",
"strict": true,
},
"include": [
"src/**/*",
"node_modules/@subql/types/dist/global.d.ts"
]
}
"node_modules/@subql/types-core/dist/global.d.ts",
"node_modules/@subql/types/dist/global.d.ts",
],
}
4 changes: 2 additions & 2 deletions bifrost-parachain/src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EventRecord } from "@polkadot/types/interfaces";
import { SubstrateExtrinsic, SubstrateBlock } from "@subql/types";
import { SpecVersion, Event, Extrinsic } from "../types";

let specVersion: SpecVersion;
let specVersion: SpecVersion | undefined;
export async function handleBlock(block: SubstrateBlock): Promise<void> {
// Initialise Spec Version
if (!specVersion) {
Expand Down Expand Up @@ -82,4 +82,4 @@ function wrapExtrinsics(wrappedBlock: SubstrateBlock): SubstrateExtrinsic[] {
events.findIndex((evt) => evt.event.method === "ExtrinsicSuccess") > -1,
};
});
}
}
Loading