@polkadot/rpc-core 7.8.2-5 → 7.8.2-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.cjs CHANGED
@@ -115,6 +115,8 @@ var _registryDefault = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("re
115
115
 
116
116
  var _getBlockRegistry = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("getBlockRegistry");
117
117
 
118
+ var _getBlockHash = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("getBlockHash");
119
+
118
120
  var _storageCache = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("storageCache");
119
121
 
120
122
  class RpcCore {
@@ -137,6 +139,10 @@ class RpcCore {
137
139
  writable: true,
138
140
  value: void 0
139
141
  });
142
+ Object.defineProperty(this, _getBlockHash, {
143
+ writable: true,
144
+ value: void 0
145
+ });
140
146
  Object.defineProperty(this, _storageCache, {
141
147
  writable: true,
142
148
  value: new Map()
@@ -189,6 +195,16 @@ class RpcCore {
189
195
  getInstanceId: () => (0, _classPrivateFieldLooseBase2.default)(this, _instanceId)[_instanceId]
190
196
  });
191
197
  }
198
+ /**
199
+ * @description Sets a function to resolve block hash from block number
200
+ */
201
+
202
+
203
+ setResolveBlockHash(resolveBlockHash) {
204
+ (0, _classPrivateFieldLooseBase2.default)(this, _getBlockHash)[_getBlockHash] = (0, _util.memoize)(resolveBlockHash, {
205
+ getInstanceId: () => (0, _classPrivateFieldLooseBase2.default)(this, _instanceId)[_instanceId]
206
+ });
207
+ }
192
208
 
193
209
  addUserInterfaces(userRpc) {
194
210
  // add any extra user-defined sections
@@ -248,7 +264,10 @@ class RpcCore {
248
264
  let memoized = null; // execute the RPC call, doing a registry swap for historic as applicable
249
265
 
250
266
  const callWithRegistry = async (isScale, values) => {
251
- const blockHash = hashIndex === -1 ? null : values[hashIndex];
267
+ var _classPrivateFieldLoo, _classPrivateFieldLoo2;
268
+
269
+ const blockId = hashIndex === -1 ? null : values[hashIndex];
270
+ const blockHash = blockId && def.params[hashIndex].type === 'BlockNumber' ? await ((_classPrivateFieldLoo = (_classPrivateFieldLoo2 = (0, _classPrivateFieldLooseBase2.default)(this, _getBlockHash))[_getBlockHash]) === null || _classPrivateFieldLoo === void 0 ? void 0 : _classPrivateFieldLoo.call(_classPrivateFieldLoo2, blockId)) : blockId;
252
271
  const {
253
272
  registry
254
273
  } = isScale && blockHash && (0, _classPrivateFieldLooseBase2.default)(this, _getBlockRegistry)[_getBlockRegistry] ? await (0, _classPrivateFieldLooseBase2.default)(this, _getBlockRegistry)[_getBlockRegistry]((0, _util.u8aToU8a)(blockHash)) : {
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-5",
23
+ "version": "7.8.2-9",
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-5",
95
- "@polkadot/rpc-provider": "7.8.2-5",
96
- "@polkadot/types": "7.8.2-5",
94
+ "@polkadot/rpc-augment": "7.8.2-9",
95
+ "@polkadot/rpc-provider": "7.8.2-9",
96
+ "@polkadot/types": "7.8.2-9",
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-5'
14
+ version: '7.8.2-9'
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-5'
8
+ version: '7.8.2-9'
9
9
  };