Skip to content

Commit

Permalink
Merge pull request #80 from subquery/strict-codegen
Browse files Browse the repository at this point in the history
Update project with strict codegen
  • Loading branch information
bz888 committed May 18, 2023
2 parents 43d4e07 + 82c7c1a commit c79516e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 11 additions & 3 deletions Polkadot/Polkadot-starter/src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import {
} from "@subql/types";
import { StarterEntity } from "../types";
import { Balance } from "@polkadot/types/interfaces";
import assert from "assert";

export async function handleBlock(block: SubstrateBlock): Promise<void> {
//Create a new starterEntity with ID using block hash
let record = new StarterEntity(block.block.header.hash.toString());
let record = new StarterEntity(
block.block.header.hash.toString(),
block.block.header.number.toNumber()
);

//Record block number
record.field1 = block.block.header.number.toNumber();
await record.save();
}

Expand All @@ -24,6 +28,8 @@ export async function handleEvent(event: SubstrateEvent): Promise<void> {
const record = await StarterEntity.get(
event.block.block.header.hash.toString()
);
assert(record, "record does not exist")

record.field2 = account.toString();
//Big integer type Balance of a transfer event
record.field3 = (balance as Balance).toBigInt();
Expand All @@ -34,9 +40,11 @@ export async function handleCall(extrinsic: SubstrateExtrinsic): Promise<void> {
const record = await StarterEntity.get(
extrinsic.block.block.header.hash.toString()
);
assert(record, "record does not exist")

//Date type timestamp
record.field4 = extrinsic.block.timestamp;
//Boolean tyep
//Boolean type
record.field5 = true;
await record.save();
}
3 changes: 2 additions & 1 deletion Polkadot/Polkadot-starter/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"module": "commonjs",
"outDir": "dist",
"rootDir": "src",
"target": "es2017"
"target": "es2017",
"strict": true
},
"include": ["src/**/*", "node_modules/@subql/types/dist/global.d.ts"]
}

0 comments on commit c79516e

Please sign in to comment.