@polkadot/types-known 6.12.2-6 → 7.0.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.
Files changed (57) hide show
  1. package/bundle.cjs +22 -34
  2. package/bundle.d.ts +2 -1
  3. package/bundle.js +3 -2
  4. package/chain/index.cjs +12 -0
  5. package/chain/index.d.ts +3 -0
  6. package/chain/index.js +5 -0
  7. package/package.json +92 -5
  8. package/packageInfo.cjs +1 -1
  9. package/packageInfo.js +1 -1
  10. package/spec/centrifuge-chain.cjs +98 -0
  11. package/spec/centrifuge-chain.d.ts +3 -0
  12. package/spec/centrifuge-chain.js +89 -0
  13. package/spec/index.cjs +45 -0
  14. package/spec/index.d.ts +3 -0
  15. package/spec/index.js +26 -0
  16. package/spec/kusama.cjs +177 -0
  17. package/spec/kusama.d.ts +3 -0
  18. package/spec/kusama.js +167 -0
  19. package/spec/node-template.cjs +17 -0
  20. package/spec/node-template.d.ts +3 -0
  21. package/spec/node-template.js +10 -0
  22. package/spec/node.cjs +17 -0
  23. package/spec/node.d.ts +3 -0
  24. package/spec/node.js +10 -0
  25. package/spec/polkadot.cjs +74 -0
  26. package/spec/polkadot.d.ts +3 -0
  27. package/spec/polkadot.js +65 -0
  28. package/spec/rococo.cjs +53 -0
  29. package/spec/rococo.d.ts +3 -0
  30. package/spec/rococo.js +43 -0
  31. package/spec/shell.cjs +17 -0
  32. package/spec/shell.d.ts +3 -0
  33. package/spec/shell.js +10 -0
  34. package/spec/statemint.cjs +35 -0
  35. package/spec/statemint.d.ts +3 -0
  36. package/spec/statemint.js +25 -0
  37. package/spec/westend.cjs +90 -0
  38. package/spec/westend.d.ts +3 -0
  39. package/spec/westend.js +80 -0
  40. package/upgrades/index.cjs +66 -0
  41. package/upgrades/index.d.ts +3 -0
  42. package/upgrades/index.js +47 -0
  43. package/upgrades/kusama.cjs +11 -0
  44. package/upgrades/kusama.d.ts +3 -0
  45. package/upgrades/kusama.js +4 -0
  46. package/upgrades/polkadot.cjs +11 -0
  47. package/upgrades/polkadot.d.ts +3 -0
  48. package/upgrades/polkadot.js +4 -0
  49. package/upgrades/types.cjs +1 -0
  50. package/upgrades/types.d.ts +1 -0
  51. package/upgrades/types.js +1 -0
  52. package/upgrades/westend.cjs +11 -0
  53. package/upgrades/westend.d.ts +3 -0
  54. package/upgrades/westend.js +4 -0
  55. package/util.cjs +139 -0
  56. package/util.d.ts +27 -0
  57. package/util.js +102 -0
package/util.js ADDED
@@ -0,0 +1,102 @@
1
+ // Copyright 2017-2021 @polkadot/types-known authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { bnToBn, isNull, isUndefined, objectSpread } from '@polkadot/util';
4
+ import typesChain from "./chain/index.js";
5
+ import typesSpec from "./spec/index.js";
6
+ import upgrades from "./upgrades/index.js";
7
+
8
+ function withNames(chainName, specName, fn) {
9
+ return fn(chainName.toString(), specName.toString());
10
+ } // flatten a VersionedType[] into a Record<string, string>
11
+
12
+ /** @internal */
13
+
14
+
15
+ function filterVersions(versions = [], specVersion) {
16
+ return versions.filter(({
17
+ minmax: [min, max]
18
+ }) => (isUndefined(min) || isNull(min) || specVersion >= min) && (isUndefined(max) || isNull(max) || specVersion <= max)).reduce((result, {
19
+ types
20
+ }) => objectSpread(result, types), {});
21
+ }
22
+ /**
23
+ * @description Based on the chain and runtimeVersion, get the applicable signed extensions (ready for registration)
24
+ */
25
+
26
+
27
+ export function getSpecExtensions({
28
+ knownTypes
29
+ }, chainName, specName) {
30
+ return withNames(chainName, specName, (c, s) => {
31
+ var _knownTypes$typesBund, _knownTypes$typesBund2, _knownTypes$typesBund3, _knownTypes$typesBund4, _knownTypes$typesBund5, _knownTypes$typesBund6;
32
+
33
+ return objectSpread({}, (_knownTypes$typesBund = knownTypes.typesBundle) === null || _knownTypes$typesBund === void 0 ? void 0 : (_knownTypes$typesBund2 = _knownTypes$typesBund.spec) === null || _knownTypes$typesBund2 === void 0 ? void 0 : (_knownTypes$typesBund3 = _knownTypes$typesBund2[s]) === null || _knownTypes$typesBund3 === void 0 ? void 0 : _knownTypes$typesBund3.signedExtensions, (_knownTypes$typesBund4 = knownTypes.typesBundle) === null || _knownTypes$typesBund4 === void 0 ? void 0 : (_knownTypes$typesBund5 = _knownTypes$typesBund4.chain) === null || _knownTypes$typesBund5 === void 0 ? void 0 : (_knownTypes$typesBund6 = _knownTypes$typesBund5[c]) === null || _knownTypes$typesBund6 === void 0 ? void 0 : _knownTypes$typesBund6.signedExtensions);
34
+ });
35
+ }
36
+ /**
37
+ * @description Based on the chain and runtimeVersion, get the applicable types (ready for registration)
38
+ */
39
+
40
+ export function getSpecTypes({
41
+ knownTypes
42
+ }, chainName, specName, specVersion) {
43
+ const _specVersion = bnToBn(specVersion).toNumber();
44
+
45
+ return withNames(chainName, specName, (c, s) => {
46
+ var _knownTypes$typesBund7, _knownTypes$typesBund8, _knownTypes$typesBund9, _knownTypes$typesBund10, _knownTypes$typesBund11, _knownTypes$typesBund12, _knownTypes$typesSpec, _knownTypes$typesChai;
47
+
48
+ return (// The order here is always, based on -
49
+ // - spec then chain
50
+ // - typesBundle takes higher precedence
51
+ // - types is the final catch-all override
52
+ objectSpread({}, filterVersions(typesSpec[s], _specVersion), filterVersions(typesChain[c], _specVersion), filterVersions((_knownTypes$typesBund7 = knownTypes.typesBundle) === null || _knownTypes$typesBund7 === void 0 ? void 0 : (_knownTypes$typesBund8 = _knownTypes$typesBund7.spec) === null || _knownTypes$typesBund8 === void 0 ? void 0 : (_knownTypes$typesBund9 = _knownTypes$typesBund8[s]) === null || _knownTypes$typesBund9 === void 0 ? void 0 : _knownTypes$typesBund9.types, _specVersion), filterVersions((_knownTypes$typesBund10 = knownTypes.typesBundle) === null || _knownTypes$typesBund10 === void 0 ? void 0 : (_knownTypes$typesBund11 = _knownTypes$typesBund10.chain) === null || _knownTypes$typesBund11 === void 0 ? void 0 : (_knownTypes$typesBund12 = _knownTypes$typesBund11[c]) === null || _knownTypes$typesBund12 === void 0 ? void 0 : _knownTypes$typesBund12.types, _specVersion), (_knownTypes$typesSpec = knownTypes.typesSpec) === null || _knownTypes$typesSpec === void 0 ? void 0 : _knownTypes$typesSpec[s], (_knownTypes$typesChai = knownTypes.typesChain) === null || _knownTypes$typesChai === void 0 ? void 0 : _knownTypes$typesChai[c], knownTypes.types)
53
+ );
54
+ });
55
+ }
56
+ export function getSpecHasher({
57
+ knownTypes
58
+ }, chainName, specName) {
59
+ return withNames(chainName, specName, (c, s) => {
60
+ var _knownTypes$typesBund13, _knownTypes$typesBund14, _knownTypes$typesBund15, _knownTypes$typesBund16, _knownTypes$typesBund17, _knownTypes$typesBund18;
61
+
62
+ return knownTypes.hasher || ((_knownTypes$typesBund13 = knownTypes.typesBundle) === null || _knownTypes$typesBund13 === void 0 ? void 0 : (_knownTypes$typesBund14 = _knownTypes$typesBund13.chain) === null || _knownTypes$typesBund14 === void 0 ? void 0 : (_knownTypes$typesBund15 = _knownTypes$typesBund14[c]) === null || _knownTypes$typesBund15 === void 0 ? void 0 : _knownTypes$typesBund15.hasher) || ((_knownTypes$typesBund16 = knownTypes.typesBundle) === null || _knownTypes$typesBund16 === void 0 ? void 0 : (_knownTypes$typesBund17 = _knownTypes$typesBund16.spec) === null || _knownTypes$typesBund17 === void 0 ? void 0 : (_knownTypes$typesBund18 = _knownTypes$typesBund17[s]) === null || _knownTypes$typesBund18 === void 0 ? void 0 : _knownTypes$typesBund18.hasher) || null;
63
+ });
64
+ }
65
+ /**
66
+ * @description Based on the chain and runtimeVersion, get the applicable rpc definitions (ready for registration)
67
+ */
68
+
69
+ export function getSpecRpc({
70
+ knownTypes
71
+ }, chainName, specName) {
72
+ return withNames(chainName, specName, (c, s) => {
73
+ var _knownTypes$typesBund19, _knownTypes$typesBund20, _knownTypes$typesBund21, _knownTypes$typesBund22, _knownTypes$typesBund23, _knownTypes$typesBund24;
74
+
75
+ return objectSpread({}, (_knownTypes$typesBund19 = knownTypes.typesBundle) === null || _knownTypes$typesBund19 === void 0 ? void 0 : (_knownTypes$typesBund20 = _knownTypes$typesBund19.spec) === null || _knownTypes$typesBund20 === void 0 ? void 0 : (_knownTypes$typesBund21 = _knownTypes$typesBund20[s]) === null || _knownTypes$typesBund21 === void 0 ? void 0 : _knownTypes$typesBund21.rpc, (_knownTypes$typesBund22 = knownTypes.typesBundle) === null || _knownTypes$typesBund22 === void 0 ? void 0 : (_knownTypes$typesBund23 = _knownTypes$typesBund22.chain) === null || _knownTypes$typesBund23 === void 0 ? void 0 : (_knownTypes$typesBund24 = _knownTypes$typesBund23[c]) === null || _knownTypes$typesBund24 === void 0 ? void 0 : _knownTypes$typesBund24.rpc);
76
+ });
77
+ }
78
+ /**
79
+ * @description Based on the chain and runtimeVersion, get the applicable alias definitions (ready for registration)
80
+ */
81
+
82
+ export function getSpecAlias({
83
+ knownTypes
84
+ }, chainName, specName) {
85
+ return withNames(chainName, specName, (c, s) => {
86
+ var _knownTypes$typesBund25, _knownTypes$typesBund26, _knownTypes$typesBund27, _knownTypes$typesBund28, _knownTypes$typesBund29, _knownTypes$typesBund30;
87
+
88
+ return (// as per versions, first spec, then chain then finally non-versioned
89
+ objectSpread({}, (_knownTypes$typesBund25 = knownTypes.typesBundle) === null || _knownTypes$typesBund25 === void 0 ? void 0 : (_knownTypes$typesBund26 = _knownTypes$typesBund25.spec) === null || _knownTypes$typesBund26 === void 0 ? void 0 : (_knownTypes$typesBund27 = _knownTypes$typesBund26[s]) === null || _knownTypes$typesBund27 === void 0 ? void 0 : _knownTypes$typesBund27.alias, (_knownTypes$typesBund28 = knownTypes.typesBundle) === null || _knownTypes$typesBund28 === void 0 ? void 0 : (_knownTypes$typesBund29 = _knownTypes$typesBund28.chain) === null || _knownTypes$typesBund29 === void 0 ? void 0 : (_knownTypes$typesBund30 = _knownTypes$typesBund29[c]) === null || _knownTypes$typesBund30 === void 0 ? void 0 : _knownTypes$typesBund30.alias, knownTypes.typesAlias)
90
+ );
91
+ });
92
+ }
93
+ /**
94
+ * @description Returns a version record for known chains where upgrades are being tracked
95
+ */
96
+
97
+ export function getUpgradeVersion(genesisHash, blockNumber) {
98
+ const known = upgrades.find(u => genesisHash.eq(u.genesisHash));
99
+ return known ? [known.versions.reduce((last, version) => {
100
+ return blockNumber.gt(version.blockNumber) ? version : last;
101
+ }, undefined), known.versions.find(version => blockNumber.lte(version.blockNumber))] : [undefined, undefined];
102
+ }