Skip to content

Commit 46c00d4

Browse files
authored
Adjust known lookup with support for [u8;32] (#5764)
1 parent 2d26e74 commit 46c00d4

File tree

1 file changed

+39
-15
lines changed
  • packages/types/src/metadata/decorate/storage

1 file changed

+39
-15
lines changed

packages/types/src/metadata/decorate/storage/util.ts

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import type { PortableType } from '../../../interfaces/index.js';
55
import type { StorageEntry } from '../../../primitive/types.js';
66
import type { Registry } from '../../../types/index.js';
77

8+
import { getTypeDef } from '@polkadot/types-create';
9+
810
import { createFunction } from './createFunction.js';
911

1012
export interface ManualMetadata {
@@ -18,8 +20,8 @@ interface ManualDefinition {
1820
section: string;
1921
}
2022

21-
function findSiPrimitive (registry: Registry, _prim: string): PortableType | undefined {
22-
const prim = _prim.toLowerCase();
23+
function findSiPrimitive (registry: Registry, type: string): PortableType | undefined {
24+
const prim = type.toLowerCase();
2325

2426
return registry.lookup.types.find((t) =>
2527
(
@@ -32,27 +34,49 @@ function findSiPrimitive (registry: Registry, _prim: string): PortableType | und
3234
);
3335
}
3436

35-
function findSiType (registry: Registry, orig: string): PortableType | undefined {
36-
let portable = findSiPrimitive(registry, orig);
37+
function findSiType (registry: Registry, type: string): PortableType | undefined {
38+
let portable = findSiPrimitive(registry, type);
3739

38-
if (!portable && orig === 'Bytes') {
40+
// some types are either Sequence or Arrays, cater for these
41+
// specifically (these all come from the base substrate known keys)
42+
if (!portable && (type === 'Bytes' || type.startsWith('[u8;'))) {
3943
const u8 = findSiPrimitive(registry, 'u8');
4044

4145
if (u8) {
42-
portable = registry.lookup.types.find((t) =>
43-
(
44-
t.type.def.isSequence &&
45-
t.type.def.asSequence.type.eq(u8.id)
46-
) || (
47-
t.type.def.isHistoricMetaCompat &&
48-
t.type.def.asHistoricMetaCompat.eq(orig)
49-
)
50-
);
46+
if (type === 'Bytes') {
47+
portable = registry.lookup.types.find((t) =>
48+
(
49+
t.type.def.isSequence &&
50+
t.type.def.asSequence.type.eq(u8.id)
51+
) || (
52+
t.type.def.isHistoricMetaCompat &&
53+
t.type.def.asHistoricMetaCompat.eq(type)
54+
)
55+
);
56+
} else {
57+
const td = getTypeDef(type);
58+
59+
portable = registry.lookup.types.find((t) =>
60+
(
61+
t.type.def.isArray &&
62+
t.type.def.asArray.eq({
63+
len: td.length,
64+
type: u8.id
65+
})
66+
) || (
67+
t.type.def.isHistoricMetaCompat &&
68+
t.type.def.asHistoricMetaCompat.eq(type)
69+
)
70+
);
71+
}
5172
}
5273
}
5374

5475
if (!portable) {
55-
console.warn(`Unable to map ${orig} to a lookup index`);
76+
// Not fatal, however if this happens the storage key using this
77+
// type will not return valid values, rather it will most probably
78+
// be decoded incorrectly
79+
console.warn(`Unable to map ${type} to a lookup index`);
5680
}
5781

5882
return portable;

0 commit comments

Comments
 (0)