@dedot/api 0.18.3 → 0.18.5
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/cjs/client/BaseSubstrateClient.js +16 -0
- package/cjs/client/DedotClient.js +9 -2
- package/cjs/client/LegacyClient.js +9 -2
- package/cjs/extrinsic/submittable/BaseSubmittableExtrinsic.js +5 -1
- package/client/BaseSubstrateClient.d.ts +6 -0
- package/client/BaseSubstrateClient.js +16 -0
- package/client/DedotClient.js +9 -2
- package/client/LegacyClient.js +9 -2
- package/extrinsic/submittable/BaseSubmittableExtrinsic.js +5 -1
- package/package.json +9 -9
|
@@ -159,11 +159,27 @@ class BaseSubstrateClient extends index_js_2.JsonRpcClient {
|
|
|
159
159
|
return codecs_1.$Metadata.tryDecode(this.options.metadata[key]);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Find metadata from cached API instances by specVersion
|
|
164
|
+
* This allows reusing metadata from previously created API instances
|
|
165
|
+
* instead of downloading it again from the network
|
|
166
|
+
*/
|
|
167
|
+
findMetadataInCache(specVersion) {
|
|
168
|
+
const entries = this._apiAtCache.entries();
|
|
169
|
+
for (const [_, apiInstance] of entries) {
|
|
170
|
+
const api = apiInstance;
|
|
171
|
+
if (api?.runtimeVersion?.specVersion === specVersion) {
|
|
172
|
+
return [api.metadata, api.registry];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
162
177
|
async fetchMetadata(hash, runtime) {
|
|
163
178
|
// First try finding metadata from the provided option
|
|
164
179
|
const optionMetadata = this.getMetadataFromOptions(runtime);
|
|
165
180
|
if (optionMetadata)
|
|
166
181
|
return optionMetadata;
|
|
182
|
+
// Last resort: download metadata from the network
|
|
167
183
|
// If there is no runtime, we assume that the node supports Metadata Api V2
|
|
168
184
|
const supportedV2 = runtime ? runtime.apis[MetadataApiHash] === 2 : true;
|
|
169
185
|
if (supportedV2) {
|
|
@@ -234,8 +234,15 @@ class DedotClient// prettier-end-here
|
|
|
234
234
|
let metadata = this.metadata;
|
|
235
235
|
let registry = this.registry;
|
|
236
236
|
if (parentVersion && parentVersion.specVersion !== this.runtimeVersion.specVersion) {
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
const cachedMetadata = this.findMetadataInCache(parentVersion.specVersion);
|
|
238
|
+
if (cachedMetadata) {
|
|
239
|
+
metadata = cachedMetadata[0];
|
|
240
|
+
registry = cachedMetadata[1];
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
metadata = await this.fetchMetadata(parentHash, parentVersion);
|
|
244
|
+
registry = new codecs_1.PortableRegistry(metadata.latest, this.options.hasher);
|
|
245
|
+
}
|
|
239
246
|
}
|
|
240
247
|
const api = {
|
|
241
248
|
rpcVersion: 'v2',
|
|
@@ -239,8 +239,15 @@ class LegacyClient// prettier-end-here
|
|
|
239
239
|
let metadata = this.metadata;
|
|
240
240
|
let registry = this.registry;
|
|
241
241
|
if (targetVersion.specVersion !== this.runtimeVersion.specVersion) {
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
const cachedMetadata = this.findMetadataInCache(targetVersion.specVersion);
|
|
243
|
+
if (cachedMetadata) {
|
|
244
|
+
metadata = cachedMetadata[0];
|
|
245
|
+
registry = cachedMetadata[1];
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
metadata = await this.fetchMetadata(parentHash, targetVersion);
|
|
249
|
+
registry = new codecs_1.PortableRegistry(metadata.latest, this.options.hasher);
|
|
250
|
+
}
|
|
244
251
|
}
|
|
245
252
|
const api = {
|
|
246
253
|
rpcVersion: 'legacy',
|
|
@@ -96,7 +96,11 @@ class BaseSubmittableExtrinsic extends codecs_1.Extrinsic {
|
|
|
96
96
|
deferFinalized()?.reject(e);
|
|
97
97
|
});
|
|
98
98
|
})
|
|
99
|
-
.catch(
|
|
99
|
+
.catch((e) => {
|
|
100
|
+
deferBestChainBlockIncluded()?.reject(e);
|
|
101
|
+
deferFinalized()?.reject(e);
|
|
102
|
+
deferTx.reject(e);
|
|
103
|
+
});
|
|
100
104
|
return deferTx.promise;
|
|
101
105
|
}
|
|
102
106
|
#normalizeOptions(partialOptions, callback) {
|
|
@@ -35,6 +35,12 @@ export declare abstract class BaseSubstrateClient<Rv extends RpcVersion, ChainAp
|
|
|
35
35
|
get currentMetadataKey(): string;
|
|
36
36
|
protected shouldPreloadMetadata(): Promise<boolean>;
|
|
37
37
|
protected getMetadataFromOptions(runtime?: SubstrateRuntimeVersion): Metadata | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Find metadata from cached API instances by specVersion
|
|
40
|
+
* This allows reusing metadata from previously created API instances
|
|
41
|
+
* instead of downloading it again from the network
|
|
42
|
+
*/
|
|
43
|
+
protected findMetadataInCache(specVersion: number): [Metadata, PortableRegistry] | undefined;
|
|
38
44
|
protected fetchMetadata(hash?: BlockHash, runtime?: SubstrateRuntimeVersion): Promise<Metadata>;
|
|
39
45
|
protected cleanUp(): void;
|
|
40
46
|
/**
|
|
@@ -155,11 +155,27 @@ export class BaseSubstrateClient extends JsonRpcClient {
|
|
|
155
155
|
return $Metadata.tryDecode(this.options.metadata[key]);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Find metadata from cached API instances by specVersion
|
|
160
|
+
* This allows reusing metadata from previously created API instances
|
|
161
|
+
* instead of downloading it again from the network
|
|
162
|
+
*/
|
|
163
|
+
findMetadataInCache(specVersion) {
|
|
164
|
+
const entries = this._apiAtCache.entries();
|
|
165
|
+
for (const [_, apiInstance] of entries) {
|
|
166
|
+
const api = apiInstance;
|
|
167
|
+
if (api?.runtimeVersion?.specVersion === specVersion) {
|
|
168
|
+
return [api.metadata, api.registry];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
158
173
|
async fetchMetadata(hash, runtime) {
|
|
159
174
|
// First try finding metadata from the provided option
|
|
160
175
|
const optionMetadata = this.getMetadataFromOptions(runtime);
|
|
161
176
|
if (optionMetadata)
|
|
162
177
|
return optionMetadata;
|
|
178
|
+
// Last resort: download metadata from the network
|
|
163
179
|
// If there is no runtime, we assume that the node supports Metadata Api V2
|
|
164
180
|
const supportedV2 = runtime ? runtime.apis[MetadataApiHash] === 2 : true;
|
|
165
181
|
if (supportedV2) {
|
package/client/DedotClient.js
CHANGED
|
@@ -231,8 +231,15 @@ export class DedotClient// prettier-end-here
|
|
|
231
231
|
let metadata = this.metadata;
|
|
232
232
|
let registry = this.registry;
|
|
233
233
|
if (parentVersion && parentVersion.specVersion !== this.runtimeVersion.specVersion) {
|
|
234
|
-
|
|
235
|
-
|
|
234
|
+
const cachedMetadata = this.findMetadataInCache(parentVersion.specVersion);
|
|
235
|
+
if (cachedMetadata) {
|
|
236
|
+
metadata = cachedMetadata[0];
|
|
237
|
+
registry = cachedMetadata[1];
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
metadata = await this.fetchMetadata(parentHash, parentVersion);
|
|
241
|
+
registry = new PortableRegistry(metadata.latest, this.options.hasher);
|
|
242
|
+
}
|
|
236
243
|
}
|
|
237
244
|
const api = {
|
|
238
245
|
rpcVersion: 'v2',
|
package/client/LegacyClient.js
CHANGED
|
@@ -236,8 +236,15 @@ export class LegacyClient// prettier-end-here
|
|
|
236
236
|
let metadata = this.metadata;
|
|
237
237
|
let registry = this.registry;
|
|
238
238
|
if (targetVersion.specVersion !== this.runtimeVersion.specVersion) {
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
const cachedMetadata = this.findMetadataInCache(targetVersion.specVersion);
|
|
240
|
+
if (cachedMetadata) {
|
|
241
|
+
metadata = cachedMetadata[0];
|
|
242
|
+
registry = cachedMetadata[1];
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
metadata = await this.fetchMetadata(parentHash, targetVersion);
|
|
246
|
+
registry = new PortableRegistry(metadata.latest, this.options.hasher);
|
|
247
|
+
}
|
|
241
248
|
}
|
|
242
249
|
const api = {
|
|
243
250
|
rpcVersion: 'legacy',
|
|
@@ -93,7 +93,11 @@ export class BaseSubmittableExtrinsic extends Extrinsic {
|
|
|
93
93
|
deferFinalized()?.reject(e);
|
|
94
94
|
});
|
|
95
95
|
})
|
|
96
|
-
.catch(
|
|
96
|
+
.catch((e) => {
|
|
97
|
+
deferBestChainBlockIncluded()?.reject(e);
|
|
98
|
+
deferFinalized()?.reject(e);
|
|
99
|
+
deferTx.reject(e);
|
|
100
|
+
});
|
|
97
101
|
return deferTx.promise;
|
|
98
102
|
}
|
|
99
103
|
#normalizeOptions(partialOptions, callback) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/api",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.5",
|
|
4
4
|
"description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
|
|
5
5
|
"author": "Thang X. Vu <thang@dedot.dev>",
|
|
6
6
|
"homepage": "https://dedot.dev",
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@dedot/codecs": "0.18.
|
|
17
|
-
"@dedot/providers": "0.18.
|
|
18
|
-
"@dedot/runtime-specs": "0.18.
|
|
19
|
-
"@dedot/shape": "0.18.
|
|
20
|
-
"@dedot/storage": "0.18.
|
|
21
|
-
"@dedot/types": "0.18.
|
|
22
|
-
"@dedot/utils": "0.18.
|
|
16
|
+
"@dedot/codecs": "0.18.5",
|
|
17
|
+
"@dedot/providers": "0.18.5",
|
|
18
|
+
"@dedot/runtime-specs": "0.18.5",
|
|
19
|
+
"@dedot/shape": "0.18.5",
|
|
20
|
+
"@dedot/storage": "0.18.5",
|
|
21
|
+
"@dedot/types": "0.18.5",
|
|
22
|
+
"@dedot/utils": "0.18.5"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsc --project tsconfig.build.json && tsc --project tsconfig.build.cjs.json",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"node": ">=18"
|
|
49
49
|
},
|
|
50
50
|
"license": "Apache-2.0",
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "54b0dcfddfc775009eacd1858441b1b2b12b9cae",
|
|
52
52
|
"module": "./index.js",
|
|
53
53
|
"types": "./index.d.ts"
|
|
54
54
|
}
|