@polkadot/rpc-core 9.5.1 → 9.6.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.js +46 -85
- package/cjs/bundle.js +46 -98
- package/cjs/detectOther.js +0 -3
- package/cjs/detectPackage.js +2 -4
- package/cjs/index.js +0 -3
- package/cjs/packageInfo.js +3 -1
- package/cjs/types/index.js +0 -4
- package/cjs/util/drr.js +4 -9
- package/cjs/util/index.js +0 -6
- package/cjs/util/memo.js +1 -6
- package/cjs/util/refCountDelay.js +0 -5
- package/detectOther.js +1 -0
- package/detectPackage.js +2 -0
- package/index.js +1 -0
- package/package.json +6 -6
- package/packageInfo.js +3 -1
- package/types/index.js +3 -1
- package/util/drr.js +4 -6
- package/util/index.js +1 -0
- package/util/memo.js +1 -1
- package/util/refCountDelay.js +2 -4
package/bundle.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/rpc-core authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { Observable, publishReplay, refCount } from 'rxjs';
|
|
4
5
|
import { rpcDefinitions } from '@polkadot/types';
|
|
5
6
|
import { hexToU8a, isFunction, isNull, isUndefined, lazyMethod, logger, memoize, objectSpread, u8aConcat, u8aToU8a } from '@polkadot/util';
|
|
@@ -20,10 +21,10 @@ const EMPTY_META = {
|
|
|
20
21
|
},
|
|
21
22
|
isMap: false
|
|
22
23
|
}
|
|
23
|
-
};
|
|
24
|
+
};
|
|
24
25
|
|
|
26
|
+
// utility method to create a nicely-formatted error
|
|
25
27
|
/** @internal */
|
|
26
|
-
|
|
27
28
|
function logErrorMessage(method, {
|
|
28
29
|
noErrorLog,
|
|
29
30
|
params,
|
|
@@ -32,7 +33,6 @@ function logErrorMessage(method, {
|
|
|
32
33
|
if (noErrorLog) {
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
35
|
-
|
|
36
36
|
const inputs = params.map(({
|
|
37
37
|
isOptional,
|
|
38
38
|
name,
|
|
@@ -40,12 +40,12 @@ function logErrorMessage(method, {
|
|
|
40
40
|
}) => `${name}${isOptional ? '?' : ''}: ${type}`).join(', ');
|
|
41
41
|
l.error(`${method}(${inputs}): ${type}:: ${error.message}`);
|
|
42
42
|
}
|
|
43
|
-
|
|
44
43
|
function isTreatAsHex(key) {
|
|
45
44
|
// :code is problematic - it does not have the length attached, which is
|
|
46
45
|
// unlike all other storage entries where it is indeed properly encoded
|
|
47
46
|
return ['0x3a636f6465'].includes(key.toHex());
|
|
48
47
|
}
|
|
48
|
+
|
|
49
49
|
/**
|
|
50
50
|
* @name Rpc
|
|
51
51
|
* @summary The API may use a HTTP or WebSockets provider.
|
|
@@ -69,8 +69,6 @@ function isTreatAsHex(key) {
|
|
|
69
69
|
* const rpc = new Rpc(provider);
|
|
70
70
|
* ```
|
|
71
71
|
*/
|
|
72
|
-
|
|
73
|
-
|
|
74
72
|
export class RpcCore {
|
|
75
73
|
#instanceId;
|
|
76
74
|
#registryDefault;
|
|
@@ -79,93 +77,83 @@ export class RpcCore {
|
|
|
79
77
|
#storageCache = new Map();
|
|
80
78
|
mapping = new Map();
|
|
81
79
|
sections = [];
|
|
80
|
+
|
|
82
81
|
/**
|
|
83
82
|
* @constructor
|
|
84
83
|
* Default constructor for the Api Object
|
|
85
84
|
* @param {ProviderInterface} provider An API provider using HTTP or WebSocket
|
|
86
85
|
*/
|
|
87
|
-
|
|
88
86
|
constructor(instanceId, registry, provider, userRpc = {}) {
|
|
89
87
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
90
88
|
if (!provider || !isFunction(provider.send)) {
|
|
91
89
|
throw new Error('Expected Provider to API create');
|
|
92
90
|
}
|
|
93
|
-
|
|
94
91
|
this.#instanceId = instanceId;
|
|
95
92
|
this.#registryDefault = registry;
|
|
96
93
|
this.provider = provider;
|
|
97
|
-
const sectionNames = Object.keys(rpcDefinitions);
|
|
94
|
+
const sectionNames = Object.keys(rpcDefinitions);
|
|
98
95
|
|
|
99
|
-
|
|
96
|
+
// these are the base keys (i.e. part of jsonrpc)
|
|
97
|
+
this.sections.push(...sectionNames);
|
|
100
98
|
|
|
99
|
+
// decorate all interfaces, defined and user on this instance
|
|
101
100
|
this.addUserInterfaces(userRpc);
|
|
102
101
|
}
|
|
102
|
+
|
|
103
103
|
/**
|
|
104
104
|
* @description Returns the connected status of a provider
|
|
105
105
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
106
|
get isConnected() {
|
|
109
107
|
return this.provider.isConnected;
|
|
110
108
|
}
|
|
109
|
+
|
|
111
110
|
/**
|
|
112
111
|
* @description Manually connect from the attached provider
|
|
113
112
|
*/
|
|
114
|
-
|
|
115
|
-
|
|
116
113
|
connect() {
|
|
117
114
|
return this.provider.connect();
|
|
118
115
|
}
|
|
116
|
+
|
|
119
117
|
/**
|
|
120
118
|
* @description Manually disconnect from the attached provider
|
|
121
119
|
*/
|
|
122
|
-
|
|
123
|
-
|
|
124
120
|
disconnect() {
|
|
125
121
|
return this.provider.disconnect();
|
|
126
122
|
}
|
|
123
|
+
|
|
127
124
|
/**
|
|
128
125
|
* @description Sets a registry swap (typically from Api)
|
|
129
126
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
127
|
setRegistrySwap(registrySwap) {
|
|
133
128
|
this.#getBlockRegistry = memoize(registrySwap, {
|
|
134
129
|
getInstanceId: () => this.#instanceId
|
|
135
130
|
});
|
|
136
131
|
}
|
|
132
|
+
|
|
137
133
|
/**
|
|
138
134
|
* @description Sets a function to resolve block hash from block number
|
|
139
135
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
136
|
setResolveBlockHash(resolveBlockHash) {
|
|
143
137
|
this.#getBlockHash = memoize(resolveBlockHash, {
|
|
144
138
|
getInstanceId: () => this.#instanceId
|
|
145
139
|
});
|
|
146
140
|
}
|
|
147
|
-
|
|
148
141
|
addUserInterfaces(userRpc) {
|
|
149
142
|
// add any extra user-defined sections
|
|
150
143
|
this.sections.push(...Object.keys(userRpc).filter(k => !this.sections.includes(k)));
|
|
151
|
-
|
|
152
144
|
for (let s = 0; s < this.sections.length; s++) {
|
|
153
145
|
const section = this.sections[s];
|
|
154
146
|
const defs = objectSpread({}, rpcDefinitions[section], userRpc[section]);
|
|
155
147
|
const methods = Object.keys(defs);
|
|
156
|
-
|
|
157
148
|
for (let m = 0; m < methods.length; m++) {
|
|
158
149
|
const method = methods[m];
|
|
159
150
|
const def = defs[method];
|
|
160
151
|
const jsonrpc = def.endpoint || `${section}_${method}`;
|
|
161
|
-
|
|
162
152
|
if (!this.mapping.has(jsonrpc)) {
|
|
163
153
|
const isSubscription = !!def.pubsub;
|
|
164
|
-
|
|
165
154
|
if (!this[section]) {
|
|
166
155
|
this[section] = {};
|
|
167
156
|
}
|
|
168
|
-
|
|
169
157
|
this.mapping.set(jsonrpc, objectSpread({}, def, {
|
|
170
158
|
isSubscription,
|
|
171
159
|
jsonrpc,
|
|
@@ -177,7 +165,6 @@ export class RpcCore {
|
|
|
177
165
|
}
|
|
178
166
|
}
|
|
179
167
|
}
|
|
180
|
-
|
|
181
168
|
_memomize(creator, def) {
|
|
182
169
|
const memoOpts = {
|
|
183
170
|
getInstanceId: () => this.#instanceId
|
|
@@ -187,36 +174,32 @@ export class RpcCore {
|
|
|
187
174
|
memoized.meta = def;
|
|
188
175
|
return memoized;
|
|
189
176
|
}
|
|
190
|
-
|
|
191
177
|
_formatResult(isScale, registry, blockHash, method, def, params, result) {
|
|
192
178
|
return isScale ? this._formatOutput(registry, blockHash, method, def, params, result) : result;
|
|
193
179
|
}
|
|
194
|
-
|
|
195
180
|
_createMethodSend(section, method, def) {
|
|
196
181
|
const rpcName = def.endpoint || `${section}_${method}`;
|
|
197
182
|
const hashIndex = def.params.findIndex(({
|
|
198
183
|
isHistoric
|
|
199
184
|
}) => isHistoric);
|
|
200
|
-
let memoized = null;
|
|
185
|
+
let memoized = null;
|
|
201
186
|
|
|
187
|
+
// execute the RPC call, doing a registry swap for historic as applicable
|
|
202
188
|
const callWithRegistry = async (isScale, values) => {
|
|
203
189
|
var _this$getBlockHash;
|
|
204
|
-
|
|
205
190
|
const blockId = hashIndex === -1 ? null : values[hashIndex];
|
|
206
|
-
const blockHash = blockId && def.params[hashIndex].type === 'BlockNumber' ? await ((_this$getBlockHash = this.#getBlockHash)
|
|
191
|
+
const blockHash = blockId && def.params[hashIndex].type === 'BlockNumber' ? await ((_this$getBlockHash = this.#getBlockHash) == null ? void 0 : _this$getBlockHash.call(this, blockId)) : blockId;
|
|
207
192
|
const {
|
|
208
193
|
registry
|
|
209
194
|
} = isScale && blockHash && this.#getBlockRegistry ? await this.#getBlockRegistry(u8aToU8a(blockHash)) : {
|
|
210
195
|
registry: this.#registryDefault
|
|
211
196
|
};
|
|
197
|
+
const params = this._formatInputs(registry, null, def, values);
|
|
212
198
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
199
|
+
// only cache .at(<blockHash>) queries, e.g. where valid blockHash was supplied
|
|
216
200
|
const result = await this.provider.send(rpcName, params.map(p => p.toJSON()), !!blockHash);
|
|
217
201
|
return this._formatResult(isScale, registry, blockHash, method, def, params, result);
|
|
218
202
|
};
|
|
219
|
-
|
|
220
203
|
const creator = isScale => (...values) => {
|
|
221
204
|
const isDelayed = isScale && hashIndex !== -1 && !!values[hashIndex];
|
|
222
205
|
return new Observable(observer => {
|
|
@@ -232,24 +215,22 @@ export class RpcCore {
|
|
|
232
215
|
// delete old results from cache
|
|
233
216
|
if (isScale) {
|
|
234
217
|
var _memoized;
|
|
235
|
-
|
|
236
|
-
(_memoized = memoized) === null || _memoized === void 0 ? void 0 : _memoized.unmemoize(...values);
|
|
218
|
+
(_memoized = memoized) == null ? void 0 : _memoized.unmemoize(...values);
|
|
237
219
|
} else {
|
|
238
220
|
var _memoized2;
|
|
239
|
-
|
|
240
|
-
(_memoized2 = memoized) === null || _memoized2 === void 0 ? void 0 : _memoized2.raw.unmemoize(...values);
|
|
221
|
+
(_memoized2 = memoized) == null ? void 0 : _memoized2.raw.unmemoize(...values);
|
|
241
222
|
}
|
|
242
223
|
};
|
|
243
|
-
}).pipe(publishReplay(1),
|
|
224
|
+
}).pipe(publishReplay(1),
|
|
225
|
+
// create a Replay(1)
|
|
244
226
|
isDelayed ? refCountDelay() // Unsubscribe after delay
|
|
245
227
|
: refCount());
|
|
246
228
|
};
|
|
247
|
-
|
|
248
229
|
memoized = this._memomize(creator, def);
|
|
249
230
|
return memoized;
|
|
250
|
-
}
|
|
251
|
-
|
|
231
|
+
}
|
|
252
232
|
|
|
233
|
+
// create a subscriptor, it subscribes once and resolves with the id as subscribe
|
|
253
234
|
_createSubscriber({
|
|
254
235
|
paramsJson,
|
|
255
236
|
subName,
|
|
@@ -263,43 +244,35 @@ export class RpcCore {
|
|
|
263
244
|
});
|
|
264
245
|
});
|
|
265
246
|
}
|
|
266
|
-
|
|
267
247
|
_createMethodSubscribe(section, method, def) {
|
|
268
248
|
const [updateType, subMethod, unsubMethod] = def.pubsub;
|
|
269
249
|
const subName = `${section}_${subMethod}`;
|
|
270
250
|
const unsubName = `${section}_${unsubMethod}`;
|
|
271
251
|
const subType = `${section}_${updateType}`;
|
|
272
252
|
let memoized = null;
|
|
273
|
-
|
|
274
253
|
const creator = isScale => (...values) => {
|
|
275
254
|
return new Observable(observer => {
|
|
276
255
|
// Have at least an empty promise, as used in the unsubscribe
|
|
277
256
|
let subscriptionPromise = Promise.resolve(null);
|
|
278
257
|
const registry = this.#registryDefault;
|
|
279
|
-
|
|
280
258
|
const errorHandler = error => {
|
|
281
259
|
logErrorMessage(method, def, error);
|
|
282
260
|
observer.error(error);
|
|
283
261
|
};
|
|
284
|
-
|
|
285
262
|
try {
|
|
286
263
|
const params = this._formatInputs(registry, null, def, values);
|
|
287
|
-
|
|
288
264
|
const paramsJson = params.map(p => p.toJSON());
|
|
289
|
-
|
|
290
265
|
const update = (error, result) => {
|
|
291
266
|
if (error) {
|
|
292
267
|
logErrorMessage(method, def, error);
|
|
293
268
|
return;
|
|
294
269
|
}
|
|
295
|
-
|
|
296
270
|
try {
|
|
297
271
|
observer.next(this._formatResult(isScale, registry, null, method, def, params, result));
|
|
298
272
|
} catch (error) {
|
|
299
273
|
observer.error(error);
|
|
300
274
|
}
|
|
301
275
|
};
|
|
302
|
-
|
|
303
276
|
subscriptionPromise = this._createSubscriber({
|
|
304
277
|
paramsJson,
|
|
305
278
|
subName,
|
|
@@ -308,46 +281,39 @@ export class RpcCore {
|
|
|
308
281
|
}, errorHandler);
|
|
309
282
|
} catch (error) {
|
|
310
283
|
errorHandler(error);
|
|
311
|
-
}
|
|
312
|
-
|
|
284
|
+
}
|
|
313
285
|
|
|
286
|
+
// Teardown logic
|
|
314
287
|
return () => {
|
|
315
288
|
// Delete from cache, so old results don't hang around
|
|
316
289
|
if (isScale) {
|
|
317
290
|
var _memoized3;
|
|
318
|
-
|
|
319
|
-
(_memoized3 = memoized) === null || _memoized3 === void 0 ? void 0 : _memoized3.unmemoize(...values);
|
|
291
|
+
(_memoized3 = memoized) == null ? void 0 : _memoized3.unmemoize(...values);
|
|
320
292
|
} else {
|
|
321
293
|
var _memoized4;
|
|
294
|
+
(_memoized4 = memoized) == null ? void 0 : _memoized4.raw.unmemoize(...values);
|
|
295
|
+
}
|
|
322
296
|
|
|
323
|
-
|
|
324
|
-
} // Unsubscribe from provider
|
|
325
|
-
|
|
326
|
-
|
|
297
|
+
// Unsubscribe from provider
|
|
327
298
|
subscriptionPromise.then(subscriptionId => isNull(subscriptionId) ? Promise.resolve(false) : this.provider.unsubscribe(subType, unsubName, subscriptionId)).catch(error => logErrorMessage(method, def, error));
|
|
328
299
|
};
|
|
329
300
|
}).pipe(drr());
|
|
330
301
|
};
|
|
331
|
-
|
|
332
302
|
memoized = this._memomize(creator, def);
|
|
333
303
|
return memoized;
|
|
334
304
|
}
|
|
335
|
-
|
|
336
305
|
_formatInputs(registry, blockHash, def, inputs) {
|
|
337
306
|
const reqArgCount = def.params.filter(({
|
|
338
307
|
isOptional
|
|
339
308
|
}) => !isOptional).length;
|
|
340
309
|
const optText = reqArgCount === def.params.length ? '' : ` (${def.params.length - reqArgCount} optional)`;
|
|
341
|
-
|
|
342
310
|
if (inputs.length < reqArgCount || inputs.length > def.params.length) {
|
|
343
311
|
throw new Error(`Expected ${def.params.length} parameters${optText}, ${inputs.length} found instead`);
|
|
344
312
|
}
|
|
345
|
-
|
|
346
313
|
return inputs.map((input, index) => registry.createTypeUnsafe(def.params[index].type, [input], {
|
|
347
314
|
blockHash
|
|
348
315
|
}));
|
|
349
316
|
}
|
|
350
|
-
|
|
351
317
|
_formatOutput(registry, blockHash, method, rpc, params, result) {
|
|
352
318
|
if (rpc.type === 'StorageData') {
|
|
353
319
|
const key = params[0];
|
|
@@ -359,75 +325,71 @@ export class RpcCore {
|
|
|
359
325
|
const mapped = result.map(({
|
|
360
326
|
block,
|
|
361
327
|
changes
|
|
362
|
-
}) => [registry.createType('Hash', block), this._formatStorageSet(registry, block, params[0], changes)]);
|
|
328
|
+
}) => [registry.createType('Hash', block), this._formatStorageSet(registry, block, params[0], changes)]);
|
|
363
329
|
|
|
330
|
+
// we only query at a specific block, not a range - flatten
|
|
364
331
|
return method === 'queryStorageAt' ? mapped[0][1] : mapped;
|
|
365
332
|
}
|
|
366
|
-
|
|
367
333
|
return registry.createTypeUnsafe(rpc.type, [result], {
|
|
368
334
|
blockHash
|
|
369
335
|
});
|
|
370
336
|
}
|
|
371
|
-
|
|
372
337
|
_formatStorageData(registry, blockHash, key, value) {
|
|
373
|
-
const isEmpty = isNull(value);
|
|
374
|
-
// data will be correctly encoded (incl. numbers, excl. :code)
|
|
338
|
+
const isEmpty = isNull(value);
|
|
375
339
|
|
|
340
|
+
// we convert to Uint8Array since it maps to the raw encoding, all
|
|
341
|
+
// data will be correctly encoded (incl. numbers, excl. :code)
|
|
376
342
|
const input = isEmpty ? null : isTreatAsHex(key) ? value : u8aToU8a(value);
|
|
377
343
|
return this._newType(registry, blockHash, key, input, isEmpty);
|
|
378
344
|
}
|
|
379
|
-
|
|
380
345
|
_formatStorageSet(registry, blockHash, keys, changes) {
|
|
381
346
|
// For StorageChangeSet, the changes has the [key, value] mappings
|
|
382
|
-
const withCache = keys.length !== 1;
|
|
347
|
+
const withCache = keys.length !== 1;
|
|
348
|
+
|
|
349
|
+
// multiple return values (via state.storage subscription), decode the values
|
|
383
350
|
// one at a time, all based on the query types. Three values can be returned -
|
|
384
351
|
// - Codec - There is a valid value, non-empty
|
|
385
352
|
// - null - The storage key is empty
|
|
386
|
-
|
|
387
353
|
return keys.reduce((results, key, index) => {
|
|
388
354
|
results.push(this._formatStorageSetEntry(registry, blockHash, key, changes, withCache, index));
|
|
389
355
|
return results;
|
|
390
356
|
}, []);
|
|
391
357
|
}
|
|
392
|
-
|
|
393
358
|
_formatStorageSetEntry(registry, blockHash, key, changes, withCache, entryIndex) {
|
|
394
359
|
const hexKey = key.toHex();
|
|
395
360
|
const found = changes.find(([key]) => key === hexKey);
|
|
396
|
-
const isNotFound = isUndefined(found);
|
|
361
|
+
const isNotFound = isUndefined(found);
|
|
362
|
+
|
|
363
|
+
// if we don't find the value, this is our fallback
|
|
397
364
|
// - in the case of an array of values, fill the hole from the cache
|
|
398
365
|
// - if a single result value, don't fill - it is not an update hole
|
|
399
366
|
// - fallback to an empty option in all cases
|
|
400
|
-
|
|
401
367
|
if (isNotFound && withCache) {
|
|
402
368
|
const cached = this.#storageCache.get(hexKey);
|
|
403
|
-
|
|
404
369
|
if (cached) {
|
|
405
370
|
return cached;
|
|
406
371
|
}
|
|
407
372
|
}
|
|
408
|
-
|
|
409
373
|
const value = isNotFound ? null : found[1];
|
|
410
374
|
const isEmpty = isNull(value);
|
|
411
375
|
const input = isEmpty || isTreatAsHex(key) ? value : u8aToU8a(value);
|
|
376
|
+
const codec = this._newType(registry, blockHash, key, input, isEmpty, entryIndex);
|
|
412
377
|
|
|
413
|
-
|
|
378
|
+
// store the retrieved result - the only issue with this cache is that there is no
|
|
414
379
|
// clearing of it, so very long running processes (not just a couple of hours, longer)
|
|
415
380
|
// will increase memory beyond what is allowed.
|
|
416
|
-
|
|
417
|
-
|
|
418
381
|
this.#storageCache.set(hexKey, codec);
|
|
419
382
|
return codec;
|
|
420
383
|
}
|
|
421
|
-
|
|
422
384
|
_newType(registry, blockHash, key, input, isEmpty, entryIndex = -1) {
|
|
423
385
|
// single return value (via state.getStorage), decode the value based on the
|
|
424
386
|
// outputType that we have specified. Fallback to Raw on nothing
|
|
425
387
|
const type = key.outputType || 'Raw';
|
|
426
388
|
const meta = key.meta || EMPTY_META;
|
|
427
389
|
const entryNum = entryIndex === -1 ? '' : ` entry ${entryIndex}:`;
|
|
428
|
-
|
|
429
390
|
try {
|
|
430
|
-
return registry.createTypeUnsafe(type, [isEmpty ? meta.fallback
|
|
391
|
+
return registry.createTypeUnsafe(type, [isEmpty ? meta.fallback
|
|
392
|
+
// For old-style Linkage, we add an empty linkage at the end
|
|
431
393
|
? type.includes('Linkage<') ? u8aConcat(hexToU8a(meta.fallback.toHex()), new Uint8Array(2)) : hexToU8a(meta.fallback.toHex()) : undefined : meta.modifier.isOptional ? registry.createTypeUnsafe(type, [input], {
|
|
432
394
|
blockHash,
|
|
433
395
|
isPedantic: true
|
|
@@ -440,5 +402,4 @@ export class RpcCore {
|
|
|
440
402
|
throw new Error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:${entryNum}: ${error.message}`);
|
|
441
403
|
}
|
|
442
404
|
}
|
|
443
|
-
|
|
444
405
|
}
|
package/cjs/bundle.js
CHANGED
|
@@ -14,15 +14,10 @@ Object.defineProperty(exports, "packageInfo", {
|
|
|
14
14
|
return _packageInfo.packageInfo;
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
|
-
|
|
18
17
|
var _rxjs = require("rxjs");
|
|
19
|
-
|
|
20
18
|
var _types = require("@polkadot/types");
|
|
21
|
-
|
|
22
19
|
var _util = require("@polkadot/util");
|
|
23
|
-
|
|
24
20
|
var _util2 = require("./util");
|
|
25
|
-
|
|
26
21
|
Object.keys(_util2).forEach(function (key) {
|
|
27
22
|
if (key === "default" || key === "__esModule") return;
|
|
28
23
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -34,11 +29,10 @@ Object.keys(_util2).forEach(function (key) {
|
|
|
34
29
|
}
|
|
35
30
|
});
|
|
36
31
|
});
|
|
37
|
-
|
|
38
32
|
var _packageInfo = require("./packageInfo");
|
|
39
|
-
|
|
40
33
|
// Copyright 2017-2022 @polkadot/rpc-core authors & contributors
|
|
41
34
|
// SPDX-License-Identifier: Apache-2.0
|
|
35
|
+
|
|
42
36
|
const l = (0, _util.logger)('rpc-core');
|
|
43
37
|
const EMPTY_META = {
|
|
44
38
|
fallback: undefined,
|
|
@@ -53,21 +47,19 @@ const EMPTY_META = {
|
|
|
53
47
|
},
|
|
54
48
|
isMap: false
|
|
55
49
|
}
|
|
56
|
-
};
|
|
50
|
+
};
|
|
57
51
|
|
|
52
|
+
// utility method to create a nicely-formatted error
|
|
58
53
|
/** @internal */
|
|
59
|
-
|
|
60
54
|
function logErrorMessage(method, _ref, error) {
|
|
61
55
|
let {
|
|
62
56
|
noErrorLog,
|
|
63
57
|
params,
|
|
64
58
|
type
|
|
65
59
|
} = _ref;
|
|
66
|
-
|
|
67
60
|
if (noErrorLog) {
|
|
68
61
|
return;
|
|
69
62
|
}
|
|
70
|
-
|
|
71
63
|
const inputs = params.map(_ref2 => {
|
|
72
64
|
let {
|
|
73
65
|
isOptional,
|
|
@@ -78,12 +70,12 @@ function logErrorMessage(method, _ref, error) {
|
|
|
78
70
|
}).join(', ');
|
|
79
71
|
l.error(`${method}(${inputs}): ${type}:: ${error.message}`);
|
|
80
72
|
}
|
|
81
|
-
|
|
82
73
|
function isTreatAsHex(key) {
|
|
83
74
|
// :code is problematic - it does not have the length attached, which is
|
|
84
75
|
// unlike all other storage entries where it is indeed properly encoded
|
|
85
76
|
return ['0x3a636f6465'].includes(key.toHex());
|
|
86
77
|
}
|
|
78
|
+
|
|
87
79
|
/**
|
|
88
80
|
* @name Rpc
|
|
89
81
|
* @summary The API may use a HTTP or WebSockets provider.
|
|
@@ -107,8 +99,6 @@ function isTreatAsHex(key) {
|
|
|
107
99
|
* const rpc = new Rpc(provider);
|
|
108
100
|
* ```
|
|
109
101
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
102
|
class RpcCore {
|
|
113
103
|
#instanceId;
|
|
114
104
|
#registryDefault;
|
|
@@ -117,95 +107,84 @@ class RpcCore {
|
|
|
117
107
|
#storageCache = new Map();
|
|
118
108
|
mapping = new Map();
|
|
119
109
|
sections = [];
|
|
110
|
+
|
|
120
111
|
/**
|
|
121
112
|
* @constructor
|
|
122
113
|
* Default constructor for the Api Object
|
|
123
114
|
* @param {ProviderInterface} provider An API provider using HTTP or WebSocket
|
|
124
115
|
*/
|
|
125
|
-
|
|
126
116
|
constructor(instanceId, registry, provider) {
|
|
127
117
|
let userRpc = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
128
|
-
|
|
129
118
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
130
119
|
if (!provider || !(0, _util.isFunction)(provider.send)) {
|
|
131
120
|
throw new Error('Expected Provider to API create');
|
|
132
121
|
}
|
|
133
|
-
|
|
134
122
|
this.#instanceId = instanceId;
|
|
135
123
|
this.#registryDefault = registry;
|
|
136
124
|
this.provider = provider;
|
|
137
|
-
const sectionNames = Object.keys(_types.rpcDefinitions);
|
|
125
|
+
const sectionNames = Object.keys(_types.rpcDefinitions);
|
|
138
126
|
|
|
139
|
-
|
|
127
|
+
// these are the base keys (i.e. part of jsonrpc)
|
|
128
|
+
this.sections.push(...sectionNames);
|
|
140
129
|
|
|
130
|
+
// decorate all interfaces, defined and user on this instance
|
|
141
131
|
this.addUserInterfaces(userRpc);
|
|
142
132
|
}
|
|
133
|
+
|
|
143
134
|
/**
|
|
144
135
|
* @description Returns the connected status of a provider
|
|
145
136
|
*/
|
|
146
|
-
|
|
147
|
-
|
|
148
137
|
get isConnected() {
|
|
149
138
|
return this.provider.isConnected;
|
|
150
139
|
}
|
|
140
|
+
|
|
151
141
|
/**
|
|
152
142
|
* @description Manually connect from the attached provider
|
|
153
143
|
*/
|
|
154
|
-
|
|
155
|
-
|
|
156
144
|
connect() {
|
|
157
145
|
return this.provider.connect();
|
|
158
146
|
}
|
|
147
|
+
|
|
159
148
|
/**
|
|
160
149
|
* @description Manually disconnect from the attached provider
|
|
161
150
|
*/
|
|
162
|
-
|
|
163
|
-
|
|
164
151
|
disconnect() {
|
|
165
152
|
return this.provider.disconnect();
|
|
166
153
|
}
|
|
154
|
+
|
|
167
155
|
/**
|
|
168
156
|
* @description Sets a registry swap (typically from Api)
|
|
169
157
|
*/
|
|
170
|
-
|
|
171
|
-
|
|
172
158
|
setRegistrySwap(registrySwap) {
|
|
173
159
|
this.#getBlockRegistry = (0, _util.memoize)(registrySwap, {
|
|
174
160
|
getInstanceId: () => this.#instanceId
|
|
175
161
|
});
|
|
176
162
|
}
|
|
163
|
+
|
|
177
164
|
/**
|
|
178
165
|
* @description Sets a function to resolve block hash from block number
|
|
179
166
|
*/
|
|
180
|
-
|
|
181
|
-
|
|
182
167
|
setResolveBlockHash(resolveBlockHash) {
|
|
183
168
|
this.#getBlockHash = (0, _util.memoize)(resolveBlockHash, {
|
|
184
169
|
getInstanceId: () => this.#instanceId
|
|
185
170
|
});
|
|
186
171
|
}
|
|
187
|
-
|
|
188
172
|
addUserInterfaces(userRpc) {
|
|
189
173
|
// add any extra user-defined sections
|
|
190
174
|
this.sections.push(...Object.keys(userRpc).filter(k => !this.sections.includes(k)));
|
|
191
|
-
|
|
192
175
|
for (let s = 0; s < this.sections.length; s++) {
|
|
193
176
|
const section = this.sections[s];
|
|
194
177
|
const defs = (0, _util.objectSpread)({}, _types.rpcDefinitions[section], userRpc[section]);
|
|
195
178
|
const methods = Object.keys(defs);
|
|
196
|
-
|
|
197
179
|
for (let m = 0; m < methods.length; m++) {
|
|
198
180
|
const method = methods[m];
|
|
199
181
|
const def = defs[method];
|
|
200
182
|
const jsonrpc = def.endpoint || `${section}_${method}`;
|
|
201
|
-
|
|
202
183
|
if (!this.mapping.has(jsonrpc)) {
|
|
203
184
|
const isSubscription = !!def.pubsub;
|
|
204
|
-
|
|
205
185
|
if (!this[section]) {
|
|
206
186
|
this[section] = {};
|
|
207
187
|
}
|
|
208
|
-
|
|
209
188
|
this.mapping.set(jsonrpc, (0, _util.objectSpread)({}, def, {
|
|
210
189
|
isSubscription,
|
|
211
190
|
jsonrpc,
|
|
@@ -217,7 +196,6 @@ class RpcCore {
|
|
|
217
196
|
}
|
|
218
197
|
}
|
|
219
198
|
}
|
|
220
|
-
|
|
221
199
|
_memomize(creator, def) {
|
|
222
200
|
const memoOpts = {
|
|
223
201
|
getInstanceId: () => this.#instanceId
|
|
@@ -227,11 +205,9 @@ class RpcCore {
|
|
|
227
205
|
memoized.meta = def;
|
|
228
206
|
return memoized;
|
|
229
207
|
}
|
|
230
|
-
|
|
231
208
|
_formatResult(isScale, registry, blockHash, method, def, params, result) {
|
|
232
209
|
return isScale ? this._formatOutput(registry, blockHash, method, def, params, result) : result;
|
|
233
210
|
}
|
|
234
|
-
|
|
235
211
|
_createMethodSend(section, method, def) {
|
|
236
212
|
const rpcName = def.endpoint || `${section}_${method}`;
|
|
237
213
|
const hashIndex = def.params.findIndex(_ref3 => {
|
|
@@ -240,31 +216,28 @@ class RpcCore {
|
|
|
240
216
|
} = _ref3;
|
|
241
217
|
return isHistoric;
|
|
242
218
|
});
|
|
243
|
-
let memoized = null;
|
|
219
|
+
let memoized = null;
|
|
244
220
|
|
|
221
|
+
// execute the RPC call, doing a registry swap for historic as applicable
|
|
245
222
|
const callWithRegistry = async (isScale, values) => {
|
|
246
223
|
var _this$getBlockHash;
|
|
247
|
-
|
|
248
224
|
const blockId = hashIndex === -1 ? null : values[hashIndex];
|
|
249
|
-
const blockHash = blockId && def.params[hashIndex].type === 'BlockNumber' ? await ((_this$getBlockHash = this.#getBlockHash)
|
|
225
|
+
const blockHash = blockId && def.params[hashIndex].type === 'BlockNumber' ? await ((_this$getBlockHash = this.#getBlockHash) == null ? void 0 : _this$getBlockHash.call(this, blockId)) : blockId;
|
|
250
226
|
const {
|
|
251
227
|
registry
|
|
252
228
|
} = isScale && blockHash && this.#getBlockRegistry ? await this.#getBlockRegistry((0, _util.u8aToU8a)(blockHash)) : {
|
|
253
229
|
registry: this.#registryDefault
|
|
254
230
|
};
|
|
231
|
+
const params = this._formatInputs(registry, null, def, values);
|
|
255
232
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
233
|
+
// only cache .at(<blockHash>) queries, e.g. where valid blockHash was supplied
|
|
259
234
|
const result = await this.provider.send(rpcName, params.map(p => p.toJSON()), !!blockHash);
|
|
260
235
|
return this._formatResult(isScale, registry, blockHash, method, def, params, result);
|
|
261
236
|
};
|
|
262
|
-
|
|
263
237
|
const creator = isScale => function () {
|
|
264
238
|
for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
265
239
|
values[_key] = arguments[_key];
|
|
266
240
|
}
|
|
267
|
-
|
|
268
241
|
const isDelayed = isScale && hashIndex !== -1 && !!values[hashIndex];
|
|
269
242
|
return new _rxjs.Observable(observer => {
|
|
270
243
|
callWithRegistry(isScale, values).then(value => {
|
|
@@ -279,24 +252,22 @@ class RpcCore {
|
|
|
279
252
|
// delete old results from cache
|
|
280
253
|
if (isScale) {
|
|
281
254
|
var _memoized;
|
|
282
|
-
|
|
283
|
-
(_memoized = memoized) === null || _memoized === void 0 ? void 0 : _memoized.unmemoize(...values);
|
|
255
|
+
(_memoized = memoized) == null ? void 0 : _memoized.unmemoize(...values);
|
|
284
256
|
} else {
|
|
285
257
|
var _memoized2;
|
|
286
|
-
|
|
287
|
-
(_memoized2 = memoized) === null || _memoized2 === void 0 ? void 0 : _memoized2.raw.unmemoize(...values);
|
|
258
|
+
(_memoized2 = memoized) == null ? void 0 : _memoized2.raw.unmemoize(...values);
|
|
288
259
|
}
|
|
289
260
|
};
|
|
290
|
-
}).pipe((0, _rxjs.publishReplay)(1),
|
|
261
|
+
}).pipe((0, _rxjs.publishReplay)(1),
|
|
262
|
+
// create a Replay(1)
|
|
291
263
|
isDelayed ? (0, _util2.refCountDelay)() // Unsubscribe after delay
|
|
292
264
|
: (0, _rxjs.refCount)());
|
|
293
265
|
};
|
|
294
|
-
|
|
295
266
|
memoized = this._memomize(creator, def);
|
|
296
267
|
return memoized;
|
|
297
|
-
}
|
|
298
|
-
|
|
268
|
+
}
|
|
299
269
|
|
|
270
|
+
// create a subscriptor, it subscribes once and resolves with the id as subscribe
|
|
300
271
|
_createSubscriber(_ref4, errorHandler) {
|
|
301
272
|
let {
|
|
302
273
|
paramsJson,
|
|
@@ -311,49 +282,39 @@ class RpcCore {
|
|
|
311
282
|
});
|
|
312
283
|
});
|
|
313
284
|
}
|
|
314
|
-
|
|
315
285
|
_createMethodSubscribe(section, method, def) {
|
|
316
286
|
var _this = this;
|
|
317
|
-
|
|
318
287
|
const [updateType, subMethod, unsubMethod] = def.pubsub;
|
|
319
288
|
const subName = `${section}_${subMethod}`;
|
|
320
289
|
const unsubName = `${section}_${unsubMethod}`;
|
|
321
290
|
const subType = `${section}_${updateType}`;
|
|
322
291
|
let memoized = null;
|
|
323
|
-
|
|
324
292
|
const creator = isScale => function () {
|
|
325
293
|
for (var _len2 = arguments.length, values = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
326
294
|
values[_key2] = arguments[_key2];
|
|
327
295
|
}
|
|
328
|
-
|
|
329
296
|
return new _rxjs.Observable(observer => {
|
|
330
297
|
// Have at least an empty promise, as used in the unsubscribe
|
|
331
298
|
let subscriptionPromise = Promise.resolve(null);
|
|
332
299
|
const registry = _this.#registryDefault;
|
|
333
|
-
|
|
334
300
|
const errorHandler = error => {
|
|
335
301
|
logErrorMessage(method, def, error);
|
|
336
302
|
observer.error(error);
|
|
337
303
|
};
|
|
338
|
-
|
|
339
304
|
try {
|
|
340
305
|
const params = _this._formatInputs(registry, null, def, values);
|
|
341
|
-
|
|
342
306
|
const paramsJson = params.map(p => p.toJSON());
|
|
343
|
-
|
|
344
307
|
const update = (error, result) => {
|
|
345
308
|
if (error) {
|
|
346
309
|
logErrorMessage(method, def, error);
|
|
347
310
|
return;
|
|
348
311
|
}
|
|
349
|
-
|
|
350
312
|
try {
|
|
351
313
|
observer.next(_this._formatResult(isScale, registry, null, method, def, params, result));
|
|
352
314
|
} catch (error) {
|
|
353
315
|
observer.error(error);
|
|
354
316
|
}
|
|
355
317
|
};
|
|
356
|
-
|
|
357
318
|
subscriptionPromise = _this._createSubscriber({
|
|
358
319
|
paramsJson,
|
|
359
320
|
subName,
|
|
@@ -362,31 +323,27 @@ class RpcCore {
|
|
|
362
323
|
}, errorHandler);
|
|
363
324
|
} catch (error) {
|
|
364
325
|
errorHandler(error);
|
|
365
|
-
}
|
|
366
|
-
|
|
326
|
+
}
|
|
367
327
|
|
|
328
|
+
// Teardown logic
|
|
368
329
|
return () => {
|
|
369
330
|
// Delete from cache, so old results don't hang around
|
|
370
331
|
if (isScale) {
|
|
371
332
|
var _memoized3;
|
|
372
|
-
|
|
373
|
-
(_memoized3 = memoized) === null || _memoized3 === void 0 ? void 0 : _memoized3.unmemoize(...values);
|
|
333
|
+
(_memoized3 = memoized) == null ? void 0 : _memoized3.unmemoize(...values);
|
|
374
334
|
} else {
|
|
375
335
|
var _memoized4;
|
|
336
|
+
(_memoized4 = memoized) == null ? void 0 : _memoized4.raw.unmemoize(...values);
|
|
337
|
+
}
|
|
376
338
|
|
|
377
|
-
|
|
378
|
-
} // Unsubscribe from provider
|
|
379
|
-
|
|
380
|
-
|
|
339
|
+
// Unsubscribe from provider
|
|
381
340
|
subscriptionPromise.then(subscriptionId => (0, _util.isNull)(subscriptionId) ? Promise.resolve(false) : _this.provider.unsubscribe(subType, unsubName, subscriptionId)).catch(error => logErrorMessage(method, def, error));
|
|
382
341
|
};
|
|
383
342
|
}).pipe((0, _util2.drr)());
|
|
384
343
|
};
|
|
385
|
-
|
|
386
344
|
memoized = this._memomize(creator, def);
|
|
387
345
|
return memoized;
|
|
388
346
|
}
|
|
389
|
-
|
|
390
347
|
_formatInputs(registry, blockHash, def, inputs) {
|
|
391
348
|
const reqArgCount = def.params.filter(_ref5 => {
|
|
392
349
|
let {
|
|
@@ -395,16 +352,13 @@ class RpcCore {
|
|
|
395
352
|
return !isOptional;
|
|
396
353
|
}).length;
|
|
397
354
|
const optText = reqArgCount === def.params.length ? '' : ` (${def.params.length - reqArgCount} optional)`;
|
|
398
|
-
|
|
399
355
|
if (inputs.length < reqArgCount || inputs.length > def.params.length) {
|
|
400
356
|
throw new Error(`Expected ${def.params.length} parameters${optText}, ${inputs.length} found instead`);
|
|
401
357
|
}
|
|
402
|
-
|
|
403
358
|
return inputs.map((input, index) => registry.createTypeUnsafe(def.params[index].type, [input], {
|
|
404
359
|
blockHash
|
|
405
360
|
}));
|
|
406
361
|
}
|
|
407
|
-
|
|
408
362
|
_formatOutput(registry, blockHash, method, rpc, params, result) {
|
|
409
363
|
if (rpc.type === 'StorageData') {
|
|
410
364
|
const key = params[0];
|
|
@@ -419,69 +373,65 @@ class RpcCore {
|
|
|
419
373
|
changes
|
|
420
374
|
} = _ref6;
|
|
421
375
|
return [registry.createType('Hash', block), this._formatStorageSet(registry, block, params[0], changes)];
|
|
422
|
-
});
|
|
376
|
+
});
|
|
423
377
|
|
|
378
|
+
// we only query at a specific block, not a range - flatten
|
|
424
379
|
return method === 'queryStorageAt' ? mapped[0][1] : mapped;
|
|
425
380
|
}
|
|
426
|
-
|
|
427
381
|
return registry.createTypeUnsafe(rpc.type, [result], {
|
|
428
382
|
blockHash
|
|
429
383
|
});
|
|
430
384
|
}
|
|
431
|
-
|
|
432
385
|
_formatStorageData(registry, blockHash, key, value) {
|
|
433
|
-
const isEmpty = (0, _util.isNull)(value);
|
|
434
|
-
// data will be correctly encoded (incl. numbers, excl. :code)
|
|
386
|
+
const isEmpty = (0, _util.isNull)(value);
|
|
435
387
|
|
|
388
|
+
// we convert to Uint8Array since it maps to the raw encoding, all
|
|
389
|
+
// data will be correctly encoded (incl. numbers, excl. :code)
|
|
436
390
|
const input = isEmpty ? null : isTreatAsHex(key) ? value : (0, _util.u8aToU8a)(value);
|
|
437
391
|
return this._newType(registry, blockHash, key, input, isEmpty);
|
|
438
392
|
}
|
|
439
|
-
|
|
440
393
|
_formatStorageSet(registry, blockHash, keys, changes) {
|
|
441
394
|
// For StorageChangeSet, the changes has the [key, value] mappings
|
|
442
|
-
const withCache = keys.length !== 1;
|
|
395
|
+
const withCache = keys.length !== 1;
|
|
396
|
+
|
|
397
|
+
// multiple return values (via state.storage subscription), decode the values
|
|
443
398
|
// one at a time, all based on the query types. Three values can be returned -
|
|
444
399
|
// - Codec - There is a valid value, non-empty
|
|
445
400
|
// - null - The storage key is empty
|
|
446
|
-
|
|
447
401
|
return keys.reduce((results, key, index) => {
|
|
448
402
|
results.push(this._formatStorageSetEntry(registry, blockHash, key, changes, withCache, index));
|
|
449
403
|
return results;
|
|
450
404
|
}, []);
|
|
451
405
|
}
|
|
452
|
-
|
|
453
406
|
_formatStorageSetEntry(registry, blockHash, key, changes, withCache, entryIndex) {
|
|
454
407
|
const hexKey = key.toHex();
|
|
455
408
|
const found = changes.find(_ref7 => {
|
|
456
409
|
let [key] = _ref7;
|
|
457
410
|
return key === hexKey;
|
|
458
411
|
});
|
|
459
|
-
const isNotFound = (0, _util.isUndefined)(found);
|
|
412
|
+
const isNotFound = (0, _util.isUndefined)(found);
|
|
413
|
+
|
|
414
|
+
// if we don't find the value, this is our fallback
|
|
460
415
|
// - in the case of an array of values, fill the hole from the cache
|
|
461
416
|
// - if a single result value, don't fill - it is not an update hole
|
|
462
417
|
// - fallback to an empty option in all cases
|
|
463
|
-
|
|
464
418
|
if (isNotFound && withCache) {
|
|
465
419
|
const cached = this.#storageCache.get(hexKey);
|
|
466
|
-
|
|
467
420
|
if (cached) {
|
|
468
421
|
return cached;
|
|
469
422
|
}
|
|
470
423
|
}
|
|
471
|
-
|
|
472
424
|
const value = isNotFound ? null : found[1];
|
|
473
425
|
const isEmpty = (0, _util.isNull)(value);
|
|
474
426
|
const input = isEmpty || isTreatAsHex(key) ? value : (0, _util.u8aToU8a)(value);
|
|
427
|
+
const codec = this._newType(registry, blockHash, key, input, isEmpty, entryIndex);
|
|
475
428
|
|
|
476
|
-
|
|
429
|
+
// store the retrieved result - the only issue with this cache is that there is no
|
|
477
430
|
// clearing of it, so very long running processes (not just a couple of hours, longer)
|
|
478
431
|
// will increase memory beyond what is allowed.
|
|
479
|
-
|
|
480
|
-
|
|
481
432
|
this.#storageCache.set(hexKey, codec);
|
|
482
433
|
return codec;
|
|
483
434
|
}
|
|
484
|
-
|
|
485
435
|
_newType(registry, blockHash, key, input, isEmpty) {
|
|
486
436
|
let entryIndex = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : -1;
|
|
487
437
|
// single return value (via state.getStorage), decode the value based on the
|
|
@@ -489,9 +439,9 @@ class RpcCore {
|
|
|
489
439
|
const type = key.outputType || 'Raw';
|
|
490
440
|
const meta = key.meta || EMPTY_META;
|
|
491
441
|
const entryNum = entryIndex === -1 ? '' : ` entry ${entryIndex}:`;
|
|
492
|
-
|
|
493
442
|
try {
|
|
494
|
-
return registry.createTypeUnsafe(type, [isEmpty ? meta.fallback
|
|
443
|
+
return registry.createTypeUnsafe(type, [isEmpty ? meta.fallback
|
|
444
|
+
// For old-style Linkage, we add an empty linkage at the end
|
|
495
445
|
? type.includes('Linkage<') ? (0, _util.u8aConcat)((0, _util.hexToU8a)(meta.fallback.toHex()), new Uint8Array(2)) : (0, _util.hexToU8a)(meta.fallback.toHex()) : undefined : meta.modifier.isOptional ? registry.createTypeUnsafe(type, [input], {
|
|
496
446
|
blockHash,
|
|
497
447
|
isPedantic: true
|
|
@@ -504,7 +454,5 @@ class RpcCore {
|
|
|
504
454
|
throw new Error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:${entryNum}: ${error.message}`);
|
|
505
455
|
}
|
|
506
456
|
}
|
|
507
|
-
|
|
508
457
|
}
|
|
509
|
-
|
|
510
458
|
exports.RpcCore = RpcCore;
|
package/cjs/detectOther.js
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _packageInfo = require("@polkadot/rpc-provider/cjs/packageInfo");
|
|
9
|
-
|
|
10
8
|
var _packageInfo2 = require("@polkadot/types/cjs/packageInfo");
|
|
11
|
-
|
|
12
9
|
// Copyright 2017-2022 @polkadot/rpc-core authors & contributors
|
|
13
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
14
11
|
var _default = [_packageInfo.packageInfo, _packageInfo2.packageInfo];
|
package/cjs/detectPackage.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _util = require("@polkadot/util");
|
|
6
|
-
|
|
7
5
|
var _detectOther = _interopRequireDefault(require("./detectOther"));
|
|
8
|
-
|
|
9
6
|
var _packageInfo = require("./packageInfo");
|
|
10
|
-
|
|
11
7
|
// Copyright 2017-2022 @polkadot/rpc-core authors & contributors
|
|
12
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
13
10
|
// Do not edit, auto-generated by @polkadot/dev
|
|
11
|
+
|
|
14
12
|
(0, _util.detectPackage)(_packageInfo.packageInfo, null, _detectOther.default);
|
package/cjs/index.js
CHANGED
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
require("./detectPackage");
|
|
8
|
-
|
|
9
7
|
var _bundle = require("./bundle");
|
|
10
|
-
|
|
11
8
|
Object.keys(_bundle).forEach(function (key) {
|
|
12
9
|
if (key === "default" || key === "__esModule") return;
|
|
13
10
|
if (key in exports && exports[key] === _bundle[key]) return;
|
package/cjs/packageInfo.js
CHANGED
|
@@ -6,11 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.packageInfo = void 0;
|
|
7
7
|
// Copyright 2017-2022 @polkadot/rpc-core authors & contributors
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
9
10
|
// Do not edit, auto-generated by @polkadot/dev
|
|
11
|
+
|
|
10
12
|
const packageInfo = {
|
|
11
13
|
name: '@polkadot/rpc-core',
|
|
12
14
|
path: typeof __dirname === 'string' ? __dirname : 'auto',
|
|
13
15
|
type: 'cjs',
|
|
14
|
-
version: '9.
|
|
16
|
+
version: '9.6.1'
|
|
15
17
|
};
|
|
16
18
|
exports.packageInfo = packageInfo;
|
package/cjs/types/index.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _jsonrpc = require("@polkadot/rpc-core/types/jsonrpc");
|
|
8
|
-
|
|
9
7
|
Object.keys(_jsonrpc).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _jsonrpc[key]) return;
|
|
@@ -16,9 +14,7 @@ Object.keys(_jsonrpc).forEach(function (key) {
|
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
16
|
});
|
|
19
|
-
|
|
20
17
|
var _base = require("./base");
|
|
21
|
-
|
|
22
18
|
Object.keys(_base).forEach(function (key) {
|
|
23
19
|
if (key === "default" || key === "__esModule") return;
|
|
24
20
|
if (key in exports && exports[key] === _base[key]) return;
|
package/cjs/util/drr.js
CHANGED
|
@@ -4,15 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.drr = drr;
|
|
7
|
-
|
|
8
7
|
var _rxjs = require("rxjs");
|
|
9
|
-
|
|
10
8
|
var _util = require("@polkadot/util");
|
|
11
|
-
|
|
12
9
|
var _refCountDelay = require("./refCountDelay");
|
|
13
|
-
|
|
14
10
|
// Copyright 2017-2022 @polkadot/rpc-core authors & contributors
|
|
15
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
16
13
|
function CMP(a, b) {
|
|
17
14
|
return (0, _util.stringify)({
|
|
18
15
|
t: a
|
|
@@ -20,21 +17,19 @@ function CMP(a, b) {
|
|
|
20
17
|
t: b
|
|
21
18
|
});
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
function ERR(error) {
|
|
25
21
|
throw error;
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
function NOOP() {
|
|
24
|
+
// empty
|
|
29
25
|
}
|
|
26
|
+
|
|
30
27
|
/**
|
|
31
28
|
* Shorthand for distinctUntilChanged(), publishReplay(1) and refCount().
|
|
32
29
|
*
|
|
33
30
|
* @ignore
|
|
34
31
|
* @internal
|
|
35
32
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
33
|
function drr() {
|
|
39
34
|
let {
|
|
40
35
|
delay,
|
package/cjs/util/index.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _drr = require("./drr");
|
|
8
|
-
|
|
9
7
|
Object.keys(_drr).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _drr[key]) return;
|
|
@@ -16,9 +14,7 @@ Object.keys(_drr).forEach(function (key) {
|
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
16
|
});
|
|
19
|
-
|
|
20
17
|
var _memo = require("./memo");
|
|
21
|
-
|
|
22
18
|
Object.keys(_memo).forEach(function (key) {
|
|
23
19
|
if (key === "default" || key === "__esModule") return;
|
|
24
20
|
if (key in exports && exports[key] === _memo[key]) return;
|
|
@@ -29,9 +25,7 @@ Object.keys(_memo).forEach(function (key) {
|
|
|
29
25
|
}
|
|
30
26
|
});
|
|
31
27
|
});
|
|
32
|
-
|
|
33
28
|
var _refCountDelay = require("./refCountDelay");
|
|
34
|
-
|
|
35
29
|
Object.keys(_refCountDelay).forEach(function (key) {
|
|
36
30
|
if (key === "default" || key === "__esModule") return;
|
|
37
31
|
if (key in exports && exports[key] === _refCountDelay[key]) return;
|
package/cjs/util/memo.js
CHANGED
|
@@ -4,19 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.memo = memo;
|
|
7
|
-
|
|
8
7
|
var _rxjs = require("rxjs");
|
|
9
|
-
|
|
10
8
|
var _util = require("@polkadot/util");
|
|
11
|
-
|
|
12
9
|
var _drr = require("./drr");
|
|
13
|
-
|
|
14
10
|
// Copyright 2017-2022 @polkadot/api-derive authors & contributors
|
|
15
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
16
13
|
// Wraps a derive, doing 2 things to optimize calls -
|
|
17
14
|
// 1. creates a memo of the inner fn -> Observable, removing when unsubscribed
|
|
18
15
|
// 2. wraps the observable in a drr() (which includes an unsub delay)
|
|
19
|
-
|
|
20
16
|
/** @internal */
|
|
21
17
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
22
18
|
function memo(instanceId, inner) {
|
|
@@ -27,7 +23,6 @@ function memo(instanceId, inner) {
|
|
|
27
23
|
for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
28
24
|
params[_key] = arguments[_key];
|
|
29
25
|
}
|
|
30
|
-
|
|
31
26
|
return new _rxjs.Observable(observer => {
|
|
32
27
|
const subscription = inner(...params).subscribe(observer);
|
|
33
28
|
return () => {
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.refCountDelay = refCountDelay;
|
|
7
|
-
|
|
8
7
|
var _rxjs = require("rxjs");
|
|
9
|
-
|
|
10
8
|
// Copyright 2017-2022 @polkadot/rpc-core authors & contributors
|
|
11
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
10
|
|
|
@@ -18,17 +16,14 @@ function refCountDelay() {
|
|
|
18
16
|
let [state, refCount, connection, scheduler] = [0, 0, _rxjs.Subscription.EMPTY, _rxjs.Subscription.EMPTY];
|
|
19
17
|
return new _rxjs.Observable(ob => {
|
|
20
18
|
source.subscribe(ob);
|
|
21
|
-
|
|
22
19
|
if (refCount++ === 0) {
|
|
23
20
|
if (state === 1) {
|
|
24
21
|
scheduler.unsubscribe();
|
|
25
22
|
} else {
|
|
26
23
|
connection = source.connect();
|
|
27
24
|
}
|
|
28
|
-
|
|
29
25
|
state = 3;
|
|
30
26
|
}
|
|
31
|
-
|
|
32
27
|
return () => {
|
|
33
28
|
if (--refCount === 0) {
|
|
34
29
|
if (state === 2) {
|
package/detectOther.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/rpc-core authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { packageInfo as providerInfo } from '@polkadot/rpc-provider/packageInfo';
|
|
4
5
|
import { packageInfo as typesInfo } from '@polkadot/types/packageInfo';
|
|
5
6
|
export default [providerInfo, typesInfo];
|
package/detectPackage.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/rpc-core authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
// Do not edit, auto-generated by @polkadot/dev
|
|
5
|
+
|
|
4
6
|
import { detectPackage } from '@polkadot/util';
|
|
5
7
|
import others from "./detectOther.js";
|
|
6
8
|
import { packageInfo } from "./packageInfo.js";
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"./cjs/detectPackage.js"
|
|
21
21
|
],
|
|
22
22
|
"type": "module",
|
|
23
|
-
"version": "9.
|
|
23
|
+
"version": "9.6.1",
|
|
24
24
|
"main": "./cjs/index.js",
|
|
25
25
|
"module": "./index.js",
|
|
26
26
|
"types": "./index.d.ts",
|
|
@@ -95,11 +95,11 @@
|
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
"dependencies": {
|
|
98
|
-
"@babel/runtime": "^7.19.
|
|
99
|
-
"@polkadot/rpc-augment": "9.
|
|
100
|
-
"@polkadot/rpc-provider": "9.
|
|
101
|
-
"@polkadot/types": "9.
|
|
102
|
-
"@polkadot/util": "^10.1.
|
|
98
|
+
"@babel/runtime": "^7.19.4",
|
|
99
|
+
"@polkadot/rpc-augment": "9.6.1",
|
|
100
|
+
"@polkadot/rpc-provider": "9.6.1",
|
|
101
|
+
"@polkadot/types": "9.6.1",
|
|
102
|
+
"@polkadot/util": "^10.1.11",
|
|
103
103
|
"rxjs": "^7.5.7"
|
|
104
104
|
}
|
|
105
105
|
}
|
package/packageInfo.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/rpc-core authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
// Do not edit, auto-generated by @polkadot/dev
|
|
5
|
+
|
|
4
6
|
export const packageInfo = {
|
|
5
7
|
name: '@polkadot/rpc-core',
|
|
6
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
7
9
|
type: 'esm',
|
|
8
|
-
version: '9.
|
|
10
|
+
version: '9.6.1'
|
|
9
11
|
};
|
package/types/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/rpc-core authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
// augmented, do an augmentation export
|
|
4
|
-
export * from '@polkadot/rpc-core/types/jsonrpc';
|
|
5
|
+
export * from '@polkadot/rpc-core/types/jsonrpc';
|
|
5
6
|
|
|
7
|
+
// normal exports
|
|
6
8
|
export * from "./base.js";
|
package/util/drr.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/rpc-core authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { catchError, distinctUntilChanged, publishReplay, refCount, tap } from 'rxjs';
|
|
4
5
|
import { stringify } from '@polkadot/util';
|
|
5
6
|
import { refCountDelay } from "./refCountDelay.js";
|
|
6
|
-
|
|
7
7
|
function CMP(a, b) {
|
|
8
8
|
return stringify({
|
|
9
9
|
t: a
|
|
@@ -11,21 +11,19 @@ function CMP(a, b) {
|
|
|
11
11
|
t: b
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
|
-
|
|
15
14
|
function ERR(error) {
|
|
16
15
|
throw error;
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
function NOOP() {
|
|
18
|
+
// empty
|
|
20
19
|
}
|
|
20
|
+
|
|
21
21
|
/**
|
|
22
22
|
* Shorthand for distinctUntilChanged(), publishReplay(1) and refCount().
|
|
23
23
|
*
|
|
24
24
|
* @ignore
|
|
25
25
|
* @internal
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
27
|
export function drr({
|
|
30
28
|
delay,
|
|
31
29
|
skipChange = false,
|
package/util/index.js
CHANGED
package/util/memo.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/api-derive authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { Observable } from 'rxjs';
|
|
4
5
|
import { memoize } from '@polkadot/util';
|
|
5
6
|
import { drr } from "./drr.js";
|
|
6
7
|
// Wraps a derive, doing 2 things to optimize calls -
|
|
7
8
|
// 1. creates a memo of the inner fn -> Observable, removing when unsubscribed
|
|
8
9
|
// 2. wraps the observable in a drr() (which includes an unsub delay)
|
|
9
|
-
|
|
10
10
|
/** @internal */
|
|
11
11
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
12
12
|
export function memo(instanceId, inner) {
|
package/util/refCountDelay.js
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/rpc-core authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { asapScheduler, Observable, Subscription } from 'rxjs';
|
|
4
|
-
/** @internal */
|
|
5
5
|
|
|
6
|
+
/** @internal */
|
|
6
7
|
export function refCountDelay(delay = 1750) {
|
|
7
8
|
return source => {
|
|
8
9
|
// state: 0 = disconnected, 1 = disconnecting, 2 = connecting, 3 = connected
|
|
9
10
|
let [state, refCount, connection, scheduler] = [0, 0, Subscription.EMPTY, Subscription.EMPTY];
|
|
10
11
|
return new Observable(ob => {
|
|
11
12
|
source.subscribe(ob);
|
|
12
|
-
|
|
13
13
|
if (refCount++ === 0) {
|
|
14
14
|
if (state === 1) {
|
|
15
15
|
scheduler.unsubscribe();
|
|
16
16
|
} else {
|
|
17
17
|
connection = source.connect();
|
|
18
18
|
}
|
|
19
|
-
|
|
20
19
|
state = 3;
|
|
21
20
|
}
|
|
22
|
-
|
|
23
21
|
return () => {
|
|
24
22
|
if (--refCount === 0) {
|
|
25
23
|
if (state === 2) {
|