@polkadot/rpc-core 10.3.4 → 10.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bundle.d.ts CHANGED
@@ -2,6 +2,11 @@ import type { ProviderInterface } from '@polkadot/rpc-provider/types';
2
2
  import type { AnyNumber, DefinitionRpc, DefinitionRpcExt, DefinitionRpcSub, Registry } from '@polkadot/types/types';
3
3
  export { packageInfo } from './packageInfo.js';
4
4
  export * from './util/index.js';
5
+ interface Options {
6
+ isPedantic?: boolean;
7
+ provider: ProviderInterface;
8
+ userRpc?: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>;
9
+ }
5
10
  /**
6
11
  * @name Rpc
7
12
  * @summary The API may use a HTTP or WebSockets provider.
@@ -32,10 +37,10 @@ export declare class RpcCore {
32
37
  readonly sections: string[];
33
38
  /**
34
39
  * @constructor
35
- * Default constructor for the Api Object
36
- * @param {ProviderInterface} provider An API provider using HTTP or WebSocket
40
+ * Default constructor for the core RPC handler
41
+ * @param {ProviderInterface} provider An API provider using any of the supported providers (HTTP, SC or WebSocket)
37
42
  */
38
- constructor(instanceId: string, registry: Registry, provider: ProviderInterface, userRpc?: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>);
43
+ constructor(instanceId: string, registry: Registry, { isPedantic, provider, userRpc }: Options);
39
44
  /**
40
45
  * @description Returns the connected status of a provider
41
46
  */
@@ -64,7 +69,7 @@ export declare class RpcCore {
64
69
  private _createMethodSend;
65
70
  private _createSubscriber;
66
71
  private _createMethodSubscribe;
67
- private _formatInputs;
72
+ private _formatParams;
68
73
  private _formatOutput;
69
74
  private _formatStorageData;
70
75
  private _formatStorageSet;
package/bundle.js CHANGED
@@ -1,5 +1,3 @@
1
- var _RpcCore_instanceId, _RpcCore_registryDefault, _RpcCore_getBlockRegistry, _RpcCore_getBlockHash, _RpcCore_storageCache;
2
- import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
1
  import { Observable, publishReplay, refCount } from 'rxjs';
4
2
  import { rpcDefinitions } from '@polkadot/types';
5
3
  import { hexToU8a, isFunction, isNull, isUndefined, lazyMethod, logger, memoize, objectSpread, u8aConcat, u8aToU8a } from '@polkadot/util';
@@ -20,8 +18,7 @@ function logErrorMessage(method, { noErrorLog, params, type }, error) {
20
18
  if (noErrorLog) {
21
19
  return;
22
20
  }
23
- const inputs = params.map(({ isOptional, name, type }) => `${name}${isOptional ? '?' : ''}: ${type}`).join(', ');
24
- l.error(`${method}(${inputs}): ${type}:: ${error.message}`);
21
+ l.error(`${method}(${params.map(({ isOptional, name, type }) => `${name}${isOptional ? '?' : ''}: ${type}`).join(', ')}): ${type}:: ${error.message}`);
25
22
  }
26
23
  function isTreatAsHex(key) {
27
24
  // :code is problematic - it does not have the length attached, which is
@@ -54,23 +51,20 @@ function isTreatAsHex(key) {
54
51
  export class RpcCore {
55
52
  /**
56
53
  * @constructor
57
- * Default constructor for the Api Object
58
- * @param {ProviderInterface} provider An API provider using HTTP or WebSocket
54
+ * Default constructor for the core RPC handler
55
+ * @param {ProviderInterface} provider An API provider using any of the supported providers (HTTP, SC or WebSocket)
59
56
  */
60
- constructor(instanceId, registry, provider, userRpc = {}) {
61
- _RpcCore_instanceId.set(this, void 0);
62
- _RpcCore_registryDefault.set(this, void 0);
63
- _RpcCore_getBlockRegistry.set(this, void 0);
64
- _RpcCore_getBlockHash.set(this, void 0);
65
- _RpcCore_storageCache.set(this, new Map());
57
+ constructor(instanceId, registry, { isPedantic = true, provider, userRpc = {} }) {
58
+ this.__internal__storageCache = new Map();
66
59
  this.mapping = new Map();
67
60
  this.sections = [];
68
61
  // eslint-disable-next-line @typescript-eslint/unbound-method
69
62
  if (!provider || !isFunction(provider.send)) {
70
63
  throw new Error('Expected Provider to API create');
71
64
  }
72
- __classPrivateFieldSet(this, _RpcCore_instanceId, instanceId, "f");
73
- __classPrivateFieldSet(this, _RpcCore_registryDefault, registry, "f");
65
+ this.__internal__instanceId = instanceId;
66
+ this.__internal__isPedantic = isPedantic;
67
+ this.__internal__registryDefault = registry;
74
68
  this.provider = provider;
75
69
  const sectionNames = Object.keys(rpcDefinitions);
76
70
  // these are the base keys (i.e. part of jsonrpc)
@@ -100,26 +94,26 @@ export class RpcCore {
100
94
  * @description Sets a registry swap (typically from Api)
101
95
  */
102
96
  setRegistrySwap(registrySwap) {
103
- __classPrivateFieldSet(this, _RpcCore_getBlockRegistry, memoize(registrySwap, {
104
- getInstanceId: () => __classPrivateFieldGet(this, _RpcCore_instanceId, "f")
105
- }), "f");
97
+ this.__internal__getBlockRegistry = memoize(registrySwap, {
98
+ getInstanceId: () => this.__internal__instanceId
99
+ });
106
100
  }
107
101
  /**
108
102
  * @description Sets a function to resolve block hash from block number
109
103
  */
110
104
  setResolveBlockHash(resolveBlockHash) {
111
- __classPrivateFieldSet(this, _RpcCore_getBlockHash, memoize(resolveBlockHash, {
112
- getInstanceId: () => __classPrivateFieldGet(this, _RpcCore_instanceId, "f")
113
- }), "f");
105
+ this.__internal__getBlockHash = memoize(resolveBlockHash, {
106
+ getInstanceId: () => this.__internal__instanceId
107
+ });
114
108
  }
115
109
  addUserInterfaces(userRpc) {
116
110
  // add any extra user-defined sections
117
111
  this.sections.push(...Object.keys(userRpc).filter((k) => !this.sections.includes(k)));
118
- for (let s = 0; s < this.sections.length; s++) {
112
+ for (let s = 0, scount = this.sections.length; s < scount; s++) {
119
113
  const section = this.sections[s];
120
114
  const defs = objectSpread({}, rpcDefinitions[section], userRpc[section]);
121
115
  const methods = Object.keys(defs);
122
- for (let m = 0; m < methods.length; m++) {
116
+ for (let m = 0, mcount = methods.length; m < mcount; m++) {
123
117
  const method = methods[m];
124
118
  const def = defs[method];
125
119
  const jsonrpc = def.endpoint || `${section}_${method}`;
@@ -137,7 +131,7 @@ export class RpcCore {
137
131
  }
138
132
  }
139
133
  _memomize(creator, def) {
140
- const memoOpts = { getInstanceId: () => __classPrivateFieldGet(this, _RpcCore_instanceId, "f") };
134
+ const memoOpts = { getInstanceId: () => this.__internal__instanceId };
141
135
  const memoized = memoize(creator(true), memoOpts);
142
136
  memoized.raw = memoize(creator(false), memoOpts);
143
137
  memoized.meta = def;
@@ -158,12 +152,12 @@ export class RpcCore {
158
152
  ? null
159
153
  : values[hashIndex];
160
154
  const blockHash = blockId && def.params[hashIndex].type === 'BlockNumber'
161
- ? await __classPrivateFieldGet(this, _RpcCore_getBlockHash, "f")?.call(this, blockId)
155
+ ? await this.__internal__getBlockHash?.(blockId)
162
156
  : blockId;
163
- const { registry } = isScale && blockHash && __classPrivateFieldGet(this, _RpcCore_getBlockRegistry, "f")
164
- ? await __classPrivateFieldGet(this, _RpcCore_getBlockRegistry, "f").call(this, u8aToU8a(blockHash))
165
- : { registry: __classPrivateFieldGet(this, _RpcCore_registryDefault, "f") };
166
- const params = this._formatInputs(registry, null, def, values);
157
+ const { registry } = isScale && blockHash && this.__internal__getBlockRegistry
158
+ ? await this.__internal__getBlockRegistry(u8aToU8a(blockHash))
159
+ : { registry: this.__internal__registryDefault };
160
+ const params = this._formatParams(registry, null, def, values);
167
161
  // only cache .at(<blockHash>) queries, e.g. where valid blockHash was supplied
168
162
  const result = await this.provider.send(rpcName, params.map((p) => p.toJSON()), !!blockHash);
169
163
  return this._formatResult(isScale, registry, blockHash, method, def, params, result);
@@ -223,14 +217,13 @@ export class RpcCore {
223
217
  return new Observable((observer) => {
224
218
  // Have at least an empty promise, as used in the unsubscribe
225
219
  let subscriptionPromise = Promise.resolve(null);
226
- const registry = __classPrivateFieldGet(this, _RpcCore_registryDefault, "f");
220
+ const registry = this.__internal__registryDefault;
227
221
  const errorHandler = (error) => {
228
222
  logErrorMessage(method, def, error);
229
223
  observer.error(error);
230
224
  };
231
225
  try {
232
- const params = this._formatInputs(registry, null, def, values);
233
- const paramsJson = params.map((p) => p.toJSON());
226
+ const params = this._formatParams(registry, null, def, values);
234
227
  const update = (error, result) => {
235
228
  if (error) {
236
229
  logErrorMessage(method, def, error);
@@ -243,7 +236,7 @@ export class RpcCore {
243
236
  observer.error(error);
244
237
  }
245
238
  };
246
- subscriptionPromise = this._createSubscriber({ paramsJson, subName, subType, update }, errorHandler);
239
+ subscriptionPromise = this._createSubscriber({ paramsJson: params.map((p) => p.toJSON()), subName, subType, update }, errorHandler);
247
240
  }
248
241
  catch (error) {
249
242
  errorHandler(error);
@@ -269,15 +262,17 @@ export class RpcCore {
269
262
  memoized = this._memomize(creator, def);
270
263
  return memoized;
271
264
  }
272
- _formatInputs(registry, blockHash, def, inputs) {
273
- const reqArgCount = def.params.filter(({ isOptional }) => !isOptional).length;
274
- const optText = reqArgCount === def.params.length
275
- ? ''
276
- : ` (${def.params.length - reqArgCount} optional)`;
277
- if (inputs.length < reqArgCount || inputs.length > def.params.length) {
278
- throw new Error(`Expected ${def.params.length} parameters${optText}, ${inputs.length} found instead`);
265
+ _formatParams(registry, blockHash, def, inputs) {
266
+ const count = inputs.length;
267
+ const reqCount = def.params.filter(({ isOptional }) => !isOptional).length;
268
+ if (count < reqCount || count > def.params.length) {
269
+ throw new Error(`Expected ${def.params.length} parameters${reqCount === def.params.length ? '' : ` (${def.params.length - reqCount} optional)`}, ${count} found instead`);
279
270
  }
280
- return inputs.map((input, index) => registry.createTypeUnsafe(def.params[index].type, [input], { blockHash }));
271
+ const params = new Array(count);
272
+ for (let i = 0; i < count; i++) {
273
+ params[i] = registry.createTypeUnsafe(def.params[i].type, [inputs[i]], { blockHash });
274
+ }
275
+ return params;
281
276
  }
282
277
  _formatOutput(registry, blockHash, method, rpc, params, result) {
283
278
  if (rpc.type === 'StorageData') {
@@ -291,10 +286,16 @@ export class RpcCore {
291
286
  : registry.createType('StorageChangeSet', result);
292
287
  }
293
288
  else if (rpc.type === 'Vec<StorageChangeSet>') {
294
- const mapped = result.map(({ block, changes }) => [
295
- registry.createType('Hash', block),
296
- this._formatStorageSet(registry, block, params[0], changes)
297
- ]);
289
+ const jsonSet = result;
290
+ const count = jsonSet.length;
291
+ const mapped = new Array(count);
292
+ for (let i = 0; i < count; i++) {
293
+ const { block, changes } = jsonSet[i];
294
+ mapped[i] = [
295
+ registry.createType('BlockHash', block),
296
+ this._formatStorageSet(registry, block, params[0], changes)
297
+ ];
298
+ }
298
299
  // we only query at a specific block, not a range - flatten
299
300
  return method === 'queryStorageAt'
300
301
  ? mapped[0][1]
@@ -315,15 +316,15 @@ export class RpcCore {
315
316
  }
316
317
  _formatStorageSet(registry, blockHash, keys, changes) {
317
318
  // For StorageChangeSet, the changes has the [key, value] mappings
318
- const withCache = keys.length !== 1;
319
- // multiple return values (via state.storage subscription), decode the values
320
- // one at a time, all based on the query types. Three values can be returned -
321
- // - Codec - There is a valid value, non-empty
322
- // - null - The storage key is empty
323
- return keys.reduce((results, key, index) => {
324
- results.push(this._formatStorageSetEntry(registry, blockHash, key, changes, withCache, index));
325
- return results;
326
- }, []);
319
+ const count = keys.length;
320
+ const withCache = count !== 1;
321
+ const values = new Array(count);
322
+ // multiple return values (via state.storage subscription), decode the
323
+ // values one at a time, all based on the supplied query types
324
+ for (let i = 0; i < count; i++) {
325
+ values[i] = this._formatStorageSetEntry(registry, blockHash, keys[i], changes, withCache, i);
326
+ }
327
+ return values;
327
328
  }
328
329
  _formatStorageSetEntry(registry, blockHash, key, changes, withCache, entryIndex) {
329
330
  const hexKey = key.toHex();
@@ -334,7 +335,7 @@ export class RpcCore {
334
335
  // - if a single result value, don't fill - it is not an update hole
335
336
  // - fallback to an empty option in all cases
336
337
  if (isNotFound && withCache) {
337
- const cached = __classPrivateFieldGet(this, _RpcCore_storageCache, "f").get(hexKey);
338
+ const cached = this.__internal__storageCache.get(hexKey);
338
339
  if (cached) {
339
340
  return cached;
340
341
  }
@@ -350,7 +351,7 @@ export class RpcCore {
350
351
  // store the retrieved result - the only issue with this cache is that there is no
351
352
  // clearing of it, so very long running processes (not just a couple of hours, longer)
352
353
  // will increase memory beyond what is allowed.
353
- __classPrivateFieldGet(this, _RpcCore_storageCache, "f").set(hexKey, codec);
354
+ this.__internal__storageCache.set(hexKey, codec);
354
355
  return codec;
355
356
  }
356
357
  _newType(registry, blockHash, key, input, isEmpty, entryIndex = -1) {
@@ -371,13 +372,12 @@ export class RpcCore {
371
372
  : hexToU8a(meta.fallback.toHex())
372
373
  : undefined
373
374
  : meta.modifier.isOptional
374
- ? registry.createTypeUnsafe(type, [input], { blockHash, isPedantic: true })
375
+ ? registry.createTypeUnsafe(type, [input], { blockHash, isPedantic: this.__internal__isPedantic })
375
376
  : input
376
- ], { blockHash, isFallback: isEmpty && !!meta.fallback, isOptional: meta.modifier.isOptional, isPedantic: !meta.modifier.isOptional });
377
+ ], { blockHash, isFallback: isEmpty && !!meta.fallback, isOptional: meta.modifier.isOptional, isPedantic: this.__internal__isPedantic && !meta.modifier.isOptional });
377
378
  }
378
379
  catch (error) {
379
380
  throw new Error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:${entryNum}: ${error.message}`);
380
381
  }
381
382
  }
382
383
  }
383
- _RpcCore_instanceId = new WeakMap(), _RpcCore_registryDefault = new WeakMap(), _RpcCore_getBlockRegistry = new WeakMap(), _RpcCore_getBlockHash = new WeakMap(), _RpcCore_storageCache = new WeakMap();
package/cjs/bundle.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- var _RpcCore_instanceId, _RpcCore_registryDefault, _RpcCore_getBlockRegistry, _RpcCore_getBlockHash, _RpcCore_storageCache;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.RpcCore = exports.packageInfo = void 0;
5
4
  const tslib_1 = require("tslib");
@@ -24,8 +23,7 @@ function logErrorMessage(method, { noErrorLog, params, type }, error) {
24
23
  if (noErrorLog) {
25
24
  return;
26
25
  }
27
- const inputs = params.map(({ isOptional, name, type }) => `${name}${isOptional ? '?' : ''}: ${type}`).join(', ');
28
- l.error(`${method}(${inputs}): ${type}:: ${error.message}`);
26
+ l.error(`${method}(${params.map(({ isOptional, name, type }) => `${name}${isOptional ? '?' : ''}: ${type}`).join(', ')}): ${type}:: ${error.message}`);
29
27
  }
30
28
  function isTreatAsHex(key) {
31
29
  // :code is problematic - it does not have the length attached, which is
@@ -58,23 +56,20 @@ function isTreatAsHex(key) {
58
56
  class RpcCore {
59
57
  /**
60
58
  * @constructor
61
- * Default constructor for the Api Object
62
- * @param {ProviderInterface} provider An API provider using HTTP or WebSocket
59
+ * Default constructor for the core RPC handler
60
+ * @param {ProviderInterface} provider An API provider using any of the supported providers (HTTP, SC or WebSocket)
63
61
  */
64
- constructor(instanceId, registry, provider, userRpc = {}) {
65
- _RpcCore_instanceId.set(this, void 0);
66
- _RpcCore_registryDefault.set(this, void 0);
67
- _RpcCore_getBlockRegistry.set(this, void 0);
68
- _RpcCore_getBlockHash.set(this, void 0);
69
- _RpcCore_storageCache.set(this, new Map());
62
+ constructor(instanceId, registry, { isPedantic = true, provider, userRpc = {} }) {
63
+ this.__internal__storageCache = new Map();
70
64
  this.mapping = new Map();
71
65
  this.sections = [];
72
66
  // eslint-disable-next-line @typescript-eslint/unbound-method
73
67
  if (!provider || !(0, util_1.isFunction)(provider.send)) {
74
68
  throw new Error('Expected Provider to API create');
75
69
  }
76
- tslib_1.__classPrivateFieldSet(this, _RpcCore_instanceId, instanceId, "f");
77
- tslib_1.__classPrivateFieldSet(this, _RpcCore_registryDefault, registry, "f");
70
+ this.__internal__instanceId = instanceId;
71
+ this.__internal__isPedantic = isPedantic;
72
+ this.__internal__registryDefault = registry;
78
73
  this.provider = provider;
79
74
  const sectionNames = Object.keys(types_1.rpcDefinitions);
80
75
  // these are the base keys (i.e. part of jsonrpc)
@@ -104,26 +99,26 @@ class RpcCore {
104
99
  * @description Sets a registry swap (typically from Api)
105
100
  */
106
101
  setRegistrySwap(registrySwap) {
107
- tslib_1.__classPrivateFieldSet(this, _RpcCore_getBlockRegistry, (0, util_1.memoize)(registrySwap, {
108
- getInstanceId: () => tslib_1.__classPrivateFieldGet(this, _RpcCore_instanceId, "f")
109
- }), "f");
102
+ this.__internal__getBlockRegistry = (0, util_1.memoize)(registrySwap, {
103
+ getInstanceId: () => this.__internal__instanceId
104
+ });
110
105
  }
111
106
  /**
112
107
  * @description Sets a function to resolve block hash from block number
113
108
  */
114
109
  setResolveBlockHash(resolveBlockHash) {
115
- tslib_1.__classPrivateFieldSet(this, _RpcCore_getBlockHash, (0, util_1.memoize)(resolveBlockHash, {
116
- getInstanceId: () => tslib_1.__classPrivateFieldGet(this, _RpcCore_instanceId, "f")
117
- }), "f");
110
+ this.__internal__getBlockHash = (0, util_1.memoize)(resolveBlockHash, {
111
+ getInstanceId: () => this.__internal__instanceId
112
+ });
118
113
  }
119
114
  addUserInterfaces(userRpc) {
120
115
  // add any extra user-defined sections
121
116
  this.sections.push(...Object.keys(userRpc).filter((k) => !this.sections.includes(k)));
122
- for (let s = 0; s < this.sections.length; s++) {
117
+ for (let s = 0, scount = this.sections.length; s < scount; s++) {
123
118
  const section = this.sections[s];
124
119
  const defs = (0, util_1.objectSpread)({}, types_1.rpcDefinitions[section], userRpc[section]);
125
120
  const methods = Object.keys(defs);
126
- for (let m = 0; m < methods.length; m++) {
121
+ for (let m = 0, mcount = methods.length; m < mcount; m++) {
127
122
  const method = methods[m];
128
123
  const def = defs[method];
129
124
  const jsonrpc = def.endpoint || `${section}_${method}`;
@@ -141,7 +136,7 @@ class RpcCore {
141
136
  }
142
137
  }
143
138
  _memomize(creator, def) {
144
- const memoOpts = { getInstanceId: () => tslib_1.__classPrivateFieldGet(this, _RpcCore_instanceId, "f") };
139
+ const memoOpts = { getInstanceId: () => this.__internal__instanceId };
145
140
  const memoized = (0, util_1.memoize)(creator(true), memoOpts);
146
141
  memoized.raw = (0, util_1.memoize)(creator(false), memoOpts);
147
142
  memoized.meta = def;
@@ -162,12 +157,12 @@ class RpcCore {
162
157
  ? null
163
158
  : values[hashIndex];
164
159
  const blockHash = blockId && def.params[hashIndex].type === 'BlockNumber'
165
- ? await tslib_1.__classPrivateFieldGet(this, _RpcCore_getBlockHash, "f")?.call(this, blockId)
160
+ ? await this.__internal__getBlockHash?.(blockId)
166
161
  : blockId;
167
- const { registry } = isScale && blockHash && tslib_1.__classPrivateFieldGet(this, _RpcCore_getBlockRegistry, "f")
168
- ? await tslib_1.__classPrivateFieldGet(this, _RpcCore_getBlockRegistry, "f").call(this, (0, util_1.u8aToU8a)(blockHash))
169
- : { registry: tslib_1.__classPrivateFieldGet(this, _RpcCore_registryDefault, "f") };
170
- const params = this._formatInputs(registry, null, def, values);
162
+ const { registry } = isScale && blockHash && this.__internal__getBlockRegistry
163
+ ? await this.__internal__getBlockRegistry((0, util_1.u8aToU8a)(blockHash))
164
+ : { registry: this.__internal__registryDefault };
165
+ const params = this._formatParams(registry, null, def, values);
171
166
  // only cache .at(<blockHash>) queries, e.g. where valid blockHash was supplied
172
167
  const result = await this.provider.send(rpcName, params.map((p) => p.toJSON()), !!blockHash);
173
168
  return this._formatResult(isScale, registry, blockHash, method, def, params, result);
@@ -227,14 +222,13 @@ class RpcCore {
227
222
  return new rxjs_1.Observable((observer) => {
228
223
  // Have at least an empty promise, as used in the unsubscribe
229
224
  let subscriptionPromise = Promise.resolve(null);
230
- const registry = tslib_1.__classPrivateFieldGet(this, _RpcCore_registryDefault, "f");
225
+ const registry = this.__internal__registryDefault;
231
226
  const errorHandler = (error) => {
232
227
  logErrorMessage(method, def, error);
233
228
  observer.error(error);
234
229
  };
235
230
  try {
236
- const params = this._formatInputs(registry, null, def, values);
237
- const paramsJson = params.map((p) => p.toJSON());
231
+ const params = this._formatParams(registry, null, def, values);
238
232
  const update = (error, result) => {
239
233
  if (error) {
240
234
  logErrorMessage(method, def, error);
@@ -247,7 +241,7 @@ class RpcCore {
247
241
  observer.error(error);
248
242
  }
249
243
  };
250
- subscriptionPromise = this._createSubscriber({ paramsJson, subName, subType, update }, errorHandler);
244
+ subscriptionPromise = this._createSubscriber({ paramsJson: params.map((p) => p.toJSON()), subName, subType, update }, errorHandler);
251
245
  }
252
246
  catch (error) {
253
247
  errorHandler(error);
@@ -273,15 +267,17 @@ class RpcCore {
273
267
  memoized = this._memomize(creator, def);
274
268
  return memoized;
275
269
  }
276
- _formatInputs(registry, blockHash, def, inputs) {
277
- const reqArgCount = def.params.filter(({ isOptional }) => !isOptional).length;
278
- const optText = reqArgCount === def.params.length
279
- ? ''
280
- : ` (${def.params.length - reqArgCount} optional)`;
281
- if (inputs.length < reqArgCount || inputs.length > def.params.length) {
282
- throw new Error(`Expected ${def.params.length} parameters${optText}, ${inputs.length} found instead`);
270
+ _formatParams(registry, blockHash, def, inputs) {
271
+ const count = inputs.length;
272
+ const reqCount = def.params.filter(({ isOptional }) => !isOptional).length;
273
+ if (count < reqCount || count > def.params.length) {
274
+ throw new Error(`Expected ${def.params.length} parameters${reqCount === def.params.length ? '' : ` (${def.params.length - reqCount} optional)`}, ${count} found instead`);
283
275
  }
284
- return inputs.map((input, index) => registry.createTypeUnsafe(def.params[index].type, [input], { blockHash }));
276
+ const params = new Array(count);
277
+ for (let i = 0; i < count; i++) {
278
+ params[i] = registry.createTypeUnsafe(def.params[i].type, [inputs[i]], { blockHash });
279
+ }
280
+ return params;
285
281
  }
286
282
  _formatOutput(registry, blockHash, method, rpc, params, result) {
287
283
  if (rpc.type === 'StorageData') {
@@ -295,10 +291,16 @@ class RpcCore {
295
291
  : registry.createType('StorageChangeSet', result);
296
292
  }
297
293
  else if (rpc.type === 'Vec<StorageChangeSet>') {
298
- const mapped = result.map(({ block, changes }) => [
299
- registry.createType('Hash', block),
300
- this._formatStorageSet(registry, block, params[0], changes)
301
- ]);
294
+ const jsonSet = result;
295
+ const count = jsonSet.length;
296
+ const mapped = new Array(count);
297
+ for (let i = 0; i < count; i++) {
298
+ const { block, changes } = jsonSet[i];
299
+ mapped[i] = [
300
+ registry.createType('BlockHash', block),
301
+ this._formatStorageSet(registry, block, params[0], changes)
302
+ ];
303
+ }
302
304
  // we only query at a specific block, not a range - flatten
303
305
  return method === 'queryStorageAt'
304
306
  ? mapped[0][1]
@@ -319,15 +321,15 @@ class RpcCore {
319
321
  }
320
322
  _formatStorageSet(registry, blockHash, keys, changes) {
321
323
  // For StorageChangeSet, the changes has the [key, value] mappings
322
- const withCache = keys.length !== 1;
323
- // multiple return values (via state.storage subscription), decode the values
324
- // one at a time, all based on the query types. Three values can be returned -
325
- // - Codec - There is a valid value, non-empty
326
- // - null - The storage key is empty
327
- return keys.reduce((results, key, index) => {
328
- results.push(this._formatStorageSetEntry(registry, blockHash, key, changes, withCache, index));
329
- return results;
330
- }, []);
324
+ const count = keys.length;
325
+ const withCache = count !== 1;
326
+ const values = new Array(count);
327
+ // multiple return values (via state.storage subscription), decode the
328
+ // values one at a time, all based on the supplied query types
329
+ for (let i = 0; i < count; i++) {
330
+ values[i] = this._formatStorageSetEntry(registry, blockHash, keys[i], changes, withCache, i);
331
+ }
332
+ return values;
331
333
  }
332
334
  _formatStorageSetEntry(registry, blockHash, key, changes, withCache, entryIndex) {
333
335
  const hexKey = key.toHex();
@@ -338,7 +340,7 @@ class RpcCore {
338
340
  // - if a single result value, don't fill - it is not an update hole
339
341
  // - fallback to an empty option in all cases
340
342
  if (isNotFound && withCache) {
341
- const cached = tslib_1.__classPrivateFieldGet(this, _RpcCore_storageCache, "f").get(hexKey);
343
+ const cached = this.__internal__storageCache.get(hexKey);
342
344
  if (cached) {
343
345
  return cached;
344
346
  }
@@ -354,7 +356,7 @@ class RpcCore {
354
356
  // store the retrieved result - the only issue with this cache is that there is no
355
357
  // clearing of it, so very long running processes (not just a couple of hours, longer)
356
358
  // will increase memory beyond what is allowed.
357
- tslib_1.__classPrivateFieldGet(this, _RpcCore_storageCache, "f").set(hexKey, codec);
359
+ this.__internal__storageCache.set(hexKey, codec);
358
360
  return codec;
359
361
  }
360
362
  _newType(registry, blockHash, key, input, isEmpty, entryIndex = -1) {
@@ -375,9 +377,9 @@ class RpcCore {
375
377
  : (0, util_1.hexToU8a)(meta.fallback.toHex())
376
378
  : undefined
377
379
  : meta.modifier.isOptional
378
- ? registry.createTypeUnsafe(type, [input], { blockHash, isPedantic: true })
380
+ ? registry.createTypeUnsafe(type, [input], { blockHash, isPedantic: this.__internal__isPedantic })
379
381
  : input
380
- ], { blockHash, isFallback: isEmpty && !!meta.fallback, isOptional: meta.modifier.isOptional, isPedantic: !meta.modifier.isOptional });
382
+ ], { blockHash, isFallback: isEmpty && !!meta.fallback, isOptional: meta.modifier.isOptional, isPedantic: this.__internal__isPedantic && !meta.modifier.isOptional });
381
383
  }
382
384
  catch (error) {
383
385
  throw new Error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:${entryNum}: ${error.message}`);
@@ -385,4 +387,3 @@ class RpcCore {
385
387
  }
386
388
  }
387
389
  exports.RpcCore = RpcCore;
388
- _RpcCore_instanceId = new WeakMap(), _RpcCore_registryDefault = new WeakMap(), _RpcCore_getBlockRegistry = new WeakMap(), _RpcCore_getBlockHash = new WeakMap(), _RpcCore_storageCache = new WeakMap();
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.packageInfo = void 0;
4
- exports.packageInfo = { name: '@polkadot/rpc-core', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '10.3.4' };
4
+ exports.packageInfo = { name: '@polkadot/rpc-core', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '10.5.1' };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "bugs": "https://github.com/polkadot-js/api/issues",
4
4
  "description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
5
5
  "engines": {
6
- "node": ">=14"
6
+ "node": ">=16"
7
7
  },
8
8
  "homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-core#readme",
9
9
  "license": "Apache-2.0",
@@ -18,7 +18,7 @@
18
18
  "./cjs/detectPackage.js"
19
19
  ],
20
20
  "type": "module",
21
- "version": "10.3.4",
21
+ "version": "10.5.1",
22
22
  "main": "./cjs/index.js",
23
23
  "module": "./index.js",
24
24
  "types": "./index.d.ts",
@@ -96,11 +96,11 @@
96
96
  }
97
97
  },
98
98
  "dependencies": {
99
- "@polkadot/rpc-augment": "10.3.4",
100
- "@polkadot/rpc-provider": "10.3.4",
101
- "@polkadot/types": "10.3.4",
102
- "@polkadot/util": "^11.1.3",
103
- "rxjs": "^7.8.0",
99
+ "@polkadot/rpc-augment": "10.5.1",
100
+ "@polkadot/rpc-provider": "10.5.1",
101
+ "@polkadot/types": "10.5.1",
102
+ "@polkadot/util": "^12.1.1",
103
+ "rxjs": "^7.8.1",
104
104
  "tslib": "^2.5.0"
105
105
  }
106
106
  }
package/packageInfo.js CHANGED
@@ -1 +1 @@
1
- export const packageInfo = { name: '@polkadot/rpc-core', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '10.3.4' };
1
+ export const packageInfo = { name: '@polkadot/rpc-core', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '10.5.1' };