@polkadot/types/types#IEvent TypeScript Examples

The following examples show how to use @polkadot/types/types#IEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: test-staking.ts    From moonbeam with GNU General Public License v3.0 6 votes vote down vote up
async function getExtrinsicResult(
  context: DevTestContext,
  pallet: string,
  call: string
): Promise<string | null> {
  const signedBlock = await context.polkadotApi.rpc.chain.getBlock();
  const apiAt = await context.polkadotApi.at(signedBlock.block.header.hash);
  const allEvents = await apiAt.query.system.events();

  const extrinsicIndex = signedBlock.block.extrinsics.findIndex(
    (ext) => pallet == ext.method.section && call === ext.method.method
  );
  if (extrinsicIndex === -1) {
    return null;
  }

  const failedEvent = allEvents.find(
    ({ phase, event }) =>
      phase.isApplyExtrinsic &&
      phase.asApplyExtrinsic.eq(extrinsicIndex) &&
      context.polkadotApi.events.system.ExtrinsicFailed.is(event)
  );
  if (!failedEvent) {
    return null;
  }

  const event: IEvent<[SpRuntimeDispatchError, FrameSupportWeightsDispatchInfo]> =
    failedEvent.event as any;
  const [dispatchError, _dispatchInfo] = event.data;
  if (dispatchError.isModule) {
    const decodedError = context.polkadotApi.registry.findMetaError(dispatchError.asModule);
    return decodedError.name;
  }

  return dispatchError.toString();
}
Example #2
Source File: Parachains.tsx    From crust-apps with Apache License 2.0 6 votes vote down vote up
function includeEntry (map: EventMap, event: Event, blockHash: string, blockNumber: BN): void {
  const { descriptor } = (event as unknown as IEvent<[CandidateReceipt]>).data[0];

  if (descriptor) {
    map[descriptor.paraId.toString()] = {
      blockHash,
      blockNumber,
      relayParent: descriptor.relayParent.toHex()
    };
  }
}