1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.extractStorageArgs = void 0;
|
4 | const util_1 = require("@polkadot/util");
|
5 | function sig({ lookup }, { method, section }, args) {
|
6 | return `${section}.${method}(${args.map((a) => lookup.getTypeDef(a).type).join(', ')})`;
|
7 | }
|
8 | function 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 |
|
25 | return [creator, args];
|
26 | }
|
27 | exports.extractStorageArgs = extractStorageArgs;
|