polkadot-api 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,113 +1,18 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
2
  var __export = (target, all) => {
4
3
  for (var name in all)
5
4
  __defProp(target, name, { get: all[name], enumerable: true });
6
5
  };
7
- var __publicField = (obj, key, value) => {
8
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
- return value;
10
- };
11
6
 
12
7
  // src/client.ts
8
+ import { getObservableClient } from "@polkadot-api/observable-client";
13
9
  import {
14
10
  createClient as createRawClient
15
11
  } from "@polkadot-api/substrate-client";
16
- import { firstValueFrom as firstValueFrom4 } from "rxjs";
17
-
18
- // src/constants.ts
19
- import { firstValueFrom, map as map2 } from "rxjs";
20
-
21
- // src/runtime.ts
22
- import { combineLatest, filter, map } from "rxjs";
23
- var Runtime = class {
24
- constructor(ctx, checksums) {
25
- __publicField(this, "_ctx");
26
- __publicField(this, "_checksums");
27
- this._ctx = ctx;
28
- this._checksums = checksums;
29
- }
30
- };
31
- function getRuntimeContext(runtime) {
32
- return runtime._ctx;
33
- }
34
- function getImportedChecksum(runtime, idx) {
35
- return runtime._checksums[idx];
36
- }
37
- var createRuntime = (ctx, checksums) => new Runtime(ctx, checksums);
38
- var getRuntimeApi = (checksums, chainHead) => {
39
- let latestRuntime;
40
- let resolve = null;
41
- latestRuntime = new Promise((res) => {
42
- resolve = res;
43
- });
44
- const runtimeWithChecksums$ = combineLatest([chainHead.runtime$, checksums]);
45
- runtimeWithChecksums$.subscribe(([x, checksums2]) => {
46
- if (x) {
47
- const runtime = createRuntime(x, checksums2);
48
- if (resolve) {
49
- resolve(runtime);
50
- resolve = null;
51
- } else {
52
- latestRuntime = Promise.resolve(runtime);
53
- }
54
- } else if (!resolve) {
55
- latestRuntime = new Promise((res) => {
56
- resolve = res;
57
- });
58
- }
59
- });
60
- const result = runtimeWithChecksums$.pipe(
61
- filter(([x]) => Boolean(x)),
62
- map(([x, checksums2]) => createRuntime(x, checksums2))
63
- );
64
- result.latest = () => latestRuntime;
65
- return result;
66
- };
67
- var compatibilityHelper = (runtimeApi, checksumIdx) => (getChecksum) => {
68
- function isCompatibleSync(runtime) {
69
- const ctx = getRuntimeContext(runtime);
70
- const checksum = getImportedChecksum(runtime, checksumIdx);
71
- return getChecksum(ctx) === checksum;
72
- }
73
- const isCompatible = (runtime) => {
74
- if (runtime) {
75
- return isCompatibleSync(runtime);
76
- }
77
- return runtimeApi.latest().then(isCompatibleSync);
78
- };
79
- const waitChecksums = async () => {
80
- const runtime = await runtimeApi.latest();
81
- return (ctx) => getChecksum(ctx) === getImportedChecksum(runtime, checksumIdx);
82
- };
83
- const compatibleRuntime$ = (chainHead, hash, error) => combineLatest([chainHead.getRuntimeContext$(hash), waitChecksums()]).pipe(
84
- map(([ctx, isCompatible2]) => {
85
- if (!isCompatible2(ctx)) {
86
- throw error();
87
- }
88
- return ctx;
89
- })
90
- );
91
- const withCompatibleRuntime = (chainHead, mapper, error) => (source$) => combineLatest([
92
- source$.pipe(chainHead.withRuntime(mapper)),
93
- waitChecksums()
94
- ]).pipe(
95
- map(([[x, ctx], isCompatible2]) => {
96
- if (!isCompatible2(ctx)) {
97
- throw error();
98
- }
99
- return [x, ctx];
100
- })
101
- );
102
- return {
103
- isCompatible,
104
- waitChecksums,
105
- withCompatibleRuntime,
106
- compatibleRuntime$
107
- };
108
- };
12
+ import { firstValueFrom as firstValueFrom5 } from "rxjs";
109
13
 
110
14
  // src/constants.ts
15
+ import { firstValueFrom, map } from "rxjs";
111
16
  var createConstantEntry = (palletName, name, chainHead, compatibilityHelper2) => {
112
17
  const { isCompatible, compatibleRuntime$ } = compatibilityHelper2(
113
18
  (ctx) => ctx.checksumBuilder.buildConstant(palletName, name)
@@ -128,11 +33,11 @@ var createConstantEntry = (palletName, name, chainHead, compatibilityHelper2) =>
128
33
  if (runtime) {
129
34
  if (!isCompatible(runtime))
130
35
  throw checksumError();
131
- return getValueWithContext(getRuntimeContext(runtime));
36
+ return getValueWithContext(runtime._getCtx());
132
37
  }
133
38
  return firstValueFrom(
134
39
  compatibleRuntime$(chainHead, null, checksumError).pipe(
135
- map2(getValueWithContext)
40
+ map(getValueWithContext)
136
41
  )
137
42
  );
138
43
  };
@@ -140,7 +45,7 @@ var createConstantEntry = (palletName, name, chainHead, compatibilityHelper2) =>
140
45
  };
141
46
 
142
47
  // src/event.ts
143
- import { firstValueFrom as firstValueFrom2, map as map3, mergeMap } from "rxjs";
48
+ import { firstValueFrom as firstValueFrom2, map as map2, mergeMap } from "rxjs";
144
49
 
145
50
  // src/utils/shareLatest.ts
146
51
  import { ReplaySubject, share } from "rxjs";
@@ -183,8 +88,8 @@ function firstValueFromWithSignal(source, signal) {
183
88
  }
184
89
 
185
90
  // src/utils/concatMapEager.ts
186
- import { defer, Observable as Observable4 } from "rxjs";
187
- var concatMapEager = (mapper, concurrent = Infinity) => (source$) => new Observable4((observer) => {
91
+ import { defer, Observable as Observable3 } from "rxjs";
92
+ var concatMapEager = (mapper, concurrent = Infinity) => (source$) => new Observable3((observer) => {
188
93
  let topSubscription;
189
94
  const queues = /* @__PURE__ */ new Map();
190
95
  const innerSubscriptions = /* @__PURE__ */ new Map();
@@ -265,8 +170,8 @@ var concatMapEager = (mapper, concurrent = Infinity) => (source$) => new Observa
265
170
  });
266
171
 
267
172
  // src/utils/raceMap.ts
268
- import { Observable as Observable5, Subscription as Subscription3 } from "rxjs";
269
- var raceMap = (mapper, concurrent) => (source$) => new Observable5((observer) => {
173
+ import { Observable as Observable4, Subscription as Subscription3 } from "rxjs";
174
+ var raceMap = (mapper, concurrent) => (source$) => new Observable4((observer) => {
270
175
  let innerSubscriptions = new Array();
271
176
  let isOuterDone = false;
272
177
  const createSubscription = (value) => {
@@ -314,6 +219,30 @@ var raceMap = (mapper, concurrent) => (source$) => new Observable5((observer) =>
314
219
  };
315
220
  });
316
221
 
222
+ // src/utils/continue-with.ts
223
+ import { Observable as Observable5 } from "rxjs";
224
+ var NOTIN = {};
225
+ var continueWith = (mapper) => (source) => new Observable5((observer) => {
226
+ let latestValue = NOTIN;
227
+ let subscription = source.subscribe({
228
+ next(v) {
229
+ observer.next(latestValue = v);
230
+ },
231
+ error(e) {
232
+ observer.error(e);
233
+ },
234
+ complete() {
235
+ if (latestValue === NOTIN)
236
+ observer.complete();
237
+ else
238
+ subscription = mapper(latestValue).subscribe(observer);
239
+ }
240
+ });
241
+ return () => {
242
+ subscription.unsubscribe();
243
+ };
244
+ });
245
+
317
246
  // src/event.ts
318
247
  var createEventEntry = (pallet, name, chainHead, compatibilityHelper2) => {
319
248
  const { isCompatible, withCompatibleRuntime } = compatibilityHelper2(
@@ -324,7 +253,7 @@ var createEventEntry = (pallet, name, chainHead, compatibilityHelper2) => {
324
253
  withCompatibleRuntime(chainHead, (x) => x.hash, checksumError),
325
254
  concatMapEager(
326
255
  ([block]) => chainHead.eventsAt$(block.hash).pipe(
327
- map3((events) => {
256
+ map2((events) => {
328
257
  const winners = events.filter(
329
258
  (e) => e.event.type === pallet && e.event.value.type === name
330
259
  );
@@ -344,12 +273,108 @@ var createEventEntry = (pallet, name, chainHead, compatibilityHelper2) => {
344
273
  );
345
274
  const watch = (f) => shared$.pipe(mergeMap((x) => f ? x.filter((d) => f(d.payload)) : x));
346
275
  const pull = () => firstValueFrom2(shared$);
347
- const filter2 = (events) => events.filter((e) => e.type === pallet && e.value.type === name).map((x) => x.value.value);
348
- return { watch, pull, filter: filter2, isCompatible };
276
+ const filter3 = (events) => events.filter((e) => e.type === pallet && e.value.type === name).map((x) => x.value.value);
277
+ return { watch, pull, filter: filter3, isCompatible };
349
278
  };
350
279
 
351
- // src/client.ts
352
- import { getObservableClient } from "@polkadot-api/observable-client";
280
+ // src/runtime.ts
281
+ import {
282
+ ReplaySubject as ReplaySubject2,
283
+ combineLatest,
284
+ connectable,
285
+ filter,
286
+ firstValueFrom as firstValueFrom3,
287
+ map as map3
288
+ } from "rxjs";
289
+ var Runtime = class _Runtime {
290
+ constructor(_ctx, _checksums, _descriptors) {
291
+ this._ctx = _ctx;
292
+ this._checksums = _checksums;
293
+ this._descriptors = _descriptors;
294
+ }
295
+ /**
296
+ * @access package - Internal implementation detail. Do not use.
297
+ */
298
+ static _create(ctx, checksums, descriptors) {
299
+ return new _Runtime(ctx, checksums, descriptors);
300
+ }
301
+ /**
302
+ * @access package - Internal implementation detail. Do not use.
303
+ */
304
+ _getCtx() {
305
+ return this._ctx;
306
+ }
307
+ /**
308
+ * @access package - Internal implementation detail. Do not use.
309
+ */
310
+ _getPalletChecksum(opType, pallet, name) {
311
+ return this._checksums[this._descriptors.pallets[pallet][opType][name]];
312
+ }
313
+ /**
314
+ * @access package - Internal implementation detail. Do not use.
315
+ */
316
+ _getApiChecksum(name, method) {
317
+ return this._checksums[this._descriptors.apis[name][method]];
318
+ }
319
+ };
320
+ var getRuntimeApi = (checksums, descriptors, chainHead) => {
321
+ const runtimeWithChecksums$ = connectable(
322
+ combineLatest([chainHead.runtime$, checksums, descriptors]).pipe(
323
+ map3(
324
+ ([x, checksums2, descriptors2]) => x ? Runtime._create(x, checksums2, descriptors2) : null
325
+ )
326
+ ),
327
+ {
328
+ connector: () => new ReplaySubject2(1)
329
+ }
330
+ );
331
+ runtimeWithChecksums$.connect();
332
+ const result = runtimeWithChecksums$.pipe(
333
+ filter((v) => Boolean(v))
334
+ );
335
+ result.latest = () => firstValueFrom3(result);
336
+ return result;
337
+ };
338
+ var compatibilityHelper = (runtimeApi, getDescriptorChecksum) => (getChecksum) => {
339
+ function isCompatibleSync(runtime) {
340
+ return getChecksum(runtime._getCtx()) === getDescriptorChecksum(runtime);
341
+ }
342
+ const isCompatible = (runtime) => {
343
+ if (runtime) {
344
+ return isCompatibleSync(runtime);
345
+ }
346
+ return runtimeApi.latest().then(isCompatibleSync);
347
+ };
348
+ const waitChecksums = async () => {
349
+ const runtime = await runtimeApi.latest();
350
+ return (ctx) => getChecksum(ctx) === getDescriptorChecksum(runtime);
351
+ };
352
+ const compatibleRuntime$ = (chainHead, hash, error) => combineLatest([chainHead.getRuntimeContext$(hash), waitChecksums()]).pipe(
353
+ map3(([ctx, isCompatible2]) => {
354
+ if (!isCompatible2(ctx)) {
355
+ throw error();
356
+ }
357
+ return ctx;
358
+ })
359
+ );
360
+ const withCompatibleRuntime = (chainHead, mapper, error) => (source$) => combineLatest([
361
+ source$.pipe(chainHead.withRuntime(mapper)),
362
+ waitChecksums()
363
+ ]).pipe(
364
+ map3(([[x, ctx], isCompatible2]) => {
365
+ if (!isCompatible2(ctx)) {
366
+ throw error();
367
+ }
368
+ return [x, ctx];
369
+ })
370
+ );
371
+ return {
372
+ isCompatible,
373
+ waitChecksums,
374
+ withCompatibleRuntime,
375
+ compatibleRuntime$
376
+ };
377
+ };
353
378
 
354
379
  // src/runtime-call.ts
355
380
  import { toHex } from "@polkadot-api/utils";
@@ -501,184 +526,49 @@ var createStorageEntry = (pallet, name, chainHead, compatibilityHelper2) => {
501
526
  return { isCompatible, getValue, getValues, getEntries, watchValue };
502
527
  };
503
528
 
504
- // src/tx.ts
529
+ // src/tx/tx.ts
505
530
  import {
506
531
  AccountId,
507
532
  Binary,
508
533
  Enum,
509
534
  Tuple,
510
- compact,
535
+ compact as compact3,
511
536
  u128,
512
- u32,
513
- u8
537
+ u32 as u323,
538
+ u8 as u82
514
539
  } from "@polkadot-api/substrate-bindings";
515
- import { fromHex, mergeUint8, toHex as toHex2 } from "@polkadot-api/utils";
540
+ import { fromHex as fromHex5, mergeUint8, toHex as toHex4 } from "@polkadot-api/utils";
516
541
  import {
517
- Observable as Observable8,
518
- concat,
519
- firstValueFrom as firstValueFrom3,
520
- lastValueFrom,
521
- map as map6,
522
- mergeMap as mergeMap3,
523
- of,
524
- startWith,
525
- take,
526
- withLatestFrom
542
+ firstValueFrom as firstValueFrom4,
543
+ map as map12,
544
+ mergeMap as mergeMap6,
545
+ take as take3,
546
+ throwError
527
547
  } from "rxjs";
528
548
  import { getPolkadotSigner } from "@polkadot-api/signer";
529
- var getTxSuccessFromSystemEvents = (systemEvents, txIdx) => {
530
- const events = systemEvents.filter((x) => x.phase.type === "ApplyExtrinsic" && x.phase.value === txIdx).map((x) => x.event);
531
- const lastEvent = events[events.length - 1];
532
- const ok = lastEvent.type === "System" && lastEvent.value.type === "ExtrinsicSuccess";
533
- return { ok, events };
534
- };
535
- var accountIdEnc = AccountId().enc;
536
- var getSubmitFns = (chainHead, client) => {
537
- const tx$ = (tx) => concat(
538
- chainHead.finalized$.pipe(
539
- take(1),
540
- mergeMap3((finalized) => chainHead.validateTx$(tx, finalized.hash)),
541
- map6((isValid) => {
542
- if (!isValid)
543
- throw new Error("Invalid");
544
- return { type: "broadcasted" };
545
- })
546
- ),
547
- new Observable8((observer) => {
548
- const subscription = chainHead.trackTx$(tx).subscribe(observer);
549
- subscription.add(
550
- client.broadcastTx$(tx).subscribe({
551
- error(e) {
552
- observer.error(e);
553
- }
554
- })
555
- );
556
- return subscription;
557
- })
558
- );
559
- const submit$ = (transaction) => tx$(transaction).pipe(
560
- mergeMap3((result) => {
561
- return result.type !== "finalized" ? of(result) : chainHead.eventsAt$(result.block.hash).pipe(
562
- map6((events) => ({
563
- ...result,
564
- ...getTxSuccessFromSystemEvents(
565
- events,
566
- Number(result.block.index)
567
- )
568
- }))
569
- );
570
- })
571
- );
572
- const submit = async (transaction) => lastValueFrom(submit$(transaction)).then((x) => {
573
- if (x.type !== "finalized")
574
- throw null;
575
- const result = { ...x };
576
- delete result.type;
577
- return result;
578
- });
579
- return { submit$, submit };
580
- };
581
- var queryInfoRawDec = Tuple(compact, compact, u8, u128).dec;
582
- var queryInfoDec = (input) => queryInfoRawDec(input)[3];
583
- var fakeSignature = new Uint8Array(64);
584
- var getFakeSignature = () => fakeSignature;
585
- var createTxEntry = (pallet, name, assetChecksum, chainHead, submits, signer, compatibilityHelper2) => {
586
- const { isCompatible, compatibleRuntime$ } = compatibilityHelper2(
587
- (ctx) => ctx.checksumBuilder.buildCall(pallet, name)
588
- );
589
- const checksumError = () => new Error(`Incompatible runtime entry Tx(${pallet}.${name})`);
590
- const fn = (arg) => {
591
- const getCallDataWithContext = ({ dynamicBuilder, asset: [assetEnc, assetCheck] }, arg2, hinted = {}) => {
592
- let returnHinted = hinted;
593
- if (hinted.asset) {
594
- if (assetChecksum !== assetCheck)
595
- throw new Error(`Incompatible runtime asset`);
596
- returnHinted = { ...hinted, asset: assetEnc(hinted.asset) };
597
- }
598
- const { location, codec } = dynamicBuilder.buildCall(pallet, name);
599
- return {
600
- callData: Binary.fromBytes(
601
- mergeUint8(new Uint8Array(location), codec.enc(arg2))
602
- ),
603
- hinted: returnHinted
604
- };
605
- };
606
- const getCallData$ = (arg2, hinted = {}) => compatibleRuntime$(chainHead, null, checksumError).pipe(
607
- map6((ctx) => getCallDataWithContext(ctx, arg2, hinted))
608
- );
609
- const getEncodedData = (runtime) => {
610
- if (runtime) {
611
- if (!isCompatible(runtime)) {
612
- throw checksumError();
613
- }
614
- return getCallDataWithContext(getRuntimeContext(runtime), arg).callData;
615
- }
616
- return firstValueFrom3(getCallData$(arg).pipe(map6((x) => x.callData)));
617
- };
618
- const sign$ = (from, _hinted) => getCallData$(arg, _hinted).pipe(
619
- withLatestFrom(chainHead.finalized$),
620
- take(1),
621
- mergeMap3(
622
- ([{ callData, hinted }, finalized]) => signer(from, callData.asBytes(), finalized, hinted)
623
- )
624
- );
625
- const sign = (from, _hinted) => firstValueFrom3(sign$(from, _hinted)).then(toHex2);
626
- const signAndSubmit = (from, _hinted) => sign(from, _hinted).then(submits.submit);
627
- const signSubmitAndWatch = (from, _hinted) => sign$(from, _hinted).pipe(
628
- mergeMap3((result) => {
629
- const tx = toHex2(result);
630
- return submits.submit$(tx).pipe(startWith({ type: "signed", tx }));
631
- })
632
- );
633
- const getEstimatedFees = async (from, _hinted) => {
634
- const fakeSigner = getPolkadotSigner(
635
- from instanceof Uint8Array ? from : accountIdEnc(from),
636
- "Sr25519",
637
- getFakeSignature
638
- );
639
- const encoded = fromHex(await sign(fakeSigner, _hinted));
640
- const args = toHex2(mergeUint8(encoded, u32.enc(encoded.length)));
641
- return firstValueFrom3(
642
- chainHead.call$(null, "TransactionPaymentApi_query_info", args).pipe(map6(queryInfoDec))
643
- );
644
- };
645
- return {
646
- getEstimatedFees,
647
- decodedCall: {
648
- type: pallet,
649
- value: Enum(name, arg)
650
- },
651
- getEncodedData,
652
- sign,
653
- signSubmitAndWatch,
654
- signAndSubmit
655
- };
656
- };
657
- return Object.assign(fn, { isCompatible });
658
- };
659
549
 
660
- // src/get-create-tx.ts
661
- import { combineLatest as combineLatest2, mergeMap as mergeMap4, of as of6, take as take2 } from "rxjs";
550
+ // src/tx/create-tx.ts
551
+ import { combineLatest as combineLatest2, mergeMap as mergeMap4, of as of6, take } from "rxjs";
662
552
 
663
- // src/signed-extensions/user/ChargeTransactionPayment.ts
553
+ // src/tx/signed-extensions/user/ChargeTransactionPayment.ts
664
554
  import { compactBn } from "@polkadot-api/substrate-bindings";
665
- import { of as of3 } from "rxjs";
555
+ import { of as of2 } from "rxjs";
666
556
 
667
- // src/signed-extensions/utils.ts
668
- import { map as map7, noop as noop2, of as of2 } from "rxjs";
557
+ // src/tx/signed-extensions/utils.ts
558
+ import { map as map6, noop as noop2, of } from "rxjs";
669
559
  import {
670
560
  Storage,
671
561
  Twox64Concat,
672
- u32 as u322
562
+ u32
673
563
  } from "@polkadot-api/substrate-bindings";
674
564
  import { getDynamicBuilder, getLookupFn } from "@polkadot-api/metadata-builders";
675
- import { fromHex as fromHex2 } from "@polkadot-api/utils";
565
+ import { fromHex } from "@polkadot-api/utils";
676
566
  var empty = new Uint8Array();
677
567
  var genesisHashStorageKey = Storage("System")("BlockHash", noop2, [
678
- u322,
568
+ u32,
679
569
  Twox64Concat
680
570
  ]).enc(0);
681
- var genesisHashFromCtx = (ctx) => ctx.chainHead.storage$(ctx.at, "value", () => genesisHashStorageKey, null).pipe(map7((result) => fromHex2(result)));
571
+ var genesisHashFromCtx = (ctx) => ctx.chainHead.storage$(ctx.at, "value", () => genesisHashStorageKey, null).pipe(map6((result) => fromHex(result)));
682
572
  var systemVersionProp$ = (propName, metadata) => {
683
573
  const lookupFn = getLookupFn(metadata.lookup);
684
574
  const dynamicBuilder = getDynamicBuilder(metadata);
@@ -690,19 +580,19 @@ var systemVersionProp$ = (propName, metadata) => {
690
580
  const valueEnc = dynamicBuilder.buildDefinition(
691
581
  systemVersion.value[propName].id
692
582
  ).enc;
693
- return of2(valueEnc(systemVersionDec(constant.value)[propName]));
583
+ return of(valueEnc(systemVersionDec(constant.value)[propName]));
694
584
  };
695
585
 
696
- // src/signed-extensions/user/ChargeTransactionPayment.ts
697
- var ChargeTransactionPayment = (tip) => of3({
586
+ // src/tx/signed-extensions/user/ChargeTransactionPayment.ts
587
+ var ChargeTransactionPayment = (tip) => of2({
698
588
  value: compactBn.enc(tip),
699
589
  additionalSigned: empty
700
590
  });
701
591
 
702
- // src/signed-extensions/user/CheckMortality.ts
703
- import { map as map8, of as of4 } from "rxjs";
592
+ // src/tx/signed-extensions/user/CheckMortality.ts
593
+ import { map as map7, of as of3 } from "rxjs";
704
594
  import { Bytes, enhanceEncoder, u16 } from "@polkadot-api/substrate-bindings";
705
- import { fromHex as fromHex3 } from "@polkadot-api/utils";
595
+ import { fromHex as fromHex2 } from "@polkadot-api/utils";
706
596
  function trailingZeroes(n) {
707
597
  let i = 0;
708
598
  while (!(n & 1)) {
@@ -724,14 +614,14 @@ var zero = new Uint8Array([0]);
724
614
  var CheckMortality = (input, ctx) => {
725
615
  if (!input)
726
616
  return genesisHashFromCtx(ctx).pipe(
727
- map8((additionalSigned) => ({
617
+ map7((additionalSigned) => ({
728
618
  additionalSigned,
729
619
  value: zero
730
620
  }))
731
621
  );
732
622
  const { period, blockNumber } = input;
733
- return of4({
734
- additionalSigned: fromHex3(ctx.at),
623
+ return of3({
624
+ additionalSigned: fromHex2(ctx.at),
735
625
  value: mortal({
736
626
  period,
737
627
  phase: blockNumber % period
@@ -739,19 +629,19 @@ var CheckMortality = (input, ctx) => {
739
629
  });
740
630
  };
741
631
 
742
- // src/signed-extensions/user/ChargeAssetTxPayment.ts
743
- import { of as of5 } from "rxjs";
632
+ // src/tx/signed-extensions/user/ChargeAssetTxPayment.ts
633
+ import { of as of4 } from "rxjs";
744
634
  import {
745
635
  Bytes as Bytes2,
746
636
  Option,
747
637
  Struct,
748
- compact as compact2
638
+ compact
749
639
  } from "@polkadot-api/substrate-bindings";
750
640
  var encoder = Struct({
751
- tip: compact2,
641
+ tip: compact,
752
642
  asset: Option(Bytes2(Infinity))
753
643
  }).enc;
754
- var ChargeAssetTxPayment = (tip, asset) => of5({
644
+ var ChargeAssetTxPayment = (tip, asset) => of4({
755
645
  value: encoder({
756
646
  tip,
757
647
  asset
@@ -759,217 +649,470 @@ var ChargeAssetTxPayment = (tip, asset) => of5({
759
649
  additionalSigned: empty
760
650
  });
761
651
 
762
- // src/signed-extensions/chain/index.ts
652
+ // src/tx/signed-extensions/chain/index.ts
763
653
  var chain_exports = {};
764
654
  __export(chain_exports, {
765
655
  CheckGenesis: () => CheckGenesis,
766
656
  CheckNonce: () => CheckNonce,
767
657
  CheckSpecVersion: () => CheckSpecVersion,
768
- CheckTxVersion: () => CheckTxVersion
658
+ CheckTxVersion: () => CheckTxVersion,
659
+ getNonce: () => getNonce
769
660
  });
770
661
 
771
- // src/signed-extensions/chain/CheckGenesis.ts
772
- import { map as map9 } from "rxjs";
662
+ // src/tx/signed-extensions/chain/CheckGenesis.ts
663
+ import { map as map8 } from "rxjs";
773
664
  var CheckGenesis = (ctx) => genesisHashFromCtx(ctx).pipe(
774
- map9((additionalSigned) => ({ value: empty, additionalSigned }))
665
+ map8((additionalSigned) => ({ value: empty, additionalSigned }))
775
666
  );
776
667
 
777
- // src/signed-extensions/chain/CheckNonce.ts
778
- import { map as map10 } from "rxjs";
779
- import { compact as compact3, u16 as u162, u32 as u323, u64, u8 as u82 } from "@polkadot-api/substrate-bindings";
780
- import { fromHex as fromHex4, toHex as toHex3 } from "@polkadot-api/utils";
668
+ // src/tx/signed-extensions/chain/CheckNonce.ts
669
+ import { mergeMap as mergeMap3, of as of5 } from "rxjs";
670
+ import { compact as compact2, u16 as u162, u32 as u322, u64, u8 } from "@polkadot-api/substrate-bindings";
671
+ import { fromHex as fromHex3, toHex as toHex2 } from "@polkadot-api/utils";
672
+ var NONCE_RUNTIME_CALL = "AccountNonceApi_account_nonce";
781
673
  var lenToDecoder = {
782
- 1: u82.dec,
674
+ 1: u8.dec,
783
675
  2: u162.dec,
784
- 4: u323.dec,
676
+ 4: u322.dec,
785
677
  8: u64.dec
786
678
  };
787
- var CheckNonce = (ctx) => ctx.chainHead.call$(ctx.at, "AccountNonceApi_account_nonce", toHex3(ctx.from)).pipe(
788
- map10((result) => {
789
- const bytes = fromHex4(result);
679
+ var getNonce = (input) => of5({ value: compact2.enc(input), additionalSigned: empty });
680
+ var CheckNonce = (ctx) => ctx.chainHead.call$(ctx.at, NONCE_RUNTIME_CALL, toHex2(ctx.from)).pipe(
681
+ mergeMap3((result) => {
682
+ const bytes = fromHex3(result);
790
683
  const decoder = lenToDecoder[bytes.length];
791
684
  if (!decoder)
792
- throw new Error("AccountNonceApi_account_nonce retrieved wrong data");
793
- return compact3.enc(decoder(bytes));
794
- }),
795
- map10((value) => ({ value, additionalSigned: empty }))
685
+ throw new Error(`${NONCE_RUNTIME_CALL} retrieved wrong data`);
686
+ return getNonce(decoder(bytes));
687
+ })
796
688
  );
797
689
 
798
- // src/signed-extensions/chain/CheckSpecVersion.ts
799
- import { map as map11 } from "rxjs";
690
+ // src/tx/signed-extensions/chain/CheckSpecVersion.ts
691
+ import { map as map9 } from "rxjs";
800
692
  var CheckSpecVersion = ({ metadata }) => systemVersionProp$("spec_version", metadata).pipe(
801
- map11((additionalSigned) => ({ additionalSigned, value: empty }))
693
+ map9((additionalSigned) => ({ additionalSigned, value: empty }))
802
694
  );
803
695
 
804
- // src/signed-extensions/chain/CheckTxVersion.ts
805
- import { map as map12 } from "rxjs";
696
+ // src/tx/signed-extensions/chain/CheckTxVersion.ts
697
+ import { map as map10 } from "rxjs";
806
698
  var CheckTxVersion = ({ metadata }) => systemVersionProp$("transaction_version", metadata).pipe(
807
- map12((additionalSigned) => ({ additionalSigned, value: empty }))
699
+ map10((additionalSigned) => ({ additionalSigned, value: empty }))
808
700
  );
809
701
 
810
- // src/get-create-tx.ts
702
+ // src/tx/create-tx.ts
811
703
  import { _void } from "@polkadot-api/substrate-bindings";
812
- var getCreateTx = (chainHead) => {
813
- return (signer, callData, atBlock, hinted) => {
814
- return chainHead.getRuntimeContext$(atBlock.hash).pipe(
815
- take2(1),
816
- mergeMap4((ctx) => {
817
- const signedExtensionsCtx = {
818
- metadata: ctx.metadata,
819
- chainHead,
704
+ var createTx = (chainHead, signer, callData, atBlock, hinted = {}) => chainHead.getRuntimeContext$(atBlock.hash).pipe(
705
+ take(1),
706
+ mergeMap4((ctx) => {
707
+ const signedExtensionsCtx = {
708
+ metadata: ctx.metadata,
709
+ chainHead,
710
+ callData,
711
+ at: atBlock.hash,
712
+ from: signer.publicKey
713
+ };
714
+ const mortality = !hinted.mortality ? { period: 64, blockNumber: atBlock.number } : hinted.mortality.mortal ? { period: hinted.mortality.period, blockNumber: atBlock.number } : void 0;
715
+ return combineLatest2(
716
+ ctx.metadata.extrinsic.signedExtensions.map(
717
+ ({ identifier, type, additionalSigned }) => {
718
+ if (identifier === "CheckMortality")
719
+ return CheckMortality(mortality, signedExtensionsCtx);
720
+ if (identifier === "ChargeTransactionPayment")
721
+ return ChargeTransactionPayment(hinted.tip ?? 0n);
722
+ if (identifier === "ChargeAssetTxPayment")
723
+ return ChargeAssetTxPayment(hinted.tip ?? 0n, hinted.asset);
724
+ if (identifier === "CheckNonce" && "nonce" in hinted)
725
+ return getNonce(hinted.nonce);
726
+ const fn = chain_exports[identifier];
727
+ if (!fn) {
728
+ if (ctx.dynamicBuilder.buildDefinition(type) === _void && ctx.dynamicBuilder.buildDefinition(additionalSigned) === _void)
729
+ return of6({
730
+ value: empty,
731
+ additionalSigned: empty
732
+ });
733
+ throw new Error(`Unsupported signed-extension: ${identifier}`);
734
+ }
735
+ return fn(signedExtensionsCtx);
736
+ }
737
+ )
738
+ ).pipe(
739
+ mergeMap4(
740
+ (signedExtensions) => signer.sign(
820
741
  callData,
821
- at: atBlock.hash,
822
- from: signer.publicKey
823
- };
824
- const mortality = !hinted?.mortality ? { period: 64, blockNumber: atBlock.number } : hinted.mortality.mortal ? { period: hinted.mortality.period, blockNumber: atBlock.number } : void 0;
825
- return combineLatest2(
826
- ctx.metadata.extrinsic.signedExtensions.map(
827
- ({ identifier, type, additionalSigned }) => {
828
- if (identifier === "CheckMortality")
829
- return CheckMortality(mortality, signedExtensionsCtx);
830
- if (identifier === "ChargeTransactionPayment")
831
- return ChargeTransactionPayment(hinted?.tip ?? 0n);
832
- if (identifier === "ChargeAssetTxPayment")
833
- return ChargeAssetTxPayment(hinted?.tip ?? 0n, hinted?.asset);
834
- const fn = chain_exports[identifier];
835
- if (!fn) {
836
- if (ctx.dynamicBuilder.buildDefinition(type) === _void && ctx.dynamicBuilder.buildDefinition(additionalSigned) === _void)
837
- return of6({
838
- value: empty,
839
- additionalSigned: empty
840
- });
841
- throw new Error(`Unsupported signed-extension: ${identifier}`);
842
- }
843
- return fn(signedExtensionsCtx);
844
- }
845
- )
846
- ).pipe(
847
- mergeMap4(
848
- (signedExtensions) => signer.sign(
849
- callData,
850
- Object.fromEntries(
851
- ctx.metadata.extrinsic.signedExtensions.map(
852
- ({ identifier }, idx) => [
853
- identifier,
854
- { identifier, ...signedExtensions[idx] }
855
- ]
856
- )
857
- ),
858
- ctx.metadataRaw,
859
- atBlock.number
742
+ Object.fromEntries(
743
+ ctx.metadata.extrinsic.signedExtensions.map(
744
+ ({ identifier }, idx) => [
745
+ identifier,
746
+ { identifier, ...signedExtensions[idx] }
747
+ ]
860
748
  )
861
- )
862
- );
863
- })
749
+ ),
750
+ ctx.metadataRaw,
751
+ atBlock.number
752
+ )
753
+ )
864
754
  );
865
- };
866
- };
755
+ })
756
+ );
867
757
 
868
- // src/client.ts
869
- var createTypedApi = (descriptors, createTxFromSigner, chainHead, submitFns) => {
870
- const runtimeApi = getRuntimeApi(descriptors.checksums, chainHead);
871
- const { pallets, apis: runtimeApis } = descriptors;
872
- const query = {};
873
- for (const pallet in pallets) {
874
- query[pallet] || (query[pallet] = {});
875
- const [stgEntries] = pallets[pallet];
876
- for (const name in stgEntries) {
877
- query[pallet][name] = createStorageEntry(
878
- pallet,
879
- name,
880
- chainHead,
881
- compatibilityHelper(runtimeApi, stgEntries[name])
882
- );
758
+ // src/tx/submit-fns.ts
759
+ import { Blake2256 } from "@polkadot-api/substrate-bindings";
760
+ import {
761
+ EMPTY,
762
+ Observable as Observable10,
763
+ concat,
764
+ distinctUntilChanged as distinctUntilChanged2,
765
+ filter as filter2,
766
+ lastValueFrom,
767
+ map as map11,
768
+ mergeMap as mergeMap5,
769
+ of as of7,
770
+ take as take2
771
+ } from "rxjs";
772
+ import { fromHex as fromHex4, toHex as toHex3 } from "@polkadot-api/utils";
773
+ var hashFromTx = (tx) => toHex3(Blake2256(fromHex4(tx)));
774
+ var computeState = (analized$, blocks$) => new Observable10((observer) => {
775
+ const analyzedBlocks = /* @__PURE__ */ new Map();
776
+ let pinnedBlocks;
777
+ let latestState;
778
+ const computeNextState = () => {
779
+ let current = pinnedBlocks.best;
780
+ let analyzed = analyzedBlocks.get(current);
781
+ while (!analyzed) {
782
+ const block = pinnedBlocks.blocks.get(current);
783
+ if (!block)
784
+ break;
785
+ analyzed = analyzedBlocks.get(current = block.parent);
883
786
  }
884
- }
885
- const tx = {};
886
- for (const pallet in pallets) {
887
- tx[pallet] || (tx[pallet] = {});
888
- const [, txEntries] = pallets[pallet];
889
- for (const name in txEntries) {
890
- tx[pallet][name] = createTxEntry(
891
- pallet,
892
- name,
893
- descriptors.asset,
894
- chainHead,
895
- submitFns,
896
- createTxFromSigner,
897
- compatibilityHelper(runtimeApi, txEntries[name])
898
- );
787
+ if (!analyzed)
788
+ return;
789
+ const isFinalized = pinnedBlocks.blocks.get(analyzed.hash).number <= pinnedBlocks.blocks.get(pinnedBlocks.finalized).number;
790
+ const found = analyzed.found.type;
791
+ if (found && typeof latestState === "object" && latestState.hash === analyzed.hash) {
792
+ if (isFinalized)
793
+ observer.complete();
794
+ return;
899
795
  }
900
- }
901
- const events = {};
902
- for (const pallet in pallets) {
903
- events[pallet] || (events[pallet] = {});
904
- const [, , evEntries] = pallets[pallet];
905
- for (const name in evEntries) {
906
- events[pallet][name] = createEventEntry(
907
- pallet,
908
- name,
909
- chainHead,
910
- compatibilityHelper(runtimeApi, evEntries[name])
911
- );
796
+ observer.next(
797
+ latestState = found ? {
798
+ hash: analyzed.hash,
799
+ ...analyzed.found
800
+ } : analyzed.found.isValid
801
+ );
802
+ if (isFinalized) {
803
+ if (found)
804
+ observer.complete();
805
+ else if (!analyzed.found.isValid)
806
+ observer.error(new Error("Invalid"));
912
807
  }
913
- }
914
- const constants = {};
915
- for (const pallet in pallets) {
916
- constants[pallet] || (constants[pallet] = {});
917
- const [, , , , ctEntries] = pallets[pallet];
918
- for (const name in ctEntries) {
919
- constants[pallet][name] = createConstantEntry(
920
- pallet,
921
- name,
922
- chainHead,
923
- compatibilityHelper(runtimeApi, ctEntries[name])
924
- );
808
+ };
809
+ const subscription = blocks$.pipe(
810
+ distinctUntilChanged2(
811
+ (a, b) => a.finalized === b.finalized && a.best === b.best
812
+ )
813
+ ).subscribe({
814
+ next: (pinned) => {
815
+ pinnedBlocks = pinned;
816
+ if (analyzedBlocks.size === 0)
817
+ return;
818
+ computeNextState();
819
+ },
820
+ error(e) {
821
+ observer.error(e);
925
822
  }
926
- }
927
- const apis = {};
928
- for (const api in runtimeApis) {
929
- apis[api] || (apis[api] = {});
930
- const methods = runtimeApis[api];
931
- for (const method in methods) {
932
- apis[api][method] = createRuntimeCallEntry(
933
- api,
934
- method,
935
- chainHead,
936
- compatibilityHelper(runtimeApi, methods[method])
823
+ });
824
+ subscription.add(
825
+ analized$.subscribe({
826
+ next: (block) => {
827
+ analyzedBlocks.set(block.hash, block);
828
+ computeNextState();
829
+ },
830
+ error(e) {
831
+ observer.error(e);
832
+ }
833
+ })
834
+ );
835
+ return subscription;
836
+ }).pipe(distinctUntilChanged2((a, b) => a === b));
837
+ var getTxSuccessFromSystemEvents = (systemEvents, txIdx) => {
838
+ const events = systemEvents.filter((x) => x.phase.type === "ApplyExtrinsic" && x.phase.value === txIdx).map((x) => x.event);
839
+ const lastEvent = events[events.length - 1];
840
+ const ok = lastEvent.type === "System" && lastEvent.value.type === "ExtrinsicSuccess";
841
+ return { ok, events };
842
+ };
843
+ var submit$ = (chainHead, broadcastTx$, tx, at, emitSign = false) => {
844
+ const txHash = hashFromTx(tx);
845
+ const getTxEvent = (type, rest) => ({
846
+ type,
847
+ txHash,
848
+ ...rest
849
+ });
850
+ const at$ = chainHead.pinnedBlocks$.pipe(
851
+ take2(1),
852
+ map11((blocks) => blocks.blocks.get(at)?.hash ?? blocks.finalized)
853
+ );
854
+ const validate$ = at$.pipe(
855
+ mergeMap5(
856
+ (at2) => chainHead.validateTx$(at2, tx).pipe(
857
+ filter2((x) => !x),
858
+ map11(() => {
859
+ throw new Error("Invalid");
860
+ })
861
+ )
862
+ )
863
+ );
864
+ const track$ = new Observable10((observer) => {
865
+ const subscription = chainHead.trackTx$(tx).subscribe(observer);
866
+ subscription.add(
867
+ broadcastTx$(tx).subscribe({
868
+ error(e) {
869
+ observer.error(e);
870
+ }
871
+ })
872
+ );
873
+ return subscription;
874
+ });
875
+ const bestBlockState$ = computeState(track$, chainHead.pinnedBlocks$).pipe(
876
+ map11((x) => {
877
+ if (x === true || x === false)
878
+ return getTxEvent("txBestBlocksState", {
879
+ found: false,
880
+ isValid: x
881
+ });
882
+ return getTxEvent("txBestBlocksState", {
883
+ found: true,
884
+ block: {
885
+ index: x.index,
886
+ hash: x.hash
887
+ },
888
+ ...getTxSuccessFromSystemEvents(x.events, x.index)
889
+ });
890
+ })
891
+ );
892
+ return concat(
893
+ emitSign ? of7(getTxEvent("signed", {})) : EMPTY,
894
+ validate$,
895
+ of7(getTxEvent("broadcasted", {})),
896
+ bestBlockState$.pipe(
897
+ continueWith(
898
+ ({ found, type, ...rest }) => found ? of7(getTxEvent("finalized", rest)) : EMPTY
899
+ )
900
+ )
901
+ );
902
+ };
903
+ var submit = async (chainHead, broadcastTx$, transaction, at) => lastValueFrom(submit$(chainHead, broadcastTx$, transaction, at)).then((x) => {
904
+ if (x.type !== "finalized")
905
+ throw null;
906
+ const result = { ...x };
907
+ delete result.type;
908
+ return result;
909
+ });
910
+
911
+ // src/tx/tx.ts
912
+ var accountIdEnc = AccountId().enc;
913
+ var queryInfoRawDec = Tuple(compact3, compact3, u82, u128).dec;
914
+ var queryInfoDec = (input) => queryInfoRawDec(input)[3];
915
+ var fakeSignature = new Uint8Array(64);
916
+ var getFakeSignature = () => fakeSignature;
917
+ var createTxEntry = (pallet, name, assetChecksum, chainHead, broadcast, compatibilityHelper2) => {
918
+ const { isCompatible, compatibleRuntime$ } = compatibilityHelper2(
919
+ (ctx) => ctx.checksumBuilder.buildCall(pallet, name)
920
+ );
921
+ const checksumError = () => new Error(`Incompatible runtime entry Tx(${pallet}.${name})`);
922
+ const fn = (arg) => {
923
+ const getCallDataWithContext = ({ dynamicBuilder, asset: [assetEnc, assetCheck] }, arg2, txOptions = {}) => {
924
+ let returnOptions = txOptions;
925
+ if (txOptions.asset) {
926
+ if (assetChecksum !== assetCheck)
927
+ throw new Error(`Incompatible runtime asset`);
928
+ returnOptions = { ...txOptions, asset: assetEnc(txOptions.asset) };
929
+ }
930
+ const { location, codec } = dynamicBuilder.buildCall(pallet, name);
931
+ return {
932
+ callData: Binary.fromBytes(
933
+ mergeUint8(new Uint8Array(location), codec.enc(arg2))
934
+ ),
935
+ options: returnOptions
936
+ };
937
+ };
938
+ const getCallData$ = (arg2, options = {}) => compatibleRuntime$(chainHead, null, checksumError).pipe(
939
+ map12((ctx) => getCallDataWithContext(ctx, arg2, options))
940
+ );
941
+ const getEncodedData = (runtime) => {
942
+ if (!runtime)
943
+ return firstValueFrom4(getCallData$(arg).pipe(map12((x) => x.callData)));
944
+ if (!isCompatible(runtime))
945
+ throw checksumError();
946
+ return getCallDataWithContext(runtime._getCtx(), arg).callData;
947
+ };
948
+ const sign$ = (from, { ..._options }, atBlock) => getCallData$(arg, _options).pipe(
949
+ mergeMap6(
950
+ ({ callData, options }) => createTx(chainHead, from, callData.asBytes(), atBlock, options)
951
+ )
952
+ );
953
+ const _sign = (from, { at, ..._options } = {}) => {
954
+ return (!at || at === "finalized" ? chainHead.finalized$ : at === "best" ? chainHead.best$ : chainHead.bestBlocks$.pipe(
955
+ map12((x) => x.find((b) => b.hash === at))
956
+ )).pipe(
957
+ take3(1),
958
+ mergeMap6(
959
+ (atBlock) => atBlock ? sign$(from, _options, atBlock).pipe(
960
+ map12((signed) => ({
961
+ tx: toHex4(signed),
962
+ block: atBlock
963
+ }))
964
+ ) : throwError(() => new Error(`Uknown block ${at}`))
965
+ )
937
966
  );
967
+ };
968
+ const sign = (from, options) => firstValueFrom4(_sign(from, options)).then((x) => x.tx);
969
+ const signAndSubmit = (from, _options) => firstValueFrom4(_sign(from, _options)).then(
970
+ ({ tx, block }) => submit(chainHead, broadcast, tx, block.hash)
971
+ );
972
+ const signSubmitAndWatch = (from, _options) => _sign(from, _options).pipe(
973
+ mergeMap6(
974
+ ({ tx, block }) => submit$(chainHead, broadcast, tx, block.hash, true)
975
+ )
976
+ );
977
+ const getEstimatedFees = async (from, _options) => {
978
+ const fakeSigner = getPolkadotSigner(
979
+ from instanceof Uint8Array ? from : accountIdEnc(from),
980
+ "Sr25519",
981
+ getFakeSignature
982
+ );
983
+ const encoded = fromHex5(await sign(fakeSigner, _options));
984
+ const args = toHex4(mergeUint8(encoded, u323.enc(encoded.length)));
985
+ return firstValueFrom4(
986
+ chainHead.call$(null, "TransactionPaymentApi_query_info", args).pipe(map12(queryInfoDec))
987
+ );
988
+ };
989
+ return {
990
+ getEstimatedFees,
991
+ decodedCall: {
992
+ type: pallet,
993
+ value: Enum(name, arg)
994
+ },
995
+ getEncodedData,
996
+ sign,
997
+ signSubmitAndWatch,
998
+ signAndSubmit
999
+ };
1000
+ };
1001
+ return Object.assign(fn, { isCompatible });
1002
+ };
1003
+
1004
+ // src/client.ts
1005
+ var createTypedApi = (chainDefinition, chainHead, broadcast$) => {
1006
+ const runtime = getRuntimeApi(
1007
+ chainDefinition.checksums,
1008
+ chainDefinition.descriptors,
1009
+ chainHead
1010
+ );
1011
+ const target = {};
1012
+ const createProxy = (propCall) => new Proxy(target, {
1013
+ get(_, prop) {
1014
+ return propCall(prop);
938
1015
  }
939
- }
1016
+ });
1017
+ const createProxyPath = (pathCall) => {
1018
+ const cache = {};
1019
+ return createProxy((a) => {
1020
+ if (!cache[a])
1021
+ cache[a] = {};
1022
+ return createProxy((b) => {
1023
+ if (!cache[a][b])
1024
+ cache[a][b] = pathCall(a, b);
1025
+ return cache[a][b];
1026
+ });
1027
+ });
1028
+ };
1029
+ const query = createProxyPath(
1030
+ (pallet, name) => createStorageEntry(
1031
+ pallet,
1032
+ name,
1033
+ chainHead,
1034
+ compatibilityHelper(
1035
+ runtime,
1036
+ (r) => r._getPalletChecksum(0 /* Storage */, pallet, name)
1037
+ )
1038
+ )
1039
+ );
1040
+ const tx = createProxyPath(
1041
+ (pallet, name) => createTxEntry(
1042
+ pallet,
1043
+ name,
1044
+ chainDefinition.asset,
1045
+ chainHead,
1046
+ broadcast$,
1047
+ compatibilityHelper(
1048
+ runtime,
1049
+ (r) => r._getPalletChecksum(1 /* Tx */, pallet, name)
1050
+ )
1051
+ )
1052
+ );
1053
+ const event = createProxyPath(
1054
+ (pallet, name) => createEventEntry(
1055
+ pallet,
1056
+ name,
1057
+ chainHead,
1058
+ compatibilityHelper(
1059
+ runtime,
1060
+ (r) => r._getPalletChecksum(2 /* Event */, pallet, name)
1061
+ )
1062
+ )
1063
+ );
1064
+ const constants = createProxyPath(
1065
+ (pallet, name) => createConstantEntry(
1066
+ pallet,
1067
+ name,
1068
+ chainHead,
1069
+ compatibilityHelper(
1070
+ runtime,
1071
+ (r) => r._getPalletChecksum(4 /* Const */, pallet, name)
1072
+ )
1073
+ )
1074
+ );
1075
+ const apis = createProxyPath(
1076
+ (api, method) => createRuntimeCallEntry(
1077
+ api,
1078
+ method,
1079
+ chainHead,
1080
+ compatibilityHelper(runtime, (r) => r._getApiChecksum(api, method))
1081
+ )
1082
+ );
940
1083
  return {
941
1084
  query,
942
1085
  tx,
943
- event: events,
1086
+ event,
944
1087
  apis,
945
1088
  constants,
946
- runtime: runtimeApi
1089
+ runtime
947
1090
  };
948
1091
  };
949
1092
  function createClient(provider) {
950
1093
  const rawClient = createRawClient(provider);
951
1094
  const client = getObservableClient(rawClient);
952
1095
  const chainHead = client.chainHead$();
953
- const createTxFromSigner = getCreateTx(chainHead);
954
- const submitFns = getSubmitFns(chainHead, client);
955
- const { submit, submit$: submitAndWatch } = submitFns;
956
1096
  const { getChainSpecData } = rawClient;
1097
+ const _request = rawClient.request;
1098
+ const { broadcastTx$ } = client;
957
1099
  return {
958
1100
  getChainSpecData,
959
1101
  finalizedBlock$: chainHead.finalized$,
960
- getFinalizedBlock: () => firstValueFrom4(chainHead.finalized$),
1102
+ getFinalizedBlock: () => firstValueFrom5(chainHead.finalized$),
961
1103
  bestBlocks$: chainHead.bestBlocks$,
962
- getBestBlocks: () => firstValueFrom4(chainHead.bestBlocks$),
1104
+ getBestBlocks: () => firstValueFrom5(chainHead.bestBlocks$),
963
1105
  watchBlockBody: chainHead.body$,
964
- getBlockBody: (hash) => firstValueFrom4(chainHead.body$(hash)),
965
- getBlockHeader: (hash) => firstValueFrom4(chainHead.header$(hash ?? null)),
966
- submit,
967
- submitAndWatch,
968
- getTypedApi: (descriptors) => createTypedApi(descriptors, createTxFromSigner, chainHead, submitFns),
1106
+ getBlockBody: (hash) => firstValueFrom5(chainHead.body$(hash)),
1107
+ getBlockHeader: (hash) => firstValueFrom5(chainHead.header$(hash ?? null)),
1108
+ submit: (...args) => submit(chainHead, broadcastTx$, ...args),
1109
+ submitAndWatch: (...args) => submit$(chainHead, broadcastTx$, ...args),
1110
+ getTypedApi: (chainDefinition) => createTypedApi(chainDefinition, chainHead, broadcastTx$),
969
1111
  destroy: () => {
970
1112
  chainHead.unfollow();
971
1113
  client.destroy();
972
- }
1114
+ },
1115
+ _request
973
1116
  };
974
1117
  }
975
1118