|
@@ -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)
|
|
|
}
|
|
|
|
|
|
-/// //////////////// Sudo extrinsic calls ///////////////////////////////////////
|
|
|
-
|
|
|
-// soft-peg interface for typegen-generated `*Call` types
|
|
|
-export interface IGenericExtrinsicObject<T> {
|
|
|
- readonly extrinsic: SubstrateExtrinsic
|
|
|
- readonly expectedArgTypes: string[]
|
|
|
- args: T
|
|
|
-}
|
|
|
-
|
|
|
-// arguments for calling extrinsic as sudo
|
|
|
-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,
|
|
|
-
|
|
|
- // in ideal world this parameter would not be needed, but there is no way to associate parameters
|
|
|
- // used in sudo to extrinsic parameters without it
|
|
|
- argsIndeces: Record<keyof DataParams, number>
|
|
|
-): EventObject['args'] {
|
|
|
- const CallFactory = callFactoryConstructor
|
|
|
- // this is equal to DataParams but only this notation works properly
|
|
|
- // escape when extrinsic info is not available
|
|
|
- if (!rawEvent.extrinsic) {
|
|
|
- throw new Error('Invalid event - no extrinsic set') // this should never happen
|
|
|
- }
|
|
|
-
|
|
|
- // regural extrinsic call?
|
|
|
- if (rawEvent.extrinsic.section !== 'sudo') {
|
|
|
- return new CallFactory(rawEvent).args
|
|
|
- }
|
|
|
-
|
|
|
- // sudo extrinsic call
|
|
|
-
|
|
|
- const callArgs = extractSudoCallParameters<DataParams>(rawEvent)
|
|
|
-
|
|
|
- // convert naming convention (underscore_names to camelCase)
|
|
|
- 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)
|
|
|
-
|
|
|
- // prepare partial event object
|
|
|
- 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
|
|
|
-
|
|
|
- // create event object and extract processed args
|
|
|
- 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') // this should never happen
|
|
|
- }
|
|
|
-
|
|
|
- // see Substrate's sudo frame for more info about sudo extrinsics and `call` argument index
|
|
|
- const argIndex =
|
|
|
- false ||
|
|
|
- (rawEvent.extrinsic.method === 'sudoAs' && 1) || // who, *call*
|
|
|
- (rawEvent.extrinsic.method === 'sudo' && 0) || // *call*
|
|
|
- (rawEvent.extrinsic.method === 'sudoUncheckedWeight' && 0) // *call*, _weight
|
|
|
-
|
|
|
- // ensure `call` argument was found
|
|
|
- if (argIndex === false) {
|
|
|
- // this could possibly happen in sometime in future if new sudo options are introduced in Substrate
|
|
|
- throw new Error('Not implemented situation with sudo')
|
|
|
- }
|
|
|
-
|
|
|
- // typecast call arguments
|
|
|
- const callArgs = (rawEvent.extrinsic.args[argIndex].value as unknown) as ISudoCallArgs<DataParams>
|
|
|
-
|
|
|
- return callArgs
|
|
|
-}
|
|
|
-
|
|
|
-// FIXME:
|
|
|
-type MappingsMemoryCache = {
|
|
|
- lastCreatedProposalThreadId?: ThreadId
|
|
|
-}
|
|
|
-
|
|
|
-export const MemoryCache: MappingsMemoryCache = {}
|
|
|
-
|
|
|
export function deserializeMetadata<T>(
|
|
|
metadataType: AnyMetadataClass<T>,
|
|
|
metadataBytes: Bytes
|