@polkadot/rpc-core 7.8.2-7 → 7.9.2-0

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.cjs CHANGED
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
@@ -17,10 +15,6 @@ Object.defineProperty(exports, "packageInfo", {
17
15
  }
18
16
  });
19
17
 
20
- var _classPrivateFieldLooseBase2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseBase"));
21
-
22
- var _classPrivateFieldLooseKey2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseKey"));
23
-
24
18
  var _rxjs = require("rxjs");
25
19
 
26
20
  var _types = require("@polkadot/types");
@@ -109,45 +103,26 @@ function isTreatAsHex(key) {
109
103
  */
110
104
 
111
105
 
112
- var _instanceId = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("instanceId");
113
-
114
- var _registryDefault = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("registryDefault");
115
-
116
- var _getBlockRegistry = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("getBlockRegistry");
117
-
118
- var _storageCache = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("storageCache");
119
-
120
106
  class RpcCore {
107
+ #instanceId;
108
+ #registryDefault;
109
+ #getBlockRegistry;
110
+ #getBlockHash;
111
+ #storageCache = new Map();
112
+ mapping = new Map();
113
+ sections = [];
121
114
  /**
122
115
  * @constructor
123
116
  * Default constructor for the Api Object
124
117
  * @param {ProviderInterface} provider An API provider using HTTP or WebSocket
125
118
  */
119
+
126
120
  constructor(instanceId, registry, provider) {
127
121
  let userRpc = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
128
- Object.defineProperty(this, _instanceId, {
129
- writable: true,
130
- value: void 0
131
- });
132
- Object.defineProperty(this, _registryDefault, {
133
- writable: true,
134
- value: void 0
135
- });
136
- Object.defineProperty(this, _getBlockRegistry, {
137
- writable: true,
138
- value: void 0
139
- });
140
- Object.defineProperty(this, _storageCache, {
141
- writable: true,
142
- value: new Map()
143
- });
144
- this.mapping = new Map();
145
- this.provider = void 0;
146
- this.sections = [];
147
122
  // eslint-disable-next-line @typescript-eslint/unbound-method
148
123
  (0, _util.assert)(provider && (0, _util.isFunction)(provider.send), 'Expected Provider to API create');
149
- (0, _classPrivateFieldLooseBase2.default)(this, _instanceId)[_instanceId] = instanceId;
150
- (0, _classPrivateFieldLooseBase2.default)(this, _registryDefault)[_registryDefault] = registry;
124
+ this.#instanceId = instanceId;
125
+ this.#registryDefault = registry;
151
126
  this.provider = provider;
152
127
  const sectionNames = Object.keys(_types.rpcDefinitions); // these are the base keys (i.e. part of jsonrpc)
153
128
 
@@ -185,8 +160,18 @@ class RpcCore {
185
160
 
186
161
 
187
162
  setRegistrySwap(registrySwap) {
188
- (0, _classPrivateFieldLooseBase2.default)(this, _getBlockRegistry)[_getBlockRegistry] = (0, _util.memoize)(registrySwap, {
189
- getInstanceId: () => (0, _classPrivateFieldLooseBase2.default)(this, _instanceId)[_instanceId]
163
+ this.#getBlockRegistry = (0, _util.memoize)(registrySwap, {
164
+ getInstanceId: () => this.#instanceId
165
+ });
166
+ }
167
+ /**
168
+ * @description Sets a function to resolve block hash from block number
169
+ */
170
+
171
+
172
+ setResolveBlockHash(resolveBlockHash) {
173
+ this.#getBlockHash = (0, _util.memoize)(resolveBlockHash, {
174
+ getInstanceId: () => this.#instanceId
190
175
  });
191
176
  }
192
177
 
@@ -225,7 +210,7 @@ class RpcCore {
225
210
 
226
211
  _memomize(creator, def) {
227
212
  const memoOpts = {
228
- getInstanceId: () => (0, _classPrivateFieldLooseBase2.default)(this, _instanceId)[_instanceId]
213
+ getInstanceId: () => this.#instanceId
229
214
  };
230
215
  const memoized = (0, _util.memoize)(creator(true), memoOpts);
231
216
  memoized.raw = (0, _util.memoize)(creator(false), memoOpts);
@@ -248,11 +233,14 @@ class RpcCore {
248
233
  let memoized = null; // execute the RPC call, doing a registry swap for historic as applicable
249
234
 
250
235
  const callWithRegistry = async (isScale, values) => {
251
- const blockHash = hashIndex === -1 ? null : values[hashIndex];
236
+ var _this$getBlockHash;
237
+
238
+ const blockId = hashIndex === -1 ? null : values[hashIndex];
239
+ const blockHash = blockId && def.params[hashIndex].type === 'BlockNumber' ? await ((_this$getBlockHash = this.#getBlockHash) === null || _this$getBlockHash === void 0 ? void 0 : _this$getBlockHash.call(this, blockId)) : blockId;
252
240
  const {
253
241
  registry
254
- } = isScale && blockHash && (0, _classPrivateFieldLooseBase2.default)(this, _getBlockRegistry)[_getBlockRegistry] ? await (0, _classPrivateFieldLooseBase2.default)(this, _getBlockRegistry)[_getBlockRegistry]((0, _util.u8aToU8a)(blockHash)) : {
255
- registry: (0, _classPrivateFieldLooseBase2.default)(this, _registryDefault)[_registryDefault]
242
+ } = isScale && blockHash && this.#getBlockRegistry ? await this.#getBlockRegistry((0, _util.u8aToU8a)(blockHash)) : {
243
+ registry: this.#registryDefault
256
244
  };
257
245
 
258
246
  const params = this._formatInputs(registry, null, def, values); // only cache .at(<blockHash>) queries, e.g. where valid blockHash was supplied
@@ -331,8 +319,7 @@ class RpcCore {
331
319
  return new _rxjs.Observable(observer => {
332
320
  // Have at least an empty promise, as used in the unsubscribe
333
321
  let subscriptionPromise = Promise.resolve(null);
334
-
335
- const registry = (0, _classPrivateFieldLooseBase2.default)(_this, _registryDefault)[_registryDefault];
322
+ const registry = _this.#registryDefault;
336
323
 
337
324
  const errorHandler = error => {
338
325
  logErrorMessage(method, def, error);
@@ -459,14 +446,13 @@ class RpcCore {
459
446
  // - if a single result value, don't fill - it is not an update hole
460
447
  // - fallback to an empty option in all cases
461
448
 
462
- const value = (0, _util.isUndefined)(found) ? witCache && (0, _classPrivateFieldLooseBase2.default)(this, _storageCache)[_storageCache].get(hexKey) || null : found[1];
449
+ const value = (0, _util.isUndefined)(found) ? witCache && this.#storageCache.get(hexKey) || null : found[1];
463
450
  const isEmpty = (0, _util.isNull)(value);
464
451
  const input = isEmpty || isTreatAsHex(key) ? value : (0, _util.u8aToU8a)(value); // store the retrieved result - the only issue with this cache is that there is no
465
452
  // clearing of it, so very long running processes (not just a couple of hours, longer)
466
453
  // will increase memory beyond what is allowed.
467
454
 
468
- (0, _classPrivateFieldLooseBase2.default)(this, _storageCache)[_storageCache].set(hexKey, value);
469
-
455
+ this.#storageCache.set(hexKey, value);
470
456
  return this._newType(registry, blockHash, key, input, isEmpty, entryIndex);
471
457
  }
472
458
 
package/bundle.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ProviderInterface } from '@polkadot/rpc-provider/types';
2
- import type { DefinitionRpc, DefinitionRpcExt, DefinitionRpcSub, Registry } from '@polkadot/types/types';
2
+ import type { AnyNumber, DefinitionRpc, DefinitionRpcExt, DefinitionRpcSub, Registry } from '@polkadot/types/types';
3
3
  export { packageInfo } from './packageInfo';
4
4
  export * from './util';
5
5
  /**
@@ -54,6 +54,10 @@ export declare class RpcCore {
54
54
  setRegistrySwap(registrySwap: (blockHash: Uint8Array) => Promise<{
55
55
  registry: Registry;
56
56
  }>): void;
57
+ /**
58
+ * @description Sets a function to resolve block hash from block number
59
+ */
60
+ setResolveBlockHash(resolveBlockHash: (blockNumber: AnyNumber) => Promise<Uint8Array>): void;
57
61
  addUserInterfaces(userRpc: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>): void;
58
62
  private _memomize;
59
63
  private _formatResult;
package/bundle.js CHANGED
@@ -70,6 +70,7 @@ export class RpcCore {
70
70
  #instanceId;
71
71
  #registryDefault;
72
72
  #getBlockRegistry;
73
+ #getBlockHash;
73
74
  #storageCache = new Map();
74
75
  mapping = new Map();
75
76
  sections = [];
@@ -125,6 +126,16 @@ export class RpcCore {
125
126
  getInstanceId: () => this.#instanceId
126
127
  });
127
128
  }
129
+ /**
130
+ * @description Sets a function to resolve block hash from block number
131
+ */
132
+
133
+
134
+ setResolveBlockHash(resolveBlockHash) {
135
+ this.#getBlockHash = memoize(resolveBlockHash, {
136
+ getInstanceId: () => this.#instanceId
137
+ });
138
+ }
128
139
 
129
140
  addUserInterfaces(userRpc) {
130
141
  // add any extra user-defined sections
@@ -181,7 +192,10 @@ export class RpcCore {
181
192
  let memoized = null; // execute the RPC call, doing a registry swap for historic as applicable
182
193
 
183
194
  const callWithRegistry = async (isScale, values) => {
184
- const blockHash = hashIndex === -1 ? null : values[hashIndex];
195
+ var _this$getBlockHash;
196
+
197
+ const blockId = hashIndex === -1 ? null : values[hashIndex];
198
+ const blockHash = blockId && def.params[hashIndex].type === 'BlockNumber' ? await ((_this$getBlockHash = this.#getBlockHash) === null || _this$getBlockHash === void 0 ? void 0 : _this$getBlockHash.call(this, blockId)) : blockId;
185
199
  const {
186
200
  registry
187
201
  } = isScale && blockHash && this.#getBlockRegistry ? await this.#getBlockRegistry(u8aToU8a(blockHash)) : {
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "./detectPackage.cjs"
21
21
  ],
22
22
  "type": "module",
23
- "version": "7.8.2-7",
23
+ "version": "7.9.2-0",
24
24
  "main": "index.cjs",
25
25
  "module": "index.js",
26
26
  "types": "index.d.ts",
@@ -91,9 +91,9 @@
91
91
  },
92
92
  "dependencies": {
93
93
  "@babel/runtime": "^7.17.2",
94
- "@polkadot/rpc-augment": "7.8.2-7",
95
- "@polkadot/rpc-provider": "7.8.2-7",
96
- "@polkadot/types": "7.8.2-7",
94
+ "@polkadot/rpc-augment": "7.9.2-0",
95
+ "@polkadot/rpc-provider": "7.9.2-0",
96
+ "@polkadot/types": "7.9.2-0",
97
97
  "@polkadot/util": "^8.4.1",
98
98
  "rxjs": "^7.5.4"
99
99
  }
package/packageInfo.cjs CHANGED
@@ -11,6 +11,6 @@ const packageInfo = {
11
11
  name: '@polkadot/rpc-core',
12
12
  path: typeof __dirname === 'string' ? __dirname : 'auto',
13
13
  type: 'cjs',
14
- version: '7.8.2-7'
14
+ version: '7.9.2-0'
15
15
  };
16
16
  exports.packageInfo = packageInfo;
package/packageInfo.js CHANGED
@@ -5,5 +5,5 @@ export const packageInfo = {
5
5
  name: '@polkadot/rpc-core',
6
6
  path: new URL('.', import.meta.url).pathname,
7
7
  type: 'esm',
8
- version: '7.8.2-7'
8
+ version: '7.9.2-0'
9
9
  };