@polkadot/rpc-core 16.4.8 → 16.4.9
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 +2 -1
- package/cjs/bundle.js +21 -20
- package/cjs/packageInfo.js +1 -1
- package/package.json +5 -5
- package/packageInfo.js +1 -1
package/bundle.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Observable, publishReplay, refCount } from 'rxjs';
|
|
2
2
|
import { LRUCache } from '@polkadot/rpc-provider';
|
|
3
3
|
import { rpcDefinitions } from '@polkadot/types';
|
|
4
|
+
import { unwrapStorageSi } from '@polkadot/types/util';
|
|
4
5
|
import { hexToU8a, isFunction, isNull, isUndefined, lazyMethod, logger, memoize, objectSpread, u8aConcat, u8aToU8a } from '@polkadot/util';
|
|
5
6
|
import { drr, refCountDelay } from './util/index.js';
|
|
6
7
|
export { packageInfo } from './packageInfo.js';
|
|
@@ -384,7 +385,7 @@ export class RpcCore {
|
|
|
384
385
|
_newType(registry, blockHash, key, input, isEmpty, entryIndex = -1) {
|
|
385
386
|
// single return value (via state.getStorage), decode the value based on the
|
|
386
387
|
// outputType that we have specified. Fallback to Raw on nothing
|
|
387
|
-
const type = key.outputType || 'Raw';
|
|
388
|
+
const type = key.meta ? registry.createLookupType(unwrapStorageSi(key.meta.type)) : (key.outputType || 'Raw');
|
|
388
389
|
const meta = key.meta || EMPTY_META;
|
|
389
390
|
const entryNum = entryIndex === -1
|
|
390
391
|
? ''
|
package/cjs/bundle.js
CHANGED
|
@@ -5,12 +5,13 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const rxjs_1 = require("rxjs");
|
|
6
6
|
const rpc_provider_1 = require("@polkadot/rpc-provider");
|
|
7
7
|
const types_1 = require("@polkadot/types");
|
|
8
|
-
const util_1 = require("@polkadot/util");
|
|
8
|
+
const util_1 = require("@polkadot/types/util");
|
|
9
|
+
const util_2 = require("@polkadot/util");
|
|
9
10
|
const index_js_1 = require("./util/index.js");
|
|
10
11
|
var packageInfo_js_1 = require("./packageInfo.js");
|
|
11
12
|
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
|
|
12
13
|
tslib_1.__exportStar(require("./util/index.js"), exports);
|
|
13
|
-
const l = (0,
|
|
14
|
+
const l = (0, util_2.logger)('rpc-core');
|
|
14
15
|
const EMPTY_META = {
|
|
15
16
|
fallback: undefined,
|
|
16
17
|
modifier: { isOptional: true },
|
|
@@ -74,7 +75,7 @@ class RpcCore {
|
|
|
74
75
|
* @param {number} [options.rpcCacheCapacity] Custom size of the rpc LRUCache capacity. Defaults to `RPC_CORE_DEFAULT_CAPACITY` (1024 * 10 * 10)
|
|
75
76
|
*/
|
|
76
77
|
constructor(instanceId, registry, { isPedantic = true, provider, rpcCacheCapacity, ttl, userRpc = {} }) {
|
|
77
|
-
if (!provider || !(0,
|
|
78
|
+
if (!provider || !(0, util_2.isFunction)(provider.send)) {
|
|
78
79
|
throw new Error('Expected Provider to API create');
|
|
79
80
|
}
|
|
80
81
|
this.#instanceId = instanceId;
|
|
@@ -125,7 +126,7 @@ class RpcCore {
|
|
|
125
126
|
* @description Sets a registry swap (typically from Api)
|
|
126
127
|
*/
|
|
127
128
|
setRegistrySwap(registrySwap) {
|
|
128
|
-
this.#getBlockRegistry = (0,
|
|
129
|
+
this.#getBlockRegistry = (0, util_2.memoize)(registrySwap, {
|
|
129
130
|
getInstanceId: () => this.#instanceId
|
|
130
131
|
});
|
|
131
132
|
}
|
|
@@ -133,7 +134,7 @@ class RpcCore {
|
|
|
133
134
|
* @description Sets a function to resolve block hash from block number
|
|
134
135
|
*/
|
|
135
136
|
setResolveBlockHash(resolveBlockHash) {
|
|
136
|
-
this.#getBlockHash = (0,
|
|
137
|
+
this.#getBlockHash = (0, util_2.memoize)(resolveBlockHash, {
|
|
137
138
|
getInstanceId: () => this.#instanceId
|
|
138
139
|
});
|
|
139
140
|
}
|
|
@@ -142,7 +143,7 @@ class RpcCore {
|
|
|
142
143
|
this.sections.push(...Object.keys(userRpc).filter((k) => !this.sections.includes(k)));
|
|
143
144
|
for (let s = 0, scount = this.sections.length; s < scount; s++) {
|
|
144
145
|
const section = this.sections[s];
|
|
145
|
-
const defs = (0,
|
|
146
|
+
const defs = (0, util_2.objectSpread)({}, types_1.rpcDefinitions[section], userRpc[section]);
|
|
146
147
|
const methods = Object.keys(defs);
|
|
147
148
|
for (let m = 0, mcount = methods.length; m < mcount; m++) {
|
|
148
149
|
const method = methods[m];
|
|
@@ -153,8 +154,8 @@ class RpcCore {
|
|
|
153
154
|
if (!this[section]) {
|
|
154
155
|
this[section] = {};
|
|
155
156
|
}
|
|
156
|
-
this.mapping.set(jsonrpc, (0,
|
|
157
|
-
(0,
|
|
157
|
+
this.mapping.set(jsonrpc, (0, util_2.objectSpread)({}, def, { isSubscription, jsonrpc, method, section }));
|
|
158
|
+
(0, util_2.lazyMethod)(this[section], method, () => isSubscription
|
|
158
159
|
? this._createMethodSubscribe(section, method, def)
|
|
159
160
|
: this._createMethodSend(section, method, def));
|
|
160
161
|
}
|
|
@@ -163,8 +164,8 @@ class RpcCore {
|
|
|
163
164
|
}
|
|
164
165
|
_memomize(creator, def) {
|
|
165
166
|
const memoOpts = { getInstanceId: () => this.#instanceId };
|
|
166
|
-
const memoized = (0,
|
|
167
|
-
memoized.raw = (0,
|
|
167
|
+
const memoized = (0, util_2.memoize)(creator(true), memoOpts);
|
|
168
|
+
memoized.raw = (0, util_2.memoize)(creator(false), memoOpts);
|
|
168
169
|
memoized.meta = def;
|
|
169
170
|
return memoized;
|
|
170
171
|
}
|
|
@@ -186,7 +187,7 @@ class RpcCore {
|
|
|
186
187
|
? await this.#getBlockHash?.(blockId)
|
|
187
188
|
: blockId;
|
|
188
189
|
const { registry } = isScale && blockHash && this.#getBlockRegistry
|
|
189
|
-
? await this.#getBlockRegistry((0,
|
|
190
|
+
? await this.#getBlockRegistry((0, util_2.u8aToU8a)(blockHash))
|
|
190
191
|
: { registry: this.#registryDefault };
|
|
191
192
|
const params = this._formatParams(registry, null, def, values);
|
|
192
193
|
// only cache .at(<blockHash>) queries, e.g. where valid blockHash was supplied
|
|
@@ -283,7 +284,7 @@ class RpcCore {
|
|
|
283
284
|
}
|
|
284
285
|
// Unsubscribe from provider
|
|
285
286
|
subscriptionPromise
|
|
286
|
-
.then((subscriptionId) => (0,
|
|
287
|
+
.then((subscriptionId) => (0, util_2.isNull)(subscriptionId)
|
|
287
288
|
? Promise.resolve(false)
|
|
288
289
|
: this.provider.unsubscribe(subType, unsubName, subscriptionId))
|
|
289
290
|
.catch((error) => logErrorMessage(method, def, error));
|
|
@@ -335,14 +336,14 @@ class RpcCore {
|
|
|
335
336
|
return registry.createTypeUnsafe(rpc.type, [result], { blockHash });
|
|
336
337
|
}
|
|
337
338
|
_formatStorageData(registry, blockHash, key, value) {
|
|
338
|
-
const isEmpty = (0,
|
|
339
|
+
const isEmpty = (0, util_2.isNull)(value);
|
|
339
340
|
// we convert to Uint8Array since it maps to the raw encoding, all
|
|
340
341
|
// data will be correctly encoded (incl. numbers, excl. :code)
|
|
341
342
|
const input = isEmpty
|
|
342
343
|
? null
|
|
343
344
|
: isTreatAsHex(key)
|
|
344
345
|
? value
|
|
345
|
-
: (0,
|
|
346
|
+
: (0, util_2.u8aToU8a)(value);
|
|
346
347
|
return this._newType(registry, blockHash, key, input, isEmpty);
|
|
347
348
|
}
|
|
348
349
|
_formatStorageSet(registry, blockHash, keys, changes) {
|
|
@@ -360,7 +361,7 @@ class RpcCore {
|
|
|
360
361
|
_formatStorageSetEntry(registry, blockHash, key, changes, withCache, entryIndex) {
|
|
361
362
|
const hexKey = key.toHex();
|
|
362
363
|
const found = changes.find(([key]) => key === hexKey);
|
|
363
|
-
const isNotFound = (0,
|
|
364
|
+
const isNotFound = (0, util_2.isUndefined)(found);
|
|
364
365
|
// if we don't find the value, this is our fallback
|
|
365
366
|
// - in the case of an array of values, fill the hole from the cache
|
|
366
367
|
// - if a single result value, don't fill - it is not an update hole
|
|
@@ -375,10 +376,10 @@ class RpcCore {
|
|
|
375
376
|
const value = isNotFound
|
|
376
377
|
? null
|
|
377
378
|
: found[1];
|
|
378
|
-
const isEmpty = (0,
|
|
379
|
+
const isEmpty = (0, util_2.isNull)(value);
|
|
379
380
|
const input = isEmpty || isTreatAsHex(key)
|
|
380
381
|
? value
|
|
381
|
-
: (0,
|
|
382
|
+
: (0, util_2.u8aToU8a)(value);
|
|
382
383
|
const codec = this._newType(registry, blockHash, key, input, isEmpty, entryIndex);
|
|
383
384
|
this._setToCache(hexKey, codec);
|
|
384
385
|
return codec;
|
|
@@ -389,7 +390,7 @@ class RpcCore {
|
|
|
389
390
|
_newType(registry, blockHash, key, input, isEmpty, entryIndex = -1) {
|
|
390
391
|
// single return value (via state.getStorage), decode the value based on the
|
|
391
392
|
// outputType that we have specified. Fallback to Raw on nothing
|
|
392
|
-
const type = key.outputType || 'Raw';
|
|
393
|
+
const type = key.meta ? registry.createLookupType((0, util_1.unwrapStorageSi)(key.meta.type)) : (key.outputType || 'Raw');
|
|
393
394
|
const meta = key.meta || EMPTY_META;
|
|
394
395
|
const entryNum = entryIndex === -1
|
|
395
396
|
? ''
|
|
@@ -400,8 +401,8 @@ class RpcCore {
|
|
|
400
401
|
? meta.fallback
|
|
401
402
|
// For old-style Linkage, we add an empty linkage at the end
|
|
402
403
|
? type.includes('Linkage<')
|
|
403
|
-
? (0,
|
|
404
|
-
: (0,
|
|
404
|
+
? (0, util_2.u8aConcat)((0, util_2.hexToU8a)(meta.fallback.toHex()), new Uint8Array(2))
|
|
405
|
+
: (0, util_2.hexToU8a)(meta.fallback.toHex())
|
|
405
406
|
: undefined
|
|
406
407
|
: meta.modifier.isOptional
|
|
407
408
|
? registry.createTypeUnsafe(type, [input], { blockHash, isPedantic: this.#isPedantic })
|
package/cjs/packageInfo.js
CHANGED
|
@@ -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: '16.4.
|
|
4
|
+
exports.packageInfo = { name: '@polkadot/rpc-core', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '16.4.9' };
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"./cjs/packageDetect.js"
|
|
19
19
|
],
|
|
20
20
|
"type": "module",
|
|
21
|
-
"version": "16.4.
|
|
21
|
+
"version": "16.4.9",
|
|
22
22
|
"main": "./cjs/index.js",
|
|
23
23
|
"module": "./index.js",
|
|
24
24
|
"types": "./index.d.ts",
|
|
@@ -199,10 +199,10 @@
|
|
|
199
199
|
}
|
|
200
200
|
},
|
|
201
201
|
"dependencies": {
|
|
202
|
-
"@polkadot/rpc-augment": "16.4.
|
|
203
|
-
"@polkadot/rpc-provider": "16.4.
|
|
204
|
-
"@polkadot/types": "16.4.
|
|
205
|
-
"@polkadot/util": "^13.5.
|
|
202
|
+
"@polkadot/rpc-augment": "16.4.9",
|
|
203
|
+
"@polkadot/rpc-provider": "16.4.9",
|
|
204
|
+
"@polkadot/types": "16.4.9",
|
|
205
|
+
"@polkadot/util": "^13.5.7",
|
|
206
206
|
"rxjs": "^7.8.1",
|
|
207
207
|
"tslib": "^2.8.1"
|
|
208
208
|
}
|
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: '16.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: '16.4.9' };
|