@dedot/api 0.18.8 → 1.0.0
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 +12 -2
- package/cjs/json-rpc/group/ChainHead/ChainHead.js +226 -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 +13 -3
- 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 +18 -2
- package/json-rpc/group/ChainHead/ChainHead.js +226 -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/client/LegacyClient.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { BlockHash } from '@dedot/codecs';
|
|
1
|
+
import { BlockHash, type Extrinsic, Metadata } from '@dedot/codecs';
|
|
2
2
|
import type { JsonRpcProvider } from '@dedot/providers';
|
|
3
|
-
import {
|
|
3
|
+
import { Callback, GenericSubstrateApi, TxUnsub } from '@dedot/types';
|
|
4
|
+
import { HexString } from '@dedot/utils';
|
|
4
5
|
import type { SubstrateApi } from '../chaintypes/index.js';
|
|
5
6
|
import { BaseStorageQuery } from '../storage/index.js';
|
|
6
|
-
import type { ApiOptions, ISubstrateClientAt } from '../types.js';
|
|
7
|
+
import type { ApiOptions, BlockExplorer, IChainSpec, ISubstrateClientAt } from '../types.js';
|
|
7
8
|
import { BaseSubstrateClient } from './BaseSubstrateClient.js';
|
|
8
9
|
/**
|
|
9
10
|
* @name LegacyClient
|
|
@@ -43,9 +44,10 @@ import { BaseSubstrateClient } from './BaseSubstrateClient.js';
|
|
|
43
44
|
* run().catch(console.error);
|
|
44
45
|
* ```
|
|
45
46
|
*/
|
|
46
|
-
export declare class LegacyClient<ChainApi extends
|
|
47
|
-
extends BaseSubstrateClient<
|
|
47
|
+
export declare class LegacyClient<ChainApi extends GenericSubstrateApi = SubstrateApi>// prettier-end-here
|
|
48
|
+
extends BaseSubstrateClient<ChainApi> {
|
|
48
49
|
#private;
|
|
50
|
+
protected _blockExplorer?: BlockExplorer;
|
|
49
51
|
/**
|
|
50
52
|
* Use factory methods (`create`, `new`) to create `Dedot` instances.
|
|
51
53
|
*
|
|
@@ -57,20 +59,20 @@ export declare class LegacyClient<ChainApi extends VersionedGenericSubstrateApi
|
|
|
57
59
|
*
|
|
58
60
|
* @param options
|
|
59
61
|
*/
|
|
60
|
-
static create<ChainApi extends
|
|
62
|
+
static create<ChainApi extends GenericSubstrateApi = SubstrateApi>(options: ApiOptions | JsonRpcProvider): Promise<LegacyClient<ChainApi>>;
|
|
61
63
|
/**
|
|
62
64
|
* Alias for __LegacyClient.create__
|
|
63
65
|
*
|
|
64
66
|
* @param options
|
|
65
67
|
*/
|
|
66
|
-
static new<ChainApi extends
|
|
67
|
-
protected onDisconnected: () => Promise<void>;
|
|
68
|
+
static new<ChainApi extends GenericSubstrateApi = SubstrateApi>(options: ApiOptions | JsonRpcProvider): Promise<LegacyClient<ChainApi>>;
|
|
68
69
|
protected beforeDisconnect(): Promise<void>;
|
|
69
70
|
/**
|
|
70
71
|
* Initialize APIs before usage
|
|
71
72
|
*/
|
|
72
73
|
protected doInitialize(): Promise<void>;
|
|
73
74
|
protected cleanUp(): void;
|
|
75
|
+
protected setMetadata(metadata: Metadata): Promise<void>;
|
|
74
76
|
/**
|
|
75
77
|
* @description Entry-point for inspecting constants (parameter types) for all pallets (modules).
|
|
76
78
|
*
|
|
@@ -79,7 +81,7 @@ export declare class LegacyClient<ChainApi extends VersionedGenericSubstrateApi
|
|
|
79
81
|
* console.log('ss58Prefix:', ss58Prefix)
|
|
80
82
|
* ```
|
|
81
83
|
*/
|
|
82
|
-
get consts(): ChainApi[
|
|
84
|
+
get consts(): ChainApi['consts'];
|
|
83
85
|
/**
|
|
84
86
|
* @description Entry-point for executing query to on-chain storage.
|
|
85
87
|
*
|
|
@@ -88,15 +90,15 @@ export declare class LegacyClient<ChainApi extends VersionedGenericSubstrateApi
|
|
|
88
90
|
* console.log('Balance:', balance);
|
|
89
91
|
* ```
|
|
90
92
|
*/
|
|
91
|
-
get query(): ChainApi[
|
|
93
|
+
get query(): ChainApi['query'];
|
|
92
94
|
/**
|
|
93
95
|
* @description Entry-point for inspecting errors from metadata
|
|
94
96
|
*/
|
|
95
|
-
get errors(): ChainApi[
|
|
97
|
+
get errors(): ChainApi['errors'];
|
|
96
98
|
/**
|
|
97
99
|
* @description Entry-point for inspecting events from metadata
|
|
98
100
|
*/
|
|
99
|
-
get events(): ChainApi[
|
|
101
|
+
get events(): ChainApi['events'];
|
|
100
102
|
/**
|
|
101
103
|
* @description Entry-point for executing runtime api
|
|
102
104
|
*
|
|
@@ -109,9 +111,9 @@ export declare class LegacyClient<ChainApi extends VersionedGenericSubstrateApi
|
|
|
109
111
|
* const queryInfo = await api.call.transactionPaymentApi.queryInfo(tx.toU8a(), tx.length);
|
|
110
112
|
* ```
|
|
111
113
|
*/
|
|
112
|
-
get call(): ChainApi[
|
|
113
|
-
protected callAt(hash?: BlockHash): ChainApi[
|
|
114
|
-
get view(): ChainApi[
|
|
114
|
+
get call(): ChainApi['call'];
|
|
115
|
+
protected callAt(hash?: BlockHash): ChainApi['call'];
|
|
116
|
+
get view(): ChainApi['view'];
|
|
115
117
|
/**
|
|
116
118
|
* @description Entry-point for executing on-chain transactions
|
|
117
119
|
*
|
|
@@ -123,13 +125,16 @@ export declare class LegacyClient<ChainApi extends VersionedGenericSubstrateApi
|
|
|
123
125
|
* });
|
|
124
126
|
* ```
|
|
125
127
|
*/
|
|
126
|
-
get tx(): ChainApi[
|
|
128
|
+
get tx(): ChainApi['tx'];
|
|
129
|
+
get block(): BlockExplorer;
|
|
130
|
+
get chainSpec(): IChainSpec;
|
|
127
131
|
/**
|
|
128
132
|
* Create a new API instance at a specific block hash
|
|
129
133
|
* This is useful when we want to inspect the state of the chain at a specific block hash
|
|
130
134
|
*
|
|
131
135
|
* @param hash
|
|
132
136
|
*/
|
|
133
|
-
at<ChainApiAt extends GenericSubstrateApi = ChainApi
|
|
137
|
+
at<ChainApiAt extends GenericSubstrateApi = ChainApi>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
|
|
134
138
|
protected getStorageQuery(): BaseStorageQuery;
|
|
139
|
+
sendTx(tx: HexString | Extrinsic, callback?: Callback): TxUnsub;
|
|
135
140
|
}
|
package/client/LegacyClient.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { PortableRegistry } from '@dedot/codecs';
|
|
2
|
-
import { assert } from '@dedot/utils';
|
|
2
|
+
import { assert, noop } from '@dedot/utils';
|
|
3
3
|
import { ConstantExecutor, ErrorExecutor, EventExecutor, RuntimeApiExecutor, StorageQueryExecutor, TxExecutor, ViewFunctionExecutor, } from '../executor/index.js';
|
|
4
|
+
import { SubmittableExtrinsic } from '../extrinsic/submittable/SubmittableExtrinsic.js';
|
|
4
5
|
import { newProxyChain } from '../proxychain.js';
|
|
5
6
|
import { LegacyStorageQuery } from '../storage/index.js';
|
|
6
|
-
import { BaseSubstrateClient } from './BaseSubstrateClient.js';
|
|
7
|
+
import { BaseSubstrateClient, ensurePresence } from './BaseSubstrateClient.js';
|
|
8
|
+
import { LegacyBlockExplorer } from './explorer/index.js';
|
|
9
|
+
import { detectHasherFromHeader, detectHasherFromMetadata } from './utils.js';
|
|
7
10
|
const KEEP_ALIVE_INTERVAL = 10_000; // in ms
|
|
8
11
|
/**
|
|
9
12
|
* @name LegacyClient
|
|
@@ -47,6 +50,8 @@ export class LegacyClient// prettier-end-here
|
|
|
47
50
|
extends BaseSubstrateClient {
|
|
48
51
|
#runtimeSubscriptionUnsub;
|
|
49
52
|
#healthTimer;
|
|
53
|
+
#hasher;
|
|
54
|
+
_blockExplorer;
|
|
50
55
|
/**
|
|
51
56
|
* Use factory methods (`create`, `new`) to create `Dedot` instances.
|
|
52
57
|
*
|
|
@@ -71,9 +76,6 @@ export class LegacyClient// prettier-end-here
|
|
|
71
76
|
static async new(options) {
|
|
72
77
|
return LegacyClient.create(options);
|
|
73
78
|
}
|
|
74
|
-
onDisconnected = async () => {
|
|
75
|
-
await this.#unsubscribeUpdates();
|
|
76
|
-
};
|
|
77
79
|
async beforeDisconnect() {
|
|
78
80
|
await this.#unsubscribeUpdates();
|
|
79
81
|
}
|
|
@@ -81,46 +83,91 @@ export class LegacyClient// prettier-end-here
|
|
|
81
83
|
* Initialize APIs before usage
|
|
82
84
|
*/
|
|
83
85
|
async doInitialize() {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
// Determine if this is the first initialization
|
|
87
|
+
const shouldInitialize = !this._genesisHash;
|
|
88
|
+
if (shouldInitialize) {
|
|
89
|
+
// First load: Run all requests in parallel for speed
|
|
90
|
+
let [genesisHash, runtimeVersion, metadata] = await Promise.all([
|
|
91
|
+
this.rpc.chain_getBlockHash(0),
|
|
92
|
+
this.#getRuntimeVersion(),
|
|
93
|
+
(await this.shouldPreloadMetadata()) ? this.fetchMetadata() : Promise.resolve(undefined),
|
|
94
|
+
]);
|
|
95
|
+
this._genesisHash = genesisHash;
|
|
96
|
+
this._runtimeVersion = runtimeVersion;
|
|
97
|
+
await this.setupMetadata(metadata);
|
|
98
|
+
// Initialize block explorer
|
|
99
|
+
this._blockExplorer = new LegacyBlockExplorer(this);
|
|
100
|
+
// Subscribe to updates
|
|
101
|
+
this.#subscribeUpdates();
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// Reconnect: Only fetch runtime version to check for changes
|
|
105
|
+
const newRuntimeVersion = await this.#getRuntimeVersion();
|
|
106
|
+
// Only fetch metadata if spec version has changed
|
|
107
|
+
if (newRuntimeVersion.specVersion !== this._runtimeVersion?.specVersion) {
|
|
108
|
+
this._runtimeVersion = newRuntimeVersion;
|
|
109
|
+
const metadata = await this.fetchMetadata();
|
|
110
|
+
await this.setupMetadata(metadata);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
93
113
|
}
|
|
94
114
|
cleanUp() {
|
|
95
115
|
super.cleanUp();
|
|
96
116
|
this.#healthTimer = undefined;
|
|
97
117
|
this.#runtimeSubscriptionUnsub = undefined;
|
|
118
|
+
this._blockExplorer = undefined;
|
|
98
119
|
}
|
|
99
120
|
#subscribeRuntimeUpgrades() {
|
|
100
121
|
if (this.#runtimeSubscriptionUnsub)
|
|
101
122
|
return;
|
|
102
|
-
this.
|
|
103
|
-
|
|
123
|
+
this.#runtimeSubscriptionUnsub = this.block.best(async (block) => {
|
|
124
|
+
if (!block.runtimeUpgraded)
|
|
125
|
+
return;
|
|
126
|
+
const { hash } = block;
|
|
127
|
+
// Fetch the runtime version at this block
|
|
128
|
+
const runtimeVersion = await this.#getRuntimeVersion(hash);
|
|
129
|
+
// Check if the spec version has actually changed
|
|
104
130
|
if (runtimeVersion.specVersion !== this.runtimeVersion?.specVersion) {
|
|
105
131
|
this.startRuntimeUpgrade();
|
|
106
|
-
this._runtimeVersion =
|
|
107
|
-
const newMetadata = await this.fetchMetadata(
|
|
132
|
+
this._runtimeVersion = runtimeVersion;
|
|
133
|
+
const newMetadata = await this.fetchMetadata(hash, this._runtimeVersion);
|
|
108
134
|
await this.setupMetadata(newMetadata);
|
|
109
|
-
this.emit('runtimeUpgraded', this._runtimeVersion);
|
|
135
|
+
this.emit('runtimeUpgraded', this._runtimeVersion, block);
|
|
110
136
|
this.doneRuntimeUpgrade();
|
|
111
137
|
}
|
|
112
|
-
})
|
|
113
|
-
.then((unsub) => {
|
|
114
|
-
this.#runtimeSubscriptionUnsub = unsub;
|
|
115
138
|
});
|
|
116
139
|
}
|
|
117
140
|
async #getRuntimeVersion(at) {
|
|
118
141
|
return this.toSubstrateRuntimeVersion(await this.rpc.state_getRuntimeVersion(at));
|
|
119
142
|
}
|
|
143
|
+
async setMetadata(metadata) {
|
|
144
|
+
this._metadata = metadata;
|
|
145
|
+
// Detect hasher if not provided by user
|
|
146
|
+
// Here we assume that hasher method of a chain is less likely to be changed via runtime upgrades
|
|
147
|
+
// So for now, we only need to detect it in initial connection and reuse it later
|
|
148
|
+
if (!this.#hasher && !this.options.hasher) {
|
|
149
|
+
// Try metadata first
|
|
150
|
+
this.#hasher = detectHasherFromMetadata(metadata);
|
|
151
|
+
// Fallback to block header detection
|
|
152
|
+
if (!this.#hasher) {
|
|
153
|
+
try {
|
|
154
|
+
const hash = await this.rpc.chain_getFinalizedHead();
|
|
155
|
+
const header = await this.rpc.chain_getHeader(hash);
|
|
156
|
+
if (header) {
|
|
157
|
+
this.#hasher = detectHasherFromHeader(header, hash);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// Ignore errors in fallback detection
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
this._registry = new PortableRegistry(metadata.latest, this.#hasher || this.options.hasher);
|
|
166
|
+
}
|
|
120
167
|
#subscribeHealth() {
|
|
121
168
|
this.#unsubscribeHealth();
|
|
122
169
|
this.#healthTimer = setInterval(() => {
|
|
123
|
-
this.rpc.system_health().catch(
|
|
170
|
+
this.rpc.system_health().catch(noop);
|
|
124
171
|
}, KEEP_ALIVE_INTERVAL);
|
|
125
172
|
}
|
|
126
173
|
#unsubscribeHealth() {
|
|
@@ -135,16 +182,23 @@ export class LegacyClient// prettier-end-here
|
|
|
135
182
|
return;
|
|
136
183
|
}
|
|
137
184
|
try {
|
|
138
|
-
|
|
185
|
+
this.#runtimeSubscriptionUnsub();
|
|
139
186
|
this.#runtimeSubscriptionUnsub = undefined;
|
|
140
187
|
}
|
|
141
188
|
catch {
|
|
142
189
|
// ignore
|
|
143
190
|
}
|
|
144
191
|
}
|
|
192
|
+
#subscribeStalingDetection() {
|
|
193
|
+
const stalingDetectionFn = this.getStalingDetectionFn();
|
|
194
|
+
if (!stalingDetectionFn)
|
|
195
|
+
return;
|
|
196
|
+
this.block.best(stalingDetectionFn);
|
|
197
|
+
}
|
|
145
198
|
#subscribeUpdates() {
|
|
146
199
|
this.#subscribeRuntimeUpgrades();
|
|
147
200
|
this.#subscribeHealth();
|
|
201
|
+
this.#subscribeStalingDetection();
|
|
148
202
|
}
|
|
149
203
|
async #unsubscribeUpdates() {
|
|
150
204
|
await this.#unsubscribeRuntimeUpdates();
|
|
@@ -221,6 +275,22 @@ export class LegacyClient// prettier-end-here
|
|
|
221
275
|
get tx() {
|
|
222
276
|
return newProxyChain({ executor: new TxExecutor(this) });
|
|
223
277
|
}
|
|
278
|
+
get block() {
|
|
279
|
+
return ensurePresence(this._blockExplorer);
|
|
280
|
+
}
|
|
281
|
+
get chainSpec() {
|
|
282
|
+
return {
|
|
283
|
+
chainName: () => {
|
|
284
|
+
return this.rpc.system_chain();
|
|
285
|
+
},
|
|
286
|
+
genesisHash: () => {
|
|
287
|
+
return Promise.resolve(this.genesisHash);
|
|
288
|
+
},
|
|
289
|
+
properties: () => {
|
|
290
|
+
return this.rpc.system_properties();
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
}
|
|
224
294
|
/**
|
|
225
295
|
* Create a new API instance at a specific block hash
|
|
226
296
|
* This is useful when we want to inspect the state of the chain at a specific block hash
|
|
@@ -243,7 +313,7 @@ export class LegacyClient// prettier-end-here
|
|
|
243
313
|
}
|
|
244
314
|
else {
|
|
245
315
|
metadata = await this.fetchMetadata(parentHash, targetVersion);
|
|
246
|
-
registry = new PortableRegistry(metadata.latest, this.options.hasher);
|
|
316
|
+
registry = new PortableRegistry(metadata.latest, this.#hasher || this.options.hasher);
|
|
247
317
|
}
|
|
248
318
|
}
|
|
249
319
|
const api = {
|
|
@@ -281,4 +351,10 @@ export class LegacyClient// prettier-end-here
|
|
|
281
351
|
return header.parentHash;
|
|
282
352
|
}
|
|
283
353
|
}
|
|
354
|
+
sendTx(tx, callback) {
|
|
355
|
+
return SubmittableExtrinsic.fromTx(this, tx) // --
|
|
356
|
+
.send((result) => {
|
|
357
|
+
callback && callback(result);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
284
360
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { BlockHash, type Extrinsic, Metadata } from '@dedot/codecs';
|
|
2
|
+
import type { JsonRpcProvider } from '@dedot/providers';
|
|
3
|
+
import { Callback, GenericSubstrateApi, TxUnsub } from '@dedot/types';
|
|
4
|
+
import { HexString } from '@dedot/utils';
|
|
5
|
+
import type { SubstrateApi } from '../chaintypes/index.js';
|
|
6
|
+
import { Archive, ChainHead, ChainSpec, PinnedBlock } from '../json-rpc/index.js';
|
|
7
|
+
import { BaseStorageQuery } from '../storage/index.js';
|
|
8
|
+
import type { ApiOptions, BlockExplorer, DedotClientEvent, ISubstrateClientAt, TxBroadcaster } from '../types.js';
|
|
9
|
+
import { BaseSubstrateClient } from './BaseSubstrateClient.js';
|
|
10
|
+
/**
|
|
11
|
+
* @name V2Client
|
|
12
|
+
* @description New promised-based API Client for Polkadot & Substrate based on JSON-RPC V2
|
|
13
|
+
*
|
|
14
|
+
* __Unstable, use with caution.__
|
|
15
|
+
*/
|
|
16
|
+
export declare class V2Client<ChainApi extends GenericSubstrateApi = SubstrateApi>// prettier-end-here
|
|
17
|
+
extends BaseSubstrateClient<ChainApi, DedotClientEvent> {
|
|
18
|
+
#private;
|
|
19
|
+
protected _chainHead?: ChainHead;
|
|
20
|
+
protected _chainSpec?: ChainSpec;
|
|
21
|
+
protected _archive?: Archive;
|
|
22
|
+
protected _txBroadcaster?: TxBroadcaster;
|
|
23
|
+
protected _blockExplorer?: BlockExplorer;
|
|
24
|
+
/**
|
|
25
|
+
* Use factory methods (`create`, `new`) to create `V2Client` instances.
|
|
26
|
+
*
|
|
27
|
+
* @param options
|
|
28
|
+
*/
|
|
29
|
+
constructor(options: ApiOptions | JsonRpcProvider);
|
|
30
|
+
/**
|
|
31
|
+
* Factory method to create a new V2Client instance
|
|
32
|
+
*
|
|
33
|
+
* @param options
|
|
34
|
+
*/
|
|
35
|
+
static create<ChainApi extends GenericSubstrateApi = SubstrateApi>(options: ApiOptions | JsonRpcProvider): Promise<V2Client<ChainApi>>;
|
|
36
|
+
/**
|
|
37
|
+
* Alias for __V2Client.create__
|
|
38
|
+
*
|
|
39
|
+
* @param options
|
|
40
|
+
*/
|
|
41
|
+
static new<ChainApi extends GenericSubstrateApi = SubstrateApi>(options: ApiOptions | JsonRpcProvider): Promise<V2Client<ChainApi>>;
|
|
42
|
+
get chainSpec(): ChainSpec;
|
|
43
|
+
get chainHead(): ChainHead;
|
|
44
|
+
get archive(): Archive | undefined;
|
|
45
|
+
get txBroadcaster(): TxBroadcaster;
|
|
46
|
+
/**
|
|
47
|
+
* Initialize APIs before usage
|
|
48
|
+
*/
|
|
49
|
+
protected doInitialize(): Promise<void>;
|
|
50
|
+
protected subscribeRuntimeUpgrades(): void;
|
|
51
|
+
protected onRuntimeUpgrade: (block: PinnedBlock) => Promise<void>;
|
|
52
|
+
protected setMetadata(metadata: Metadata): Promise<void>;
|
|
53
|
+
protected beforeDisconnect(): Promise<void>;
|
|
54
|
+
protected cleanUp(): void;
|
|
55
|
+
/**
|
|
56
|
+
* @description Clear local cache, API at-block cache, and ChainHead cache
|
|
57
|
+
* @param keepMetadataCache Keep the metadata cache, only clear other caches.
|
|
58
|
+
*/
|
|
59
|
+
clearCache(keepMetadataCache?: boolean): Promise<void>;
|
|
60
|
+
get query(): ChainApi['query'];
|
|
61
|
+
get view(): ChainApi['view'];
|
|
62
|
+
get call(): ChainApi['call'];
|
|
63
|
+
protected callAt(blockHash?: BlockHash): ChainApi['call'];
|
|
64
|
+
get tx(): ChainApi['tx'];
|
|
65
|
+
get block(): BlockExplorer;
|
|
66
|
+
/**
|
|
67
|
+
* Get a new API instance at a specific block hash
|
|
68
|
+
* Supports both pinned blocks (via ChainHead) and historical blocks (via Archive fallback)
|
|
69
|
+
*
|
|
70
|
+
* @param hash
|
|
71
|
+
*/
|
|
72
|
+
at<ChainApiAt extends GenericSubstrateApi = ChainApi>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
|
|
73
|
+
protected getStorageQuery(): BaseStorageQuery;
|
|
74
|
+
sendTx(tx: HexString | Extrinsic, callback?: Callback): TxUnsub;
|
|
75
|
+
}
|