@dedot/api 0.0.1-next.9c1d51fe.10 → 0.0.1-next.b6596712.6

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 (40) 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.js +1 -0
  11. package/cjs/chaintypes/substrate/consts.js +1 -0
  12. package/cjs/chaintypes/substrate/errors.js +1 -0
  13. package/cjs/chaintypes/substrate/events.js +1 -0
  14. package/cjs/chaintypes/substrate/index.js +1 -0
  15. package/cjs/chaintypes/substrate/json-rpc.js +1 -0
  16. package/cjs/chaintypes/substrate/query.js +1 -0
  17. package/cjs/chaintypes/substrate/runtime.js +1 -0
  18. package/cjs/chaintypes/substrate/tx.js +1 -0
  19. package/cjs/chaintypes/substrate/types.js +1 -0
  20. package/cjs/client/DedotClient.js +2 -1
  21. package/cjs/client/{Dedot.js → LegacyClient.js} +9 -8
  22. package/cjs/client/index.js +1 -1
  23. package/cjs/executor/v2/StorageQueryExecutorV2.js +3 -3
  24. package/cjs/extrinsic/extensions/known/CheckMetadataHash.js +31 -0
  25. package/cjs/extrinsic/extensions/known/StorageWeightReclaim.js +10 -0
  26. package/cjs/extrinsic/extensions/known/index.js +4 -0
  27. package/client/BaseSubstrateClient.d.ts +10 -11
  28. package/client/DedotClient.d.ts +2 -1
  29. package/client/DedotClient.js +2 -1
  30. package/client/{Dedot.d.ts → LegacyClient.d.ts} +7 -6
  31. package/client/{Dedot.js → LegacyClient.js} +7 -6
  32. package/client/index.d.ts +1 -1
  33. package/client/index.js +1 -1
  34. package/executor/v2/StorageQueryExecutorV2.js +3 -3
  35. package/extrinsic/extensions/known/CheckMetadataHash.d.ts +13 -0
  36. package/extrinsic/extensions/known/CheckMetadataHash.js +27 -0
  37. package/extrinsic/extensions/known/StorageWeightReclaim.d.ts +6 -0
  38. package/extrinsic/extensions/known/StorageWeightReclaim.js +6 -0
  39. package/extrinsic/extensions/known/index.js +4 -0
  40. package/package.json +10 -10
@@ -1 +1,2 @@
1
+ // Generated by dedot cli
1
2
  export {};
@@ -1 +1,2 @@
1
+ // Generated by dedot cli
1
2
  export {};
@@ -1 +1,2 @@
1
+ // Generated by dedot cli
1
2
  export {};
@@ -1 +1,2 @@
1
+ // Generated by dedot cli
1
2
  export * from './types.js';
@@ -1,3 +1,3 @@
1
1
  import type { GenericJsonRpcApis, RpcVersion } from '@dedot/types';
2
2
  import type { JsonRpcApis } from '@dedot/types/json-rpc';
3
- export type ChainJsonRpcApis<Rv extends RpcVersion> = Pick<JsonRpcApis, 'author_hasKey' | 'author_hasSessionKeys' | 'author_insertKey' | 'author_pendingExtrinsics' | 'author_removeExtrinsic' | 'author_rotateKeys' | 'author_submitAndWatchExtrinsic' | 'author_submitExtrinsic' | 'babe_epochAuthorship' | 'beefy_getFinalizedHead' | 'beefy_subscribeJustifications' | 'chainHead_unstable_body' | 'chainHead_unstable_call' | 'chainHead_unstable_continue' | 'chainHead_unstable_follow' | 'chainHead_unstable_header' | 'chainHead_unstable_stopOperation' | 'chainHead_unstable_storage' | 'chainHead_unstable_unpin' | 'chainSpec_v1_chainName' | 'chainSpec_v1_genesisHash' | 'chainSpec_v1_properties' | 'chain_getBlock' | 'chain_getBlockHash' | 'chain_getFinalizedHead' | 'chain_getHeader' | 'chain_subscribeAllHeads' | 'chain_subscribeFinalizedHeads' | 'chain_subscribeNewHeads' | 'childstate_getKeys' | 'childstate_getKeysPaged' | 'childstate_getStorage' | 'childstate_getStorageEntries' | 'childstate_getStorageHash' | 'childstate_getStorageSize' | 'dev_getBlockStats' | 'grandpa_proveFinality' | 'grandpa_roundState' | 'grandpa_subscribeJustifications' | 'mmr_generateProof' | 'mmr_root' | 'mmr_verifyProof' | 'mmr_verifyProofStateless' | 'offchain_localStorageGet' | 'offchain_localStorageSet' | 'payment_queryFeeDetails' | 'payment_queryInfo' | 'rpc_methods' | 'state_call' | 'state_getChildReadProof' | 'state_getKeys' | 'state_getKeysPaged' | 'state_getMetadata' | 'state_getPairs' | 'state_getReadProof' | 'state_getRuntimeVersion' | 'state_getStorage' | 'state_getStorageHash' | 'state_getStorageSize' | 'state_queryStorage' | 'state_queryStorageAt' | 'state_subscribeRuntimeVersion' | 'state_subscribeStorage' | 'state_traceBlock' | 'state_trieMigrationStatus' | 'statement_broadcasts' | 'statement_dump' | 'statement_posted' | 'statement_postedClear' | 'statement_remove' | 'statement_submit' | 'sync_state_genSyncSpec' | 'system_accountNextIndex' | 'system_addLogFilter' | 'system_addReservedPeer' | 'system_chain' | 'system_chainType' | 'system_dryRun' | 'system_health' | 'system_localListenAddresses' | 'system_localPeerId' | 'system_name' | 'system_nodeRoles' | 'system_peers' | 'system_properties' | 'system_removeReservedPeer' | 'system_reservedPeers' | 'system_resetLogFilter' | 'system_syncState' | 'system_unstable_networkState' | 'system_version' | 'transactionWatch_unstable_submitAndWatch' | 'transaction_unstable_broadcast' | 'transaction_unstable_stop'> & GenericJsonRpcApis<Rv>;
3
+ export type ChainJsonRpcApis<Rv extends RpcVersion> = Pick<JsonRpcApis, 'author_hasKey' | 'author_hasSessionKeys' | 'author_insertKey' | 'author_pendingExtrinsics' | 'author_removeExtrinsic' | 'author_rotateKeys' | 'author_submitAndWatchExtrinsic' | 'author_submitExtrinsic' | 'babe_epochAuthorship' | 'beefy_getFinalizedHead' | 'beefy_subscribeJustifications' | 'chainHead_v1_body' | 'chainHead_v1_call' | 'chainHead_v1_continue' | 'chainHead_v1_follow' | 'chainHead_v1_header' | 'chainHead_v1_stopOperation' | 'chainHead_v1_storage' | 'chainHead_v1_unpin' | 'chainSpec_v1_chainName' | 'chainSpec_v1_genesisHash' | 'chainSpec_v1_properties' | 'chain_getBlock' | 'chain_getBlockHash' | 'chain_getFinalizedHead' | 'chain_getHeader' | 'chain_subscribeAllHeads' | 'chain_subscribeFinalizedHeads' | 'chain_subscribeNewHeads' | 'childstate_getKeys' | 'childstate_getKeysPaged' | 'childstate_getStorage' | 'childstate_getStorageEntries' | 'childstate_getStorageHash' | 'childstate_getStorageSize' | 'dev_getBlockStats' | 'grandpa_proveFinality' | 'grandpa_roundState' | 'grandpa_subscribeJustifications' | 'mmr_generateProof' | 'mmr_root' | 'mmr_verifyProof' | 'mmr_verifyProofStateless' | 'offchain_localStorageGet' | 'offchain_localStorageSet' | 'payment_queryFeeDetails' | 'payment_queryInfo' | 'rpc_methods' | 'state_call' | 'state_getChildReadProof' | 'state_getKeys' | 'state_getKeysPaged' | 'state_getMetadata' | 'state_getPairs' | 'state_getReadProof' | 'state_getRuntimeVersion' | 'state_getStorage' | 'state_getStorageHash' | 'state_getStorageSize' | 'state_queryStorage' | 'state_queryStorageAt' | 'state_subscribeRuntimeVersion' | 'state_subscribeStorage' | 'state_traceBlock' | 'state_trieMigrationStatus' | 'statement_broadcasts' | 'statement_dump' | 'statement_posted' | 'statement_postedClear' | 'statement_remove' | 'statement_submit' | 'sync_state_genSyncSpec' | 'system_accountNextIndex' | 'system_addLogFilter' | 'system_addReservedPeer' | 'system_chain' | 'system_chainType' | 'system_dryRun' | 'system_health' | 'system_localListenAddresses' | 'system_localPeerId' | 'system_name' | 'system_nodeRoles' | 'system_peers' | 'system_properties' | 'system_removeReservedPeer' | 'system_reservedPeers' | 'system_resetLogFilter' | 'system_syncState' | 'system_unstable_networkState' | 'system_version' | 'transactionWatch_v1_submitAndWatch' | 'transaction_v1_broadcast' | 'transaction_v1_stop'> & GenericJsonRpcApis<Rv>;
@@ -1 +1,2 @@
1
+ // Generated by dedot cli
1
2
  export {};
@@ -1 +1,2 @@
1
+ // Generated by dedot cli
1
2
  export {};
@@ -1 +1,2 @@
1
+ // Generated by dedot cli
1
2
  export {};
@@ -1 +1,2 @@
1
+ // Generated by dedot cli
1
2
  export {};
@@ -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;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Dedot = void 0;
3
+ exports.LegacyClient = void 0;
4
4
  const codecs_1 = require("@dedot/codecs");
5
5
  const index_js_1 = require("../executor/index.js");
6
6
  const proxychain_js_1 = require("../proxychain.js");
7
7
  const BaseSubstrateClient_js_1 = require("./BaseSubstrateClient.js");
8
8
  const KEEP_ALIVE_INTERVAL = 10_000; // in ms
9
9
  /**
10
- * @name Dedot
10
+ * @name LegacyClient
11
11
  * @description Promised-based API Client for Polkadot & Substrate
12
12
  *
13
13
  * Initialize API instance and interact with substrate-based network
@@ -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 Dedot 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 = {};
@@ -62,15 +63,15 @@ class Dedot extends BaseSubstrateClient_js_1.BaseSubstrateClient {
62
63
  * @param options
63
64
  */
64
65
  static async create(options) {
65
- return new Dedot(options).connect();
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
  */
72
73
  static async new(options) {
73
- return Dedot.create(options);
74
+ return LegacyClient.create(options);
74
75
  }
75
76
  onDisconnected = async () => {
76
77
  await this.#unsubscribeUpdates();
@@ -247,4 +248,4 @@ class Dedot extends BaseSubstrateClient_js_1.BaseSubstrateClient {
247
248
  return api;
248
249
  }
249
250
  }
250
- exports.Dedot = Dedot;
251
+ exports.LegacyClient = LegacyClient;
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Dedot.js"), exports);
17
+ __exportStar(require("./LegacyClient.js"), exports);
18
18
  __exportStar(require("./DedotClient.js"), exports);
@@ -35,13 +35,13 @@ class StorageQueryExecutorV2 extends StorageQueryExecutor_js_1.StorageQueryExecu
35
35
  }, {});
36
36
  }
37
37
  async subscribeStorage(keys, callback) {
38
- let initialHash = await this.chainHead.bestHash();
38
+ let best = await this.chainHead.bestBlock();
39
39
  let eventToListen = 'bestBlock';
40
40
  // TODO subscribe to finalized data source
41
41
  // initialHash = this.chainHead.finalizedHash;
42
42
  // eventToListen = 'finalizedBlock';
43
43
  const latestChanges = {};
44
- const pull = async (hash) => {
44
+ const pull = async ({ hash }) => {
45
45
  const results = await this.queryStorage(keys, hash);
46
46
  let changed = false;
47
47
  keys.forEach((key) => {
@@ -55,7 +55,7 @@ class StorageQueryExecutorV2 extends StorageQueryExecutor_js_1.StorageQueryExecu
55
55
  return;
56
56
  callback(keys.map((key) => latestChanges[key]));
57
57
  };
58
- await pull(initialHash);
58
+ await pull(best);
59
59
  const unsub = this.chainHead.on(eventToListen, pull);
60
60
  return async () => {
61
61
  unsub();
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CheckMetadataHash = void 0;
4
+ const utils_1 = require("@dedot/utils");
5
+ const SignedExtension_js_1 = require("../SignedExtension.js");
6
+ /**
7
+ * @description Genesis hash check to provide replay protection between different networks.
8
+ */
9
+ class CheckMetadataHash extends SignedExtension_js_1.SignedExtension {
10
+ async init() {
11
+ let metadataHash = this.payloadOptions.metadataHash;
12
+ if (metadataHash) {
13
+ (0, utils_1.assert)((0, utils_1.isHex)(metadataHash), 'Metadata hash is not a valid hex string');
14
+ this.data = { mode: 'Enabled' };
15
+ this.additionalSigned = metadataHash;
16
+ }
17
+ else {
18
+ this.data = { mode: 'Disabled' };
19
+ this.additionalSigned = undefined;
20
+ }
21
+ }
22
+ toPayload() {
23
+ // Ref: https://github.com/paritytech/polkadot-sdk/blob/8dbe4ee80734bba6644c7e5f879a363ce7c0a19f/substrate/frame/metadata-hash-extension/src/lib.rs#L55-L58
24
+ let enabled = this.data.mode === 'Enabled';
25
+ return {
26
+ mode: enabled ? 1 : 0, // 0 -> disabled, 1 -> enabled
27
+ metadataHash: this.additionalSigned,
28
+ };
29
+ }
30
+ }
31
+ exports.CheckMetadataHash = CheckMetadataHash;
@@ -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;
@@ -4,6 +4,7 @@ exports.knownSignedExtensions = void 0;
4
4
  const ChargeAssetTxPayment_js_1 = require("./ChargeAssetTxPayment.js");
5
5
  const ChargeTransactionPayment_js_1 = require("./ChargeTransactionPayment.js");
6
6
  const CheckGenesis_js_1 = require("./CheckGenesis.js");
7
+ const CheckMetadataHash_js_1 = require("./CheckMetadataHash.js");
7
8
  const CheckMortality_js_1 = require("./CheckMortality.js");
8
9
  const CheckNonZeroSender_js_1 = require("./CheckNonZeroSender.js");
9
10
  const CheckNonce_js_1 = require("./CheckNonce.js");
@@ -11,6 +12,7 @@ const CheckSpecVersion_js_1 = require("./CheckSpecVersion.js");
11
12
  const CheckTxVersion_js_1 = require("./CheckTxVersion.js");
12
13
  const CheckWeight_js_1 = require("./CheckWeight.js");
13
14
  const PrevalidateAttests_js_1 = require("./PrevalidateAttests.js");
15
+ const StorageWeightReclaim_js_1 = require("./StorageWeightReclaim.js");
14
16
  exports.knownSignedExtensions = {
15
17
  CheckNonZeroSender: CheckNonZeroSender_js_1.CheckNonZeroSender,
16
18
  CheckSpecVersion: CheckSpecVersion_js_1.CheckSpecVersion,
@@ -22,4 +24,6 @@ exports.knownSignedExtensions = {
22
24
  ChargeTransactionPayment: ChargeTransactionPayment_js_1.ChargeTransactionPayment,
23
25
  PrevalidateAttests: PrevalidateAttests_js_1.PrevalidateAttests,
24
26
  ChargeAssetTxPayment: ChargeAssetTxPayment_js_1.ChargeAssetTxPayment,
27
+ CheckMetadataHash: CheckMetadataHash_js_1.CheckMetadataHash,
28
+ StorageWeightReclaim: StorageWeightReclaim_js_1.StorageWeightReclaim,
25
29
  };
@@ -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;
@@ -5,7 +5,7 @@ import type { SubstrateApi } from '../chaintypes/index.js';
5
5
  import type { ApiOptions, ISubstrateClientAt } from '../types.js';
6
6
  import { BaseSubstrateClient } from './BaseSubstrateClient.js';
7
7
  /**
8
- * @name Dedot
8
+ * @name LegacyClient
9
9
  * @description Promised-based API Client for Polkadot & Substrate
10
10
  *
11
11
  * Initialize API instance and interact with substrate-based network
@@ -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 Dedot<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.
@@ -55,13 +56,13 @@ export declare class Dedot<ChainApi extends VersionedGenericSubstrateApi = Subst
55
56
  *
56
57
  * @param options
57
58
  */
58
- static create<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>(options: ApiOptions | JsonRpcProvider): Promise<Dedot<ChainApi>>;
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
  */
64
- static new<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>(options: ApiOptions | JsonRpcProvider): Promise<Dedot<ChainApi>>;
65
+ static new<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>(options: ApiOptions | JsonRpcProvider): Promise<LegacyClient<ChainApi>>;
65
66
  protected onDisconnected: () => Promise<void>;
66
67
  protected beforeDisconnect(): Promise<void>;
67
68
  /**
@@ -4,7 +4,7 @@ import { newProxyChain } from '../proxychain.js';
4
4
  import { BaseSubstrateClient } from './BaseSubstrateClient.js';
5
5
  const KEEP_ALIVE_INTERVAL = 10_000; // in ms
6
6
  /**
7
- * @name Dedot
7
+ * @name LegacyClient
8
8
  * @description Promised-based API Client for Polkadot & Substrate
9
9
  *
10
10
  * Initialize API instance and interact with substrate-based network
@@ -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 Dedot extends BaseSubstrateClient {
44
+ export class LegacyClient// prettier-end-here
45
+ extends BaseSubstrateClient {
45
46
  #runtimeSubscriptionUnsub;
46
47
  #healthTimer;
47
48
  #apiAtCache = {};
@@ -59,15 +60,15 @@ export class Dedot extends BaseSubstrateClient {
59
60
  * @param options
60
61
  */
61
62
  static async create(options) {
62
- return new Dedot(options).connect();
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
  */
69
70
  static async new(options) {
70
- return Dedot.create(options);
71
+ return LegacyClient.create(options);
71
72
  }
72
73
  onDisconnected = async () => {
73
74
  await this.#unsubscribeUpdates();
package/client/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './Dedot.js';
1
+ export * from './LegacyClient.js';
2
2
  export * from './DedotClient.js';
package/client/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from './Dedot.js';
1
+ export * from './LegacyClient.js';
2
2
  export * from './DedotClient.js';
@@ -32,13 +32,13 @@ export class StorageQueryExecutorV2 extends StorageQueryExecutor {
32
32
  }, {});
33
33
  }
34
34
  async subscribeStorage(keys, callback) {
35
- let initialHash = await this.chainHead.bestHash();
35
+ let best = await this.chainHead.bestBlock();
36
36
  let eventToListen = 'bestBlock';
37
37
  // TODO subscribe to finalized data source
38
38
  // initialHash = this.chainHead.finalizedHash;
39
39
  // eventToListen = 'finalizedBlock';
40
40
  const latestChanges = {};
41
- const pull = async (hash) => {
41
+ const pull = async ({ hash }) => {
42
42
  const results = await this.queryStorage(keys, hash);
43
43
  let changed = false;
44
44
  keys.forEach((key) => {
@@ -52,7 +52,7 @@ export class StorageQueryExecutorV2 extends StorageQueryExecutor {
52
52
  return;
53
53
  callback(keys.map((key) => latestChanges[key]));
54
54
  };
55
- await pull(initialHash);
55
+ await pull(best);
56
56
  const unsub = this.chainHead.on(eventToListen, pull);
57
57
  return async () => {
58
58
  unsub();
@@ -0,0 +1,13 @@
1
+ import { SignerPayloadJSON } from '@polkadot/types/types';
2
+ import { Hash } from '@dedot/codecs';
3
+ import { SignedExtension } from '../SignedExtension.js';
4
+ export type CheckMetadataHashMode = 'Disabled' | 'Enabled';
5
+ /**
6
+ * @description Genesis hash check to provide replay protection between different networks.
7
+ */
8
+ export declare class CheckMetadataHash extends SignedExtension<{
9
+ mode: CheckMetadataHashMode;
10
+ }, Hash | undefined> {
11
+ init(): Promise<void>;
12
+ toPayload(): Partial<SignerPayloadJSON>;
13
+ }
@@ -0,0 +1,27 @@
1
+ import { assert, isHex } from '@dedot/utils';
2
+ import { SignedExtension } from '../SignedExtension.js';
3
+ /**
4
+ * @description Genesis hash check to provide replay protection between different networks.
5
+ */
6
+ export class CheckMetadataHash extends SignedExtension {
7
+ async init() {
8
+ let metadataHash = this.payloadOptions.metadataHash;
9
+ if (metadataHash) {
10
+ assert(isHex(metadataHash), 'Metadata hash is not a valid hex string');
11
+ this.data = { mode: 'Enabled' };
12
+ this.additionalSigned = metadataHash;
13
+ }
14
+ else {
15
+ this.data = { mode: 'Disabled' };
16
+ this.additionalSigned = undefined;
17
+ }
18
+ }
19
+ toPayload() {
20
+ // Ref: https://github.com/paritytech/polkadot-sdk/blob/8dbe4ee80734bba6644c7e5f879a363ce7c0a19f/substrate/frame/metadata-hash-extension/src/lib.rs#L55-L58
21
+ let enabled = this.data.mode === 'Enabled';
22
+ return {
23
+ mode: enabled ? 1 : 0, // 0 -> disabled, 1 -> enabled
24
+ metadataHash: this.additionalSigned,
25
+ };
26
+ }
27
+ }
@@ -0,0 +1,6 @@
1
+ import { SignedExtension } from '../SignedExtension.js';
2
+ /**
3
+ * @description Storage weight reclaim mechanism.
4
+ */
5
+ export declare class StorageWeightReclaim extends SignedExtension {
6
+ }
@@ -0,0 +1,6 @@
1
+ import { SignedExtension } from '../SignedExtension.js';
2
+ /**
3
+ * @description Storage weight reclaim mechanism.
4
+ */
5
+ export class StorageWeightReclaim extends SignedExtension {
6
+ }
@@ -1,6 +1,7 @@
1
1
  import { ChargeAssetTxPayment } from './ChargeAssetTxPayment.js';
2
2
  import { ChargeTransactionPayment } from './ChargeTransactionPayment.js';
3
3
  import { CheckGenesis } from './CheckGenesis.js';
4
+ import { CheckMetadataHash } from './CheckMetadataHash.js';
4
5
  import { CheckMortality } from './CheckMortality.js';
5
6
  import { CheckNonZeroSender } from './CheckNonZeroSender.js';
6
7
  import { CheckNonce } from './CheckNonce.js';
@@ -8,6 +9,7 @@ import { CheckSpecVersion } from './CheckSpecVersion.js';
8
9
  import { CheckTxVersion } from './CheckTxVersion.js';
9
10
  import { CheckWeight } from './CheckWeight.js';
10
11
  import { PrevalidateAttests } from './PrevalidateAttests.js';
12
+ import { StorageWeightReclaim } from './StorageWeightReclaim.js';
11
13
  export const knownSignedExtensions = {
12
14
  CheckNonZeroSender,
13
15
  CheckSpecVersion,
@@ -19,4 +21,6 @@ export const knownSignedExtensions = {
19
21
  ChargeTransactionPayment,
20
22
  PrevalidateAttests,
21
23
  ChargeAssetTxPayment,
24
+ CheckMetadataHash,
25
+ StorageWeightReclaim,
22
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dedot/api",
3
- "version": "0.0.1-next.9c1d51fe.10+9c1d51f",
3
+ "version": "0.0.1-next.b6596712.6+b659671",
4
4
  "description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
5
5
  "author": "Thang X. Vu <thang@coongcrafts.io>",
6
6
  "homepage": "https://github.com/dedotdev/dedot",
@@ -13,13 +13,13 @@
13
13
  "type": "module",
14
14
  "sideEffects": false,
15
15
  "dependencies": {
16
- "@dedot/codecs": "0.0.1-next.9c1d51fe.10+9c1d51f",
17
- "@dedot/providers": "0.0.1-next.9c1d51fe.10+9c1d51f",
18
- "@dedot/runtime-specs": "0.0.1-next.9c1d51fe.10+9c1d51f",
19
- "@dedot/shape": "0.0.1-next.9c1d51fe.10+9c1d51f",
20
- "@dedot/storage": "0.0.1-next.9c1d51fe.10+9c1d51f",
21
- "@dedot/types": "0.0.1-next.9c1d51fe.10+9c1d51f",
22
- "@dedot/utils": "0.0.1-next.9c1d51fe.10+9c1d51f"
16
+ "@dedot/codecs": "0.0.1-next.b6596712.6+b659671",
17
+ "@dedot/providers": "0.0.1-next.b6596712.6+b659671",
18
+ "@dedot/runtime-specs": "0.0.1-next.b6596712.6+b659671",
19
+ "@dedot/shape": "0.0.1-next.b6596712.6+b659671",
20
+ "@dedot/storage": "0.0.1-next.b6596712.6+b659671",
21
+ "@dedot/types": "0.0.1-next.b6596712.6+b659671",
22
+ "@dedot/utils": "0.0.1-next.b6596712.6+b659671"
23
23
  },
24
24
  "scripts": {
25
25
  "build": "tsc --project tsconfig.build.json && tsc --project tsconfig.build.cjs.json",
@@ -46,9 +46,9 @@
46
46
  },
47
47
  "license": "Apache-2.0",
48
48
  "devDependencies": {
49
- "@polkadot/types": "^11.0.2"
49
+ "@polkadot/types": "^12.0.1"
50
50
  },
51
- "gitHead": "9c1d51fe7b14ed2f0361ec6329d881bd54f48c2e",
51
+ "gitHead": "b6596712119e3812b8af54d50f23371a3d556ad4",
52
52
  "module": "./index.js",
53
53
  "types": "./index.d.ts"
54
54
  }