Sameness check for v12 indexes (#2609)
* Sameness check for indexes * Update with older support
This commit is contained in:
@@ -11,12 +11,15 @@ import createUnchecked from './createUnchecked';
|
||||
|
||||
/** @internal */
|
||||
export default function fromMetadata (registry: Registry, metadata: RegistryMetadata): ModulesWithCalls {
|
||||
return metadata.asLatest.modules
|
||||
const modules = metadata.asLatest.modules;
|
||||
const isIndexed = modules.some(({ index }) => !index.eqn(255));
|
||||
|
||||
return modules
|
||||
.filter(({ calls }) => calls.isSome)
|
||||
.reduce((result, { calls, index, name }: RegistryMetadataModule, _sectionIndex): ModulesWithCalls => {
|
||||
const sectionIndex = index.eqn(255)
|
||||
? _sectionIndex
|
||||
: index.toNumber();
|
||||
const sectionIndex = isIndexed
|
||||
? index.toNumber()
|
||||
: _sectionIndex;
|
||||
const section = stringCamelCase(name.toString());
|
||||
|
||||
result[section] = calls.unwrap().reduce((newModule: Calls, callMetadata, methodIndex): Calls => {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Registry, OverrideModuleType } from '@polkadot/types/types';
|
||||
|
||||
import { getModuleTypes } from '@polkadot/types-known';
|
||||
import { Type } from '@polkadot/types/primitive';
|
||||
import { assert, stringCamelCase } from '@polkadot/util';
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
// TODO Handle consts as well
|
||||
|
||||
@@ -88,11 +88,6 @@ function convertStorage (registry: Registry, { items, prefix }: StorageMetadataV
|
||||
* @internal
|
||||
**/
|
||||
export default function toLatest (registry: Registry, { extrinsic, modules }: MetadataV12): MetadataLatest {
|
||||
const allIndexes = modules.map(({ index }) => index.toNumber());
|
||||
const hasReserved = allIndexes.some((index) => index !== 255) && allIndexes.some((index) => index === 255);
|
||||
|
||||
assert(!hasReserved, 'This API implementation only supports module indexes 0-254, index 255 is marked as reserved');
|
||||
|
||||
return registry.createType('MetadataLatest', {
|
||||
extrinsic,
|
||||
modules: modules.map((mod): ModuleMetadataLatest => {
|
||||
|
||||
Reference in New Issue
Block a user