Mark entities as removed on store remove host API call (#484)

This commit is contained in:
prathamesh0 2023-11-21 16:00:26 +05:30 committed by GitHub
parent 8c44fbbe6d
commit e6b957e921
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 27 deletions

View File

@ -282,19 +282,33 @@ export class Entity {
// Add subgraph entity specific columns. // Add subgraph entity specific columns.
entityObject = this._addSubgraphColumns(subgraphTypeDefs, entityObject, def); entityObject = this._addSubgraphColumns(subgraphTypeDefs, entityObject, def);
// Add is_pruned column. // Add is_pruned, is_removed columns.
entityObject.columns.push({ entityObject.columns.push(
name: 'isPruned', {
pgType: 'boolean', name: 'isPruned',
tsType: 'boolean', pgType: 'boolean',
columnType: 'Column', tsType: 'boolean',
columnOptions: [ columnType: 'Column',
{ columnOptions: [
option: 'default', {
value: false option: 'default',
} value: false
] }
}); ]
},
{
name: 'isRemoved',
pgType: 'boolean',
tsType: 'boolean',
columnType: 'Column',
columnOptions: [
{
option: 'default',
value: false
}
]
}
);
// Add decimalTransformer column option if required. // Add decimalTransformer column option if required.
this._addDecimalTransformerOption(entityObject); this._addDecimalTransformerOption(entityObject);

View File

@ -142,8 +142,6 @@ export class Indexer implements IndexerInterface {
this._storageLayoutMap = new Map(); this._storageLayoutMap = new Map();
this._contractMap = new Map(); this._contractMap = new Map();
this.eventSignaturesMap = new Map(); this.eventSignaturesMap = new Map();
let contractInterface: ethers.utils.Interface;
let eventSignatures: string[];
{{#each contracts as | contract |}} {{#each contracts as | contract |}}
const { abi: {{contract.contractName}}ABI{{#if contract.contractStorageLayout}}, storageLayout: {{contract.contractName}}StorageLayout{{/if}} } = {{contract.contractName}}Artifacts; const { abi: {{contract.contractName}}ABI{{#if contract.contractStorageLayout}}, storageLayout: {{contract.contractName}}StorageLayout{{/if}} } = {{contract.contractName}}Artifacts;
@ -153,15 +151,13 @@ export class Indexer implements IndexerInterface {
assert({{contract.contractName}}ABI); assert({{contract.contractName}}ABI);
this._abiMap.set(KIND_{{capitalize contract.contractName}}, {{contract.contractName}}ABI); this._abiMap.set(KIND_{{capitalize contract.contractName}}, {{contract.contractName}}ABI);
// eslint-disable-next-line prefer-const const {{contract.contractName}}ContractInterface = new ethers.utils.Interface({{contract.contractName}}ABI);
contractInterface = new ethers.utils.Interface({{contract.contractName}}ABI); this._contractMap.set(KIND_{{capitalize contract.contractName}}, {{contract.contractName}}ContractInterface);
this._contractMap.set(KIND_{{capitalize contract.contractName}}, contractInterface);
// eslint-disable-next-line prefer-const const {{contract.contractName}}EventSignatures = Object.values({{contract.contractName}}ContractInterface.events).map(value => {
eventSignatures = Object.values(contractInterface.events).map(value => { return {{contract.contractName}}ContractInterface.getEventTopic(value);
return contractInterface.getEventTopic(value);
}); });
this.eventSignaturesMap.set(KIND_{{capitalize contract.contractName}}, eventSignatures); this.eventSignaturesMap.set(KIND_{{capitalize contract.contractName}}, {{contract.contractName}}EventSignatures);
{{#if contract.contractStorageLayout}} {{#if contract.contractStorageLayout}}
assert({{contract.contractName}}StorageLayout); assert({{contract.contractName}}StorageLayout);

View File

@ -79,7 +79,7 @@ export const instantiate = async (
assert(context.block); assert(context.block);
const entityData = await database.getEntity(entityName, entityId, context.block.blockHash); const entityData = await database.getEntity(entityName, entityId, context.block.blockHash);
if (!entityData) { if (!entityData || entityData.isRemoved) {
return null; return null;
} }
@ -112,6 +112,25 @@ export const instantiate = async (
indexer.updateSubgraphState(context.contractAddress, diffData); 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': (level: number, msg: number) => {
log('log %s | %s', Level[level], __getString(msg)); log('log %s | %s', Level[level], __getString(msg));

View File

@ -935,8 +935,8 @@ export class GraphDatabase {
const entityValuePromises = entityFields.filter(field => { const entityValuePromises = entityFields.filter(field => {
const { propertyName } = field; const { propertyName } = field;
// Filter out blockHash and blockNumber from entity fields to fill the entityInstance (wasm). // Filter out custom fields from entity to fill the entityInstance (wasm).
if (propertyName === 'blockHash' || propertyName === 'blockNumber') { if (['isPruned', 'isRemoved', 'blockHash', 'blockNumber'].includes(propertyName)) {
return false; return false;
} }
@ -1013,7 +1013,7 @@ export class GraphDatabase {
const entityValuePromises = entityFields.map(async (field: any) => { const entityValuePromises = entityFields.map(async (field: any) => {
const { propertyName } = field; const { propertyName } = field;
if (propertyName === 'isPruned') { if (['isPruned', 'isRemoved'].includes(propertyName)) {
return undefined; return undefined;
} }

View File

@ -638,7 +638,7 @@ export const parseEntityValue = async (instanceExports: any, valuePtr: number):
} }
}; };
export const formatEntityValue = async (instanceExports: any, type: string, value: any, isArray: boolean): Promise<any> => { const formatEntityValue = async (instanceExports: any, type: string, value: any, isArray: boolean): Promise<any> => {
let valueToFormat = value; let valueToFormat = value;
let typeName = type; let typeName = type;
if (isArray) { if (isArray) {