Type aliases on a per-module basis (#1740)
* Type aliasses on a per-module basis * Remove test interface * Update wrapper * Move known types to types
This commit is contained in:
@@ -6658,7 +6658,7 @@
|
||||
},
|
||||
{
|
||||
"name": "judgement",
|
||||
"type": "Judgement"
|
||||
"type": "IdentityJudgement"
|
||||
}
|
||||
],
|
||||
"documentation": [
|
||||
|
||||
@@ -6264,7 +6264,7 @@
|
||||
},
|
||||
{
|
||||
"name": "judgement",
|
||||
"type": "Judgement"
|
||||
"type": "IdentityJudgement"
|
||||
}
|
||||
],
|
||||
"documentation": [
|
||||
@@ -7041,7 +7041,7 @@
|
||||
},
|
||||
{
|
||||
"name": "judgement",
|
||||
"type": "Judgement"
|
||||
"type": "SocietyJudgement"
|
||||
}
|
||||
],
|
||||
"documentation": [
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { MetadataV10, MetadataV11, ModuleMetadataV10, ModuleMetadataV11, StorageEntryTypeV10 } from '@polkadot/types/interfaces/metadata';
|
||||
import { OverrideModuleType } from '@polkadot/types/known/types';
|
||||
import { FunctionMetadataV10, FunctionMetadataV11, MetadataV10, MetadataV11, ModuleMetadataV10, ModuleMetadataV11, StorageEntryTypeV10 } from '@polkadot/types/interfaces/metadata';
|
||||
import { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { getModuleTypes } from '@polkadot/types/known';
|
||||
import { createType } from '@polkadot/types';
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
// migrate a storage entry type - only map types are different (with a kind enum)
|
||||
// all return the actual value for the enum, followed by the numeric index
|
||||
@@ -25,11 +28,31 @@ function createStorageType (registry: Registry, entryType: StorageEntryTypeV10):
|
||||
}, 1];
|
||||
}
|
||||
|
||||
// apply module-specific type overrides
|
||||
function convertCalls (registry: Registry, calls: FunctionMetadataV10[], sectionTypes: OverrideModuleType[]): FunctionMetadataV11[] {
|
||||
return calls.map(({ args, documentation, name }): FunctionMetadataV11 => {
|
||||
args.forEach(({ type }): void => {
|
||||
const queued = sectionTypes.find(({ name }): boolean => type.eq(name));
|
||||
|
||||
if (queued) {
|
||||
type.setOverride(queued.override);
|
||||
}
|
||||
});
|
||||
|
||||
return createType(registry, 'FunctionMetadataV11', { args, name, documentation });
|
||||
});
|
||||
}
|
||||
|
||||
function convertModule (registry: Registry, mod: ModuleMetadataV10): ModuleMetadataV11 {
|
||||
const calls = mod.calls.unwrapOr(null);
|
||||
const storage = mod.storage.unwrapOr(null);
|
||||
const sectionTypes = getModuleTypes(stringCamelCase(mod.name.toString())) || [];
|
||||
|
||||
return createType(registry, 'ModuleMetadataV11', {
|
||||
...mod,
|
||||
calls: calls
|
||||
? convertCalls(registry, calls, sectionTypes)
|
||||
: null,
|
||||
storage: storage
|
||||
? {
|
||||
...storage,
|
||||
|
||||
Reference in New Issue
Block a user