UNPKG

@polkadot/api

Version:

Promise and RxJS wrappers around the Polkadot JS RPC

32 lines (26 loc) 1.14 kB
// Copyright 2017-2022 @polkadot/api authors & contributors // SPDX-License-Identifier: Apache-2.0 import { assert, isUndefined } from '@polkadot/util'; function sig({ lookup }, { method, section }, args) { return `${section}.${method}(${args.map(a => lookup.getTypeDef(a).type).join(', ')})`; } // sets up the arguments in the form of [creator, args] ready to be used in a storage // call. Additionally, it verifies that the correct number of arguments have been passed export function extractStorageArgs(registry, creator, _args) { const args = _args.filter(a => !isUndefined(a)); if (creator.meta.type.isPlain) { assert(args.length === 0, () => `${sig(registry, creator, [])} does not take any arguments, ${args.length} found`); } else { const { hashers, key } = creator.meta.type.asMap; const keys = hashers.length === 1 ? [key] : registry.lookup.getSiType(key).def.asTuple.map(t => t); assert(args.length === keys.length, () => `${sig(registry, creator, keys)} is a map, requiring ${keys.length} arguments, ${args.length} found`); } // pass as tuple return [creator, args]; }