|
@@ -1,7 +1,7 @@
|
|
|
-import { DatabaseManager, SubstrateEvent, SubstrateExtrinsic, ExtrinsicArg } from '@joystream/hydra-common'
|
|
|
+import { DatabaseManager, SubstrateEvent } from '@joystream/hydra-common'
|
|
|
import { Bytes } from '@polkadot/types'
|
|
|
import { Codec } from '@polkadot/types/types'
|
|
|
-import { WorkingGroup as WGType, WorkerId, ThreadId } from '@joystream/types/augment/all'
|
|
|
+import { WorkingGroup as WGType, WorkerId } from '@joystream/types/augment/all'
|
|
|
import { Worker, Event, Network, WorkingGroup as WGEntity } from 'query-node/dist/model'
|
|
|
import { BaseModel } from '@joystream/warthog'
|
|
|
import { metaToObject } from '@joystream/metadata-protobuf/utils'
|
|
@@ -89,110 +89,6 @@ export function invalidMetadata(extraInfo: string, data?: unknown): void {
|
|
|
logger.info(errorMessage, data)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-export interface IGenericExtrinsicObject<T> {
|
|
|
- readonly extrinsic: SubstrateExtrinsic
|
|
|
- readonly expectedArgTypes: string[]
|
|
|
- args: T
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-export interface ISudoCallArgs<T> extends ExtrinsicArg {
|
|
|
- args: T
|
|
|
- callIndex: string
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
- Extracts extrinsic arguments from the Substrate event. Supports both direct extrinsic calls and sudo calls.
|
|
|
-*/
|
|
|
-export function extractExtrinsicArgs<DataParams, EventObject extends IGenericExtrinsicObject<DataParams>>(
|
|
|
- rawEvent: SubstrateEvent,
|
|
|
- callFactoryConstructor: new (event: SubstrateEvent) => EventObject,
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- argsIndeces: Record<keyof DataParams, number>
|
|
|
-): EventObject['args'] {
|
|
|
- const CallFactory = callFactoryConstructor
|
|
|
-
|
|
|
-
|
|
|
- if (!rawEvent.extrinsic) {
|
|
|
- throw new Error('Invalid event - no extrinsic set')
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (rawEvent.extrinsic.section !== 'sudo') {
|
|
|
- return new CallFactory(rawEvent).args
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- const callArgs = extractSudoCallParameters<DataParams>(rawEvent)
|
|
|
-
|
|
|
-
|
|
|
- const clearArgs = Object.keys(callArgs.args).reduce((acc, key) => {
|
|
|
- const formattedName = key.replace(/_([a-z])/g, (tmp) => tmp[1].toUpperCase())
|
|
|
-
|
|
|
- acc[formattedName] = callArgs.args[key]
|
|
|
-
|
|
|
- return acc
|
|
|
- }, {} as DataParams)
|
|
|
-
|
|
|
-
|
|
|
- const partialEvent = {
|
|
|
- extrinsic: ({
|
|
|
- args: Object.keys(argsIndeces).reduce((acc, key) => {
|
|
|
- acc[argsIndeces[key]] = {
|
|
|
- value: clearArgs[key],
|
|
|
- }
|
|
|
-
|
|
|
- return acc
|
|
|
- }, [] as unknown[]),
|
|
|
- } as unknown) as SubstrateExtrinsic,
|
|
|
- } as SubstrateEvent
|
|
|
-
|
|
|
-
|
|
|
- const finalArgs = new CallFactory(partialEvent).args
|
|
|
-
|
|
|
- return finalArgs
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
- Extracts extrinsic call parameters used inside of sudo call.
|
|
|
-*/
|
|
|
-export function extractSudoCallParameters<DataParams>(rawEvent: SubstrateEvent): ISudoCallArgs<DataParams> {
|
|
|
- if (!rawEvent.extrinsic) {
|
|
|
- throw new Error('Invalid event - no extrinsic set')
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- const argIndex =
|
|
|
- false ||
|
|
|
- (rawEvent.extrinsic.method === 'sudoAs' && 1) ||
|
|
|
- (rawEvent.extrinsic.method === 'sudo' && 0) ||
|
|
|
- (rawEvent.extrinsic.method === 'sudoUncheckedWeight' && 0)
|
|
|
-
|
|
|
-
|
|
|
- if (argIndex === false) {
|
|
|
-
|
|
|
- throw new Error('Not implemented situation with sudo')
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- const callArgs = (rawEvent.extrinsic.args[argIndex].value as unknown) as ISudoCallArgs<DataParams>
|
|
|
-
|
|
|
- return callArgs
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-type MappingsMemoryCache = {
|
|
|
- lastCreatedProposalThreadId?: ThreadId
|
|
|
-}
|
|
|
-
|
|
|
-export const MemoryCache: MappingsMemoryCache = {}
|
|
|
-
|
|
|
export function deserializeMetadata<T>(
|
|
|
metadataType: AnyMetadataClass<T>,
|
|
|
metadataBytes: Bytes
|