forked from subquery/cosmos-subql-starter
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc0e6a9
commit e3302c5
Showing
3 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {AlmanacRecord, AlmanacResolution, Block, Event, Transaction} from "../../types"; | ||
import {parseAttributes, WasmdEventAttributesI} from "../utils"; | ||
|
||
export async function cacheAlmanacResolution(contractId: string, agentId: string, record: AlmanacRecord): Promise<void> { | ||
try { | ||
logger.info(`[cacheAlmanacResolution] (recordId ${record.id}): caching record`); | ||
const resolutionEntity = AlmanacResolution.create({ | ||
id: record.id, | ||
agentId, | ||
contractId, | ||
recordId: record.id, | ||
}); | ||
await resolutionEntity.save(); | ||
} catch (error) { | ||
logger.error(`[cacheAlmanacResolution] (recordId: ${record.id}): ${error.stack}`); | ||
} | ||
} | ||
|
||
export async function expireAlmanacResolutionsRelativeToHeight(height: bigint): Promise<void> { | ||
/* for contract in almanac contracts { | ||
* expiryHeight = contract.expiryHeight | ||
* } | ||
*/ | ||
|
||
const blocks = await Block.getByHeight(BigInt(height)); | ||
// const blocks = await Block.getByHeight(BigInt(expiryHeight)); | ||
if (!blocks || blocks.length !== 1) { | ||
logger.error(`[expireAlmanacResolutionAtHeight] (height: ${height}): found ${blocks?.length ?? 0} blocks at that height`); | ||
} | ||
|
||
const events = await Event.getByBlockId(blocks[0].id); | ||
if (!events || events.length !== 1) { | ||
logger.error(`[expireAlmanacResolutionAtHeight] (height: ${height}): found ${events?.length ?? 0} events at that height`); | ||
} | ||
|
||
for (const event of events) { | ||
const attributes = parseAttributes<WasmdEventAttributesI>(event.attributes); | ||
if (!attributes.action || attributes.action !== "register") { | ||
continue; | ||
} | ||
|
||
// NB: recordId is equivalent to ID of register event. | ||
await expireAlmanacResolution(event.id); | ||
} | ||
} | ||
|
||
export async function expireAlmanacResolution(recordId: string): Promise<void> { | ||
try { | ||
logger.info(`[expireAlmanacResolution] (recordId ${recordId}): expiring record`); | ||
await AlmanacResolution.remove(recordId); | ||
} catch (error) { | ||
logger.warn(`[expireAlmanacResolution] (recordId: ${recordId}): ${error.stack}`); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters