mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-08 16:54:08 +00:00
Mark entities as removed on store remove host API call (#484)
This commit is contained in:
@@ -79,7 +79,7 @@ export const instantiate = async (
|
||||
assert(context.block);
|
||||
const entityData = await database.getEntity(entityName, entityId, context.block.blockHash);
|
||||
|
||||
if (!entityData) {
|
||||
if (!entityData || entityData.isRemoved) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -112,6 +112,25 @@ export const instantiate = async (
|
||||
indexer.updateSubgraphState(context.contractAddress, diffData);
|
||||
}
|
||||
},
|
||||
'store.remove': async (entity: number, id: number) => {
|
||||
const entityName = __getString(entity);
|
||||
const entityId = __getString(id);
|
||||
|
||||
assert(context.block);
|
||||
const entityData = await database.getEntity(entityName, entityId, context.block.blockHash);
|
||||
|
||||
if (!entityData || entityData.isRemoved) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add an additional entry at block with isRemoved set to true
|
||||
entityData.blockHash = context.block.blockHash;
|
||||
entityData.blockNumber = context.block.blockNumber;
|
||||
entityData.isRemoved = true;
|
||||
|
||||
const dbEntity = await database.saveEntity(entityName, entityData);
|
||||
database.cacheUpdatedEntityByName(entityName, dbEntity);
|
||||
},
|
||||
|
||||
'log.log': (level: number, msg: number) => {
|
||||
log('log %s | %s', Level[level], __getString(msg));
|
||||
|
||||
Reference in New Issue
Block a user