1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | function createStorageHasher(registry, hasher) {
|
8 |
|
9 |
|
10 | if (hasher.toNumber() >= 2) {
|
11 | return registry.createTypeUnsafe('StorageHasherV10', [hasher.toNumber() + 1]);
|
12 | }
|
13 |
|
14 | return registry.createTypeUnsafe('StorageHasherV10', [hasher]);
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 | function createStorageType(registry, entryType) {
|
20 | if (entryType.isMap) {
|
21 | return [{ ...entryType.asMap,
|
22 | hasher: createStorageHasher(registry, entryType.asMap.hasher)
|
23 | }, 1];
|
24 | }
|
25 |
|
26 | if (entryType.isDoubleMap) {
|
27 | return [{ ...entryType.asDoubleMap,
|
28 | hasher: createStorageHasher(registry, entryType.asDoubleMap.hasher),
|
29 | key2Hasher: createStorageHasher(registry, entryType.asDoubleMap.key2Hasher)
|
30 | }, 2];
|
31 | }
|
32 |
|
33 | return [entryType.asPlain, 0];
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 | function convertModule(registry, mod) {
|
39 | const storage = mod.storage.unwrapOr(null);
|
40 | return registry.createTypeUnsafe('ModuleMetadataV10', [{ ...mod,
|
41 | storage: storage ? { ...storage,
|
42 | items: storage.items.map(item => ({ ...item,
|
43 | type: registry.createTypeUnsafe('StorageEntryTypeV10', createStorageType(registry, item.type))
|
44 | }))
|
45 | } : null
|
46 | }]);
|
47 | }
|
48 |
|
49 |
|
50 |
|
51 | export function toV10(registry, {
|
52 | modules
|
53 | }) {
|
54 | return registry.createTypeUnsafe('MetadataV10', [{
|
55 | modules: modules.map(mod => convertModule(registry, mod))
|
56 | }]);
|
57 | } |
\ | No newline at end of file |