@polkadot-api/substrate-client 0.0.2 → 0.1.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/dist/index.d.mts CHANGED
@@ -215,15 +215,23 @@ declare function getChainHead(request: ClientRequest<string, FollowEventRpc>): C
215
215
 
216
216
  type Transaction = (tx: string, error: (e: Error) => void) => UnsubscribeFn;
217
217
 
218
- declare const getTransaction: (request: ClientRequest<string, any>, rpcMethods: Promise<Set<string>> | Set<string>) => (tx: string, error: (e: Error) => void) => () => void;
218
+ declare const getTransaction: (request: ClientRequest<string, any>) => (tx: string, error: (e: Error) => void) => () => void;
219
+
220
+ interface ChainSpecData {
221
+ name: string;
222
+ genesisHash: string;
223
+ properties: any;
224
+ }
225
+ declare const createGetChainSpec: (clientRequest: ClientRequest<any, any>) => () => Promise<ChainSpecData>;
219
226
 
220
227
  interface SubstrateClient {
221
228
  chainHead: ChainHead;
222
229
  transaction: Transaction;
223
230
  destroy: UnsubscribeFn;
231
+ getChainSpecData: () => Promise<ChainSpecData>;
224
232
  request: <T>(method: string, params: any[], abortSignal?: AbortSignal) => Promise<T>;
225
233
  _request: <Reply, Notification>(method: string, params: any[], cb?: ClientRequestCb<Reply, Notification>) => UnsubscribeFn;
226
234
  }
227
235
  declare const createClient: (provider: JsonRpcProvider) => SubstrateClient;
228
236
 
229
- export { type AbortablePromiseFn, type BestBlockChanged, type ChainHead, type Client, type ClientInnerRequest, type ClientInnerRequestCb, type ClientRequest, type ClientRequestCb, DestroyedError, DisjointError, type Finalized, type FollowEventWithRuntime, type FollowEventWithoutRuntime, type FollowInnerSubscriptionCb, type FollowResponse, type FollowSubscriptionCb, type IRpcError, type Initialized, type InitializedWithRuntime$1 as InitializedWithRuntime, type NewBlock, type NewBlockWithRuntime$1 as NewBlockWithRuntime, OperationError, OperationInaccessibleError, OperationLimitError, RpcError, type Runtime, StopError, type StorageItemInput, type StorageItemResponse, type StorageResult, type SubstrateClient, type Transaction, type UnsubscribeFn, createClient, getChainHead, getTransaction };
237
+ export { type AbortablePromiseFn, type BestBlockChanged, type ChainHead, type ChainSpecData, type Client, type ClientInnerRequest, type ClientInnerRequestCb, type ClientRequest, type ClientRequestCb, DestroyedError, DisjointError, type Finalized, type FollowEventWithRuntime, type FollowEventWithoutRuntime, type FollowInnerSubscriptionCb, type FollowResponse, type FollowSubscriptionCb, type IRpcError, type Initialized, type InitializedWithRuntime$1 as InitializedWithRuntime, type NewBlock, type NewBlockWithRuntime$1 as NewBlockWithRuntime, OperationError, OperationInaccessibleError, OperationLimitError, RpcError, type Runtime, StopError, type StorageItemInput, type StorageItemResponse, type StorageResult, type SubstrateClient, type Transaction, type UnsubscribeFn, createClient, createGetChainSpec, getChainHead, getTransaction };
package/dist/index.d.ts CHANGED
@@ -215,15 +215,23 @@ declare function getChainHead(request: ClientRequest<string, FollowEventRpc>): C
215
215
 
216
216
  type Transaction = (tx: string, error: (e: Error) => void) => UnsubscribeFn;
217
217
 
218
- declare const getTransaction: (request: ClientRequest<string, any>, rpcMethods: Promise<Set<string>> | Set<string>) => (tx: string, error: (e: Error) => void) => () => void;
218
+ declare const getTransaction: (request: ClientRequest<string, any>) => (tx: string, error: (e: Error) => void) => () => void;
219
+
220
+ interface ChainSpecData {
221
+ name: string;
222
+ genesisHash: string;
223
+ properties: any;
224
+ }
225
+ declare const createGetChainSpec: (clientRequest: ClientRequest<any, any>) => () => Promise<ChainSpecData>;
219
226
 
220
227
  interface SubstrateClient {
221
228
  chainHead: ChainHead;
222
229
  transaction: Transaction;
223
230
  destroy: UnsubscribeFn;
231
+ getChainSpecData: () => Promise<ChainSpecData>;
224
232
  request: <T>(method: string, params: any[], abortSignal?: AbortSignal) => Promise<T>;
225
233
  _request: <Reply, Notification>(method: string, params: any[], cb?: ClientRequestCb<Reply, Notification>) => UnsubscribeFn;
226
234
  }
227
235
  declare const createClient: (provider: JsonRpcProvider) => SubstrateClient;
228
236
 
229
- export { type AbortablePromiseFn, type BestBlockChanged, type ChainHead, type Client, type ClientInnerRequest, type ClientInnerRequestCb, type ClientRequest, type ClientRequestCb, DestroyedError, DisjointError, type Finalized, type FollowEventWithRuntime, type FollowEventWithoutRuntime, type FollowInnerSubscriptionCb, type FollowResponse, type FollowSubscriptionCb, type IRpcError, type Initialized, type InitializedWithRuntime$1 as InitializedWithRuntime, type NewBlock, type NewBlockWithRuntime$1 as NewBlockWithRuntime, OperationError, OperationInaccessibleError, OperationLimitError, RpcError, type Runtime, StopError, type StorageItemInput, type StorageItemResponse, type StorageResult, type SubstrateClient, type Transaction, type UnsubscribeFn, createClient, getChainHead, getTransaction };
237
+ export { type AbortablePromiseFn, type BestBlockChanged, type ChainHead, type ChainSpecData, type Client, type ClientInnerRequest, type ClientInnerRequestCb, type ClientRequest, type ClientRequestCb, DestroyedError, DisjointError, type Finalized, type FollowEventWithRuntime, type FollowEventWithoutRuntime, type FollowInnerSubscriptionCb, type FollowResponse, type FollowSubscriptionCb, type IRpcError, type Initialized, type InitializedWithRuntime$1 as InitializedWithRuntime, type NewBlock, type NewBlockWithRuntime$1 as NewBlockWithRuntime, OperationError, OperationInaccessibleError, OperationLimitError, RpcError, type Runtime, StopError, type StorageItemInput, type StorageItemResponse, type StorageResult, type SubstrateClient, type Transaction, type UnsubscribeFn, createClient, createGetChainSpec, getChainHead, getTransaction };
package/dist/index.js CHANGED
@@ -102,43 +102,54 @@ var getSubscriptionsManager = () => {
102
102
  };
103
103
  };
104
104
 
105
- // src/transaction/transaction.ts
106
- var getTxBroadcastNames = (input) => {
107
- if (input.has("transaction_v1_broadcast"))
108
- return ["transaction_v1_broadcast", "transaction_v1_stop"];
109
- if (input.has("transactionWatch_unstable_submitAndWatch"))
110
- return [
111
- "transactionWatch_unstable_submitAndWatch",
112
- "transactionWatch_unstable_unwatch"
113
- ];
114
- return ["transaction_unstable_submitAndWatch", "transaction_unstable_unwatch"];
105
+ // src/methods.ts
106
+ var chainHead = {
107
+ body: "",
108
+ call: "",
109
+ continue: "",
110
+ follow: "",
111
+ header: "",
112
+ stopOperation: "",
113
+ storage: "",
114
+ unfollow: "",
115
+ unpin: "",
116
+ followEvent: ""
117
+ };
118
+ var chainSpec = {
119
+ chainName: "",
120
+ genesisHash: "",
121
+ properties: ""
122
+ };
123
+ var transaction = {
124
+ broadcast: "",
125
+ stop: ""
126
+ };
127
+ var transactionWatch = {
128
+ submitAndWatch: "",
129
+ unwatch: ""
115
130
  };
116
- var getTransaction = (request, rpcMethods) => (tx, error) => {
117
- const broadcast = (tx2, broadcastFn, cancelBroadcastFn) => request(broadcastFn, [tx2], {
131
+ Object.entries({ chainHead, chainSpec, transaction, transactionWatch }).forEach(
132
+ ([fnGroupName, methods]) => {
133
+ Object.keys(methods).forEach((methodName) => {
134
+ ;
135
+ methods[methodName] = `${fnGroupName}_v1_${methodName}`;
136
+ });
137
+ }
138
+ );
139
+
140
+ // src/transaction/transaction.ts
141
+ var getTransaction = (request) => (tx, error) => {
142
+ let cancel = request(transaction.broadcast, [tx], {
118
143
  onSuccess: (subscriptionId) => {
119
144
  cancel = subscriptionId === null ? noop2 : () => {
120
- request(cancelBroadcastFn, [subscriptionId]);
145
+ request(transaction.stop, [subscriptionId]);
121
146
  };
122
147
  if (subscriptionId === null) {
123
- error(
124
- new Error("Max # of broadcasted transactions has been reached")
125
- );
148
+ error(new Error("Max # of broadcasted transactions has been reached"));
126
149
  }
127
150
  },
128
151
  onError: error
129
152
  });
130
- let isActive = true;
131
- let cancel = () => {
132
- isActive = false;
133
- };
134
- if (rpcMethods instanceof Promise) {
135
- rpcMethods.then(getTxBroadcastNames).then((names) => {
136
- if (!isActive)
137
- return;
138
- cancel = broadcast(tx, ...names);
139
- });
140
- } else
141
- cancel = broadcast(tx, ...getTxBroadcastNames(rpcMethods));
142
153
  return () => {
143
154
  cancel();
144
155
  };
@@ -179,7 +190,7 @@ var OperationInaccessibleError = class extends Error {
179
190
  // src/chainhead/operation-promise.ts
180
191
  var createOperationPromise = (operationName, factory) => (request) => abortablePromiseFn((res, rej, ...args) => {
181
192
  const [requestArgs, logicCb] = factory(...args);
182
- let cancel = request(operationName, requestArgs, {
193
+ let cancel = request(operationName(), requestArgs, {
183
194
  onSuccess: (response, followSubscription) => {
184
195
  if (response.result === "limitReached") {
185
196
  cancel = noop2;
@@ -214,7 +225,7 @@ var createOperationPromise = (operationName, factory) => (request) => abortableP
214
225
  if (!isOperationGoing)
215
226
  return;
216
227
  done();
217
- request("chainHead_unstable_stopOperation", [response.operationId]);
228
+ request(chainHead.stopOperation, [response.operationId]);
218
229
  };
219
230
  },
220
231
  onError: rej
@@ -226,7 +237,7 @@ var createOperationPromise = (operationName, factory) => (request) => abortableP
226
237
 
227
238
  // src/chainhead/body.ts
228
239
  var createBodyFn = createOperationPromise(
229
- "chainHead_unstable_body",
240
+ () => chainHead.body,
230
241
  (hash) => [
231
242
  [hash],
232
243
  (e, res) => {
@@ -237,7 +248,7 @@ var createBodyFn = createOperationPromise(
237
248
 
238
249
  // src/chainhead/call.ts
239
250
  var createCallFn = createOperationPromise(
240
- "chainHead_unstable_call",
251
+ () => chainHead.call,
241
252
  (hash, fnName, callParameters) => [
242
253
  [hash, fnName, callParameters],
243
254
  (e, res) => {
@@ -248,7 +259,7 @@ var createCallFn = createOperationPromise(
248
259
 
249
260
  // src/chainhead/header.ts
250
261
  var createHeaderFn = (request) => (hash) => new Promise((res, rej) => {
251
- request("chainHead_unstable_header", [hash], {
262
+ request(chainHead.header, [hash], {
252
263
  onSuccess: res,
253
264
  onError: rej
254
265
  });
@@ -261,57 +272,53 @@ var createStorageCb = (request) => (hash, inputs, childTrie, onItems, onError, o
261
272
  onDone();
262
273
  return import_utils2.noop;
263
274
  }
264
- let cancel = request(
265
- "chainHead_unstable_storage",
266
- [hash, inputs, childTrie],
267
- {
268
- onSuccess: (response, followSubscription) => {
269
- if (response.result === "limitReached" || response.discardedItems === inputs.length)
270
- return onError(new OperationLimitError());
271
- const doneListening = followSubscription(response.operationId, {
272
- next: (event) => {
273
- switch (event.event) {
274
- case "operationStorageItems": {
275
- onItems(event.items);
276
- break;
277
- }
278
- case "operationStorageDone": {
279
- _onDone();
280
- break;
281
- }
282
- case "operationError": {
283
- _onError(new OperationError(event.error));
284
- break;
285
- }
286
- case "operationInaccessible": {
287
- _onError(new OperationInaccessibleError());
288
- break;
289
- }
290
- default:
291
- request("chainHead_unstable_continue", [event.operationId]);
275
+ let cancel = request(chainHead.storage, [hash, inputs, childTrie], {
276
+ onSuccess: (response, followSubscription) => {
277
+ if (response.result === "limitReached" || response.discardedItems === inputs.length)
278
+ return onError(new OperationLimitError());
279
+ const doneListening = followSubscription(response.operationId, {
280
+ next: (event) => {
281
+ switch (event.event) {
282
+ case "operationStorageItems": {
283
+ onItems(event.items);
284
+ break;
292
285
  }
293
- },
294
- error: onError
295
- });
296
- cancel = () => {
297
- doneListening();
298
- request("chainHead_unstable_stopOperation", [response.operationId]);
299
- };
300
- const _onError = (e) => {
301
- cancel = import_utils2.noop;
302
- doneListening();
303
- onError(e);
304
- };
305
- const _onDone = () => {
306
- cancel = import_utils2.noop;
307
- doneListening();
308
- onDone();
309
- };
310
- onDiscardedItems(response.discardedItems);
311
- },
312
- onError
313
- }
314
- );
286
+ case "operationStorageDone": {
287
+ _onDone();
288
+ break;
289
+ }
290
+ case "operationError": {
291
+ _onError(new OperationError(event.error));
292
+ break;
293
+ }
294
+ case "operationInaccessible": {
295
+ _onError(new OperationInaccessibleError());
296
+ break;
297
+ }
298
+ default:
299
+ request(chainHead.continue, [event.operationId]);
300
+ }
301
+ },
302
+ error: onError
303
+ });
304
+ cancel = () => {
305
+ doneListening();
306
+ request(chainHead.stopOperation, [response.operationId]);
307
+ };
308
+ const _onError = (e) => {
309
+ cancel = import_utils2.noop;
310
+ doneListening();
311
+ onError(e);
312
+ };
313
+ const _onDone = () => {
314
+ cancel = import_utils2.noop;
315
+ doneListening();
316
+ onDone();
317
+ };
318
+ onDiscardedItems(response.discardedItems);
319
+ },
320
+ onError
321
+ });
315
322
  return () => {
316
323
  cancel();
317
324
  };
@@ -354,7 +361,7 @@ var createStorageFn = (request) => {
354
361
 
355
362
  // src/chainhead/unpin.ts
356
363
  var createUnpinFn = (request) => (hashes) => hashes.length > 0 ? new Promise((res, rej) => {
357
- request("chainHead_unstable_unpin", [hashes], {
364
+ request(chainHead.unpin, [hashes], {
358
365
  onSuccess() {
359
366
  res();
360
367
  },
@@ -405,7 +412,7 @@ function getChainHead(request) {
405
412
  unfollow(!(error instanceof DestroyedError));
406
413
  };
407
414
  const onFollowRequestSuccess = (subscriptionId, follow) => {
408
- const done = follow("chainHead_unstable_followEvent", subscriptionId, {
415
+ const done = follow(chainHead.followEvent, subscriptionId, {
409
416
  next: onAllFollowEventsNext,
410
417
  error: onAllFollowEventsError
411
418
  });
@@ -413,7 +420,7 @@ function getChainHead(request) {
413
420
  followSubscription = null;
414
421
  unfollow = noop2;
415
422
  done();
416
- sendUnfollow && request("chainHead_unstable_unfollow", [subscriptionId]);
423
+ sendUnfollow && request(chainHead.unfollow, [subscriptionId]);
417
424
  subscriptions.errorAll(new DisjointError());
418
425
  ongoingRequests.forEach((cb) => {
419
426
  cb();
@@ -433,7 +440,7 @@ function getChainHead(request) {
433
440
  deferredFollow.res(e);
434
441
  };
435
442
  let unfollow = request(
436
- "chainHead_unstable_follow",
443
+ chainHead.follow,
437
444
  [withRuntime],
438
445
  { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError }
439
446
  );
@@ -591,21 +598,104 @@ var createClient = (gProvider) => {
591
598
  };
592
599
  };
593
600
 
601
+ // src/chainspec.ts
602
+ var createGetChainSpec = (clientRequest) => {
603
+ const request = abortablePromiseFn(
604
+ (onSuccess, onError, method, params) => clientRequest(method, params, { onSuccess, onError })
605
+ );
606
+ let cachedPromise = null;
607
+ return async () => {
608
+ if (cachedPromise)
609
+ return cachedPromise;
610
+ return cachedPromise = Promise.all([
611
+ request(chainSpec.chainName, []),
612
+ request(chainSpec.genesisHash, []),
613
+ request(chainSpec.properties, [])
614
+ ]).then(([name, genesisHash, properties]) => ({
615
+ name,
616
+ genesisHash,
617
+ properties
618
+ }));
619
+ };
620
+ };
621
+
622
+ // src/request-compatibility-enhancer.ts
623
+ var getCompatibilityEnhancer = (rpcMethodsP, request) => (methods) => {
624
+ let enhancedRequest = null;
625
+ return (method, ...rest) => {
626
+ if (enhancedRequest)
627
+ return enhancedRequest(method, ...rest);
628
+ let isRunning = true;
629
+ let cleanup = () => {
630
+ isRunning = false;
631
+ };
632
+ rpcMethodsP.then((rpcMethods) => {
633
+ enhancedRequest = (method2, ...iRest) => {
634
+ if (rpcMethods.has(method2))
635
+ return request(method2, ...iRest);
636
+ iRest[1]?.onError(new Error(`Unsupported method ${method2}`));
637
+ return noop2;
638
+ };
639
+ if (rpcMethods.has(method))
640
+ return;
641
+ const parts = method.split("_");
642
+ if (parts[1] !== "v1")
643
+ return;
644
+ parts[1] = "unstable";
645
+ method = parts.join("_");
646
+ if (rpcMethods.has(method))
647
+ Object.entries(methods).forEach(([key, value]) => {
648
+ methods[key] = value.replace("_v1_", "_unstable_");
649
+ });
650
+ else if (parts[0] === "transaction") {
651
+ let unwatch;
652
+ let version;
653
+ const txGroup = ["transactionWatch", "transaction"].find(
654
+ (group) => {
655
+ version = ["v1", "unstable"].find(
656
+ (v) => rpcMethods.has(unwatch = `${group}_${v}_unwatch`)
657
+ );
658
+ return !!version;
659
+ }
660
+ );
661
+ if (txGroup) {
662
+ methods.broadcast = `${txGroup}_${version}_submitAndWatch`;
663
+ methods.stop = unwatch;
664
+ }
665
+ }
666
+ }).then(() => {
667
+ if (isRunning)
668
+ cleanup = enhancedRequest(method, ...rest);
669
+ });
670
+ return () => {
671
+ cleanup();
672
+ };
673
+ };
674
+ };
675
+
594
676
  // src/index.ts
595
677
  var createClient2 = (provider) => {
596
678
  const client = createClient(provider);
597
679
  const request = abortablePromiseFn(
598
680
  (onSuccess, onError, method, params) => client.request(method, params, { onSuccess, onError })
599
681
  );
600
- let rpcMethods = request("rpc_methods", []).then(
601
- (x) => rpcMethods = new Set(Array.isArray(x) ? x : x.methods)
682
+ const rpcMethods = request("rpc_methods", []).then(
683
+ (x) => new Set(Array.isArray(x) ? x : x.methods),
684
+ () => /* @__PURE__ */ new Set()
685
+ );
686
+ const compatibilityEnhancer = getCompatibilityEnhancer(
687
+ rpcMethods,
688
+ client.request
602
689
  );
603
- rpcMethods.catch(noop2);
604
690
  return {
605
- chainHead: getChainHead(client.request),
691
+ chainHead: getChainHead(
692
+ compatibilityEnhancer(chainHead)
693
+ ),
606
694
  transaction: getTransaction(
607
- client.request,
608
- rpcMethods
695
+ compatibilityEnhancer(transaction)
696
+ ),
697
+ getChainSpecData: createGetChainSpec(
698
+ compatibilityEnhancer(chainSpec)
609
699
  ),
610
700
  destroy: () => {
611
701
  client.disconnect();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/internal-utils/abortablePromiseFn.ts","../src/internal-utils/deferred-promise.ts","../src/internal-utils/noop.ts","../src/internal-utils/subscriptions-manager.ts","../src/transaction/transaction.ts","../src/chainhead/errors.ts","../src/chainhead/operation-promise.ts","../src/chainhead/body.ts","../src/chainhead/call.ts","../src/chainhead/header.ts","../src/chainhead/storage-subscription.ts","../src/chainhead/storage.ts","../src/chainhead/unpin.ts","../src/client/DestroyedError.ts","../src/chainhead/chainhead.ts","../src/client/RpcError.ts","../src/client/createClient.ts"],"sourcesContent":["import type { JsonRpcProvider } from \"@polkadot-api/json-rpc-provider\"\nimport { getTransaction } from \"./transaction/transaction\"\nimport { getChainHead } from \"./chainhead\"\nimport {\n ClientRequest,\n ClientRequestCb,\n createClient as createRawClient,\n} from \"./client\"\nimport type { ChainHead } from \"./chainhead\"\nimport type { Transaction } from \"./transaction\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { abortablePromiseFn, noop } from \"./internal-utils\"\n\nexport type * from \"./common-types\"\nexport type * from \"./client\"\nexport type * from \"./transaction\"\nexport type * from \"./chainhead\"\n\nexport { RpcError, DestroyedError } from \"./client\"\nexport {\n StopError,\n DisjointError,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./chainhead\"\n\nexport interface SubstrateClient {\n chainHead: ChainHead\n transaction: Transaction\n destroy: UnsubscribeFn\n request: <T>(\n method: string,\n params: any[],\n abortSignal?: AbortSignal,\n ) => Promise<T>\n _request: <Reply, Notification>(\n method: string,\n params: any[],\n cb?: ClientRequestCb<Reply, Notification>,\n ) => UnsubscribeFn\n}\n\nexport const createClient = (provider: JsonRpcProvider): SubstrateClient => {\n const client = createRawClient(provider)\n\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => client.request(method, params, { onSuccess, onError }),\n )\n\n let rpcMethods: Promise<Set<string>> | Set<string> = request<\n { methods: Array<string> } | Array<string>\n >(\"rpc_methods\", []).then(\n (x) => (rpcMethods = new Set(Array.isArray(x) ? x : x.methods)),\n )\n rpcMethods.catch(noop)\n\n return {\n chainHead: getChainHead(client.request as ClientRequest<any, any>),\n transaction: getTransaction(\n client.request as ClientRequest<string, any>,\n rpcMethods,\n ),\n destroy: () => {\n client.disconnect()\n },\n request,\n _request: client.request,\n }\n}\n","import { AbortError, noop } from \"@polkadot-api/utils\"\nimport { AbortablePromiseFn } from \"../common-types\"\n\nexport const abortablePromiseFn =\n <T, A extends Array<any>>(\n fn: (\n ...args: [...[res: (x: T) => void, rej: (e: any) => void], ...A]\n ) => () => void,\n ): AbortablePromiseFn<A, T> =>\n (...args): Promise<T> =>\n new Promise((res, rej) => {\n let cancel = noop\n\n const [actualArgs, abortSignal] =\n args[args.length - 1] instanceof AbortSignal\n ? ([args.slice(0, args.length - 1), args[args.length - 1]] as [\n A,\n AbortSignal,\n ])\n : ([args] as unknown as [A])\n\n const onAbort = () => {\n cancel()\n rej(new AbortError())\n }\n\n abortSignal?.addEventListener(\"abort\", onAbort, { once: true })\n\n const withCleanup =\n <T>(fn: (x: T) => void): ((x: T) => void) =>\n (x) => {\n cancel = noop\n abortSignal?.removeEventListener(\"abort\", onAbort)\n fn(x)\n }\n\n cancel = fn(...[withCleanup(res), withCleanup(rej), ...actualArgs])\n })\n","export interface DeferredPromise<T> {\n promise: Promise<T>\n res: (value: T) => void\n rej: (err: Error) => void\n}\n\nexport function deferred<T>(): DeferredPromise<T> {\n let res: (value: T) => void = () => {}\n let rej: (err: Error) => void = () => {}\n\n const promise = new Promise<T>((_res, _rej) => {\n res = _res\n rej = _rej\n })\n\n return { promise, res, rej }\n}\n","export const noop = (): void => {}\n","export interface Subscriber<T> {\n next: (data: T) => void\n error: (e: Error) => void\n}\n\nexport const getSubscriptionsManager = <T>() => {\n const subscriptions = new Map<string, Subscriber<T>>()\n\n return {\n has: subscriptions.has.bind(subscriptions),\n subscribe(id: string, subscriber: Subscriber<T>) {\n subscriptions.set(id, subscriber)\n },\n unsubscribe(id: string) {\n subscriptions.delete(id)\n },\n next(id: string, data: T) {\n subscriptions.get(id)?.next(data)\n },\n error(id: string, e: Error) {\n const subscriber = subscriptions.get(id)\n if (subscriber) {\n subscriptions.delete(id)\n subscriber.error(e)\n }\n },\n errorAll(e: Error) {\n const subscribers = [...subscriptions.values()]\n subscriptions.clear()\n subscribers.forEach((s) => {\n s.error(e)\n })\n },\n }\n}\n\nexport type SubscriptionManager<T> = ReturnType<\n typeof getSubscriptionsManager<T>\n>\n","import { noop } from \"@/internal-utils\"\nimport { type ClientRequest } from \"../client\"\n\nconst getTxBroadcastNames = (input: Set<string>): [string, string] => {\n // Proper\n if (input.has(\"transaction_v1_broadcast\"))\n return [\"transaction_v1_broadcast\", \"transaction_v1_stop\"]\n\n // Fallback for versions not up-to-date yet\n if (input.has(\"transactionWatch_unstable_submitAndWatch\"))\n return [\n \"transactionWatch_unstable_submitAndWatch\",\n \"transactionWatch_unstable_unwatch\",\n ]\n\n // Fallback for very old versions\n return [\"transaction_unstable_submitAndWatch\", \"transaction_unstable_unwatch\"]\n}\n\nexport const getTransaction =\n (\n request: ClientRequest<string, any>,\n rpcMethods: Promise<Set<string>> | Set<string>,\n ) =>\n (tx: string, error: (e: Error) => void) => {\n const broadcast = (\n tx: string,\n broadcastFn: string,\n cancelBroadcastFn: string,\n ) =>\n request(broadcastFn, [tx], {\n onSuccess: (subscriptionId) => {\n cancel =\n subscriptionId === null\n ? noop\n : () => {\n request(cancelBroadcastFn, [subscriptionId])\n }\n\n if (subscriptionId === null) {\n error(\n new Error(\"Max # of broadcasted transactions has been reached\"),\n )\n }\n },\n onError: error,\n })\n\n let isActive = true\n let cancel = () => {\n isActive = false\n }\n\n if (rpcMethods instanceof Promise) {\n rpcMethods.then(getTxBroadcastNames).then((names) => {\n if (!isActive) return\n cancel = broadcast(tx, ...names)\n })\n } else cancel = broadcast(tx, ...getTxBroadcastNames(rpcMethods))\n\n return () => {\n cancel()\n }\n }\n","export class StopError extends Error {\n constructor() {\n super(\"ChainHead stopped\")\n this.name = \"StopError\"\n }\n}\n\nexport class DisjointError extends Error {\n constructor() {\n super(\"ChainHead disjointed\")\n this.name = \"DisjointError\"\n }\n}\n\nexport class OperationLimitError extends Error {\n constructor() {\n super(\"ChainHead operations limit reached\")\n this.name = \"OperationLimitError\"\n }\n}\n\nexport class OperationError extends Error {\n constructor(error: string) {\n super(error)\n this.name = \"OperationError\"\n }\n}\n\nexport class OperationInaccessibleError extends Error {\n constructor() {\n super(\"ChainHead operation inaccessible\")\n this.name = \"OperationInaccessibleError\"\n }\n}\n","import { abortablePromiseFn, noop } from \"@/internal-utils\"\nimport {\n CommonOperationEventsRpc,\n OperationResponseRpc,\n} from \"./json-rpc-types\"\nimport {\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./errors\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createOperationPromise =\n <I extends { operationId: string; event: string }, O, A extends Array<any>>(\n operationName: string,\n factory: (\n ...args: A\n ) => [\n Array<any>,\n (e: I, res: (x: O) => void, rej: (e: Error) => void) => void,\n ],\n ) =>\n (\n request: ClientInnerRequest<\n OperationResponseRpc,\n I | CommonOperationEventsRpc\n >,\n ) =>\n abortablePromiseFn<O, A>((res, rej, ...args) => {\n const [requestArgs, logicCb] = factory(...args)\n let cancel = request(operationName, requestArgs, {\n onSuccess: (response, followSubscription) => {\n if (response.result === \"limitReached\") {\n cancel = noop\n return rej(new OperationLimitError())\n }\n\n let isOperationGoing = true\n let done = noop\n const _res = (x: O) => {\n isOperationGoing = false\n done()\n res(x)\n }\n const _rej = (x: Error) => {\n isOperationGoing = false\n done()\n rej(x)\n }\n\n done = followSubscription(response.operationId, {\n next: (e) => {\n const _e = e as CommonOperationEventsRpc\n if (_e.event === \"operationError\") {\n rej(new OperationError(_e.error))\n } else if (_e.event === \"operationInaccessible\") {\n rej(new OperationInaccessibleError())\n } else {\n logicCb(e as I, _res, _rej)\n }\n },\n error: _rej,\n })\n\n cancel = () => {\n if (!isOperationGoing) return\n done()\n request(\"chainHead_unstable_stopOperation\", [response.operationId])\n }\n },\n onError: rej,\n })\n\n return () => {\n cancel()\n }\n })\n","import type { OperationBodyDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createBodyFn = createOperationPromise(\n \"chainHead_unstable_body\",\n (hash: string) => [\n [hash],\n (e: OperationBodyDoneRpc, res: (x: Array<string>) => void) => {\n res(e.value)\n },\n ],\n)\n","import type { OperationCallDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createCallFn = createOperationPromise(\n \"chainHead_unstable_call\",\n (hash: string, fnName: string, callParameters: string) => [\n [hash, fnName, callParameters],\n (e: OperationCallDoneRpc, res: (output: string) => void) => {\n res(e.output)\n },\n ],\n)\n","import { ClientInnerRequest } from \"./public-types\"\n\nexport const createHeaderFn =\n (request: ClientInnerRequest<string, unknown>) => (hash: string) =>\n new Promise<string>((res, rej) => {\n request(\"chainHead_unstable_header\", [hash], {\n onSuccess: res,\n onError: rej,\n })\n })\n","import { noop } from \"@polkadot-api/utils\"\nimport {\n ClientInnerRequest,\n FollowResponse,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"..\"\nimport {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\n\nexport const createStorageCb =\n (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n ): FollowResponse[\"storageSubscription\"] =>\n (hash, inputs, childTrie, onItems, onError, onDone, onDiscardedItems) => {\n if (inputs.length === 0) {\n onDone()\n return noop\n }\n\n let cancel = request(\n \"chainHead_unstable_storage\",\n [hash, inputs, childTrie],\n {\n onSuccess: (response, followSubscription) => {\n if (\n response.result === \"limitReached\" ||\n response.discardedItems === inputs.length\n )\n return onError(new OperationLimitError())\n\n const doneListening = followSubscription(response.operationId, {\n next: (event) => {\n switch (event.event) {\n case \"operationStorageItems\": {\n onItems(event.items)\n break\n }\n case \"operationStorageDone\": {\n _onDone()\n break\n }\n case \"operationError\": {\n _onError(new OperationError(event.error))\n break\n }\n case \"operationInaccessible\": {\n _onError(new OperationInaccessibleError())\n break\n }\n default:\n request(\"chainHead_unstable_continue\", [event.operationId])\n }\n },\n error: onError,\n })\n\n cancel = () => {\n doneListening()\n request(\"chainHead_unstable_stopOperation\", [response.operationId])\n }\n\n const _onError = (e: Error) => {\n cancel = noop\n doneListening()\n onError(e)\n }\n\n const _onDone = () => {\n cancel = noop\n doneListening()\n onDone()\n }\n\n onDiscardedItems(response.discardedItems)\n },\n onError,\n },\n )\n\n return () => {\n cancel()\n }\n }\n","import { ClientInnerRequest, FollowResponse, OperationLimitError } from \"..\"\nimport type {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { abortablePromiseFn } from \"@/internal-utils\"\nimport { createStorageCb } from \"./storage-subscription\"\n\nexport const createStorageFn = (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n): FollowResponse[\"storage\"] => {\n const cbStore = createStorageCb(request)\n return abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {\n const isDescendants = type.startsWith(\"descendants\")\n let result: any = isDescendants ? [] : null\n\n const onItems: Parameters<typeof cbStore>[3] = isDescendants\n ? (items) => {\n result.push(items)\n }\n : (items) => {\n result = items[0]?.[type as \"value\"]\n }\n\n const cancel = cbStore(\n hash,\n [{ key, type }],\n childTrie ?? null,\n onItems,\n reject,\n () => {\n try {\n resolve(isDescendants ? result.flat() : result)\n } catch (e) {\n reject(e)\n }\n },\n (nDiscarded) => {\n if (nDiscarded > 0) {\n cancel()\n reject(new OperationLimitError())\n }\n },\n )\n return cancel\n })\n}\n","import { ClientInnerRequest } from \"./public-types\"\n\nexport const createUnpinFn =\n (request: ClientInnerRequest<null, unknown>) => (hashes: string[]) =>\n hashes.length > 0\n ? new Promise<void>((res, rej) => {\n request(\"chainHead_unstable_unpin\", [hashes], {\n onSuccess() {\n res()\n },\n onError: rej,\n })\n })\n : Promise.resolve()\n","export class DestroyedError extends Error {\n constructor() {\n super(\"Client destroyed\")\n this.name = \"DestroyedError\"\n }\n}\n","import type { ClientRequest, FollowSubscriptionCb } from \"@/client\"\nimport type {\n FollowEventWithRuntimeRpc,\n FollowEventWithoutRuntimeRpc,\n OperationEventsRpc,\n StopRpc,\n} from \"./json-rpc-types\"\nimport type {\n ChainHead,\n ClientInnerRequest,\n FollowEventWithoutRuntime,\n FollowEventWithRuntime,\n FollowResponse,\n} from \"./public-types\"\nimport {\n Subscriber,\n getSubscriptionsManager,\n noop,\n deferred,\n} from \"@/internal-utils\"\nimport { createBodyFn } from \"./body\"\nimport { createCallFn } from \"./call\"\nimport { createHeaderFn } from \"./header\"\nimport { createStorageFn } from \"./storage\"\nimport { createUnpinFn } from \"./unpin\"\nimport { DisjointError, StopError } from \"./errors\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { DestroyedError } from \"@/client/DestroyedError\"\n\ntype FollowEventRpc =\n | FollowEventWithRuntimeRpc\n | FollowEventWithoutRuntimeRpc\n | OperationEventsRpc\n | StopRpc\n\nfunction isOperationEvent(event: FollowEventRpc): event is OperationEventsRpc {\n return (event as OperationEventsRpc).operationId !== undefined\n}\n\nexport function getChainHead(\n request: ClientRequest<string, FollowEventRpc>,\n): ChainHead {\n return (\n withRuntime: boolean,\n onFollowEvent:\n | ((event: FollowEventWithoutRuntime) => void)\n | ((event: FollowEventWithRuntime) => void),\n onFollowError: (e: Error) => void,\n ): FollowResponse => {\n const subscriptions = getSubscriptionsManager<OperationEventsRpc>()\n\n const ongoingRequests = new Set<() => void>()\n const deferredFollow = deferred<string | Error>()\n let followSubscription: Promise<string | Error> | string | null =\n deferredFollow.promise\n\n const onAllFollowEventsNext = (event: FollowEventRpc) => {\n if (isOperationEvent(event)) {\n if (!subscriptions.has(event.operationId))\n console.warn(\"Uknown operationId on\", event)\n\n return subscriptions.next(event.operationId, event)\n }\n\n if (event.event !== \"stop\") {\n if (event.event === \"initialized\") {\n return onFollowEvent({\n type: event.event,\n finalizedBlockHashes:\n \"finalizedBlockHash\" in event\n ? [event.finalizedBlockHash]\n : event.finalizedBlockHashes,\n finalizedBlockRuntime: (event as any).finalizedBlockRuntime,\n })\n }\n\n const { event: type, ...rest } = event\n // This is kinda dangerous, but YOLO\n return onFollowEvent({ type, ...rest } as any)\n }\n\n onFollowError(new StopError())\n unfollow(false)\n }\n\n const onAllFollowEventsError = (error: Error) => {\n onFollowError(error)\n unfollow(!(error instanceof DestroyedError))\n }\n\n const onFollowRequestSuccess = (\n subscriptionId: string,\n follow: FollowSubscriptionCb<FollowEventRpc>,\n ) => {\n const done = follow(\"chainHead_unstable_followEvent\", subscriptionId, {\n next: onAllFollowEventsNext,\n error: onAllFollowEventsError,\n })\n\n unfollow = (sendUnfollow = true) => {\n followSubscription = null\n unfollow = noop\n done()\n sendUnfollow && request(\"chainHead_unstable_unfollow\", [subscriptionId])\n subscriptions.errorAll(new DisjointError())\n ongoingRequests.forEach((cb) => {\n cb()\n })\n ongoingRequests.clear()\n }\n\n followSubscription = subscriptionId\n deferredFollow.res(subscriptionId)\n }\n\n const onFollowRequestError = (e: Error) => {\n if (e instanceof DestroyedError) {\n unfollow(false)\n } else {\n onFollowError(e)\n }\n followSubscription = null\n deferredFollow.res(e)\n }\n\n let unfollow: (internal?: boolean) => void = request(\n \"chainHead_unstable_follow\",\n [withRuntime],\n { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError },\n )\n\n const fRequest: ClientInnerRequest<any, any> = (method, params, cb) => {\n const disjoint = () => {\n cb?.onError(new DisjointError())\n }\n\n if (followSubscription === null) {\n disjoint()\n return noop\n }\n\n const onSubscription = (subscription: string) => {\n if (!cb) return request(method, [subscription, ...params])\n\n ongoingRequests.add(disjoint)\n\n const onSubscribeOperation = (\n operationId: string,\n subscriber: Subscriber<any>,\n ) => {\n if (followSubscription === null) {\n subscriber.error(new DisjointError())\n return noop\n }\n\n subscriptions.subscribe(operationId, subscriber)\n\n return () => {\n subscriptions.unsubscribe(operationId)\n }\n }\n\n const cleanup = request(method, [subscription, ...params], {\n onSuccess: (response) => {\n ongoingRequests.delete(disjoint)\n cb.onSuccess(response, onSubscribeOperation)\n },\n onError: (e) => {\n ongoingRequests.delete(disjoint)\n cb.onError(e)\n },\n })\n\n return () => {\n ongoingRequests.delete(disjoint)\n cleanup()\n }\n }\n\n if (typeof followSubscription === \"string\")\n return onSubscription(followSubscription)\n\n let onCancel = noop\n followSubscription.then((x) => {\n if (x instanceof Error) return disjoint()\n if (followSubscription) onCancel = onSubscription(x)\n })\n\n return () => {\n onCancel()\n }\n }\n\n return {\n unfollow() {\n unfollow()\n followSubscription = null\n },\n body: createBodyFn(fRequest),\n call: createCallFn(fRequest),\n header: createHeaderFn(fRequest),\n storage: createStorageFn(fRequest),\n storageSubscription: createStorageCb(fRequest),\n unpin: createUnpinFn(fRequest),\n _request: fRequest,\n }\n }\n}\n","export interface IRpcError {\n code: number\n message: string\n data?: any\n}\n\nexport class RpcError extends Error implements IRpcError {\n code\n data\n constructor(e: IRpcError) {\n super(e.message)\n this.code = e.code\n this.data = e.data\n this.name = \"RpcError\"\n }\n}\n","import {\n JsonRpcConnection,\n JsonRpcProvider,\n} from \"@polkadot-api/json-rpc-provider\"\nimport { UnsubscribeFn } from \"../common-types\"\nimport { RpcError, IRpcError } from \"./RpcError\"\nimport { getSubscriptionsManager, Subscriber } from \"@/internal-utils\"\nimport { DestroyedError } from \"./DestroyedError\"\n\nexport type FollowSubscriptionCb<T> = (\n methodName: string,\n subscriptionId: string,\n cb: Subscriber<T>,\n) => UnsubscribeFn\n\nexport type ClientRequestCb<T, TT> = {\n onSuccess: (result: T, followSubscription: FollowSubscriptionCb<TT>) => void\n onError: (e: Error) => void\n}\n\nexport type ClientRequest<T, TT> = (\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n) => UnsubscribeFn\n\nexport interface Client {\n disconnect: () => void\n request: ClientRequest<any, any>\n}\n\nlet nextClientId = 1\nexport const createClient = (gProvider: JsonRpcProvider): Client => {\n let clientId = nextClientId++\n const responses = new Map<string, ClientRequestCb<any, any>>()\n const subscriptions = getSubscriptionsManager()\n\n let connection: JsonRpcConnection | null = null\n\n const send = (\n id: string,\n method: string,\n params: Array<boolean | string | number | null>,\n ) => {\n connection!.send(\n JSON.stringify({\n jsonrpc: \"2.0\",\n id,\n method,\n params,\n }),\n )\n }\n\n function onMessage(message: string): void {\n try {\n let id: string,\n result,\n error: IRpcError | undefined,\n params: { subscription: any; result: any; error?: IRpcError },\n subscription: string\n\n const parsed = JSON.parse(message)\n ;({ id, result, error, params } = parsed)\n\n if (id) {\n const cb = responses.get(id)\n if (!cb) return\n\n responses.delete(id)\n\n return error\n ? cb.onError(new RpcError(error))\n : cb.onSuccess(result, (methodName, opaqueId, subscriber) => {\n const subscriptionId = methodName + opaqueId\n subscriptions.subscribe(subscriptionId, subscriber)\n return () => {\n subscriptions.unsubscribe(subscriptionId)\n }\n })\n }\n\n // at this point, it means that it should be a notification\n ;({ subscription, result, error } = params)\n if (!subscription || (!error && !Object.hasOwn(params, \"result\"))) throw 0\n\n const subscriptionId = parsed.method + subscription\n\n if (error) {\n subscriptions.error(subscriptionId, new RpcError(error!))\n } else {\n subscriptions.next(subscriptionId, result)\n }\n } catch (e) {\n console.warn(\"Error parsing incomming message: \" + message)\n console.error(e)\n }\n }\n connection = gProvider(onMessage)\n\n const disconnect = () => {\n connection?.disconnect()\n connection = null\n subscriptions.errorAll(new DestroyedError())\n responses.forEach((r) => r.onError(new DestroyedError()))\n responses.clear()\n }\n\n let nextId = 1\n const request = <T, TT>(\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n ): UnsubscribeFn => {\n if (!connection) throw new Error(\"Not connected\")\n const id = `${clientId}-${nextId++}`\n\n if (cb) responses.set(id, cb)\n send(id, method, params)\n\n return (): void => {\n responses.delete(id)\n }\n }\n\n return {\n request,\n disconnect,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAAA;AAAA;AAAA;;;ACAA,mBAAiC;AAG1B,IAAM,qBACX,CACE,OAIF,IAAI,SACF,IAAI,QAAQ,CAAC,KAAK,QAAQ;AACxB,MAAI,SAAS;AAEb,QAAM,CAAC,YAAY,WAAW,IAC5B,KAAK,KAAK,SAAS,CAAC,aAAa,cAC5B,CAAC,KAAK,MAAM,GAAG,KAAK,SAAS,CAAC,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,IAItD,CA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AAS,MAAM;AACb,aAAO,WAAW;AAAA,IACpB;AAAA,IACA;AAAA,IACA,UAAU,OAAO;AAAA,EACnB;AACF;","names":["createClient","fn","noop","tx","noop","noop","import_utils","noop","subscriptionId","createClient","noop"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/internal-utils/abortablePromiseFn.ts","../src/internal-utils/deferred-promise.ts","../src/internal-utils/noop.ts","../src/internal-utils/subscriptions-manager.ts","../src/methods.ts","../src/transaction/transaction.ts","../src/chainhead/errors.ts","../src/chainhead/operation-promise.ts","../src/chainhead/body.ts","../src/chainhead/call.ts","../src/chainhead/header.ts","../src/chainhead/storage-subscription.ts","../src/chainhead/storage.ts","../src/chainhead/unpin.ts","../src/client/DestroyedError.ts","../src/chainhead/chainhead.ts","../src/client/RpcError.ts","../src/client/createClient.ts","../src/chainspec.ts","../src/request-compatibility-enhancer.ts"],"sourcesContent":["import type { JsonRpcProvider } from \"@polkadot-api/json-rpc-provider\"\nimport { getTransaction } from \"./transaction/transaction\"\nimport { getChainHead } from \"./chainhead\"\nimport {\n ClientRequest,\n ClientRequestCb,\n createClient as createRawClient,\n} from \"./client\"\nimport type { ChainHead } from \"./chainhead\"\nimport type { Transaction } from \"./transaction\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { ChainSpecData, createGetChainSpec } from \"./chainspec\"\nimport { getCompatibilityEnhancer } from \"./request-compatibility-enhancer\"\nimport { chainHead, chainSpec, transaction } from \"./methods\"\n\nexport type * from \"./common-types\"\nexport type * from \"./client\"\nexport type * from \"./transaction\"\nexport type * from \"./chainhead\"\nexport type * from \"./chainspec\"\n\nexport { RpcError, DestroyedError } from \"./client\"\nexport {\n StopError,\n DisjointError,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./chainhead\"\n\nexport interface SubstrateClient {\n chainHead: ChainHead\n transaction: Transaction\n destroy: UnsubscribeFn\n getChainSpecData: () => Promise<ChainSpecData>\n request: <T>(\n method: string,\n params: any[],\n abortSignal?: AbortSignal,\n ) => Promise<T>\n _request: <Reply, Notification>(\n method: string,\n params: any[],\n cb?: ClientRequestCb<Reply, Notification>,\n ) => UnsubscribeFn\n}\n\nexport const createClient = (provider: JsonRpcProvider): SubstrateClient => {\n const client = createRawClient(provider)\n\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => client.request(method, params, { onSuccess, onError }),\n )\n\n const rpcMethods: Promise<Set<string>> = request<\n { methods: Array<string> } | Array<string>\n >(\"rpc_methods\", []).then(\n (x) => new Set(Array.isArray(x) ? x : x.methods),\n () => new Set(),\n )\n\n const compatibilityEnhancer = getCompatibilityEnhancer(\n rpcMethods,\n client.request,\n )\n\n return {\n chainHead: getChainHead(\n compatibilityEnhancer(chainHead) as ClientRequest<any, any>,\n ),\n transaction: getTransaction(\n compatibilityEnhancer(transaction) as ClientRequest<string, any>,\n ),\n getChainSpecData: createGetChainSpec(\n compatibilityEnhancer(chainSpec) as ClientRequest<any, any>,\n ),\n destroy: () => {\n client.disconnect()\n },\n request,\n _request: client.request,\n }\n}\n","import { AbortError, noop } from \"@polkadot-api/utils\"\nimport { AbortablePromiseFn } from \"../common-types\"\n\nexport const abortablePromiseFn =\n <T, A extends Array<any>>(\n fn: (\n ...args: [...[res: (x: T) => void, rej: (e: any) => void], ...A]\n ) => () => void,\n ): AbortablePromiseFn<A, T> =>\n (...args): Promise<T> =>\n new Promise((res, rej) => {\n let cancel = noop\n\n const [actualArgs, abortSignal] =\n args[args.length - 1] instanceof AbortSignal\n ? ([args.slice(0, args.length - 1), args[args.length - 1]] as [\n A,\n AbortSignal,\n ])\n : ([args] as unknown as [A])\n\n const onAbort = () => {\n cancel()\n rej(new AbortError())\n }\n\n abortSignal?.addEventListener(\"abort\", onAbort, { once: true })\n\n const withCleanup =\n <T>(fn: (x: T) => void): ((x: T) => void) =>\n (x) => {\n cancel = noop\n abortSignal?.removeEventListener(\"abort\", onAbort)\n fn(x)\n }\n\n cancel = fn(...[withCleanup(res), withCleanup(rej), ...actualArgs])\n })\n","export interface DeferredPromise<T> {\n promise: Promise<T>\n res: (value: T) => void\n rej: (err: Error) => void\n}\n\nexport function deferred<T>(): DeferredPromise<T> {\n let res: (value: T) => void = () => {}\n let rej: (err: Error) => void = () => {}\n\n const promise = new Promise<T>((_res, _rej) => {\n res = _res\n rej = _rej\n })\n\n return { promise, res, rej }\n}\n","export const noop = (): void => {}\n","export interface Subscriber<T> {\n next: (data: T) => void\n error: (e: Error) => void\n}\n\nexport const getSubscriptionsManager = <T>() => {\n const subscriptions = new Map<string, Subscriber<T>>()\n\n return {\n has: subscriptions.has.bind(subscriptions),\n subscribe(id: string, subscriber: Subscriber<T>) {\n subscriptions.set(id, subscriber)\n },\n unsubscribe(id: string) {\n subscriptions.delete(id)\n },\n next(id: string, data: T) {\n subscriptions.get(id)?.next(data)\n },\n error(id: string, e: Error) {\n const subscriber = subscriptions.get(id)\n if (subscriber) {\n subscriptions.delete(id)\n subscriber.error(e)\n }\n },\n errorAll(e: Error) {\n const subscribers = [...subscriptions.values()]\n subscriptions.clear()\n subscribers.forEach((s) => {\n s.error(e)\n })\n },\n }\n}\n\nexport type SubscriptionManager<T> = ReturnType<\n typeof getSubscriptionsManager<T>\n>\n","export const chainHead = {\n body: \"\",\n call: \"\",\n continue: \"\",\n follow: \"\",\n header: \"\",\n stopOperation: \"\",\n storage: \"\",\n unfollow: \"\",\n unpin: \"\",\n followEvent: \"\",\n}\n\nexport const chainSpec = {\n chainName: \"\",\n genesisHash: \"\",\n properties: \"\",\n}\n\nexport const transaction = {\n broadcast: \"\",\n stop: \"\",\n}\n\nexport const transactionWatch = {\n submitAndWatch: \"\",\n unwatch: \"\",\n}\n\nObject.entries({ chainHead, chainSpec, transaction, transactionWatch }).forEach(\n ([fnGroupName, methods]) => {\n Object.keys(methods).forEach((methodName) => {\n ;(methods as any)[methodName] = `${fnGroupName}_v1_${methodName}`\n })\n },\n)\n","import { noop } from \"@/internal-utils\"\nimport { type ClientRequest } from \"../client\"\nimport { transaction } from \"@/methods\"\n\nexport const getTransaction =\n (request: ClientRequest<string, any>) =>\n (tx: string, error: (e: Error) => void) => {\n let cancel = request(transaction.broadcast, [tx], {\n onSuccess: (subscriptionId) => {\n cancel =\n subscriptionId === null\n ? noop\n : () => {\n request(transaction.stop, [subscriptionId])\n }\n\n if (subscriptionId === null) {\n error(new Error(\"Max # of broadcasted transactions has been reached\"))\n }\n },\n onError: error,\n })\n\n return () => {\n cancel()\n }\n }\n","export class StopError extends Error {\n constructor() {\n super(\"ChainHead stopped\")\n this.name = \"StopError\"\n }\n}\n\nexport class DisjointError extends Error {\n constructor() {\n super(\"ChainHead disjointed\")\n this.name = \"DisjointError\"\n }\n}\n\nexport class OperationLimitError extends Error {\n constructor() {\n super(\"ChainHead operations limit reached\")\n this.name = \"OperationLimitError\"\n }\n}\n\nexport class OperationError extends Error {\n constructor(error: string) {\n super(error)\n this.name = \"OperationError\"\n }\n}\n\nexport class OperationInaccessibleError extends Error {\n constructor() {\n super(\"ChainHead operation inaccessible\")\n this.name = \"OperationInaccessibleError\"\n }\n}\n","import { abortablePromiseFn, noop } from \"@/internal-utils\"\nimport {\n CommonOperationEventsRpc,\n OperationResponseRpc,\n} from \"./json-rpc-types\"\nimport {\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./errors\"\nimport { ClientInnerRequest } from \"./public-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createOperationPromise =\n <I extends { operationId: string; event: string }, O, A extends Array<any>>(\n operationName: () => string,\n factory: (\n ...args: A\n ) => [\n Array<any>,\n (e: I, res: (x: O) => void, rej: (e: Error) => void) => void,\n ],\n ) =>\n (\n request: ClientInnerRequest<\n OperationResponseRpc,\n I | CommonOperationEventsRpc\n >,\n ) =>\n abortablePromiseFn<O, A>((res, rej, ...args) => {\n const [requestArgs, logicCb] = factory(...args)\n let cancel = request(operationName(), requestArgs, {\n onSuccess: (response, followSubscription) => {\n if (response.result === \"limitReached\") {\n cancel = noop\n return rej(new OperationLimitError())\n }\n\n let isOperationGoing = true\n let done = noop\n const _res = (x: O) => {\n isOperationGoing = false\n done()\n res(x)\n }\n const _rej = (x: Error) => {\n isOperationGoing = false\n done()\n rej(x)\n }\n\n done = followSubscription(response.operationId, {\n next: (e) => {\n const _e = e as CommonOperationEventsRpc\n if (_e.event === \"operationError\") {\n rej(new OperationError(_e.error))\n } else if (_e.event === \"operationInaccessible\") {\n rej(new OperationInaccessibleError())\n } else {\n logicCb(e as I, _res, _rej)\n }\n },\n error: _rej,\n })\n\n cancel = () => {\n if (!isOperationGoing) return\n done()\n request(chainHead.stopOperation, [response.operationId])\n }\n },\n onError: rej,\n })\n\n return () => {\n cancel()\n }\n })\n","import { chainHead } from \"@/methods\"\nimport type { OperationBodyDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createBodyFn = createOperationPromise(\n () => chainHead.body,\n (hash: string) => [\n [hash],\n (e: OperationBodyDoneRpc, res: (x: Array<string>) => void) => {\n res(e.value)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport type { OperationCallDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createCallFn = createOperationPromise(\n () => chainHead.call,\n (hash: string, fnName: string, callParameters: string) => [\n [hash, fnName, callParameters],\n (e: OperationCallDoneRpc, res: (output: string) => void) => {\n res(e.output)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createHeaderFn =\n (request: ClientInnerRequest<string, unknown>) => (hash: string) =>\n new Promise<string>((res, rej) => {\n request(chainHead.header, [hash], {\n onSuccess: res,\n onError: rej,\n })\n })\n","import { noop } from \"@polkadot-api/utils\"\nimport {\n ClientInnerRequest,\n FollowResponse,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"..\"\nimport {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createStorageCb =\n (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n ): FollowResponse[\"storageSubscription\"] =>\n (hash, inputs, childTrie, onItems, onError, onDone, onDiscardedItems) => {\n if (inputs.length === 0) {\n onDone()\n return noop\n }\n\n let cancel = request(chainHead.storage, [hash, inputs, childTrie], {\n onSuccess: (response, followSubscription) => {\n if (\n response.result === \"limitReached\" ||\n response.discardedItems === inputs.length\n )\n return onError(new OperationLimitError())\n\n const doneListening = followSubscription(response.operationId, {\n next: (event) => {\n switch (event.event) {\n case \"operationStorageItems\": {\n onItems(event.items)\n break\n }\n case \"operationStorageDone\": {\n _onDone()\n break\n }\n case \"operationError\": {\n _onError(new OperationError(event.error))\n break\n }\n case \"operationInaccessible\": {\n _onError(new OperationInaccessibleError())\n break\n }\n default:\n request(chainHead.continue, [event.operationId])\n }\n },\n error: onError,\n })\n\n cancel = () => {\n doneListening()\n request(chainHead.stopOperation, [response.operationId])\n }\n\n const _onError = (e: Error) => {\n cancel = noop\n doneListening()\n onError(e)\n }\n\n const _onDone = () => {\n cancel = noop\n doneListening()\n onDone()\n }\n\n onDiscardedItems(response.discardedItems)\n },\n onError,\n })\n\n return () => {\n cancel()\n }\n }\n","import { ClientInnerRequest, FollowResponse, OperationLimitError } from \"..\"\nimport type {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { abortablePromiseFn } from \"@/internal-utils\"\nimport { createStorageCb } from \"./storage-subscription\"\n\nexport const createStorageFn = (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n): FollowResponse[\"storage\"] => {\n const cbStore = createStorageCb(request)\n return abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {\n const isDescendants = type.startsWith(\"descendants\")\n let result: any = isDescendants ? [] : null\n\n const onItems: Parameters<typeof cbStore>[3] = isDescendants\n ? (items) => {\n result.push(items)\n }\n : (items) => {\n result = items[0]?.[type as \"value\"]\n }\n\n const cancel = cbStore(\n hash,\n [{ key, type }],\n childTrie ?? null,\n onItems,\n reject,\n () => {\n try {\n resolve(isDescendants ? result.flat() : result)\n } catch (e) {\n reject(e)\n }\n },\n (nDiscarded) => {\n if (nDiscarded > 0) {\n cancel()\n reject(new OperationLimitError())\n }\n },\n )\n return cancel\n })\n}\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createUnpinFn =\n (request: ClientInnerRequest<null, unknown>) => (hashes: string[]) =>\n hashes.length > 0\n ? new Promise<void>((res, rej) => {\n request(chainHead.unpin, [hashes], {\n onSuccess() {\n res()\n },\n onError: rej,\n })\n })\n : Promise.resolve()\n","export class DestroyedError extends Error {\n constructor() {\n super(\"Client destroyed\")\n this.name = \"DestroyedError\"\n }\n}\n","import type { ClientRequest, FollowSubscriptionCb } from \"@/client\"\nimport type {\n FollowEventWithRuntimeRpc,\n FollowEventWithoutRuntimeRpc,\n OperationEventsRpc,\n StopRpc,\n} from \"./json-rpc-types\"\nimport type {\n ChainHead,\n ClientInnerRequest,\n FollowEventWithoutRuntime,\n FollowEventWithRuntime,\n FollowResponse,\n} from \"./public-types\"\nimport {\n Subscriber,\n getSubscriptionsManager,\n noop,\n deferred,\n} from \"@/internal-utils\"\nimport { createBodyFn } from \"./body\"\nimport { createCallFn } from \"./call\"\nimport { createHeaderFn } from \"./header\"\nimport { createStorageFn } from \"./storage\"\nimport { createUnpinFn } from \"./unpin\"\nimport { DisjointError, StopError } from \"./errors\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { DestroyedError } from \"@/client/DestroyedError\"\nimport { chainHead } from \"@/methods\"\n\ntype FollowEventRpc =\n | FollowEventWithRuntimeRpc\n | FollowEventWithoutRuntimeRpc\n | OperationEventsRpc\n | StopRpc\n\nfunction isOperationEvent(event: FollowEventRpc): event is OperationEventsRpc {\n return (event as OperationEventsRpc).operationId !== undefined\n}\n\nexport function getChainHead(\n request: ClientRequest<string, FollowEventRpc>,\n): ChainHead {\n return (\n withRuntime: boolean,\n onFollowEvent:\n | ((event: FollowEventWithoutRuntime) => void)\n | ((event: FollowEventWithRuntime) => void),\n onFollowError: (e: Error) => void,\n ): FollowResponse => {\n const subscriptions = getSubscriptionsManager<OperationEventsRpc>()\n\n const ongoingRequests = new Set<() => void>()\n const deferredFollow = deferred<string | Error>()\n let followSubscription: Promise<string | Error> | string | null =\n deferredFollow.promise\n\n const onAllFollowEventsNext = (event: FollowEventRpc) => {\n if (isOperationEvent(event)) {\n if (!subscriptions.has(event.operationId))\n console.warn(\"Uknown operationId on\", event)\n\n return subscriptions.next(event.operationId, event)\n }\n\n if (event.event !== \"stop\") {\n if (event.event === \"initialized\") {\n return onFollowEvent({\n type: event.event,\n finalizedBlockHashes:\n \"finalizedBlockHash\" in event\n ? [event.finalizedBlockHash]\n : event.finalizedBlockHashes,\n finalizedBlockRuntime: (event as any).finalizedBlockRuntime,\n })\n }\n\n const { event: type, ...rest } = event\n // This is kinda dangerous, but YOLO\n return onFollowEvent({ type, ...rest } as any)\n }\n\n onFollowError(new StopError())\n unfollow(false)\n }\n\n const onAllFollowEventsError = (error: Error) => {\n onFollowError(error)\n unfollow(!(error instanceof DestroyedError))\n }\n\n const onFollowRequestSuccess = (\n subscriptionId: string,\n follow: FollowSubscriptionCb<FollowEventRpc>,\n ) => {\n const done = follow(chainHead.followEvent, subscriptionId, {\n next: onAllFollowEventsNext,\n error: onAllFollowEventsError,\n })\n\n unfollow = (sendUnfollow = true) => {\n followSubscription = null\n unfollow = noop\n done()\n sendUnfollow && request(chainHead.unfollow, [subscriptionId])\n subscriptions.errorAll(new DisjointError())\n ongoingRequests.forEach((cb) => {\n cb()\n })\n ongoingRequests.clear()\n }\n\n followSubscription = subscriptionId\n deferredFollow.res(subscriptionId)\n }\n\n const onFollowRequestError = (e: Error) => {\n if (e instanceof DestroyedError) {\n unfollow(false)\n } else {\n onFollowError(e)\n }\n followSubscription = null\n deferredFollow.res(e)\n }\n\n let unfollow: (internal?: boolean) => void = request(\n chainHead.follow,\n [withRuntime],\n { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError },\n )\n\n const fRequest: ClientInnerRequest<any, any> = (method, params, cb) => {\n const disjoint = () => {\n cb?.onError(new DisjointError())\n }\n\n if (followSubscription === null) {\n disjoint()\n return noop\n }\n\n const onSubscription = (subscription: string) => {\n if (!cb) return request(method, [subscription, ...params])\n\n ongoingRequests.add(disjoint)\n\n const onSubscribeOperation = (\n operationId: string,\n subscriber: Subscriber<any>,\n ) => {\n if (followSubscription === null) {\n subscriber.error(new DisjointError())\n return noop\n }\n\n subscriptions.subscribe(operationId, subscriber)\n\n return () => {\n subscriptions.unsubscribe(operationId)\n }\n }\n\n const cleanup = request(method, [subscription, ...params], {\n onSuccess: (response) => {\n ongoingRequests.delete(disjoint)\n cb.onSuccess(response, onSubscribeOperation)\n },\n onError: (e) => {\n ongoingRequests.delete(disjoint)\n cb.onError(e)\n },\n })\n\n return () => {\n ongoingRequests.delete(disjoint)\n cleanup()\n }\n }\n\n if (typeof followSubscription === \"string\")\n return onSubscription(followSubscription)\n\n let onCancel = noop\n followSubscription.then((x) => {\n if (x instanceof Error) return disjoint()\n if (followSubscription) onCancel = onSubscription(x)\n })\n\n return () => {\n onCancel()\n }\n }\n\n return {\n unfollow() {\n unfollow()\n followSubscription = null\n },\n body: createBodyFn(fRequest),\n call: createCallFn(fRequest),\n header: createHeaderFn(fRequest),\n storage: createStorageFn(fRequest),\n storageSubscription: createStorageCb(fRequest),\n unpin: createUnpinFn(fRequest),\n _request: fRequest,\n }\n }\n}\n","export interface IRpcError {\n code: number\n message: string\n data?: any\n}\n\nexport class RpcError extends Error implements IRpcError {\n code\n data\n constructor(e: IRpcError) {\n super(e.message)\n this.code = e.code\n this.data = e.data\n this.name = \"RpcError\"\n }\n}\n","import {\n JsonRpcConnection,\n JsonRpcProvider,\n} from \"@polkadot-api/json-rpc-provider\"\nimport { UnsubscribeFn } from \"../common-types\"\nimport { RpcError, IRpcError } from \"./RpcError\"\nimport { getSubscriptionsManager, Subscriber } from \"@/internal-utils\"\nimport { DestroyedError } from \"./DestroyedError\"\n\nexport type FollowSubscriptionCb<T> = (\n methodName: string,\n subscriptionId: string,\n cb: Subscriber<T>,\n) => UnsubscribeFn\n\nexport type ClientRequestCb<T, TT> = {\n onSuccess: (result: T, followSubscription: FollowSubscriptionCb<TT>) => void\n onError: (e: Error) => void\n}\n\nexport type ClientRequest<T, TT> = (\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n) => UnsubscribeFn\n\nexport interface Client {\n disconnect: () => void\n request: ClientRequest<any, any>\n}\n\nlet nextClientId = 1\nexport const createClient = (gProvider: JsonRpcProvider): Client => {\n let clientId = nextClientId++\n const responses = new Map<string, ClientRequestCb<any, any>>()\n const subscriptions = getSubscriptionsManager()\n\n let connection: JsonRpcConnection | null = null\n\n const send = (\n id: string,\n method: string,\n params: Array<boolean | string | number | null>,\n ) => {\n connection!.send(\n JSON.stringify({\n jsonrpc: \"2.0\",\n id,\n method,\n params,\n }),\n )\n }\n\n function onMessage(message: string): void {\n try {\n let id: string,\n result,\n error: IRpcError | undefined,\n params: { subscription: any; result: any; error?: IRpcError },\n subscription: string\n\n const parsed = JSON.parse(message)\n ;({ id, result, error, params } = parsed)\n\n if (id) {\n const cb = responses.get(id)\n if (!cb) return\n\n responses.delete(id)\n\n return error\n ? cb.onError(new RpcError(error))\n : cb.onSuccess(result, (methodName, opaqueId, subscriber) => {\n const subscriptionId = methodName + opaqueId\n subscriptions.subscribe(subscriptionId, subscriber)\n return () => {\n subscriptions.unsubscribe(subscriptionId)\n }\n })\n }\n\n // at this point, it means that it should be a notification\n ;({ subscription, result, error } = params)\n if (!subscription || (!error && !Object.hasOwn(params, \"result\"))) throw 0\n\n const subscriptionId = parsed.method + subscription\n\n if (error) {\n subscriptions.error(subscriptionId, new RpcError(error!))\n } else {\n subscriptions.next(subscriptionId, result)\n }\n } catch (e) {\n console.warn(\"Error parsing incomming message: \" + message)\n console.error(e)\n }\n }\n connection = gProvider(onMessage)\n\n const disconnect = () => {\n connection?.disconnect()\n connection = null\n subscriptions.errorAll(new DestroyedError())\n responses.forEach((r) => r.onError(new DestroyedError()))\n responses.clear()\n }\n\n let nextId = 1\n const request = <T, TT>(\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n ): UnsubscribeFn => {\n if (!connection) throw new Error(\"Not connected\")\n const id = `${clientId}-${nextId++}`\n\n if (cb) responses.set(id, cb)\n send(id, method, params)\n\n return (): void => {\n responses.delete(id)\n }\n }\n\n return {\n request,\n disconnect,\n }\n}\n","import { ClientRequest } from \"./client\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { chainSpec } from \"./methods\"\n\nexport interface ChainSpecData {\n name: string\n genesisHash: string\n properties: any\n}\n\nexport const createGetChainSpec = (clientRequest: ClientRequest<any, any>) => {\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => clientRequest(method, params, { onSuccess, onError }),\n )\n let cachedPromise: null | Promise<ChainSpecData> = null\n\n return async (): Promise<ChainSpecData> => {\n if (cachedPromise) return cachedPromise\n return (cachedPromise = Promise.all([\n request<string>(chainSpec.chainName, []),\n request<string>(chainSpec.genesisHash, []),\n request<any>(chainSpec.properties, []),\n ]).then(([name, genesisHash, properties]) => ({\n name,\n genesisHash,\n properties,\n })))\n }\n}\n","import type { ClientRequest } from \"@/client\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { noop } from \"./internal-utils\"\n\nexport const getCompatibilityEnhancer =\n <T, E>(rpcMethodsP: Promise<Set<string>>, request: ClientRequest<T, E>) =>\n (methods: Record<string, string>): ClientRequest<T, E> => {\n let enhancedRequest: ClientRequest<T, E> | null = null\n\n return ((method, ...rest) => {\n if (enhancedRequest) return enhancedRequest(method, ...rest)\n\n let isRunning = true\n let cleanup: UnsubscribeFn = () => {\n isRunning = false\n }\n\n rpcMethodsP\n .then((rpcMethods) => {\n enhancedRequest = (method, ...iRest) => {\n if (rpcMethods.has(method)) return request(method, ...iRest)\n iRest[1]?.onError(new Error(`Unsupported method ${method}`))\n return noop\n }\n\n if (rpcMethods.has(method)) return\n\n const parts = method.split(\"_\")\n if (parts[1] !== \"v1\") return\n\n parts[1] = \"unstable\"\n method = parts.join(\"_\")\n\n if (rpcMethods.has(method))\n Object.entries(methods).forEach(([key, value]) => {\n methods[key] = value.replace(\"_v1_\", \"_unstable_\")\n })\n else if (parts[0] === \"transaction\") {\n // old versions of smoldot and Polkadot-SDK don't support transaction_xx_broadcast\n // some old versions have `transactions_unstable_submitAndWatch` while others have `transaction_xx_submitAndWatch`\n // if we find any of this options, then we will can use them as if they were broadast/stop\n let unwatch: string | undefined\n let version: string | undefined\n\n const txGroup = [\"transactionWatch\", \"transaction\"].find(\n (group) => {\n version = [\"v1\", \"unstable\"].find((v) =>\n rpcMethods.has((unwatch = `${group}_${v}_unwatch`)),\n )\n return !!version\n },\n )\n\n if (txGroup) {\n methods.broadcast = `${txGroup}_${version}_submitAndWatch`\n methods.stop = unwatch!\n }\n }\n })\n .then(() => {\n if (isRunning) cleanup = enhancedRequest!(method, ...rest)\n })\n\n return () => {\n cleanup()\n }\n }) as ClientRequest<T, E>\n }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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,MAAM;AACb,aAAO,WAAW;AAAA,IACpB;AAAA,IACA;AAAA,IACA,UAAU,OAAO;AAAA,EACnB;AACF;","names":["createClient","fn","noop","noop","noop","import_utils","noop","subscriptionId","method","noop","createClient"]}