UNPKG

1.12 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.extractStorageArgs = void 0;
4const util_1 = require("@polkadot/util");
5function sig({ lookup }, { method, section }, args) {
6 return `${section}.${method}(${args.map((a) => lookup.getTypeDef(a).type).join(', ')})`;
7}
8function extractStorageArgs(registry, creator, _args) {
9 const args = _args.filter((a) => !(0, util_1.isUndefined)(a));
10 if (creator.meta.type.isPlain) {
11 if (args.length !== 0) {
12 throw new Error(`${sig(registry, creator, [])} does not take any arguments, ${args.length} found`);
13 }
14 }
15 else {
16 const { hashers, key } = creator.meta.type.asMap;
17 const keys = hashers.length === 1
18 ? [key]
19 : registry.lookup.getSiType(key).def.asTuple.map((t) => t);
20 if (args.length !== keys.length) {
21 throw new Error(`${sig(registry, creator, keys)} is a map, requiring ${keys.length} arguments, ${args.length} found`);
22 }
23 }
24 // pass as tuple
25 return [creator, args];
26}
27exports.extractStorageArgs = extractStorageArgs;