@dedot/api 0.15.2 → 0.15.3-next.65898ecf.10

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 (47) hide show
  1. package/chaintypes/substrate/index.d.ts +21 -1
  2. package/chaintypes/substrate/index.js +0 -1
  3. package/cjs/chaintypes/substrate/index.js +0 -1
  4. package/cjs/client/DedotClient.js +39 -6
  5. package/cjs/executor/Executor.js +1 -0
  6. package/cjs/executor/v2/StorageQueryExecutorV2.js +1 -3
  7. package/cjs/executor/v2/TxExecutorV2.js +5 -3
  8. package/cjs/json-rpc/group/Archive.js +226 -0
  9. package/cjs/json-rpc/group/ChainHead/ChainHead.js +121 -44
  10. package/cjs/json-rpc/group/ChainHead/error.js +5 -0
  11. package/cjs/json-rpc/group/index.js +1 -0
  12. package/cjs/json-rpc/subscriptionsInfo.js +4 -0
  13. package/cjs/storage/LegacyStorageQuery.js +5 -0
  14. package/cjs/storage/NewStorageQuery.js +5 -0
  15. package/client/BaseSubstrateClient.d.ts +3 -3
  16. package/client/DedotClient.d.ts +6 -4
  17. package/client/DedotClient.js +42 -9
  18. package/client/LegacyClient.d.ts +2 -2
  19. package/executor/Executor.d.ts +5 -5
  20. package/executor/Executor.js +1 -0
  21. package/executor/StorageQueryExecutor.d.ts +2 -2
  22. package/executor/v2/RuntimeApiExecutorV2.d.ts +2 -2
  23. package/executor/v2/StorageQueryExecutorV2.d.ts +4 -4
  24. package/executor/v2/StorageQueryExecutorV2.js +1 -3
  25. package/executor/v2/TxExecutorV2.d.ts +2 -1
  26. package/executor/v2/TxExecutorV2.js +5 -3
  27. package/executor/v2/ViewFunctionExecutorV2.d.ts +2 -2
  28. package/extrinsic/extensions/SignedExtension.d.ts +3 -3
  29. package/extrinsic/submittable/BaseSubmittableExtrinsic.d.ts +2 -2
  30. package/extrinsic/submittable/SubmittableExtrinsicV2.d.ts +2 -2
  31. package/json-rpc/group/Archive.d.ts +134 -0
  32. package/json-rpc/group/Archive.js +222 -0
  33. package/json-rpc/group/ChainHead/ChainHead.d.ts +10 -0
  34. package/json-rpc/group/ChainHead/ChainHead.js +121 -44
  35. package/json-rpc/group/ChainHead/error.d.ts +3 -0
  36. package/json-rpc/group/ChainHead/error.js +5 -0
  37. package/json-rpc/group/index.d.ts +1 -0
  38. package/json-rpc/group/index.js +1 -0
  39. package/json-rpc/subscriptionsInfo.js +4 -0
  40. package/package.json +9 -9
  41. package/storage/BaseStorageQuery.d.ts +5 -6
  42. package/storage/LegacyStorageQuery.d.ts +4 -3
  43. package/storage/LegacyStorageQuery.js +5 -0
  44. package/storage/NewStorageQuery.d.ts +5 -4
  45. package/storage/NewStorageQuery.js +5 -0
  46. package/storage/QueryableStorage.d.ts +2 -2
  47. package/types.d.ts +10 -5
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./JsonRpcGroup.js"), exports);
18
+ __exportStar(require("./Archive.js"), exports);
18
19
  __exportStar(require("./ChainSpec.js"), exports);
19
20
  __exportStar(require("./Transaction.js"), exports);
20
21
  __exportStar(require("./TransactionWatch.js"), exports);
@@ -17,4 +17,8 @@ exports.subscriptionsInfo = {
17
17
  'transactionWatch_unstable_unwatch',
18
18
  ],
19
19
  transactionWatch_v1_submitAndWatch: ['transactionWatch_v1_watchEvent', 'transactionWatch_v1_unwatch'],
20
+ archive_v1_storage: ['archive_v1_storageEvent', 'archive_v1_stopStorage'],
21
+ archive_v1_storageDiff: ['archive_v1_storageDiffEvent', 'archive_v1_stopStorageDiff'],
22
+ archive_unstable_storage: ['archive_unstable_storageEvent', 'archive_unstable_stopStorage'],
23
+ archive_unstable_storageDiff: ['archive_unstable_storageDiffEvent', 'archive_unstable_stopStorageDiff'],
20
24
  };
@@ -15,6 +15,11 @@ const BaseStorageQuery_js_1 = require("./BaseStorageQuery.js");
15
15
  * - Efficient change tracking for subscriptions
16
16
  */
17
17
  class LegacyStorageQuery extends BaseStorageQuery_js_1.BaseStorageQuery {
18
+ client;
19
+ constructor(client) {
20
+ super(client);
21
+ this.client = client;
22
+ }
18
23
  /**
19
24
  * Query multiple storage items in a single call using state_queryStorageAt
20
25
  *
@@ -16,6 +16,11 @@ const BaseStorageQuery_js_1 = require("./BaseStorageQuery.js");
16
16
  * - Efficient change detection for subscriptions
17
17
  */
18
18
  class NewStorageQuery extends BaseStorageQuery_js_1.BaseStorageQuery {
19
+ client;
20
+ constructor(client) {
21
+ super(client);
22
+ this.client = client;
23
+ }
19
24
  /**
20
25
  * Query multiple storage items in a single call using chainHead_storage
21
26
  *
@@ -15,7 +15,7 @@ export declare function ensurePresence<T>(value: T): NonNullable<T>;
15
15
  export declare abstract class BaseSubstrateClient<Rv extends RpcVersion, ChainApi extends VersionedGenericSubstrateApi = SubstrateApi, Events extends string = ApiEvent> extends JsonRpcClient<ChainApi, Events> implements ISubstrateClient<ChainApi[Rv], Events> {
16
16
  rpcVersion: RpcVersion;
17
17
  protected _options: ApiOptions;
18
- protected _registry?: PortableRegistry;
18
+ protected _registry?: PortableRegistry<ChainApi[Rv]>;
19
19
  protected _metadata?: Metadata;
20
20
  protected _genesisHash?: Hash;
21
21
  protected _runtimeVersion?: SubstrateRuntimeVersion;
@@ -61,7 +61,7 @@ export declare abstract class BaseSubstrateClient<Rv extends RpcVersion, ChainAp
61
61
  disconnect(): Promise<void>;
62
62
  get options(): ApiOptions;
63
63
  get metadata(): Metadata;
64
- get registry(): PortableRegistry;
64
+ get registry(): PortableRegistry<ChainApi[Rv]>;
65
65
  get genesisHash(): Hash;
66
66
  get runtimeVersion(): SubstrateRuntimeVersion;
67
67
  getRuntimeVersion(): Promise<SubstrateRuntimeVersion>;
@@ -106,5 +106,5 @@ export declare abstract class BaseSubstrateClient<Rv extends RpcVersion, ChainAp
106
106
  }, callback: Callback<{
107
107
  [K in keyof Fns]: QueryFnResult<Fns[K]>;
108
108
  }>): Promise<Unsub>;
109
- protected getStorageQuery(): BaseStorageQuery<RpcVersion>;
109
+ protected getStorageQuery(): BaseStorageQuery;
110
110
  }
@@ -1,8 +1,8 @@
1
1
  import { BlockHash } from '@dedot/codecs';
2
2
  import type { JsonRpcProvider } from '@dedot/providers';
3
- import { GenericSubstrateApi, RpcV2, RpcVersion, VersionedGenericSubstrateApi } from '@dedot/types';
3
+ import { GenericSubstrateApi, RpcV2, VersionedGenericSubstrateApi } from '@dedot/types';
4
4
  import type { SubstrateApi } from '../chaintypes/index.js';
5
- import { ChainHead, ChainSpec, PinnedBlock } from '../json-rpc/index.js';
5
+ import { Archive, ChainHead, ChainSpec, PinnedBlock } from '../json-rpc/index.js';
6
6
  import { BaseStorageQuery } from '../storage/index.js';
7
7
  import type { ApiOptions, DedotClientEvent, ISubstrateClientAt, TxBroadcaster } from '../types.js';
8
8
  import { BaseSubstrateClient } from './BaseSubstrateClient.js';
@@ -17,6 +17,7 @@ export declare class DedotClient<ChainApi extends VersionedGenericSubstrateApi =
17
17
  #private;
18
18
  protected _chainHead?: ChainHead;
19
19
  protected _chainSpec?: ChainSpec;
20
+ protected _archive?: Archive;
20
21
  protected _txBroadcaster?: TxBroadcaster;
21
22
  /**
22
23
  * Use factory methods (`create`, `new`) to create `DedotClient` instances.
@@ -38,6 +39,7 @@ export declare class DedotClient<ChainApi extends VersionedGenericSubstrateApi =
38
39
  static new<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>(options: ApiOptions | JsonRpcProvider): Promise<DedotClient<ChainApi>>;
39
40
  get chainSpec(): ChainSpec;
40
41
  get chainHead(): ChainHead;
42
+ archive(): Promise<Archive>;
41
43
  get txBroadcaster(): TxBroadcaster;
42
44
  /**
43
45
  * Initialize APIs before usage
@@ -55,10 +57,10 @@ export declare class DedotClient<ChainApi extends VersionedGenericSubstrateApi =
55
57
  get tx(): ChainApi[RpcV2]['tx'];
56
58
  /**
57
59
  * Get a new API instance at a specific block hash
58
- * For now, this only supports pinned block hashes from the chain head
60
+ * Supports both pinned blocks (via ChainHead) and historical blocks (via Archive fallback)
59
61
  *
60
62
  * @param hash
61
63
  */
62
64
  at<ChainApiAt extends GenericSubstrateApi = ChainApi[RpcV2]>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
63
- protected getStorageQuery(): BaseStorageQuery<RpcVersion>;
65
+ protected getStorageQuery(): BaseStorageQuery;
64
66
  }
@@ -1,8 +1,8 @@
1
- import { $H256, PortableRegistry } from '@dedot/codecs';
1
+ import { $H256, $RuntimeVersion, PortableRegistry } from '@dedot/codecs';
2
2
  import { u32 } from '@dedot/shape';
3
- import { assert, concatU8a, noop, twox64Concat, u8aToHex, xxhashAsU8a } from '@dedot/utils';
3
+ import { assert, concatU8a, noop, twox64Concat, u8aToHex, xxhashAsU8a, DedotError } from '@dedot/utils';
4
4
  import { ConstantExecutor, ErrorExecutor, EventExecutor, RuntimeApiExecutorV2, StorageQueryExecutorV2, ViewFunctionExecutorV2, TxExecutorV2, } from '../executor/index.js';
5
- import { ChainHead, ChainSpec, Transaction, TransactionWatch } from '../json-rpc/index.js';
5
+ import { Archive, ChainHead, ChainSpec, Transaction, TransactionWatch } from '../json-rpc/index.js';
6
6
  import { newProxyChain } from '../proxychain.js';
7
7
  import { NewStorageQuery } from '../storage/index.js';
8
8
  import { BaseSubstrateClient, ensurePresence } from './BaseSubstrateClient.js';
@@ -16,6 +16,7 @@ export class DedotClient// prettier-end-here
16
16
  extends BaseSubstrateClient {
17
17
  _chainHead;
18
18
  _chainSpec;
19
+ _archive;
19
20
  _txBroadcaster;
20
21
  #apiAtCache = {};
21
22
  /**
@@ -48,6 +49,11 @@ export class DedotClient// prettier-end-here
48
49
  get chainHead() {
49
50
  return ensurePresence(this._chainHead);
50
51
  }
52
+ async archive() {
53
+ assert(this._archive, 'Archive instance is not initialized');
54
+ assert(await this._archive.supported(), 'Archive JSON-RPC is not supported by the connected server');
55
+ return this._archive;
56
+ }
51
57
  get txBroadcaster() {
52
58
  this.chainHead; // Ensure chain head is initialized
53
59
  assert(this._txBroadcaster, 'JSON-RPC method to broadcast transactions is not supported by the server/node.');
@@ -68,6 +74,12 @@ export class DedotClient// prettier-end-here
68
74
  const rpcMethods = (await this.rpc.rpc_methods()).methods;
69
75
  this._chainHead = new ChainHead(this, { rpcMethods });
70
76
  this._chainSpec = new ChainSpec(this, { rpcMethods });
77
+ // Always initialize Archive, but only set up fallback if supported
78
+ this._archive = new Archive(this, { rpcMethods });
79
+ // Set up ChainHead with Archive fallback only if Archive is supported
80
+ if (await this._archive.supported()) {
81
+ this._chainHead.withArchive(this._archive);
82
+ }
71
83
  this._txBroadcaster = await this.#initializeTxBroadcaster(rpcMethods);
72
84
  // Fetching node information
73
85
  let [_, genesisHash] = await Promise.all([
@@ -130,6 +142,7 @@ export class DedotClient// prettier-end-here
130
142
  super.cleanUp();
131
143
  this._chainHead = undefined;
132
144
  this._chainSpec = undefined;
145
+ this._archive = undefined;
133
146
  this._txBroadcaster = undefined;
134
147
  this.#apiAtCache = {};
135
148
  }
@@ -156,19 +169,39 @@ export class DedotClient// prettier-end-here
156
169
  }
157
170
  /**
158
171
  * Get a new API instance at a specific block hash
159
- * For now, this only supports pinned block hashes from the chain head
172
+ * Supports both pinned blocks (via ChainHead) and historical blocks (via Archive fallback)
160
173
  *
161
174
  * @param hash
162
175
  */
163
176
  async at(hash) {
164
177
  if (this.#apiAtCache[hash])
165
178
  return this.#apiAtCache[hash];
179
+ let targetVersion;
180
+ // Try to get block info from ChainHead first (for pinned blocks)
166
181
  const targetBlock = this.chainHead.findBlock(hash);
167
- assert(targetBlock, 'Block is not pinned!');
168
- let targetVersion = targetBlock.runtime;
169
- if (!targetVersion) {
170
- // fallback to fetching on-chain runtime if we can't find it in the block
171
- targetVersion = this.toSubstrateRuntimeVersion(await this.callAt(hash).core.version());
182
+ if (targetBlock) {
183
+ targetVersion = targetBlock.runtime;
184
+ if (!targetVersion) {
185
+ // fallback to fetching on-chain runtime if we can't find it in the block
186
+ targetVersion = this.toSubstrateRuntimeVersion(await this.callAt(hash).core.version());
187
+ }
188
+ }
189
+ else {
190
+ // Block not pinned, try via Archive fallback if supported
191
+ if (this._archive && (await this._archive.supported())) {
192
+ console.warn(`Block ${hash} is not pinned, using Archive for historical access`);
193
+ try {
194
+ // Fetch runtime version via Archive
195
+ const runtimeRaw = await this._archive.call('Core_version', '0x', hash);
196
+ targetVersion = this.toSubstrateRuntimeVersion($RuntimeVersion.tryDecode(runtimeRaw));
197
+ }
198
+ catch (error) {
199
+ throw new DedotError(`Unable to fetch runtime version for block ${hash}: ${error}`);
200
+ }
201
+ }
202
+ else {
203
+ throw new DedotError('Block is not pinned and Archive JSON-RPC is not supported by the server/node!');
204
+ }
172
205
  }
173
206
  let metadata = this.metadata;
174
207
  let registry = this.registry;
@@ -1,6 +1,6 @@
1
1
  import { BlockHash } from '@dedot/codecs';
2
2
  import type { JsonRpcProvider } from '@dedot/providers';
3
- import { GenericSubstrateApi, RpcLegacy, RpcVersion, VersionedGenericSubstrateApi } from '@dedot/types';
3
+ import { GenericSubstrateApi, RpcLegacy, VersionedGenericSubstrateApi } from '@dedot/types';
4
4
  import type { SubstrateApi } from '../chaintypes/index.js';
5
5
  import { BaseStorageQuery } from '../storage/index.js';
6
6
  import type { ApiOptions, ISubstrateClientAt } from '../types.js';
@@ -131,5 +131,5 @@ export declare class LegacyClient<ChainApi extends VersionedGenericSubstrateApi
131
131
  * @param hash
132
132
  */
133
133
  at<ChainApiAt extends GenericSubstrateApi = ChainApi[RpcLegacy]>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
134
- protected getStorageQuery(): BaseStorageQuery<RpcVersion>;
134
+ protected getStorageQuery(): BaseStorageQuery;
135
135
  }
@@ -1,7 +1,7 @@
1
1
  import type { BlockHash, PalletDefLatest } from '@dedot/codecs';
2
2
  import type { GenericSubstrateApi } from '@dedot/types';
3
3
  import { HexString } from '@dedot/utils';
4
- import { ISubstrateClientAt } from '../types.js';
4
+ import { ISubstrateClient, ISubstrateClientAt } from '../types.js';
5
5
  export interface StateCallParams {
6
6
  func: string;
7
7
  params: HexString;
@@ -13,10 +13,10 @@ export interface StateCallParams {
13
13
  */
14
14
  export declare abstract class Executor<ChainApi extends GenericSubstrateApi = GenericSubstrateApi> {
15
15
  #private;
16
- readonly client: ISubstrateClientAt<ChainApi>;
17
- constructor(client: ISubstrateClientAt<ChainApi>, atBlockHash?: BlockHash);
18
- get atBlockHash(): `0x${string}` | undefined;
19
- get registry(): import("@dedot/codecs").PortableRegistry;
16
+ readonly client: ISubstrateClientAt<ChainApi> | ISubstrateClient<ChainApi, any>;
17
+ constructor(client: ISubstrateClientAt<ChainApi> | ISubstrateClient<ChainApi, any>, atBlockHash?: BlockHash);
18
+ get atBlockHash(): any;
19
+ get registry(): import("@dedot/codecs").PortableRegistry<ChainApi>;
20
20
  get metadata(): {
21
21
  types: {
22
22
  id: number;
@@ -11,6 +11,7 @@ export class Executor {
11
11
  this.#atBlockHash = atBlockHash;
12
12
  }
13
13
  get atBlockHash() {
14
+ // @ts-ignore
14
15
  return this.#atBlockHash || this.client.atBlockHash;
15
16
  }
16
17
  get registry() {
@@ -1,5 +1,5 @@
1
1
  import { BlockHash, Option, StorageData, StorageKey } from '@dedot/codecs';
2
- import type { AsyncMethod, Callback, GenericStorageQuery, GenericSubstrateApi, RpcVersion, Unsub } from '@dedot/types';
2
+ import type { AsyncMethod, Callback, GenericStorageQuery, GenericSubstrateApi, Unsub } from '@dedot/types';
3
3
  import { type BaseStorageQuery, QueryableStorage } from '../storage/index.js';
4
4
  import { Executor } from './Executor.js';
5
5
  /**
@@ -9,7 +9,7 @@ import { Executor } from './Executor.js';
9
9
  export declare class StorageQueryExecutor<ChainApi extends GenericSubstrateApi = GenericSubstrateApi> extends Executor<ChainApi> {
10
10
  doExecute(pallet: string, storage: string): GenericStorageQuery;
11
11
  protected exposeStorageMapMethods(entry: QueryableStorage): Record<string, AsyncMethod>;
12
- protected getStorageQuery(): BaseStorageQuery<RpcVersion>;
12
+ protected getStorageQuery(): BaseStorageQuery;
13
13
  protected queryStorage(keys: StorageKey[], hash?: BlockHash): Promise<Record<StorageKey, Option<StorageData>>>;
14
14
  protected subscribeStorage(keys: StorageKey[], callback: Callback<Array<StorageData | undefined>>): Promise<Unsub>;
15
15
  }
@@ -2,7 +2,7 @@ import type { BlockHash } from '@dedot/codecs';
2
2
  import type { GenericSubstrateApi } from '@dedot/types';
3
3
  import { HexString } from '@dedot/utils';
4
4
  import { ChainHead } from '../../json-rpc/index.js';
5
- import { ISubstrateClientAt } from '../../types.js';
5
+ import { ISubstrateClient, ISubstrateClientAt } from '../../types.js';
6
6
  import { StateCallParams } from '../Executor.js';
7
7
  import { RuntimeApiExecutor } from '../RuntimeApiExecutor.js';
8
8
  /**
@@ -10,6 +10,6 @@ import { RuntimeApiExecutor } from '../RuntimeApiExecutor.js';
10
10
  */
11
11
  export declare class RuntimeApiExecutorV2<ChainApi extends GenericSubstrateApi = GenericSubstrateApi> extends RuntimeApiExecutor<ChainApi> {
12
12
  chainHead: ChainHead;
13
- constructor(client: ISubstrateClientAt<ChainApi>, chainHead: ChainHead, atBlockHash?: BlockHash);
13
+ constructor(client: ISubstrateClientAt<ChainApi> | ISubstrateClient<ChainApi, any>, chainHead: ChainHead, atBlockHash?: BlockHash);
14
14
  protected stateCall(callParams: StateCallParams): Promise<HexString>;
15
15
  }
@@ -1,15 +1,15 @@
1
1
  import { BlockHash } from '@dedot/codecs';
2
- import type { AsyncMethod, GenericSubstrateApi, RpcVersion } from '@dedot/types';
2
+ import type { AsyncMethod, GenericSubstrateApi } from '@dedot/types';
3
3
  import { ChainHead } from '../../json-rpc/index.js';
4
4
  import { type BaseStorageQuery, QueryableStorage } from '../../storage/index.js';
5
- import { ISubstrateClientAt } from '../../types.js';
5
+ import { ISubstrateClient, ISubstrateClientAt } from '../../types.js';
6
6
  import { StorageQueryExecutor } from '../StorageQueryExecutor.js';
7
7
  /**
8
8
  * @name StorageQueryExecutorV2
9
9
  */
10
10
  export declare class StorageQueryExecutorV2<ChainApi extends GenericSubstrateApi = GenericSubstrateApi> extends StorageQueryExecutor<ChainApi> {
11
11
  chainHead: ChainHead;
12
- constructor(client: ISubstrateClientAt<ChainApi>, chainHead: ChainHead, atBlockHash?: BlockHash);
12
+ constructor(client: ISubstrateClientAt<ChainApi> | ISubstrateClient<ChainApi, any>, chainHead: ChainHead, atBlockHash?: BlockHash);
13
13
  protected exposeStorageMapMethods(entry: QueryableStorage): Record<string, AsyncMethod>;
14
- protected getStorageQuery(): BaseStorageQuery<RpcVersion>;
14
+ protected getStorageQuery(): BaseStorageQuery;
15
15
  }
@@ -19,9 +19,7 @@ export class StorageQueryExecutorV2 extends StorageQueryExecutor {
19
19
  const entries = async (...args) => {
20
20
  const withArgs = !!args && args.length > 0;
21
21
  const key = withArgs ? entry.encodeKey(args, true) : entry.prefixKey;
22
- const results = await this.chainHead.storage([
23
- { type: 'descendantsValues', key },
24
- ]);
22
+ const results = await this.chainHead.storage([{ type: 'descendantsValues', key }]);
25
23
  return results.map(({ key, value }) => [
26
24
  entry.decodeKey(key),
27
25
  entry.decodeValue(value),
@@ -6,6 +6,7 @@ import { TxExecutor } from '../TxExecutor.js';
6
6
  * @description Execute a transaction instruction, returns a submittable extrinsic
7
7
  */
8
8
  export declare class TxExecutorV2<ChainApi extends VersionedGenericSubstrateApi = VersionedGenericSubstrateApi> extends TxExecutor<ChainApi[RpcVersion]> {
9
- constructor(api: DedotClient<ChainApi>);
9
+ readonly client: DedotClient<ChainApi>;
10
+ constructor(client: DedotClient<ChainApi>);
10
11
  protected createExtrinsic(call: IRuntimeTxCall): any;
11
12
  }
@@ -6,9 +6,11 @@ import { TxExecutor } from '../TxExecutor.js';
6
6
  * @description Execute a transaction instruction, returns a submittable extrinsic
7
7
  */
8
8
  export class TxExecutorV2 extends TxExecutor {
9
- constructor(api) {
10
- assert(api.rpcVersion === 'v2', 'Only supports JSON-RPC v2');
11
- super(api);
9
+ client;
10
+ constructor(client) {
11
+ assert(client.rpcVersion === 'v2', 'Only supports JSON-RPC v2');
12
+ super(client);
13
+ this.client = client;
12
14
  }
13
15
  createExtrinsic(call) {
14
16
  return new SubmittableExtrinsicV2(this.client, call);
@@ -1,7 +1,7 @@
1
1
  import type { GenericSubstrateApi } from '@dedot/types';
2
2
  import { HexString } from '@dedot/utils';
3
3
  import { ChainHead } from '../../json-rpc/index.js';
4
- import { ISubstrateClientAt } from '../../types.js';
4
+ import { ISubstrateClient, ISubstrateClientAt } from '../../types.js';
5
5
  import { StateCallParams } from '../Executor.js';
6
6
  import { ViewFunctionExecutor } from '../ViewFunctionExecutor.js';
7
7
  /**
@@ -9,6 +9,6 @@ import { ViewFunctionExecutor } from '../ViewFunctionExecutor.js';
9
9
  */
10
10
  export declare class ViewFunctionExecutorV2<ChainApi extends GenericSubstrateApi = GenericSubstrateApi> extends ViewFunctionExecutor<ChainApi> {
11
11
  chainHead: ChainHead;
12
- constructor(client: ISubstrateClientAt<ChainApi>, chainHead: ChainHead);
12
+ constructor(client: ISubstrateClientAt<ChainApi> | ISubstrateClient<ChainApi, any>, chainHead: ChainHead);
13
13
  protected stateCall(callParams: StateCallParams): Promise<HexString>;
14
14
  }
@@ -19,17 +19,17 @@ interface SignedExtensionOptions {
19
19
  payloadOptions?: Partial<PayloadOptions>;
20
20
  }
21
21
  export declare abstract class SignedExtension<Data extends any = {}, AdditionalSigned extends any = []> implements ISignedExtension {
22
- readonly client: ISubstrateClient;
22
+ readonly client: ISubstrateClient<any, any>;
23
23
  readonly options?: SignedExtensionOptions | undefined;
24
24
  data: Data;
25
25
  additionalSigned: AdditionalSigned;
26
- constructor(client: ISubstrateClient, options?: SignedExtensionOptions | undefined);
26
+ constructor(client: ISubstrateClient<any, any>, options?: SignedExtensionOptions | undefined);
27
27
  init(): Promise<void>;
28
28
  fromPayload(payload: SignerPayloadJSON): Promise<void>;
29
29
  get identifier(): string;
30
30
  get $Data(): $.AnyShape;
31
31
  get $AdditionalSigned(): $.AnyShape;
32
- get registry(): PortableRegistry;
32
+ get registry(): PortableRegistry<any>;
33
33
  get signedExtensionDef(): {
34
34
  ident: string;
35
35
  typeId: number;
@@ -9,8 +9,8 @@ interface TxHooks {
9
9
  }
10
10
  export declare abstract class BaseSubmittableExtrinsic extends Extrinsic implements ISubmittableExtrinsic {
11
11
  #private;
12
- readonly client: ISubstrateClient;
13
- constructor(client: ISubstrateClient, call: IRuntimeTxCall);
12
+ readonly client: ISubstrateClient<any>;
13
+ constructor(client: ISubstrateClient<any>, call: IRuntimeTxCall);
14
14
  withHooks(hooks: TxHooks): void;
15
15
  protected transformTxResult<R extends ISubmittableResult = ISubmittableResult>(result: ISubmittableResult): R;
16
16
  paymentInfo(account: AddressOrPair, options?: Partial<PayloadOptions>): Promise<TxPaymentInfo>;
@@ -7,8 +7,8 @@ import { BaseSubmittableExtrinsic } from './BaseSubmittableExtrinsic.js';
7
7
  */
8
8
  export declare class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic {
9
9
  #private;
10
- client: DedotClient;
11
- constructor(client: DedotClient, call: IRuntimeTxCall);
10
+ client: DedotClient<any>;
11
+ constructor(client: DedotClient<any>, call: IRuntimeTxCall);
12
12
  send(): TxHash;
13
13
  send(callback: Callback): TxUnsub;
14
14
  }
@@ -0,0 +1,134 @@
1
+ import { BlockHash, Option } from '@dedot/codecs';
2
+ import { ArchiveStorageResult, PaginatedStorageQuery } from '@dedot/types/json-rpc';
3
+ import { HexString } from '@dedot/utils';
4
+ import { IJsonRpcClient } from '../../types.js';
5
+ import { JsonRpcGroup, JsonRpcGroupOptions } from './JsonRpcGroup.js';
6
+ /**
7
+ * @name Archive
8
+ * Archive JSON-RPC methods for accessing historical blockchain data.
9
+ * Functions with the `archive` prefix allow obtaining the state of the chain
10
+ * at any point in the present or in the past.
11
+ *
12
+ * JSON-RPC V2: https://paritytech.github.io/json-rpc-interface-spec/api/archive.html
13
+ */
14
+ export declare class Archive extends JsonRpcGroup {
15
+ #private;
16
+ constructor(client: IJsonRpcClient, options?: Partial<JsonRpcGroupOptions>);
17
+ /**
18
+ * Retrieves the body (list of transactions) of a given block.
19
+ * Returns an array of strings containing the hexadecimal-encoded SCALE-codec-encoded
20
+ * transactions in that block. If no block with that hash is found, null.
21
+ *
22
+ * @param hash - The block hash (optional, defaults to current finalized block)
23
+ * @returns Array of transaction hashes or null if block not found
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * // Get transactions from current finalized block
28
+ * const transactions = await archive.body();
29
+ *
30
+ * // Get transactions from specific block
31
+ * const transactions = await archive.body('0x1234...');
32
+ * ```
33
+ */
34
+ body(hash?: BlockHash): Promise<Option<Array<HexString>>>;
35
+ /**
36
+ * Get the chain's genesis hash.
37
+ * Returns a string containing the hexadecimal-encoded hash of the genesis block of the chain.
38
+ * This value is cached after the first call.
39
+ *
40
+ * @returns The genesis block hash
41
+ */
42
+ genesisHash(): Promise<HexString>;
43
+ /**
44
+ * Get the block's header.
45
+ * Returns a string containing the hexadecimal-encoded SCALE-codec encoding header of the block.
46
+ *
47
+ * @param hash - The block hash (optional, defaults to current finalized block)
48
+ * @returns The encoded block header or null if block not found
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * // Get header of current finalized block
53
+ * const header = await archive.header();
54
+ *
55
+ * // Get header of specific block
56
+ * const header = await archive.header('0x1234...');
57
+ * ```
58
+ */
59
+ header(hash?: BlockHash): Promise<Option<HexString>>;
60
+ /**
61
+ * Get the height of the current finalized block.
62
+ * Returns an integer height of the current finalized block of the chain.
63
+ *
64
+ * @returns The height of the finalized block
65
+ */
66
+ finalizedHeight(): Promise<number>;
67
+ /**
68
+ * Get the hash of the current finalized block.
69
+ * Returns a string containing the hexadecimal-encoded hash of the current finalized block.
70
+ * This is a convenience method that combines finalizedHeight() and hashByHeight().
71
+ *
72
+ * @returns The hash of the current finalized block
73
+ */
74
+ finalizedHash(): Promise<HexString>;
75
+ /**
76
+ * Get the hashes of blocks from the given height.
77
+ * Returns an array (possibly empty) of strings containing hexadecimal-encoded hashes of block headers.
78
+ *
79
+ * Note: For heights <= finalized height, there is guaranteed to be one block.
80
+ * For heights > finalized height, there may be zero, one or multiple blocks depending on forks.
81
+ *
82
+ * @param height - The block height
83
+ * @returns Array of block hashes at the given height
84
+ */
85
+ hashByHeight(height: number): Promise<Array<HexString>>;
86
+ /**
87
+ * Call into the Runtime API at a specified block's state.
88
+ *
89
+ * @param func - The runtime API function to call
90
+ * @param params - The parameters for the function call (SCALE-encoded)
91
+ * @param hash - The block hash (optional, defaults to current finalized block)
92
+ * @returns The result of the runtime call
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * // Call Core_version on current finalized block
97
+ * const version = await archive.call('Core_version', '0x');
98
+ *
99
+ * // Call Core_version on specific block
100
+ * const version = await archive.call('Core_version', '0x', '0x1234...');
101
+ * ```
102
+ */
103
+ call(func: string, params: HexString, hash?: BlockHash): Promise<HexString>;
104
+ /**
105
+ * Returns storage entries at a specific block's state.
106
+ * This method collects all storage events and returns them as a single result.
107
+ *
108
+ * @param items - Array of storage queries with optional pagination
109
+ * @param childTrie - Optional child trie key
110
+ * @param hash - The block hash (optional, defaults to current finalized block)
111
+ * @returns Storage results array
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * // Query storage from current finalized block
116
+ * const results = await archive.storage([{ key: '0x1234', type: 'value' }]);
117
+ *
118
+ * // Query storage from specific block
119
+ * const results = await archive.storage([{ key: '0x1234', type: 'value' }], null, '0xabcd...');
120
+ * ```
121
+ */
122
+ storage(items: Array<PaginatedStorageQuery>, childTrie?: HexString | null, hash?: BlockHash): Promise<ArchiveStorageResult>;
123
+ /**
124
+ * Clears the internal cache used for storing archive query results.
125
+ * This can be useful for memory management or when you want to force fresh data retrieval.
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * // Clear all cached results
130
+ * archive.clearCache();
131
+ * ```
132
+ */
133
+ clearCache(): void;
134
+ }