Create linkage compatible types in V14 conversion (#4816)
* Create linkage compatible types in V14 conversion * Handle Linkage in extractTypes * Linkage fallback type * CHANGELOG
This commit is contained in:
@@ -10,6 +10,7 @@ Changes:
|
||||
- Allow for optional `definitions.ts` in typegen (only use chain)
|
||||
- Optimize `Compact<*>` decoding in Uint8Array streams
|
||||
- Use `I*` interfaces for extrinsic payload getters
|
||||
- Re-add support for historic linked-map queries
|
||||
- Update to latest Substrate, Kusama & Polkadot static metadata
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import type { RpcInterfaceMethod } from './types';
|
||||
import { Observable, publishReplay, refCount } from 'rxjs';
|
||||
|
||||
import { rpcDefinitions } from '@polkadot/types';
|
||||
import { assert, hexToU8a, isFunction, isNull, isUndefined, lazyMethod, logger, memoize, objectSpread, u8aToU8a } from '@polkadot/util';
|
||||
import { assert, hexToU8a, isFunction, isNull, isUndefined, lazyMethod, logger, memoize, objectSpread, u8aConcat, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { drr, refCountDelay } from './util';
|
||||
|
||||
@@ -455,7 +455,10 @@ export class RpcCore {
|
||||
return registry.createTypeUnsafe(type, [
|
||||
isEmpty
|
||||
? meta.fallback
|
||||
? hexToU8a(meta.fallback.toHex())
|
||||
// For old-style Linkage, we add an empty linkage at the end
|
||||
? type.includes('Linkage<')
|
||||
? u8aConcat(hexToU8a(meta.fallback.toHex()), new Uint8Array(2))
|
||||
: hexToU8a(meta.fallback.toHex())
|
||||
: undefined
|
||||
: meta.modifier.isOptional
|
||||
? registry.createTypeUnsafe(type, [input], { blockHash, isPedantic: true })
|
||||
|
||||
@@ -30,7 +30,7 @@ const mapping: Record<TypeDefInfo, (type: string, typeDef: TypeDef) => Extracted
|
||||
[TypeDefInfo.Enum]: extractSubArray,
|
||||
[TypeDefInfo.HashMap]: extractSubArray,
|
||||
[TypeDefInfo.Int]: unhandled,
|
||||
[TypeDefInfo.Linkage]: unhandled,
|
||||
[TypeDefInfo.Linkage]: extractSubSingle,
|
||||
[TypeDefInfo.Null]: unhandled,
|
||||
[TypeDefInfo.Option]: extractSubSingle,
|
||||
[TypeDefInfo.Plain]: (_: string, typeDef: TypeDef) => typeDef.lookupName || typeDef.type,
|
||||
|
||||
@@ -13,6 +13,8 @@ import { knownOrigins } from '../../interfaces/runtime/definitions';
|
||||
|
||||
interface MapDef {
|
||||
hashers: StorageHasherV13[];
|
||||
isLinked: boolean;
|
||||
isOptional: boolean;
|
||||
keys: Type[];
|
||||
value: Type;
|
||||
}
|
||||
@@ -211,7 +213,7 @@ function convertEvents (specs: TypeSpec[], registry: Registry, modName: Text, ev
|
||||
}]);
|
||||
}
|
||||
|
||||
function createMapEntry (specs: TypeSpec[], registry: Registry, sectionTypes: OverrideModuleType, { hashers, keys, value }: MapDef): StorageEntryTypeV14 {
|
||||
function createMapEntry (specs: TypeSpec[], registry: Registry, sectionTypes: OverrideModuleType, { hashers, isLinked, isOptional, keys, value }: MapDef): StorageEntryTypeV14 {
|
||||
setTypeOverride(sectionTypes, [value, ...(Array.isArray(keys) ? keys : [keys])]);
|
||||
|
||||
return registry.createTypeUnsafe('StorageEntryTypeV14', [{
|
||||
@@ -220,7 +222,11 @@ function createMapEntry (specs: TypeSpec[], registry: Registry, sectionTypes: Ov
|
||||
key: hashers.length === 1
|
||||
? compatType(specs, keys[0])
|
||||
: makeTupleType(specs, keys.map((t) => compatType(specs, t))),
|
||||
value: compatType(specs, value)
|
||||
value: isLinked
|
||||
// For previous-generation linked-map support, the actual storage result
|
||||
// is a Tuple with the value and the Linkage (Option appears in teh value-part only)
|
||||
? compatType(specs, `(${isOptional ? `Option<${value.toString()}>` : value.toString()}, Linkage<${keys[0].toString()}>)`)
|
||||
: compatType(specs, value)
|
||||
}
|
||||
}]);
|
||||
}
|
||||
@@ -247,6 +253,8 @@ function convertStorage (specs: TypeSpec[], registry: Registry, { items, prefix
|
||||
|
||||
entryType = createMapEntry(specs, registry, sectionTypes, {
|
||||
hashers: [map.hasher],
|
||||
isLinked: map.linked.isTrue,
|
||||
isOptional: modifier.isOptional,
|
||||
keys: [map.key],
|
||||
value: map.value
|
||||
});
|
||||
@@ -255,6 +263,8 @@ function convertStorage (specs: TypeSpec[], registry: Registry, { items, prefix
|
||||
|
||||
entryType = createMapEntry(specs, registry, sectionTypes, {
|
||||
hashers: [dm.hasher, dm.key2Hasher],
|
||||
isLinked: false,
|
||||
isOptional: modifier.isOptional,
|
||||
keys: [dm.key1, dm.key2],
|
||||
value: dm.value
|
||||
});
|
||||
@@ -263,6 +273,8 @@ function convertStorage (specs: TypeSpec[], registry: Registry, { items, prefix
|
||||
|
||||
entryType = createMapEntry(specs, registry, sectionTypes, {
|
||||
hashers: nm.hashers,
|
||||
isLinked: false,
|
||||
isOptional: modifier.isOptional,
|
||||
keys: nm.keyVec,
|
||||
value: nm.value
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user