@dedot/api 0.18.6 → 1.0.0-next.a0f8d41e.25

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 (102) hide show
  1. package/chaintypes/substrate/consts.d.ts +2 -2
  2. package/chaintypes/substrate/consts.js +1 -0
  3. package/chaintypes/substrate/errors.d.ts +909 -909
  4. package/chaintypes/substrate/errors.js +1 -0
  5. package/chaintypes/substrate/events.d.ts +664 -664
  6. package/chaintypes/substrate/events.js +1 -0
  7. package/chaintypes/substrate/index.d.ts +13 -16
  8. package/chaintypes/substrate/index.js +1 -0
  9. package/chaintypes/substrate/json-rpc.d.ts +2 -2
  10. package/chaintypes/substrate/json-rpc.js +1 -0
  11. package/chaintypes/substrate/query.d.ts +509 -527
  12. package/chaintypes/substrate/query.js +1 -0
  13. package/chaintypes/substrate/runtime.d.ts +123 -123
  14. package/chaintypes/substrate/runtime.js +1 -0
  15. package/chaintypes/substrate/tx.d.ts +1311 -1311
  16. package/chaintypes/substrate/tx.js +1 -0
  17. package/chaintypes/substrate/types.js +1 -0
  18. package/chaintypes/substrate/view-functions.d.ts +2 -2
  19. package/chaintypes/substrate/view-functions.js +1 -0
  20. package/cjs/chaintypes/substrate/consts.js +1 -0
  21. package/cjs/chaintypes/substrate/errors.js +1 -0
  22. package/cjs/chaintypes/substrate/events.js +1 -0
  23. package/cjs/chaintypes/substrate/index.js +1 -0
  24. package/cjs/chaintypes/substrate/json-rpc.js +1 -0
  25. package/cjs/chaintypes/substrate/query.js +1 -0
  26. package/cjs/chaintypes/substrate/runtime.js +1 -0
  27. package/cjs/chaintypes/substrate/tx.js +1 -0
  28. package/cjs/chaintypes/substrate/types.js +1 -0
  29. package/cjs/chaintypes/substrate/view-functions.js +1 -0
  30. package/cjs/client/BaseSubstrateClient.js +45 -2
  31. package/cjs/client/DedotClient.js +356 -224
  32. package/cjs/client/LegacyClient.js +99 -23
  33. package/cjs/client/V2Client.js +316 -0
  34. package/cjs/client/explorer/LegacyBlockExplorer.js +263 -0
  35. package/cjs/client/explorer/V2BlockExplorer.js +74 -0
  36. package/cjs/client/explorer/index.js +18 -0
  37. package/cjs/client/utils.js +57 -0
  38. package/cjs/executor/EventExecutor.js +1 -0
  39. package/cjs/executor/RuntimeApiExecutor.js +49 -2
  40. package/cjs/executor/StorageQueryExecutor.js +114 -2
  41. package/cjs/executor/ViewFunctionExecutor.js +21 -2
  42. package/cjs/executor/v2/StorageQueryExecutorV2.js +7 -1
  43. package/cjs/executor/validation-helpers.js +181 -0
  44. package/cjs/extrinsic/submittable/BaseSubmittableExtrinsic.js +86 -2
  45. package/cjs/extrinsic/submittable/SubmittableExtrinsic.js +38 -16
  46. package/cjs/extrinsic/submittable/SubmittableExtrinsicV2.js +65 -35
  47. package/cjs/json-rpc/group/ChainHead/ChainHead.js +233 -21
  48. package/cjs/storage/QueryableStorage.js +1 -0
  49. package/client/BaseSubstrateClient.d.ts +34 -18
  50. package/client/BaseSubstrateClient.js +47 -4
  51. package/client/DedotClient.d.ts +346 -49
  52. package/client/DedotClient.js +356 -224
  53. package/client/LegacyClient.d.ts +22 -17
  54. package/client/LegacyClient.js +101 -25
  55. package/client/V2Client.d.ts +75 -0
  56. package/client/V2Client.js +312 -0
  57. package/client/explorer/LegacyBlockExplorer.d.ts +68 -0
  58. package/client/explorer/LegacyBlockExplorer.js +259 -0
  59. package/client/explorer/V2BlockExplorer.d.ts +40 -0
  60. package/client/explorer/V2BlockExplorer.js +70 -0
  61. package/client/explorer/index.d.ts +2 -0
  62. package/client/explorer/index.js +2 -0
  63. package/client/utils.d.ts +18 -0
  64. package/client/utils.js +52 -0
  65. package/executor/ConstantExecutor.d.ts +1 -2
  66. package/executor/ErrorExecutor.d.ts +2 -2
  67. package/executor/EventExecutor.d.ts +2 -2
  68. package/executor/EventExecutor.js +1 -0
  69. package/executor/Executor.d.ts +4 -5
  70. package/executor/RuntimeApiExecutor.d.ts +2 -2
  71. package/executor/RuntimeApiExecutor.js +27 -3
  72. package/executor/StorageQueryExecutor.d.ts +3 -2
  73. package/executor/StorageQueryExecutor.js +92 -3
  74. package/executor/TxExecutor.d.ts +2 -2
  75. package/executor/ViewFunctionExecutor.d.ts +2 -2
  76. package/executor/ViewFunctionExecutor.js +22 -3
  77. package/executor/v2/RuntimeApiExecutorV2.d.ts +2 -3
  78. package/executor/v2/StorageQueryExecutorV2.d.ts +3 -3
  79. package/executor/v2/StorageQueryExecutorV2.js +8 -2
  80. package/executor/v2/TxExecutorV2.d.ts +5 -5
  81. package/executor/v2/ViewFunctionExecutorV2.d.ts +2 -3
  82. package/executor/validation-helpers.d.ts +36 -0
  83. package/executor/validation-helpers.js +174 -0
  84. package/extrinsic/extensions/SignedExtension.d.ts +1 -1
  85. package/extrinsic/submittable/BaseSubmittableExtrinsic.d.ts +7 -3
  86. package/extrinsic/submittable/BaseSubmittableExtrinsic.js +64 -3
  87. package/extrinsic/submittable/SubmittableExtrinsic.d.ts +4 -1
  88. package/extrinsic/submittable/SubmittableExtrinsic.js +39 -17
  89. package/extrinsic/submittable/SubmittableExtrinsicV2.d.ts +6 -3
  90. package/extrinsic/submittable/SubmittableExtrinsicV2.js +66 -36
  91. package/json-rpc/JsonRpcClient.d.ts +6 -6
  92. package/json-rpc/group/Archive.d.ts +1 -1
  93. package/json-rpc/group/ChainHead/ChainHead.d.ts +20 -2
  94. package/json-rpc/group/ChainHead/ChainHead.js +233 -21
  95. package/json-rpc/group/ChainSpec.d.ts +3 -3
  96. package/json-rpc/group/Transaction.d.ts +1 -1
  97. package/json-rpc/group/TransactionWatch.d.ts +1 -1
  98. package/package.json +9 -9
  99. package/proxychain.d.ts +3 -4
  100. package/storage/NewStorageQuery.d.ts +3 -3
  101. package/storage/QueryableStorage.js +1 -0
  102. package/types.d.ts +94 -6
package/types.d.ts CHANGED
@@ -1,9 +1,11 @@
1
- import { BlockHash, Hash, Metadata, PortableRegistry } from '@dedot/codecs';
1
+ import { BlockHash, Extrinsic, Hash, Header, Metadata, PortableRegistry } from '@dedot/codecs';
2
2
  import type { ConnectionStatus, JsonRpcProvider, ProviderEvent } from '@dedot/providers';
3
3
  import type { AnyShape } from '@dedot/shape';
4
4
  import type { IStorage } from '@dedot/storage';
5
- import type { Callback, GenericStorageQuery, GenericSubstrateApi, InjectedSigner, Query, QueryFnResult, RpcVersion, RuntimeApiName, RuntimeApiSpec, Unsub } from '@dedot/types';
5
+ import { Callback, GenericStorageQuery, GenericSubstrateApi, InjectedSigner, Query, QueryFnResult, RpcVersion, RuntimeApiName, RuntimeApiSpec, TxUnsub, Unsub } from '@dedot/types';
6
+ import { Properties } from '@dedot/types/json-rpc';
6
7
  import type { HashFn, HexString, IEventEmitter } from '@dedot/utils';
8
+ import type { SubstrateApi } from './chaintypes/index.js';
7
9
  import type { AnySignedExtension } from './extrinsic/index.js';
8
10
  import type { ChainHeadEvent } from './json-rpc/index.js';
9
11
  export type MetadataKey = `RAW_META/${string}`;
@@ -60,6 +62,20 @@ export interface ApiOptions extends JsonRpcClientOptions {
60
62
  * A signer instance to use for signing transactions
61
63
  */
62
64
  signer?: InjectedSigner;
65
+ /**
66
+ * Timeout in milliseconds for detecting stale WebSocket connections.
67
+ * When set, monitors block subscription activity and triggers reconnection
68
+ * to switch to a different endpoint if no blocks/events received within the timeout period.
69
+ *
70
+ * Note: This option is only supported when used with WsProvider.
71
+ *
72
+ * - Default: 30000 (30 seconds) - staling detection enabled
73
+ * - 0: Disabled - no staling detection
74
+ * - Any positive number: Custom timeout in milliseconds
75
+ *
76
+ * @default 30000
77
+ */
78
+ stalingDetectionTimeout?: number;
63
79
  }
64
80
  export type ApiEvent = ProviderEvent | 'ready' | 'runtimeUpgraded';
65
81
  export type DedotClientEvent = ApiEvent | ChainHeadEvent;
@@ -74,7 +90,7 @@ export interface SubstrateRuntimeVersion {
74
90
  /**
75
91
  * A generic interface for JSON-RPC clients
76
92
  */
77
- export interface IJsonRpcClient<ChainApi extends GenericSubstrateApi = GenericSubstrateApi, Events extends string = ProviderEvent> extends IEventEmitter<Events> {
93
+ export interface IJsonRpcClient<ChainApi extends GenericSubstrateApi = SubstrateApi, Events extends string = ProviderEvent> extends IEventEmitter<Events> {
78
94
  options: JsonRpcClientOptions;
79
95
  status: ConnectionStatus;
80
96
  provider: JsonRpcProvider;
@@ -85,7 +101,7 @@ export interface IJsonRpcClient<ChainApi extends GenericSubstrateApi = GenericSu
85
101
  /**
86
102
  * @internal
87
103
  */
88
- export interface IGenericSubstrateClient<ChainApi extends GenericSubstrateApi = GenericSubstrateApi> {
104
+ export interface IGenericSubstrateClient<ChainApi extends GenericSubstrateApi = SubstrateApi> {
89
105
  rpcVersion: RpcVersion;
90
106
  options: ApiOptions;
91
107
  genesisHash: Hash;
@@ -125,15 +141,37 @@ export interface IGenericSubstrateClient<ChainApi extends GenericSubstrateApi =
125
141
  /**
126
142
  * A generic interface for Substrate clients at a specific block
127
143
  */
128
- export interface ISubstrateClientAt<ChainApi extends GenericSubstrateApi = GenericSubstrateApi> extends IGenericSubstrateClient<ChainApi> {
144
+ export interface ISubstrateClientAt<ChainApi extends GenericSubstrateApi = SubstrateApi> extends IGenericSubstrateClient<ChainApi> {
129
145
  atBlockHash: BlockHash;
130
146
  }
147
+ export interface BlockInfo {
148
+ hash: BlockHash;
149
+ number: number;
150
+ parent: BlockHash;
151
+ runtimeUpgraded: boolean;
152
+ }
153
+ export interface BlockExplorer {
154
+ best(): Promise<BlockInfo>;
155
+ best(callback: (block: BlockInfo) => void): () => void;
156
+ finalized(): Promise<BlockInfo>;
157
+ finalized(callback: (block: BlockInfo) => void): () => void;
158
+ header(hash: BlockHash): Promise<Header>;
159
+ body(hash: BlockHash): Promise<HexString[]>;
160
+ }
161
+ export interface IChainSpec {
162
+ chainName(): Promise<string>;
163
+ genesisHash(): Promise<HexString>;
164
+ properties(): Promise<Properties>;
165
+ }
131
166
  /**
132
167
  * A generic interface for Substrate clients
133
168
  */
134
- export interface ISubstrateClient<ChainApi extends GenericSubstrateApi = GenericSubstrateApi, Events extends string = ApiEvent> extends IJsonRpcClient<ChainApi, Events>, IGenericSubstrateClient<ChainApi> {
169
+ export interface ISubstrateClient<ChainApi extends GenericSubstrateApi = SubstrateApi, // --
170
+ Events extends string = ApiEvent> extends IJsonRpcClient<ChainApi, Events>, IGenericSubstrateClient<ChainApi> {
135
171
  options: ApiOptions;
136
172
  tx: ChainApi['tx'];
173
+ chainSpec: IChainSpec;
174
+ block: BlockExplorer;
137
175
  at<ChainApiAt extends GenericSubstrateApi = ChainApi>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
138
176
  /**
139
177
  * Get current version of the runtime
@@ -149,6 +187,44 @@ export interface ISubstrateClient<ChainApi extends GenericSubstrateApi = Generic
149
187
  * @param signer
150
188
  */
151
189
  setSigner(signer?: InjectedSigner): void;
190
+ /**
191
+ * Broadcasts a transaction to the network and monitors its status.
192
+ *
193
+ * This method accepts a transaction (either as a hex-encoded string or an Extrinsic instance)
194
+ * and submits it to the network. It returns a TxUnsub object that allows you to:
195
+ * - Subscribe to transaction status updates via an optional callback
196
+ * - Wait for specific transaction states (finalized, included in best chain block)
197
+ *
198
+ * @param tx - The signed transaction to broadcast, either as a hex-encoded string or Extrinsic instance
199
+ * @param callback - Optional callback function to receive transaction status updates. The callback
200
+ * receives an ISubmittableResult object containing status, events, errors, tx hash, etc...
201
+ *
202
+ * @returns A TxUnsub object that is both a Promise<Unsub> and provides utility methods:
203
+ * - `.untilFinalized()` - Resolves when transaction is finalized
204
+ * - `.untilBestChainBlockIncluded()` - Resolves when transaction is included in best chain block
205
+ * - When awaited directly, resolves to an unsubscribe function
206
+ *
207
+ * @example
208
+ * // Basic usage with callback for status updates
209
+ * const unsub = await client.sendTx(rawTxHex, (result) => {
210
+ * console.log('Transaction status:', result.status);
211
+ * console.log('Transaction hash:', result.txHash);
212
+ * if (result.dispatchError) {
213
+ * console.error('Transaction failed:', result.dispatchError);
214
+ * }
215
+ * });
216
+ *
217
+ * @example
218
+ * // Wait for transaction to be included in best chain block
219
+ * const result = await client.sendTx(rawTxHex, console.log).untilBestChainBlockIncluded();
220
+ * console.log('Transaction included in block:', result);
221
+ *
222
+ * @example
223
+ * // Wait for transaction finalization
224
+ * const result = await client.sendTx(rawTxHex).untilFinalized();
225
+ * console.log('Transaction finalized:', result);
226
+ */
227
+ sendTx(tx: HexString | Extrinsic, callback?: Callback): TxUnsub;
152
228
  /**
153
229
  * Query multiple storage items in a single call or subscribe to multiple storage items
154
230
  *
@@ -185,6 +261,17 @@ export interface ISubstrateClient<ChainApi extends GenericSubstrateApi = Generic
185
261
  }, callback: Callback<{
186
262
  [K in keyof Fns]: QueryFnResult<Fns[K]>;
187
263
  }>): Promise<Unsub>;
264
+ on<Event extends Events = Events>(event: Event, handler: EventHandlerFn<Event>): () => void;
265
+ }
266
+ export type EventHandlerFn<Event extends string> = EventTypes[Event];
267
+ interface EventTypes {
268
+ ready: () => void;
269
+ connected: (connectedEndpoint: string) => void;
270
+ disconnected: () => void;
271
+ reconnecting: () => void;
272
+ runtimeUpgraded: (newRuntimeVersion: SubstrateRuntimeVersion, at: BlockInfo) => void;
273
+ error: (error?: Error) => void;
274
+ [event: string]: (...args: any[]) => void;
188
275
  }
189
276
  /**
190
277
  * A generic interface for broadcasting transactions
@@ -202,3 +289,4 @@ export interface TxBroadcaster {
202
289
  */
203
290
  supported(): Promise<boolean>;
204
291
  }
292
+ export {};