@dedot/api 0.0.1-alpha.34 → 0.0.1-alpha.36

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 (52) hide show
  1. package/chaintypes/substrate/consts.js +1 -0
  2. package/chaintypes/substrate/errors.js +1 -0
  3. package/chaintypes/substrate/events.js +1 -0
  4. package/chaintypes/substrate/index.js +1 -0
  5. package/chaintypes/substrate/json-rpc.d.ts +1 -1
  6. package/chaintypes/substrate/json-rpc.js +1 -0
  7. package/chaintypes/substrate/query.js +1 -0
  8. package/chaintypes/substrate/runtime.js +1 -0
  9. package/chaintypes/substrate/tx.js +1 -0
  10. package/chaintypes/substrate/types.d.ts +377 -377
  11. package/chaintypes/substrate/types.js +1 -0
  12. package/cjs/chaintypes/substrate/consts.js +1 -0
  13. package/cjs/chaintypes/substrate/errors.js +1 -0
  14. package/cjs/chaintypes/substrate/events.js +1 -0
  15. package/cjs/chaintypes/substrate/index.js +1 -0
  16. package/cjs/chaintypes/substrate/json-rpc.js +1 -0
  17. package/cjs/chaintypes/substrate/query.js +1 -0
  18. package/cjs/chaintypes/substrate/runtime.js +1 -0
  19. package/cjs/chaintypes/substrate/tx.js +1 -0
  20. package/cjs/chaintypes/substrate/types.js +1 -0
  21. package/cjs/client/DedotClient.js +2 -1
  22. package/cjs/client/LegacyClient.js +5 -4
  23. package/cjs/executor/ErrorExecutor.js +3 -3
  24. package/cjs/executor/EventExecutor.js +2 -2
  25. package/cjs/executor/StorageQueryExecutor.js +1 -1
  26. package/cjs/executor/TxExecutor.js +3 -3
  27. package/cjs/executor/v2/StorageQueryExecutorV2.js +4 -4
  28. package/cjs/extrinsic/extensions/known/ChargeAssetTxPayment.js +2 -2
  29. package/cjs/extrinsic/extensions/known/StorageWeightReclaim.js +10 -0
  30. package/cjs/extrinsic/extensions/known/index.js +2 -0
  31. package/cjs/extrinsic/submittable/SubmittableExtrinsic.js +2 -2
  32. package/cjs/extrinsic/submittable/SubmittableExtrinsicV2.js +11 -11
  33. package/cjs/storage/QueryableStorage.js +17 -17
  34. package/client/BaseSubstrateClient.d.ts +10 -11
  35. package/client/DedotClient.d.ts +2 -1
  36. package/client/DedotClient.js +2 -1
  37. package/client/LegacyClient.d.ts +5 -4
  38. package/client/LegacyClient.js +5 -4
  39. package/executor/ErrorExecutor.js +3 -3
  40. package/executor/EventExecutor.js +2 -2
  41. package/executor/Executor.d.ts +12 -12
  42. package/executor/StorageQueryExecutor.js +1 -1
  43. package/executor/TxExecutor.js +3 -3
  44. package/executor/v2/StorageQueryExecutorV2.js +4 -4
  45. package/extrinsic/extensions/known/ChargeAssetTxPayment.js +2 -2
  46. package/extrinsic/extensions/known/StorageWeightReclaim.d.ts +6 -0
  47. package/extrinsic/extensions/known/StorageWeightReclaim.js +6 -0
  48. package/extrinsic/extensions/known/index.js +2 -0
  49. package/extrinsic/submittable/SubmittableExtrinsic.js +2 -2
  50. package/extrinsic/submittable/SubmittableExtrinsicV2.js +11 -11
  51. package/package.json +10 -10
  52. package/storage/QueryableStorage.js +17 -17
@@ -1 +1,2 @@
1
+ // Generated by dedot cli
1
2
  export {};
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
4
  if (k2 === undefined) k2 = k;
4
5
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -14,7 +14,8 @@ const BaseSubstrateClient_js_1 = require("./BaseSubstrateClient.js");
14
14
  *
15
15
  * __Unstable, use with caution.__
16
16
  */
17
- class DedotClient extends BaseSubstrateClient_js_1.BaseSubstrateClient {
17
+ class DedotClient// prettier-end-here
18
+ extends BaseSubstrateClient_js_1.BaseSubstrateClient {
18
19
  _chainHead;
19
20
  _chainSpec;
20
21
  _txBroadcaster;
@@ -16,7 +16,7 @@ const KEEP_ALIVE_INTERVAL = 10_000; // in ms
16
16
  * import type { PolkadotApi } from '@dedot/chaintypes/polkadot';
17
17
  *
18
18
  * const run = async () => {
19
- * const api = await Dedot.new<PolkadotApi>('wss://rpc.polkadot.io');
19
+ * const api = await LegacyClient.new<PolkadotApi>('wss://rpc.polkadot.io');
20
20
  *
21
21
  * // Call rpc `state_getMetadata` to fetch raw scale-encoded metadata and decode it.
22
22
  * const metadata = await api.rpc.state.getMetadata();
@@ -44,7 +44,8 @@ const KEEP_ALIVE_INTERVAL = 10_000; // in ms
44
44
  * run().catch(console.error);
45
45
  * ```
46
46
  */
47
- class LegacyClient extends BaseSubstrateClient_js_1.BaseSubstrateClient {
47
+ class LegacyClient// prettier-end-here
48
+ extends BaseSubstrateClient_js_1.BaseSubstrateClient {
48
49
  #runtimeSubscriptionUnsub;
49
50
  #healthTimer;
50
51
  #apiAtCache = {};
@@ -65,7 +66,7 @@ class LegacyClient extends BaseSubstrateClient_js_1.BaseSubstrateClient {
65
66
  return new LegacyClient(options).connect();
66
67
  }
67
68
  /**
68
- * Alias for __Dedot.create__
69
+ * Alias for __LegacyClient.create__
69
70
  *
70
71
  * @param options
71
72
  */
@@ -205,7 +206,7 @@ class LegacyClient extends BaseSubstrateClient_js_1.BaseSubstrateClient {
205
206
  * // Make a transfer balance transaction
206
207
  * api.tx.balances.transferKeepAlive(<address>, <amount>)
207
208
  * .signAndSend(<keyPair|address>, { signer }, ({ status }) => {
208
- * console.log('Transaction status', status.tag);
209
+ * console.log('Transaction status', status.type);
209
210
  * });
210
211
  * ```
211
212
  */
@@ -20,7 +20,7 @@ class ErrorExecutor extends Executor_js_1.Executor {
20
20
  palletIndex: targetPallet.index,
21
21
  },
22
22
  is: (errorInfo) => {
23
- if ((0, utils_1.isObject)(errorInfo) && errorInfo.tag === 'Module') {
23
+ if ((0, utils_1.isObject)(errorInfo) && errorInfo.type === 'Module') {
24
24
  errorInfo = errorInfo.value;
25
25
  }
26
26
  if ((0, utils_1.isObject)(errorInfo) && (0, utils_1.isNumber)(errorInfo.index) && (0, utils_1.isHex)(errorInfo.error)) {
@@ -33,8 +33,8 @@ class ErrorExecutor extends Executor_js_1.Executor {
33
33
  #getErrorDef(errorTypeId, errorName) {
34
34
  const def = this.metadata.types[errorTypeId];
35
35
  (0, utils_1.assert)(def, new utils_1.UnknownApiError(`Error def not found for id ${errorTypeId}`));
36
- const { tag, value } = def.type;
37
- (0, utils_1.assert)(tag === 'Enum', new utils_1.UnknownApiError(`Error type should be an enum, found: ${tag}`));
36
+ const { type, value } = def.typeDef;
37
+ (0, utils_1.assert)(type === 'Enum', new utils_1.UnknownApiError(`Error type should be an enum, found: ${type}`));
38
38
  const errorDef = value.members.find(({ name }) => (0, utils_1.stringPascalCase)(name) === errorName);
39
39
  (0, utils_1.assert)(errorDef, new utils_1.UnknownApiError(`Error def not found for ${errorName}`));
40
40
  return {
@@ -39,8 +39,8 @@ class EventExecutor extends Executor_js_1.Executor {
39
39
  #getEventDef(eventTypeId, errorName) {
40
40
  const def = this.metadata.types[eventTypeId];
41
41
  (0, utils_1.assert)(def, new utils_1.UnknownApiError(`Event def not found for id ${eventTypeId}`));
42
- const { tag, value } = def.type;
43
- (0, utils_1.assert)(tag === 'Enum', new utils_1.UnknownApiError(`Event type should be an enum, found: ${tag}`));
42
+ const { type, value } = def.typeDef;
43
+ (0, utils_1.assert)(type === 'Enum', new utils_1.UnknownApiError(`Event type should be an enum, found: ${type}`));
44
44
  const eventDef = value.members.find(({ name }) => (0, utils_1.stringPascalCase)(name) === errorName);
45
45
  (0, utils_1.assert)(eventDef, new utils_1.UnknownApiError(`Event def not found for ${errorName}`));
46
46
  return {
@@ -52,7 +52,7 @@ class StorageQueryExecutor extends Executor_js_1.Executor {
52
52
  palletIndex: entry.pallet.index,
53
53
  ...entry.storageEntry,
54
54
  };
55
- const isMap = entry.storageEntry.type.tag === 'Map';
55
+ const isMap = entry.storageEntry.storageType.type === 'Map';
56
56
  if (isMap) {
57
57
  const queryMultiFn = async (...args) => {
58
58
  const [inArgs, callback] = extractArgs(args);
@@ -13,9 +13,9 @@ class TxExecutor extends Executor_js_1.Executor {
13
13
  const targetPallet = this.getPallet(pallet);
14
14
  (0, utils_1.assert)(targetPallet.calls, new utils_1.UnknownApiError(`Tx calls are not available for pallet ${targetPallet.name}`));
15
15
  const txType = this.metadata.types[targetPallet.calls];
16
- (0, utils_1.assert)(txType.type.tag === 'Enum', new utils_1.UnknownApiError('Tx type defs should be enum'));
17
- const isFlatEnum = txType.type.value.members.every((m) => m.fields.length === 0);
18
- const txCallDef = txType.type.value.members.find((m) => (0, utils_1.stringCamelCase)(m.name) === functionName);
16
+ (0, utils_1.assert)(txType.typeDef.type === 'Enum', new utils_1.UnknownApiError('Tx type defs should be enum'));
17
+ const isFlatEnum = txType.typeDef.value.members.every((m) => m.fields.length === 0);
18
+ const txCallDef = txType.typeDef.value.members.find((m) => (0, utils_1.stringCamelCase)(m.name) === functionName);
19
19
  (0, utils_1.assert)(txCallDef, new utils_1.UnknownApiError(`Tx call spec not found for ${pallet}.${functionName}`));
20
20
  const txCallFn = (...args) => {
21
21
  let call;
@@ -40,20 +40,20 @@ class StorageQueryExecutorV2 extends StorageQueryExecutor_js_1.StorageQueryExecu
40
40
  // TODO subscribe to finalized data source
41
41
  // initialHash = this.chainHead.finalizedHash;
42
42
  // eventToListen = 'finalizedBlock';
43
- const latestChanges = {};
43
+ const latestChanges = new Map();
44
44
  const pull = async ({ hash }) => {
45
45
  const results = await this.queryStorage(keys, hash);
46
46
  let changed = false;
47
47
  keys.forEach((key) => {
48
48
  const newValue = results[key];
49
- if (latestChanges[key] === newValue)
49
+ if (latestChanges.size > 0 && latestChanges.get(key) === newValue)
50
50
  return;
51
51
  changed = true;
52
- latestChanges[key] = newValue;
52
+ latestChanges.set(key, newValue);
53
53
  });
54
54
  if (!changed)
55
55
  return;
56
- callback(keys.map((key) => latestChanges[key]));
56
+ callback(keys.map((key) => latestChanges.get(key)));
57
57
  };
58
58
  await pull(best);
59
59
  const unsub = this.chainHead.on(eventToListen, pull);
@@ -30,8 +30,8 @@ class ChargeAssetTxPayment extends SignedExtension_js_1.SignedExtension {
30
30
  }
31
31
  $AssetId() {
32
32
  const extensionTypeDef = this.registry.findType(this.signedExtensionDef.typeId);
33
- (0, utils_1.assert)(extensionTypeDef.type.tag === 'Struct');
34
- const assetIdTypeDef = extensionTypeDef.type.value.fields.find((f) => f.name === 'asset_id');
33
+ (0, utils_1.assert)(extensionTypeDef.typeDef.type === 'Struct');
34
+ const assetIdTypeDef = extensionTypeDef.typeDef.value.fields.find((f) => f.name === 'asset_id');
35
35
  const $codec = this.registry.findCodec(assetIdTypeDef.typeId);
36
36
  const codecMetadata = $codec.metadata[0];
37
37
  if (codecMetadata.name === '$.option') {
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StorageWeightReclaim = void 0;
4
+ const SignedExtension_js_1 = require("../SignedExtension.js");
5
+ /**
6
+ * @description Storage weight reclaim mechanism.
7
+ */
8
+ class StorageWeightReclaim extends SignedExtension_js_1.SignedExtension {
9
+ }
10
+ exports.StorageWeightReclaim = StorageWeightReclaim;
@@ -12,6 +12,7 @@ const CheckSpecVersion_js_1 = require("./CheckSpecVersion.js");
12
12
  const CheckTxVersion_js_1 = require("./CheckTxVersion.js");
13
13
  const CheckWeight_js_1 = require("./CheckWeight.js");
14
14
  const PrevalidateAttests_js_1 = require("./PrevalidateAttests.js");
15
+ const StorageWeightReclaim_js_1 = require("./StorageWeightReclaim.js");
15
16
  exports.knownSignedExtensions = {
16
17
  CheckNonZeroSender: CheckNonZeroSender_js_1.CheckNonZeroSender,
17
18
  CheckSpecVersion: CheckSpecVersion_js_1.CheckSpecVersion,
@@ -24,4 +25,5 @@ exports.knownSignedExtensions = {
24
25
  PrevalidateAttests: PrevalidateAttests_js_1.PrevalidateAttests,
25
26
  ChargeAssetTxPayment: ChargeAssetTxPayment_js_1.ChargeAssetTxPayment,
26
27
  CheckMetadataHash: CheckMetadataHash_js_1.CheckMetadataHash,
28
+ StorageWeightReclaim: StorageWeightReclaim_js_1.StorageWeightReclaim,
27
29
  };
@@ -23,7 +23,7 @@ class SubmittableExtrinsic extends BaseSubmittableExtrinsic_js_1.BaseSubmittable
23
23
  const txHash = this.hash;
24
24
  if (isSubscription) {
25
25
  return this.api.rpc.author_submitAndWatchExtrinsic(txHex, async (status) => {
26
- if (status.tag === 'InBlock' || status.tag === 'Finalized') {
26
+ if (status.type === 'InBlock' || status.type === 'Finalized') {
27
27
  const blockHash = status.value;
28
28
  const [signedBlock, blockEvents] = await Promise.all([
29
29
  this.api.rpc.chain_getBlock(blockHash),
@@ -31,7 +31,7 @@ class SubmittableExtrinsic extends BaseSubmittableExtrinsic_js_1.BaseSubmittable
31
31
  ]);
32
32
  const txIndex = signedBlock.block.extrinsics.indexOf(txHex);
33
33
  (0, utils_1.assert)(txIndex >= 0, 'Extrinsic not found!');
34
- const events = blockEvents.filter(({ phase }) => phase.tag === 'ApplyExtrinsic' && phase.value === txIndex);
34
+ const events = blockEvents.filter(({ phase }) => phase.type === 'ApplyExtrinsic' && phase.value === txIndex);
35
35
  return callback(new SubmittableResult_js_1.SubmittableResult({ status, txHash, events, txIndex }));
36
36
  }
37
37
  else {
@@ -28,10 +28,10 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
28
28
  };
29
29
  const validation = await validateTx(finalizedHash);
30
30
  if (validation.isOk) {
31
- callback(new SubmittableResult_js_1.SubmittableResult({ status: { tag: 'Validated' }, txHash }));
31
+ callback(new SubmittableResult_js_1.SubmittableResult({ status: { type: 'Validated' }, txHash }));
32
32
  }
33
33
  else if (validation.isErr) {
34
- throw new errors_js_1.InvalidTxError(`Invalid Tx: ${validation.err.tag} - ${validation.err.value.tag}`, validation);
34
+ throw new errors_js_1.InvalidTxError(`Invalid Tx: ${validation.err.type} - ${validation.err.value.type}`, validation);
35
35
  }
36
36
  const checkTxIsOnChain = async (blockHash) => {
37
37
  if (blockHash === finalizedHash)
@@ -42,7 +42,7 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
42
42
  return checkTxIsOnChain(api.chainHead.findBlock(blockHash).parent);
43
43
  }
44
44
  const events = await this.getSystemEventsAt(blockHash);
45
- const txEvents = events.filter(({ phase }) => phase.tag == 'ApplyExtrinsic' && phase.value === txIndex);
45
+ const txEvents = events.filter(({ phase }) => phase.type == 'ApplyExtrinsic' && phase.value === txIndex);
46
46
  return {
47
47
  blockHash,
48
48
  index: txIndex,
@@ -88,7 +88,7 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
88
88
  if (txFound && bestChainChanged) {
89
89
  txFound = undefined;
90
90
  callback(new SubmittableResult_js_1.SubmittableResult({
91
- status: { tag: 'NoLongerInBestChain' },
91
+ status: { type: 'NoLongerInBestChain' },
92
92
  txHash,
93
93
  }));
94
94
  }
@@ -101,7 +101,7 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
101
101
  txFound = inBlock;
102
102
  const { index: txIndex, events, blockHash } = inBlock;
103
103
  callback(new SubmittableResult_js_1.SubmittableResult({
104
- status: { tag: 'BestChainBlockIncluded', value: { blockHash, txIndex } },
104
+ status: { type: 'BestChainBlockIncluded', value: { blockHash, txIndex } },
105
105
  txHash,
106
106
  events,
107
107
  txIndex,
@@ -134,7 +134,7 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
134
134
  if (inBlock) {
135
135
  const { index: txIndex, events, blockHash } = inBlock;
136
136
  callback(new SubmittableResult_js_1.SubmittableResult({
137
- status: { tag: 'Finalized', value: { blockHash, txIndex } },
137
+ status: { type: 'Finalized', value: { blockHash, txIndex } },
138
138
  txHash,
139
139
  events,
140
140
  txIndex,
@@ -148,8 +148,8 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
148
148
  return;
149
149
  callback(new SubmittableResult_js_1.SubmittableResult({
150
150
  status: {
151
- tag: 'Invalid',
152
- value: { error: `Invalid Tx: ${validation.err.tag} - ${validation.err.value.tag}` },
151
+ type: 'Invalid',
152
+ value: { error: `Invalid Tx: ${validation.err.type} - ${validation.err.value.type}` },
153
153
  },
154
154
  txHash,
155
155
  }));
@@ -158,7 +158,7 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
158
158
  };
159
159
  stopBroadcastFn = await api.txBroadcaster.broadcastTx(txHex);
160
160
  callback(new SubmittableResult_js_1.SubmittableResult({
161
- status: { tag: 'Broadcasting' },
161
+ status: { type: 'Broadcasting' },
162
162
  txHash,
163
163
  }));
164
164
  const stopBestBlockTrackingFn = api.chainHead.on('bestBlock', checkBestBlockIncluded);
@@ -184,11 +184,11 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
184
184
  try {
185
185
  // TODO handle timeout for this with the Drop status, just in-case we somehow can't find the tx in any block
186
186
  const unsub = await this.#send(({ status, txHash }) => {
187
- if (status.tag === 'BestChainBlockIncluded' || status.tag === 'Finalized') {
187
+ if (status.type === 'BestChainBlockIncluded' || status.type === 'Finalized') {
188
188
  defer.resolve(txHash);
189
189
  unsub().catch(utils_1.noop);
190
190
  }
191
- else if (status.tag === 'Invalid' || status.tag === 'Drop') {
191
+ else if (status.type === 'Invalid' || status.type === 'Drop') {
192
192
  defer.reject(new Error(status.value.error));
193
193
  unsub().catch(utils_1.noop);
194
194
  }
@@ -39,14 +39,14 @@ class QueryableStorage {
39
39
  const storageItemHash = (0, utils_2.xxhashAsU8a)(this.storageEntry.name, 128);
40
40
  return (0, utils_2.concatU8a)(palletNameHash, storageItemHash);
41
41
  }
42
- #getStorageMapInfo(type) {
43
- (0, utils_1.assert)(type.tag === 'Map');
44
- const { hashers, keyTypeId } = type.value;
42
+ #getStorageMapInfo(storageType) {
43
+ (0, utils_1.assert)(storageType.type === 'Map');
44
+ const { hashers, keyTypeId } = storageType.value;
45
45
  let keyTypeIds = [keyTypeId];
46
46
  if (hashers.length > 1) {
47
- const { type } = this.registry.findType(keyTypeId);
48
- (0, utils_1.assert)(type.tag === 'Tuple', 'Key type should be a tuple!');
49
- keyTypeIds = type.value.fields;
47
+ const { typeDef } = this.registry.findType(keyTypeId);
48
+ (0, utils_1.assert)(typeDef.type === 'Tuple', 'Key type should be a tuple!');
49
+ keyTypeIds = typeDef.value.fields;
50
50
  }
51
51
  return { hashers, keyTypeIds };
52
52
  }
@@ -56,12 +56,12 @@ class QueryableStorage {
56
56
  * @param keyInput
57
57
  */
58
58
  encodeKey(keyInput) {
59
- const { type } = this.storageEntry;
60
- if (type.tag === 'Plain') {
59
+ const { storageType } = this.storageEntry;
60
+ if (storageType.type === 'Plain') {
61
61
  return this.prefixKey;
62
62
  }
63
- else if (type.tag === 'Map') {
64
- const { hashers, keyTypeIds } = this.#getStorageMapInfo(type);
63
+ else if (storageType.type === 'Map') {
64
+ const { hashers, keyTypeIds } = this.#getStorageMapInfo(storageType);
65
65
  const extractedInputs = this.#extractRequiredKeyInputs(keyInput, hashers.length);
66
66
  const keyParts = keyTypeIds.map((keyId, index) => {
67
67
  const input = extractedInputs[index];
@@ -71,7 +71,7 @@ class QueryableStorage {
71
71
  });
72
72
  return (0, utils_2.u8aToHex)((0, utils_2.concatU8a)(this.prefixKeyAsU8a, ...keyParts));
73
73
  }
74
- throw Error(`Invalid storage entry type: ${type}`);
74
+ throw Error(`Invalid storage entry type: ${JSON.stringify(storageType)}`);
75
75
  }
76
76
  /**
77
77
  * Decode storage key to plain key input
@@ -80,16 +80,16 @@ class QueryableStorage {
80
80
  * @param key
81
81
  */
82
82
  decodeKey(key) {
83
- const { type } = this.storageEntry;
84
- if (type.tag === 'Plain') {
83
+ const { storageType } = this.storageEntry;
84
+ if (storageType.type === 'Plain') {
85
85
  return;
86
86
  }
87
- else if (type.tag === 'Map') {
87
+ else if (storageType.type === 'Map') {
88
88
  const prefix = this.prefixKey;
89
89
  if (!key.startsWith(prefix)) {
90
90
  throw new Error(`Storage key does not match this storage entry (${this.palletName}.${this.storageItem})`);
91
91
  }
92
- const { hashers, keyTypeIds } = this.#getStorageMapInfo(type);
92
+ const { hashers, keyTypeIds } = this.#getStorageMapInfo(storageType);
93
93
  let keyData = (0, utils_2.hexToU8a)((0, utils_1.hexAddPrefix)(key.slice(prefix.length)));
94
94
  const results = keyTypeIds.map((keyId, index) => {
95
95
  const [hashLen, canDecode] = HASHER_INFO[hashers[index]];
@@ -104,7 +104,7 @@ class QueryableStorage {
104
104
  });
105
105
  return hashers.length > 1 ? results : results[0];
106
106
  }
107
- throw Error(`Invalid storage entry type: ${type}`);
107
+ throw Error(`Invalid storage entry type: ${JSON.stringify(storageType)}`);
108
108
  }
109
109
  /**
110
110
  * Decode raw/bytes storage data to plain value
@@ -112,7 +112,7 @@ class QueryableStorage {
112
112
  * @param raw
113
113
  */
114
114
  decodeValue(raw) {
115
- const { modifier, type: { value: { valueTypeId }, }, default: defaultValue, } = this.storageEntry;
115
+ const { modifier, storageType: { value: { valueTypeId }, }, default: defaultValue, } = this.storageEntry;
116
116
  if (raw === null || raw === undefined) {
117
117
  if (modifier === 'Optional') {
118
118
  return undefined;
@@ -1,8 +1,7 @@
1
1
  import { BlockHash, Hash, Metadata, PortableRegistry, RuntimeVersion } from '@dedot/codecs';
2
2
  import type { JsonRpcProvider } from '@dedot/providers';
3
3
  import { type IStorage } from '@dedot/storage';
4
- import { GenericSubstrateApi, RpcVersion, VersionedGenericSubstrateApi } from '@dedot/types';
5
- import type { SubstrateApi } from '../chaintypes/index.js';
4
+ import { GenericSubstrateApi, RpcVersion } from '@dedot/types';
6
5
  import { JsonRpcClient } from '../json-rpc/index.js';
7
6
  import type { ApiEvent, ApiOptions, ISubstrateClient, ISubstrateClientAt, JsonRpcClientOptions, MetadataKey, SubstrateRuntimeVersion } from '../types.js';
8
7
  export declare function ensurePresence<T>(value: T): NonNullable<T>;
@@ -10,7 +9,7 @@ export declare function ensurePresence<T>(value: T): NonNullable<T>;
10
9
  * @name BaseSubstrateClient
11
10
  * @description Base & shared abstraction for Substrate API Clients
12
11
  */
13
- export declare abstract class BaseSubstrateClient<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> extends JsonRpcClient<ChainApi[RpcVersion], ApiEvent> implements ISubstrateClient<ChainApi[RpcVersion]> {
12
+ export declare abstract class BaseSubstrateClient<ChainApi extends GenericSubstrateApi = GenericSubstrateApi> extends JsonRpcClient<ChainApi, ApiEvent> implements ISubstrateClient<ChainApi> {
14
13
  rpcVersion: RpcVersion;
15
14
  protected _options: ApiOptions;
16
15
  protected _registry?: PortableRegistry;
@@ -54,12 +53,12 @@ export declare abstract class BaseSubstrateClient<ChainApi extends VersionedGene
54
53
  get registry(): PortableRegistry;
55
54
  get genesisHash(): Hash;
56
55
  get runtimeVersion(): SubstrateRuntimeVersion;
57
- get consts(): ChainApi[RpcVersion]['consts'];
58
- get errors(): ChainApi[RpcVersion]['errors'];
59
- get events(): ChainApi[RpcVersion]['events'];
60
- get query(): ChainApi[RpcVersion]['query'];
61
- get call(): ChainApi[RpcVersion]['call'];
62
- protected callAt(hash?: BlockHash): ChainApi[RpcVersion]['call'];
63
- get tx(): ChainApi[RpcVersion]['tx'];
64
- at<ChainApiAt extends GenericSubstrateApi = ChainApi[RpcVersion]>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
56
+ get consts(): ChainApi['consts'];
57
+ get errors(): ChainApi['errors'];
58
+ get events(): ChainApi['events'];
59
+ get query(): ChainApi['query'];
60
+ get call(): ChainApi['call'];
61
+ protected callAt(hash?: BlockHash): ChainApi['call'];
62
+ get tx(): ChainApi['tx'];
63
+ at<ChainApiAt extends GenericSubstrateApi = ChainApi>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
65
64
  }
@@ -11,7 +11,8 @@ import { BaseSubstrateClient } from './BaseSubstrateClient.js';
11
11
  *
12
12
  * __Unstable, use with caution.__
13
13
  */
14
- export declare class DedotClient<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> extends BaseSubstrateClient<ChainApi> {
14
+ export declare class DedotClient<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>// prettier-end-here
15
+ extends BaseSubstrateClient<ChainApi[RpcV2]> {
15
16
  #private;
16
17
  protected _chainHead?: ChainHead;
17
18
  protected _chainSpec?: ChainSpec;
@@ -11,7 +11,8 @@ import { BaseSubstrateClient, ensurePresence } from './BaseSubstrateClient.js';
11
11
  *
12
12
  * __Unstable, use with caution.__
13
13
  */
14
- export class DedotClient extends BaseSubstrateClient {
14
+ export class DedotClient// prettier-end-here
15
+ extends BaseSubstrateClient {
15
16
  _chainHead;
16
17
  _chainSpec;
17
18
  _txBroadcaster;
@@ -14,7 +14,7 @@ import { BaseSubstrateClient } from './BaseSubstrateClient.js';
14
14
  * import type { PolkadotApi } from '@dedot/chaintypes/polkadot';
15
15
  *
16
16
  * const run = async () => {
17
- * const api = await Dedot.new<PolkadotApi>('wss://rpc.polkadot.io');
17
+ * const api = await LegacyClient.new<PolkadotApi>('wss://rpc.polkadot.io');
18
18
  *
19
19
  * // Call rpc `state_getMetadata` to fetch raw scale-encoded metadata and decode it.
20
20
  * const metadata = await api.rpc.state.getMetadata();
@@ -42,7 +42,8 @@ import { BaseSubstrateClient } from './BaseSubstrateClient.js';
42
42
  * run().catch(console.error);
43
43
  * ```
44
44
  */
45
- export declare class LegacyClient<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> extends BaseSubstrateClient<ChainApi> {
45
+ export declare class LegacyClient<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>// prettier-end-here
46
+ extends BaseSubstrateClient<ChainApi[RpcLegacy]> {
46
47
  #private;
47
48
  /**
48
49
  * Use factory methods (`create`, `new`) to create `Dedot` instances.
@@ -57,7 +58,7 @@ export declare class LegacyClient<ChainApi extends VersionedGenericSubstrateApi
57
58
  */
58
59
  static create<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>(options: ApiOptions | JsonRpcProvider): Promise<LegacyClient<ChainApi>>;
59
60
  /**
60
- * Alias for __Dedot.create__
61
+ * Alias for __LegacyClient.create__
61
62
  *
62
63
  * @param options
63
64
  */
@@ -116,7 +117,7 @@ export declare class LegacyClient<ChainApi extends VersionedGenericSubstrateApi
116
117
  * // Make a transfer balance transaction
117
118
  * api.tx.balances.transferKeepAlive(<address>, <amount>)
118
119
  * .signAndSend(<keyPair|address>, { signer }, ({ status }) => {
119
- * console.log('Transaction status', status.tag);
120
+ * console.log('Transaction status', status.type);
120
121
  * });
121
122
  * ```
122
123
  */
@@ -13,7 +13,7 @@ const KEEP_ALIVE_INTERVAL = 10_000; // in ms
13
13
  * import type { PolkadotApi } from '@dedot/chaintypes/polkadot';
14
14
  *
15
15
  * const run = async () => {
16
- * const api = await Dedot.new<PolkadotApi>('wss://rpc.polkadot.io');
16
+ * const api = await LegacyClient.new<PolkadotApi>('wss://rpc.polkadot.io');
17
17
  *
18
18
  * // Call rpc `state_getMetadata` to fetch raw scale-encoded metadata and decode it.
19
19
  * const metadata = await api.rpc.state.getMetadata();
@@ -41,7 +41,8 @@ const KEEP_ALIVE_INTERVAL = 10_000; // in ms
41
41
  * run().catch(console.error);
42
42
  * ```
43
43
  */
44
- export class LegacyClient extends BaseSubstrateClient {
44
+ export class LegacyClient// prettier-end-here
45
+ extends BaseSubstrateClient {
45
46
  #runtimeSubscriptionUnsub;
46
47
  #healthTimer;
47
48
  #apiAtCache = {};
@@ -62,7 +63,7 @@ export class LegacyClient extends BaseSubstrateClient {
62
63
  return new LegacyClient(options).connect();
63
64
  }
64
65
  /**
65
- * Alias for __Dedot.create__
66
+ * Alias for __LegacyClient.create__
66
67
  *
67
68
  * @param options
68
69
  */
@@ -202,7 +203,7 @@ export class LegacyClient extends BaseSubstrateClient {
202
203
  * // Make a transfer balance transaction
203
204
  * api.tx.balances.transferKeepAlive(<address>, <amount>)
204
205
  * .signAndSend(<keyPair|address>, { signer }, ({ status }) => {
205
- * console.log('Transaction status', status.tag);
206
+ * console.log('Transaction status', status.type);
206
207
  * });
207
208
  * ```
208
209
  */
@@ -17,7 +17,7 @@ export class ErrorExecutor extends Executor {
17
17
  palletIndex: targetPallet.index,
18
18
  },
19
19
  is: (errorInfo) => {
20
- if (isObject(errorInfo) && errorInfo.tag === 'Module') {
20
+ if (isObject(errorInfo) && errorInfo.type === 'Module') {
21
21
  errorInfo = errorInfo.value;
22
22
  }
23
23
  if (isObject(errorInfo) && isNumber(errorInfo.index) && isHex(errorInfo.error)) {
@@ -30,8 +30,8 @@ export class ErrorExecutor extends Executor {
30
30
  #getErrorDef(errorTypeId, errorName) {
31
31
  const def = this.metadata.types[errorTypeId];
32
32
  assert(def, new UnknownApiError(`Error def not found for id ${errorTypeId}`));
33
- const { tag, value } = def.type;
34
- assert(tag === 'Enum', new UnknownApiError(`Error type should be an enum, found: ${tag}`));
33
+ const { type, value } = def.typeDef;
34
+ assert(type === 'Enum', new UnknownApiError(`Error type should be an enum, found: ${type}`));
35
35
  const errorDef = value.members.find(({ name }) => stringPascalCase(name) === errorName);
36
36
  assert(errorDef, new UnknownApiError(`Error def not found for ${errorName}`));
37
37
  return {
@@ -36,8 +36,8 @@ export class EventExecutor extends Executor {
36
36
  #getEventDef(eventTypeId, errorName) {
37
37
  const def = this.metadata.types[eventTypeId];
38
38
  assert(def, new UnknownApiError(`Event def not found for id ${eventTypeId}`));
39
- const { tag, value } = def.type;
40
- assert(tag === 'Enum', new UnknownApiError(`Event type should be an enum, found: ${tag}`));
39
+ const { type, value } = def.typeDef;
40
+ assert(type === 'Enum', new UnknownApiError(`Event type should be an enum, found: ${type}`));
41
41
  const eventDef = value.members.find(({ name }) => stringPascalCase(name) === errorName);
42
42
  assert(eventDef, new UnknownApiError(`Event def not found for ${errorName}`));
43
43
  return {