* 3.2.2

* Patch correctly
This commit is contained in:
Jaco Greeff
2020-12-28 10:07:58 +01:00
committed by GitHub
parent 0d7be67499
commit f34d48ad09
16 changed files with 98 additions and 104 deletions
+4 -10
View File
@@ -1,19 +1,13 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { DispatchError, MetadataLatest } from '@polkadot/types/interfaces';
import type { DispatchErrorModule, MetadataLatest } from '@polkadot/types/interfaces';
import type { Registry } from '@polkadot/types/types';
import type { Errors, ModuleErrors } from '../types';
import { stringCamelCase } from '@polkadot/util';
function isError (dispatchError: DispatchError, sectionIndex: number, errorIndex: number): boolean {
if (!dispatchError.isModule) {
return false;
}
const { error, index } = dispatchError.asModule;
function isError ({ error, index }: DispatchErrorModule, sectionIndex: number, errorIndex: number): boolean {
return index.eq(sectionIndex) && error.eq(errorIndex);
}
@@ -29,8 +23,8 @@ export function decorateErrors (_: Registry, { modules }: MetadataLatest, metaVe
result[stringCamelCase(name)] = errors.reduce((newModule: ModuleErrors, meta, errorIndex): ModuleErrors => {
// we don't camelCase the error name
newModule[meta.name.toString()] = {
is: (dispatchError: DispatchError): boolean =>
isError(dispatchError, sectionIndex, errorIndex),
is: (moduleError: DispatchErrorModule): boolean =>
isError(moduleError, sectionIndex, errorIndex),
meta
};
@@ -2,13 +2,13 @@
// SPDX-License-Identifier: Apache-2.0
import type { MetadataLatest } from '@polkadot/types/interfaces';
import type { AnyTuple, IEventRecord, Registry } from '@polkadot/types/types';
import type { AnyTuple, IEvent, Registry } from '@polkadot/types/types';
import type { Events, ModuleEvents } from '../types';
import { stringCamelCase } from '@polkadot/util';
function isEvent <T extends AnyTuple> (eventRecord: IEventRecord<AnyTuple>, sectionIndex: number, eventIndex: number): eventRecord is IEventRecord<T> {
return eventRecord.event.index[0] === sectionIndex && eventRecord.event.index[0] === eventIndex;
function isEvent <T extends AnyTuple> (event: IEvent<AnyTuple>, sectionIndex: number, eventIndex: number): event is IEvent<T> {
return event.index[0] === sectionIndex && event.index[0] === eventIndex;
}
/** @internal */
@@ -23,7 +23,7 @@ export function decorateEvents (_: Registry, { modules }: MetadataLatest, metaVe
result[stringCamelCase(name)] = events.unwrap().reduce((newModule: ModuleEvents, meta, eventIndex): ModuleEvents => {
// we don't camelCase the event name
newModule[meta.name.toString()] = {
is: <T extends AnyTuple> (eventRecord: IEventRecord<AnyTuple>): eventRecord is IEventRecord<T> =>
is: <T extends AnyTuple> (eventRecord: IEvent<AnyTuple>): eventRecord is IEvent<T> =>
isEvent(eventRecord, sectionIndex, eventIndex),
meta
};
+4 -4
View File
@@ -1,9 +1,9 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { DispatchError, ErrorMetadataLatest, EventMetadataLatest, ModuleConstantMetadataLatest } from '@polkadot/types/interfaces';
import type { DispatchErrorModule, ErrorMetadataLatest, EventMetadataLatest, ModuleConstantMetadataLatest } from '@polkadot/types/interfaces';
import type { StorageEntry } from '@polkadot/types/primitive/types';
import type { AnyTuple, CallFunction, Codec, IEventRecord } from '@polkadot/types/types';
import type { AnyTuple, CallFunction, Codec, IEvent } from '@polkadot/types/types';
export interface ConstantCodec extends Codec {
readonly meta: ModuleConstantMetadataLatest;
@@ -12,13 +12,13 @@ export interface ConstantCodec extends Codec {
export interface IsError {
readonly meta: ErrorMetadataLatest;
is: (dispatchError: DispatchError) => boolean;
is: (moduleError: DispatchErrorModule) => boolean;
}
export interface IsEvent <T extends AnyTuple> {
readonly meta: EventMetadataLatest;
is: (record: IEventRecord<AnyTuple>) => record is IEventRecord<T>;
is: (event: IEvent<AnyTuple>) => event is IEvent<T>;
}
export type ModuleConstants = Record<string, ConstantCodec>;