Adjust map header output type with lookup (#4536)
* Adjust map header output type with lookup * Adjust typings
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
# CHANGELOG
|
||||
|
||||
## master
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust map header output type with lookup id
|
||||
|
||||
|
||||
## 7.7.1 Feb 6, 2022
|
||||
|
||||
Upgrade priority: Low. Recommended for users with long-running scripts.
|
||||
|
||||
@@ -75,9 +75,7 @@ describe('createFunction', (): void => {
|
||||
|
||||
expect(
|
||||
u8aToHex(
|
||||
storageFn(
|
||||
'DB2mp5nNhbFN86J9hxoAog8JALMhDXgwvWMxrRMLNUFMEY4'
|
||||
)
|
||||
storageFn('DB2mp5nNhbFN86J9hxoAog8JALMhDXgwvWMxrRMLNUFMEY4')
|
||||
)
|
||||
).toEqual(
|
||||
'0x' +
|
||||
@@ -87,6 +85,9 @@ describe('createFunction', (): void => {
|
||||
'79c598d130209ab0dea15637a5b16be7' + // blake 128
|
||||
'1a7938fede32e1275281b3eee5708706d88444a6dc898a4dec463f1eb298463f' // AccountId
|
||||
);
|
||||
expect(
|
||||
storageFn.iterKey && storageFn.iterKey.meta.type.asPlain.toNumber()
|
||||
).toEqual(0);
|
||||
});
|
||||
|
||||
it('allows creating of known 2 Map keys (with Bytes)', (): void => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { ICompact, INumber } from '@polkadot/types-codec/types';
|
||||
import type { StorageEntryMetadataLatest, StorageHasher } from '../../../interfaces/metadata';
|
||||
import type { StorageEntry } from '../../../primitive/types';
|
||||
import type { StorageEntry, StorageEntryIterator } from '../../../primitive/types';
|
||||
import type { Registry } from '../../../types';
|
||||
|
||||
import { Raw } from '@polkadot/types-codec';
|
||||
@@ -126,22 +126,25 @@ function createWithMeta (registry: Registry, itemFn: CreateItemFn, options: Crea
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function extendHeadMeta (registry: Registry, { meta: { docs, name, type }, section }: CreateItemFn, { method }: StorageEntry, iterFn: (...args: unknown[]) => Raw): (...args: unknown[]) => StorageKey {
|
||||
const outputType = registry.createLookupType(type.asMap.key);
|
||||
|
||||
function extendHeadMeta (registry: Registry, { meta: { docs, name, type }, section }: CreateItemFn, { method }: StorageEntry, iterFn: (...args: unknown[]) => Raw): StorageEntryIterator {
|
||||
// metadata with a fallback value using the type of the key, the normal
|
||||
// meta fallback only applies to actual entry values, create one for head
|
||||
(iterFn as IterFn).meta = registry.createTypeUnsafe('StorageEntryMetadataLatest', [{
|
||||
const meta = registry.createTypeUnsafe<StorageEntryMetadataLatest>('StorageEntryMetadataLatest', [{
|
||||
docs,
|
||||
fallback: registry.createTypeUnsafe('Bytes', []),
|
||||
modifier: registry.createTypeUnsafe('StorageEntryModifierLatest', [1]), // required
|
||||
name,
|
||||
// FIXME???
|
||||
type: registry.createTypeUnsafe('StorageEntryTypeLatest', [outputType, 0])
|
||||
type: registry.createTypeUnsafe('StorageEntryTypeLatest', [type.asMap.key, 0])
|
||||
}]);
|
||||
|
||||
return (...args: unknown[]) =>
|
||||
registry.createTypeUnsafe('StorageKey', [iterFn(...args), { method, section }]);
|
||||
(iterFn as IterFn).meta = meta;
|
||||
|
||||
const fn = (...args: unknown[]) =>
|
||||
registry.createTypeUnsafe<StorageKey>('StorageKey', [iterFn(...args), { method, section }]);
|
||||
|
||||
fn.meta = meta;
|
||||
|
||||
return fn;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
||||
@@ -4,9 +4,14 @@
|
||||
import type { StorageEntryMetadataLatest } from '../interfaces/metadata';
|
||||
import type { Codec } from '../types';
|
||||
|
||||
export interface StorageEntryIterator {
|
||||
(...args: unknown[]): Uint8Array & Codec;
|
||||
meta: StorageEntryMetadataLatest;
|
||||
}
|
||||
|
||||
export interface StorageEntry {
|
||||
(...args: unknown[]): Uint8Array;
|
||||
iterKey?: (...args: unknown[]) => Uint8Array & Codec;
|
||||
iterKey?: StorageEntryIterator;
|
||||
keyPrefix: (...args: unknown[]) => Uint8Array;
|
||||
meta: StorageEntryMetadataLatest;
|
||||
method: string;
|
||||
|
||||
Reference in New Issue
Block a user