|
@@ -7,6 +7,7 @@ import { ClassEntity } from '../../generated/graphql-server/src/modules/class-en
|
|
|
import { decode } from './decode'
|
|
|
import {
|
|
|
ClassEntityMap,
|
|
|
+ IBatchOperation,
|
|
|
ICategory,
|
|
|
IChannel,
|
|
|
ICreateEntityOperation,
|
|
@@ -85,33 +86,35 @@ async function getNextEntityId(db: DB): Promise<number> {
|
|
|
return e.nextId
|
|
|
}
|
|
|
|
|
|
+// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
|
+export async function contentDirectory_TransactionFailed(db: DB, event: SubstrateEvent): Promise<void> {
|
|
|
+ debug(`TransactionFailed event: ${JSON.stringify(event)}`)
|
|
|
+
|
|
|
+ const failedOperationIndex = event.params[1].value as number
|
|
|
+ const operations = decode.getOperations(event)
|
|
|
+
|
|
|
+ const successfulOperations = operations.toArray().slice(0, failedOperationIndex)
|
|
|
+ if (!successfulOperations.length) return // No succesfull operations
|
|
|
+
|
|
|
+ await applyOperations(decode.getOperationsByTypes(successfulOperations), db, event)
|
|
|
+}
|
|
|
+
|
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
|
export async function contentDirectory_TransactionCompleted(db: DB, event: SubstrateEvent): Promise<void> {
|
|
|
debug(`TransactionCompleted event: ${JSON.stringify(event)}`)
|
|
|
|
|
|
- const { extrinsic, blockNumber: block } = event
|
|
|
- if (!extrinsic) {
|
|
|
- throw Error(`No extrinsic found for the event: ${event.id}`)
|
|
|
- }
|
|
|
-
|
|
|
- const { 1: operations } = extrinsic.args
|
|
|
- if (operations.name.toString() !== 'operations') {
|
|
|
- throw Error(`Could not found 'operations' in the extrinsic.args[1]`)
|
|
|
- }
|
|
|
+ const operations = decode.getOperations(event)
|
|
|
|
|
|
- const {
|
|
|
- addSchemaSupportToEntityOperations,
|
|
|
- createEntityOperations,
|
|
|
- updatePropertyValuesOperations,
|
|
|
- } = decode.getOperations(event)
|
|
|
+ await applyOperations(decode.getOperationsByTypes(operations), db, event)
|
|
|
+}
|
|
|
|
|
|
+async function applyOperations(operations: IBatchOperation, db: DB, event: SubstrateEvent) {
|
|
|
+ const { addSchemaSupportToEntityOperations, createEntityOperations, updatePropertyValuesOperations } = operations
|
|
|
// Create entities before adding schema support
|
|
|
// We need this to know which entity belongs to which class(we will need to know to update/create
|
|
|
// Channel, Video etc.). For example if there is a property update operation there is no class id
|
|
|
- await batchCreateClassEntities(db, block, createEntityOperations)
|
|
|
-
|
|
|
- await batchAddSchemaSupportToEntity(db, createEntityOperations, addSchemaSupportToEntityOperations, block)
|
|
|
-
|
|
|
+ await batchCreateClassEntities(db, event.blockNumber, createEntityOperations)
|
|
|
+ await batchAddSchemaSupportToEntity(db, createEntityOperations, addSchemaSupportToEntityOperations, event.blockNumber)
|
|
|
await batchUpdatePropertyValue(db, createEntityOperations, updatePropertyValuesOperations)
|
|
|
}
|
|
|
|