polkadot-api 0.7.2 → 0.9.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.mjs CHANGED
@@ -31,8 +31,7 @@ var createConstantEntry = (palletName, name, chainHead, compatibilityHelper2) =>
31
31
  };
32
32
  const fn = (runtime) => {
33
33
  if (runtime) {
34
- if (!isCompatible(runtime))
35
- throw checksumError();
34
+ if (!isCompatible(runtime)) throw checksumError();
36
35
  return getValueWithContext(runtime._getCtx());
37
36
  }
38
37
  return firstValueFrom(
@@ -82,8 +81,7 @@ function firstValueFromWithSignal(source, signal) {
82
81
  reject(new Error("Observable completed without emitting"));
83
82
  }
84
83
  });
85
- if (!isDone)
86
- signal?.addEventListener("abort", onAbort);
84
+ if (!isDone) signal?.addEventListener("abort", onAbort);
87
85
  });
88
86
  }
89
87
 
@@ -208,8 +206,7 @@ var raceMap = (mapper, concurrent) => (source$) => new Observable4((observer) =>
208
206
  observer.error(err);
209
207
  },
210
208
  complete() {
211
- if (innerSubscriptions.length === 0)
212
- observer.complete();
209
+ if (innerSubscriptions.length === 0) observer.complete();
213
210
  isOuterDone = true;
214
211
  }
215
212
  });
@@ -232,10 +229,8 @@ var continueWith = (mapper) => (source) => new Observable5((observer) => {
232
229
  observer.error(e);
233
230
  },
234
231
  complete() {
235
- if (latestValue === NOTIN)
236
- observer.complete();
237
- else
238
- subscription = mapper(latestValue).subscribe(observer);
232
+ if (latestValue === NOTIN) observer.complete();
233
+ else subscription = mapper(latestValue).subscribe(observer);
239
234
  }
240
235
  });
241
236
  return () => {
@@ -308,7 +303,7 @@ var Runtime = class _Runtime {
308
303
  * @access package - Internal implementation detail. Do not use.
309
304
  */
310
305
  _getPalletChecksum(opType, pallet, name) {
311
- return this._checksums[this._descriptors.pallets[pallet][opType][name]];
306
+ return this._checksums[this._descriptors[opType][pallet][name]];
312
307
  }
313
308
  /**
314
309
  * @access package - Internal implementation detail. Do not use.
@@ -380,8 +375,7 @@ var compatibilityHelper = (runtimeApi, getDescriptorChecksum) => (getChecksum) =
380
375
  import { toHex } from "@polkadot-api/utils";
381
376
  import { map as map4, mergeMap as mergeMap2 } from "rxjs";
382
377
  var isOptionalArg = (lastArg) => {
383
- if (typeof lastArg !== "object")
384
- return false;
378
+ if (typeof lastArg !== "object") return false;
385
379
  return Object.keys(lastArg).every(
386
380
  (k) => k === "at" && typeof lastArg.at === "string" || k === "signal" && lastArg.signal instanceof AbortSignal
387
381
  );
@@ -412,8 +406,7 @@ var createRuntimeCallEntry = (api, method, chainHead, compatibilityHelper2) => {
412
406
  import { debounceTime, distinctUntilChanged, map as map5 } from "rxjs";
413
407
  import { NotBestBlockError } from "@polkadot-api/observable-client";
414
408
  var isOptionalArg2 = (lastArg) => {
415
- if (typeof lastArg !== "object")
416
- return false;
409
+ if (typeof lastArg !== "object") return false;
417
410
  return Object.keys(lastArg).every(
418
411
  (k) => k === "at" && typeof lastArg.at === "string" || k === "signal" && lastArg.signal instanceof AbortSignal
419
412
  );
@@ -453,15 +446,12 @@ var createStorageEntry = (pallet, name, chainHead, compatibilityHelper2) => {
453
446
  if (isSystemNumber) {
454
447
  result$ = chainHead.bestBlocks$.pipe(
455
448
  map5((blocks) => {
456
- if (at === "finalized" || !at)
457
- return blocks.at(-1);
458
- if (at === "best")
459
- return blocks.at(0);
449
+ if (at === "finalized" || !at) return blocks.at(-1);
450
+ if (at === "best") return blocks.at(0);
460
451
  return blocks.find((block) => block.hash === at);
461
452
  }),
462
453
  map5((block) => {
463
- if (!block)
464
- throw new NotBestBlockError();
454
+ if (!block) throw new NotBestBlockError();
465
455
  return block.number;
466
456
  }),
467
457
  distinctUntilChanged()
@@ -472,12 +462,10 @@ var createStorageEntry = (pallet, name, chainHead, compatibilityHelper2) => {
472
462
  at,
473
463
  "value",
474
464
  (ctx) => {
475
- if (!isCompatible2(ctx))
476
- throw checksumError();
465
+ if (!isCompatible2(ctx)) throw checksumError();
477
466
  const codecs = ctx.dynamicBuilder.buildStorage(pallet, name);
478
467
  const actualArgs = args.length === codecs.len ? args : args.slice(0, -1);
479
- if (args !== actualArgs && !isLastArgOptional)
480
- throw invalidArgs(args);
468
+ if (args !== actualArgs && !isLastArgOptional) throw invalidArgs(args);
481
469
  return codecs.enc(...actualArgs);
482
470
  },
483
471
  null,
@@ -499,11 +487,9 @@ var createStorageEntry = (pallet, name, chainHead, compatibilityHelper2) => {
499
487
  at,
500
488
  "descendantsValues",
501
489
  (ctx) => {
502
- if (!isCompatible2(ctx))
503
- throw checksumError();
490
+ if (!isCompatible2(ctx)) throw checksumError();
504
491
  const codecs = ctx.dynamicBuilder.buildStorage(pallet, name);
505
- if (args.length > codecs.len)
506
- throw invalidArgs(args);
492
+ if (args.length > codecs.len) throw invalidArgs(args);
507
493
  const actualArgs = args.length > 0 && isLastArgOptional ? args.slice(0, -1) : args;
508
494
  if (args.length === codecs.len && actualArgs === args)
509
495
  throw invalidArgs(args);
@@ -548,7 +534,7 @@ import {
548
534
  import { getPolkadotSigner } from "@polkadot-api/signer";
549
535
 
550
536
  // src/tx/create-tx.ts
551
- import { combineLatest as combineLatest2, mergeMap as mergeMap4, of as of6, take } from "rxjs";
537
+ import { combineLatest as combineLatest2, mergeMap as mergeMap4, of as of7, take } from "rxjs";
552
538
 
553
539
  // src/tx/signed-extensions/user/ChargeTransactionPayment.ts
554
540
  import { compactBn } from "@polkadot-api/substrate-bindings";
@@ -575,8 +561,7 @@ var systemVersionProp$ = (propName, metadata) => {
575
561
  const constant = metadata.pallets.find((x) => x.name === "System").constants.find((s) => s.name === "Version");
576
562
  const systemVersion = lookupFn(constant.type);
577
563
  const systemVersionDec = dynamicBuilder.buildDefinition(constant.type).dec;
578
- if (systemVersion.type !== "struct")
579
- throw new Error("not a struct");
564
+ if (systemVersion.type !== "struct") throw new Error("not a struct");
580
565
  const valueEnc = dynamicBuilder.buildDefinition(
581
566
  systemVersion.value[propName].id
582
567
  ).enc;
@@ -653,6 +638,7 @@ var ChargeAssetTxPayment = (tip, asset) => of4({
653
638
  var chain_exports = {};
654
639
  __export(chain_exports, {
655
640
  CheckGenesis: () => CheckGenesis,
641
+ CheckMetadataHash: () => CheckMetadataHash,
656
642
  CheckNonce: () => CheckNonce,
657
643
  CheckSpecVersion: () => CheckSpecVersion,
658
644
  CheckTxVersion: () => CheckTxVersion,
@@ -665,8 +651,15 @@ var CheckGenesis = (ctx) => genesisHashFromCtx(ctx).pipe(
665
651
  map8((additionalSigned) => ({ value: empty, additionalSigned }))
666
652
  );
667
653
 
654
+ // src/tx/signed-extensions/chain/CheckMetadataHash.ts
655
+ import { of as of5 } from "rxjs";
656
+ var CheckMetadataHash = () => of5({
657
+ value: Uint8Array.from([0]),
658
+ additionalSigned: Uint8Array.from([0])
659
+ });
660
+
668
661
  // src/tx/signed-extensions/chain/CheckNonce.ts
669
- import { mergeMap as mergeMap3, of as of5 } from "rxjs";
662
+ import { mergeMap as mergeMap3, of as of6 } from "rxjs";
670
663
  import { compact as compact2, u16 as u162, u32 as u322, u64, u8 } from "@polkadot-api/substrate-bindings";
671
664
  import { fromHex as fromHex3, toHex as toHex2 } from "@polkadot-api/utils";
672
665
  var NONCE_RUNTIME_CALL = "AccountNonceApi_account_nonce";
@@ -676,7 +669,7 @@ var lenToDecoder = {
676
669
  4: u322.dec,
677
670
  8: u64.dec
678
671
  };
679
- var getNonce = (input) => of5({ value: compact2.enc(input), additionalSigned: empty });
672
+ var getNonce = (input) => of6({ value: compact2.enc(input), additionalSigned: empty });
680
673
  var CheckNonce = (ctx) => ctx.chainHead.call$(ctx.at, NONCE_RUNTIME_CALL, toHex2(ctx.from)).pipe(
681
674
  mergeMap3((result) => {
682
675
  const bytes = fromHex3(result);
@@ -726,7 +719,7 @@ var createTx = (chainHead, signer, callData, atBlock, hinted = {}) => chainHead.
726
719
  const fn = chain_exports[identifier];
727
720
  if (!fn) {
728
721
  if (ctx.dynamicBuilder.buildDefinition(type) === _void && ctx.dynamicBuilder.buildDefinition(additionalSigned) === _void)
729
- return of6({
722
+ return of7({
730
723
  value: empty,
731
724
  additionalSigned: empty
732
725
  });
@@ -766,7 +759,7 @@ import {
766
759
  lastValueFrom,
767
760
  map as map11,
768
761
  mergeMap as mergeMap5,
769
- of as of7,
762
+ of as of8,
770
763
  take as take2
771
764
  } from "rxjs";
772
765
  import { fromHex as fromHex4, toHex as toHex3 } from "@polkadot-api/utils";
@@ -780,30 +773,27 @@ var computeState = (analized$, blocks$) => new Observable10((observer) => {
780
773
  let analyzed = analyzedBlocks.get(current);
781
774
  while (!analyzed) {
782
775
  const block = pinnedBlocks.blocks.get(current);
783
- if (!block)
784
- break;
776
+ if (!block) break;
785
777
  analyzed = analyzedBlocks.get(current = block.parent);
786
778
  }
787
- if (!analyzed)
788
- return;
789
- const isFinalized = pinnedBlocks.blocks.get(analyzed.hash).number <= pinnedBlocks.blocks.get(pinnedBlocks.finalized).number;
779
+ if (!analyzed) return;
780
+ const analyzedNumber = pinnedBlocks.blocks.get(analyzed.hash).number;
781
+ const isFinalized = analyzedNumber <= pinnedBlocks.blocks.get(pinnedBlocks.finalized).number;
790
782
  const found = analyzed.found.type;
791
783
  if (found && typeof latestState === "object" && latestState.hash === analyzed.hash) {
792
- if (isFinalized)
793
- observer.complete();
784
+ if (isFinalized) observer.complete();
794
785
  return;
795
786
  }
796
787
  observer.next(
797
788
  latestState = found ? {
798
789
  hash: analyzed.hash,
790
+ number: analyzedNumber,
799
791
  ...analyzed.found
800
792
  } : analyzed.found.isValid
801
793
  );
802
794
  if (isFinalized) {
803
- if (found)
804
- observer.complete();
805
- else if (!analyzed.found.isValid)
806
- observer.error(new Error("Invalid"));
795
+ if (found) observer.complete();
796
+ else if (!analyzed.found.isValid) observer.error(new Error("Invalid"));
807
797
  }
808
798
  };
809
799
  const subscription = blocks$.pipe(
@@ -813,8 +803,7 @@ var computeState = (analized$, blocks$) => new Observable10((observer) => {
813
803
  ).subscribe({
814
804
  next: (pinned) => {
815
805
  pinnedBlocks = pinned;
816
- if (analyzedBlocks.size === 0)
817
- return;
806
+ if (analyzedBlocks.size === 0) return;
818
807
  computeNextState();
819
808
  },
820
809
  error(e) {
@@ -883,6 +872,7 @@ var submit$ = (chainHead, broadcastTx$, tx, at, emitSign = false) => {
883
872
  found: true,
884
873
  block: {
885
874
  index: x.index,
875
+ number: x.number,
886
876
  hash: x.hash
887
877
  },
888
878
  ...getTxSuccessFromSystemEvents(x.events, x.index)
@@ -890,19 +880,18 @@ var submit$ = (chainHead, broadcastTx$, tx, at, emitSign = false) => {
890
880
  })
891
881
  );
892
882
  return concat(
893
- emitSign ? of7(getTxEvent("signed", {})) : EMPTY,
883
+ emitSign ? of8(getTxEvent("signed", {})) : EMPTY,
894
884
  validate$,
895
- of7(getTxEvent("broadcasted", {})),
885
+ of8(getTxEvent("broadcasted", {})),
896
886
  bestBlockState$.pipe(
897
887
  continueWith(
898
- ({ found, type, ...rest }) => found ? of7(getTxEvent("finalized", rest)) : EMPTY
888
+ ({ found, type, ...rest }) => found ? of8(getTxEvent("finalized", rest)) : EMPTY
899
889
  )
900
890
  )
901
891
  );
902
892
  };
903
893
  var submit = async (chainHead, broadcastTx$, transaction, at) => lastValueFrom(submit$(chainHead, broadcastTx$, transaction, at)).then((x) => {
904
- if (x.type !== "finalized")
905
- throw null;
894
+ if (x.type !== "finalized") throw null;
906
895
  const result = { ...x };
907
896
  delete result.type;
908
897
  return result;
@@ -941,8 +930,7 @@ var createTxEntry = (pallet, name, assetChecksum, chainHead, broadcast, compatib
941
930
  const getEncodedData = (runtime) => {
942
931
  if (!runtime)
943
932
  return firstValueFrom4(getCallData$(arg).pipe(map12((x) => x.callData)));
944
- if (!isCompatible(runtime))
945
- throw checksumError();
933
+ if (!isCompatible(runtime)) throw checksumError();
946
934
  return getCallDataWithContext(runtime._getCtx(), arg).callData;
947
935
  };
948
936
  const sign$ = (from, { ..._options }, atBlock) => getCallData$(arg, _options).pipe(
@@ -1017,11 +1005,9 @@ var createTypedApi = (chainDefinition, chainHead, broadcast$) => {
1017
1005
  const createProxyPath = (pathCall) => {
1018
1006
  const cache = {};
1019
1007
  return createProxy((a) => {
1020
- if (!cache[a])
1021
- cache[a] = {};
1008
+ if (!cache[a]) cache[a] = {};
1022
1009
  return createProxy((b) => {
1023
- if (!cache[a][b])
1024
- cache[a][b] = pathCall(a, b);
1010
+ if (!cache[a][b]) cache[a][b] = pathCall(a, b);
1025
1011
  return cache[a][b];
1026
1012
  });
1027
1013
  });
@@ -1033,7 +1019,7 @@ var createTypedApi = (chainDefinition, chainHead, broadcast$) => {
1033
1019
  chainHead,
1034
1020
  compatibilityHelper(
1035
1021
  runtime,
1036
- (r) => r._getPalletChecksum(0 /* Storage */, pallet, name)
1022
+ (r) => r._getPalletChecksum("storage" /* Storage */, pallet, name)
1037
1023
  )
1038
1024
  )
1039
1025
  );
@@ -1046,7 +1032,7 @@ var createTypedApi = (chainDefinition, chainHead, broadcast$) => {
1046
1032
  broadcast$,
1047
1033
  compatibilityHelper(
1048
1034
  runtime,
1049
- (r) => r._getPalletChecksum(1 /* Tx */, pallet, name)
1035
+ (r) => r._getPalletChecksum("tx" /* Tx */, pallet, name)
1050
1036
  )
1051
1037
  )
1052
1038
  );
@@ -1057,7 +1043,7 @@ var createTypedApi = (chainDefinition, chainHead, broadcast$) => {
1057
1043
  chainHead,
1058
1044
  compatibilityHelper(
1059
1045
  runtime,
1060
- (r) => r._getPalletChecksum(2 /* Event */, pallet, name)
1046
+ (r) => r._getPalletChecksum("events" /* Event */, pallet, name)
1061
1047
  )
1062
1048
  )
1063
1049
  );
@@ -1068,7 +1054,7 @@ var createTypedApi = (chainDefinition, chainHead, broadcast$) => {
1068
1054
  chainHead,
1069
1055
  compatibilityHelper(
1070
1056
  runtime,
1071
- (r) => r._getPalletChecksum(4 /* Const */, pallet, name)
1057
+ (r) => r._getPalletChecksum("constants" /* Const */, pallet, name)
1072
1058
  )
1073
1059
  )
1074
1060
  );