Better error messages for misformed queries (#4007)
* Better error messages for misformed queries * Cater for raw function (no meta)
This commit is contained in:
@@ -51,7 +51,7 @@ export function unwrapStorageType (registry: Registry, type: StorageEntryTypeLat
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function decodeStorageKey (value?: string | Uint8Array | StorageKey | StorageEntry | [StorageEntry, unknown[]?]): Decoded {
|
||||
function decodeStorageKey (registry: Registry, value?: string | Uint8Array | StorageKey | StorageEntry | [StorageEntry, unknown[]?]): Decoded {
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
if (value instanceof StorageKey) {
|
||||
return {
|
||||
@@ -73,6 +73,12 @@ function decodeStorageKey (value?: string | Uint8Array | StorageKey | StorageEnt
|
||||
|
||||
assert(isFunction(fn), 'Expected function input for key construction');
|
||||
|
||||
if (fn.meta && fn.meta.type.isMap) {
|
||||
const map = fn.meta.type.asMap;
|
||||
|
||||
assert(Array.isArray(args) && args.length === map.hashers.length, () => `Expected an array of ${map.hashers.length} values as params to a Map query`);
|
||||
}
|
||||
|
||||
return {
|
||||
key: fn(...args),
|
||||
method: fn.method,
|
||||
@@ -168,7 +174,7 @@ export class StorageKey<A extends AnyTuple = AnyTuple> extends Bytes implements
|
||||
private _section?: string;
|
||||
|
||||
constructor (registry: Registry, value?: string | Uint8Array | StorageKey | StorageEntry | [StorageEntry, unknown[]?], override: Partial<StorageKeyExtra> = {}) {
|
||||
const { key, method, section } = decodeStorageKey(value);
|
||||
const { key, method, section } = decodeStorageKey(registry, value);
|
||||
|
||||
super(registry, key);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user