Skip to content

Commit eb6f2b9

Browse files
wip: resolutions
1 parent 2d5ff9e commit eb6f2b9

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/mappings/almanac/registrations.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {attemptHandling, messageId, unprocessedEventHandler} from "../utils";
22
import {CosmosEvent} from "@subql/types-cosmos";
33
import {AlmanacRecord, AlmanacRegistration} from "../../types";
4+
import {cacheAlmanacResolution} from "./resolutions";
45

56
export async function handleAlmanacRegistration(event: CosmosEvent): Promise<void> {
67
await attemptHandling(event, _handleAlmanacRegistration, unprocessedEventHandler);
@@ -57,4 +58,5 @@ async function _handleAlmanacRegistration(event: CosmosEvent): Promise<void> {
5758
blockId: event.block.block.id,
5859
});
5960
await registrationEntity.save();
61+
await cacheAlmanacResolution(address, recordEntity);
6062
}

src/mappings/primitives.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from "./utils";
1111
import {createHash} from "crypto";
1212
import {toBech32} from "@cosmjs/encoding";
13+
import {expireAlmanacResolutionsAtHeight} from "./almanac/resolutions";
1314

1415
export async function handleBlock(block: CosmosBlock): Promise<void> {
1516
await attemptHandling(block, _handleBlock, _handleBlockError);
@@ -30,16 +31,18 @@ export async function handleEvent(event: CosmosEvent): Promise<void> {
3031
async function _handleBlock(block: CosmosBlock): Promise<void> {
3132
logger.info(`[handleBlock] (block.header.height): indexing block ${block.block.header.height}`);
3233

33-
const {id, header: {chainId, height, time}} = block.block;
34+
const {id, header: {chainId, height: _height, time}} = block.block;
3435
const timestamp = new Date(time);
36+
const height = BigInt(_height);
3537
const blockEntity = Block.create({
3638
id,
3739
chainId,
38-
height: BigInt(height),
40+
height,
3941
timestamp
4042
});
4143

4244
await blockEntity.save();
45+
await expireAlmanacResolutionsAtHeight(height);
4346
}
4447

4548
async function _handleTransaction(tx: CosmosTransaction): Promise<void> {

0 commit comments

Comments
 (0)