@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.
- package/chaintypes/substrate/consts.d.ts +2 -2
- package/chaintypes/substrate/consts.js +1 -0
- package/chaintypes/substrate/errors.d.ts +909 -909
- package/chaintypes/substrate/errors.js +1 -0
- package/chaintypes/substrate/events.d.ts +664 -664
- package/chaintypes/substrate/events.js +1 -0
- package/chaintypes/substrate/index.d.ts +13 -16
- package/chaintypes/substrate/index.js +1 -0
- package/chaintypes/substrate/json-rpc.d.ts +2 -2
- package/chaintypes/substrate/json-rpc.js +1 -0
- package/chaintypes/substrate/query.d.ts +509 -527
- package/chaintypes/substrate/query.js +1 -0
- package/chaintypes/substrate/runtime.d.ts +123 -123
- package/chaintypes/substrate/runtime.js +1 -0
- package/chaintypes/substrate/tx.d.ts +1311 -1311
- package/chaintypes/substrate/tx.js +1 -0
- package/chaintypes/substrate/types.js +1 -0
- package/chaintypes/substrate/view-functions.d.ts +2 -2
- package/chaintypes/substrate/view-functions.js +1 -0
- package/cjs/chaintypes/substrate/consts.js +1 -0
- package/cjs/chaintypes/substrate/errors.js +1 -0
- package/cjs/chaintypes/substrate/events.js +1 -0
- package/cjs/chaintypes/substrate/index.js +1 -0
- package/cjs/chaintypes/substrate/json-rpc.js +1 -0
- package/cjs/chaintypes/substrate/query.js +1 -0
- package/cjs/chaintypes/substrate/runtime.js +1 -0
- package/cjs/chaintypes/substrate/tx.js +1 -0
- package/cjs/chaintypes/substrate/types.js +1 -0
- package/cjs/chaintypes/substrate/view-functions.js +1 -0
- package/cjs/client/BaseSubstrateClient.js +45 -2
- package/cjs/client/DedotClient.js +356 -224
- package/cjs/client/LegacyClient.js +99 -23
- package/cjs/client/V2Client.js +316 -0
- package/cjs/client/explorer/LegacyBlockExplorer.js +263 -0
- package/cjs/client/explorer/V2BlockExplorer.js +74 -0
- package/cjs/client/explorer/index.js +18 -0
- package/cjs/client/utils.js +57 -0
- package/cjs/executor/EventExecutor.js +1 -0
- package/cjs/executor/RuntimeApiExecutor.js +49 -2
- package/cjs/executor/StorageQueryExecutor.js +114 -2
- package/cjs/executor/ViewFunctionExecutor.js +21 -2
- package/cjs/executor/v2/StorageQueryExecutorV2.js +7 -1
- package/cjs/executor/validation-helpers.js +181 -0
- package/cjs/extrinsic/submittable/BaseSubmittableExtrinsic.js +86 -2
- package/cjs/extrinsic/submittable/SubmittableExtrinsic.js +38 -16
- package/cjs/extrinsic/submittable/SubmittableExtrinsicV2.js +65 -35
- package/cjs/json-rpc/group/ChainHead/ChainHead.js +233 -21
- package/cjs/storage/QueryableStorage.js +1 -0
- package/client/BaseSubstrateClient.d.ts +34 -18
- package/client/BaseSubstrateClient.js +47 -4
- package/client/DedotClient.d.ts +346 -49
- package/client/DedotClient.js +356 -224
- package/client/LegacyClient.d.ts +22 -17
- package/client/LegacyClient.js +101 -25
- package/client/V2Client.d.ts +75 -0
- package/client/V2Client.js +312 -0
- package/client/explorer/LegacyBlockExplorer.d.ts +68 -0
- package/client/explorer/LegacyBlockExplorer.js +259 -0
- package/client/explorer/V2BlockExplorer.d.ts +40 -0
- package/client/explorer/V2BlockExplorer.js +70 -0
- package/client/explorer/index.d.ts +2 -0
- package/client/explorer/index.js +2 -0
- package/client/utils.d.ts +18 -0
- package/client/utils.js +52 -0
- package/executor/ConstantExecutor.d.ts +1 -2
- package/executor/ErrorExecutor.d.ts +2 -2
- package/executor/EventExecutor.d.ts +2 -2
- package/executor/EventExecutor.js +1 -0
- package/executor/Executor.d.ts +4 -5
- package/executor/RuntimeApiExecutor.d.ts +2 -2
- package/executor/RuntimeApiExecutor.js +27 -3
- package/executor/StorageQueryExecutor.d.ts +3 -2
- package/executor/StorageQueryExecutor.js +92 -3
- package/executor/TxExecutor.d.ts +2 -2
- package/executor/ViewFunctionExecutor.d.ts +2 -2
- package/executor/ViewFunctionExecutor.js +22 -3
- package/executor/v2/RuntimeApiExecutorV2.d.ts +2 -3
- package/executor/v2/StorageQueryExecutorV2.d.ts +3 -3
- package/executor/v2/StorageQueryExecutorV2.js +8 -2
- package/executor/v2/TxExecutorV2.d.ts +5 -5
- package/executor/v2/ViewFunctionExecutorV2.d.ts +2 -3
- package/executor/validation-helpers.d.ts +36 -0
- package/executor/validation-helpers.js +174 -0
- package/extrinsic/extensions/SignedExtension.d.ts +1 -1
- package/extrinsic/submittable/BaseSubmittableExtrinsic.d.ts +7 -3
- package/extrinsic/submittable/BaseSubmittableExtrinsic.js +64 -3
- package/extrinsic/submittable/SubmittableExtrinsic.d.ts +4 -1
- package/extrinsic/submittable/SubmittableExtrinsic.js +39 -17
- package/extrinsic/submittable/SubmittableExtrinsicV2.d.ts +6 -3
- package/extrinsic/submittable/SubmittableExtrinsicV2.js +66 -36
- package/json-rpc/JsonRpcClient.d.ts +6 -6
- package/json-rpc/group/Archive.d.ts +1 -1
- package/json-rpc/group/ChainHead/ChainHead.d.ts +20 -2
- package/json-rpc/group/ChainHead/ChainHead.js +233 -21
- package/json-rpc/group/ChainSpec.d.ts +3 -3
- package/json-rpc/group/Transaction.d.ts +1 -1
- package/json-rpc/group/TransactionWatch.d.ts +1 -1
- package/package.json +9 -9
- package/proxychain.d.ts +3 -4
- package/storage/NewStorageQuery.d.ts +3 -3
- package/storage/QueryableStorage.js +1 -0
- 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
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 {};
|