@dedot/api 0.0.1-alpha.32
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/LICENSE +201 -0
- package/README.md +1 -0
- package/chaintypes/index.d.ts +1 -0
- package/chaintypes/index.js +1 -0
- package/chaintypes/substrate/consts.d.ts +2132 -0
- package/chaintypes/substrate/consts.js +2 -0
- package/chaintypes/substrate/errors.d.ts +3490 -0
- package/chaintypes/substrate/errors.js +2 -0
- package/chaintypes/substrate/events.d.ts +5187 -0
- package/chaintypes/substrate/events.js +2 -0
- package/chaintypes/substrate/index.d.ts +22 -0
- package/chaintypes/substrate/index.js +2 -0
- package/chaintypes/substrate/json-rpc.d.ts +3 -0
- package/chaintypes/substrate/json-rpc.js +2 -0
- package/chaintypes/substrate/query.d.ts +3829 -0
- package/chaintypes/substrate/query.js +2 -0
- package/chaintypes/substrate/runtime.d.ts +850 -0
- package/chaintypes/substrate/runtime.js +2 -0
- package/chaintypes/substrate/tx.d.ts +14269 -0
- package/chaintypes/substrate/tx.js +2 -0
- package/chaintypes/substrate/types.d.ts +30457 -0
- package/chaintypes/substrate/types.js +2 -0
- package/cjs/chaintypes/index.js +17 -0
- package/cjs/chaintypes/substrate/consts.js +3 -0
- package/cjs/chaintypes/substrate/errors.js +3 -0
- package/cjs/chaintypes/substrate/events.js +3 -0
- package/cjs/chaintypes/substrate/index.js +18 -0
- package/cjs/chaintypes/substrate/json-rpc.js +3 -0
- package/cjs/chaintypes/substrate/query.js +3 -0
- package/cjs/chaintypes/substrate/runtime.js +3 -0
- package/cjs/chaintypes/substrate/tx.js +3 -0
- package/cjs/chaintypes/substrate/types.js +3 -0
- package/cjs/client/BaseSubstrateClient.js +257 -0
- package/cjs/client/Dedot.js +250 -0
- package/cjs/client/DedotClient.js +186 -0
- package/cjs/client/index.js +18 -0
- package/cjs/executor/ConstantExecutor.js +20 -0
- package/cjs/executor/ErrorExecutor.js +46 -0
- package/cjs/executor/EventExecutor.js +52 -0
- package/cjs/executor/Executor.js +42 -0
- package/cjs/executor/RuntimeApiExecutor.js +121 -0
- package/cjs/executor/StorageQueryExecutor.js +115 -0
- package/cjs/executor/TxExecutor.js +55 -0
- package/cjs/executor/index.js +26 -0
- package/cjs/executor/v2/RuntimeApiExecutorV2.js +21 -0
- package/cjs/executor/v2/StorageQueryExecutorV2.js +65 -0
- package/cjs/executor/v2/TxExecutorV2.js +20 -0
- package/cjs/extrinsic/extensions/ExtraSignedExtension.js +87 -0
- package/cjs/extrinsic/extensions/SignedExtension.js +41 -0
- package/cjs/extrinsic/extensions/index.js +19 -0
- package/cjs/extrinsic/extensions/known/ChargeAssetTxPayment.js +43 -0
- package/cjs/extrinsic/extensions/known/ChargeTransactionPayment.js +16 -0
- package/cjs/extrinsic/extensions/known/CheckGenesis.js +19 -0
- package/cjs/extrinsic/extensions/known/CheckMortality.js +90 -0
- package/cjs/extrinsic/extensions/known/CheckNonZeroSender.js +10 -0
- package/cjs/extrinsic/extensions/known/CheckNonce.js +33 -0
- package/cjs/extrinsic/extensions/known/CheckSpecVersion.js +19 -0
- package/cjs/extrinsic/extensions/known/CheckTxVersion.js +19 -0
- package/cjs/extrinsic/extensions/known/CheckWeight.js +10 -0
- package/cjs/extrinsic/extensions/known/PrevalidateAttests.js +11 -0
- package/cjs/extrinsic/extensions/known/index.js +25 -0
- package/cjs/extrinsic/index.js +18 -0
- package/cjs/extrinsic/submittable/BaseSubmittableExtrinsic.js +70 -0
- package/cjs/extrinsic/submittable/SubmittableExtrinsic.js +47 -0
- package/cjs/extrinsic/submittable/SubmittableExtrinsicV2.js +204 -0
- package/cjs/extrinsic/submittable/SubmittableResult.js +33 -0
- package/cjs/extrinsic/submittable/errors.js +16 -0
- package/cjs/extrinsic/submittable/fakeSigner.js +13 -0
- package/cjs/extrinsic/submittable/index.js +20 -0
- package/cjs/extrinsic/submittable/utils.js +20 -0
- package/cjs/index.js +21 -0
- package/cjs/json-rpc/JsonRpcClient.js +165 -0
- package/cjs/json-rpc/group/ChainHead/BlockUsage.js +24 -0
- package/cjs/json-rpc/group/ChainHead/ChainHead.js +603 -0
- package/cjs/json-rpc/group/ChainHead/error.js +59 -0
- package/cjs/json-rpc/group/ChainHead/index.js +18 -0
- package/cjs/json-rpc/group/ChainSpec.js +19 -0
- package/cjs/json-rpc/group/JsonRpcGroup.js +89 -0
- package/cjs/json-rpc/group/Transaction.js +25 -0
- package/cjs/json-rpc/group/TransactionWatch.js +17 -0
- package/cjs/json-rpc/group/index.js +21 -0
- package/cjs/json-rpc/index.js +20 -0
- package/cjs/json-rpc/scaledResponses.js +15 -0
- package/cjs/json-rpc/subscriptionsInfo.js +20 -0
- package/cjs/package.json +1 -0
- package/cjs/proxychain.js +27 -0
- package/cjs/storage/QueryableStorage.js +161 -0
- package/cjs/storage/index.js +17 -0
- package/cjs/types.js +2 -0
- package/client/BaseSubstrateClient.d.ts +65 -0
- package/client/BaseSubstrateClient.js +252 -0
- package/client/Dedot.d.ts +131 -0
- package/client/Dedot.js +246 -0
- package/client/DedotClient.d.ts +61 -0
- package/client/DedotClient.js +182 -0
- package/client/index.d.ts +2 -0
- package/client/index.js +2 -0
- package/executor/ConstantExecutor.d.ts +10 -0
- package/executor/ConstantExecutor.js +16 -0
- package/executor/ErrorExecutor.d.ts +10 -0
- package/executor/ErrorExecutor.js +42 -0
- package/executor/EventExecutor.d.ts +10 -0
- package/executor/EventExecutor.js +48 -0
- package/executor/Executor.d.ts +149 -0
- package/executor/Executor.js +38 -0
- package/executor/RuntimeApiExecutor.d.ts +27 -0
- package/executor/RuntimeApiExecutor.js +117 -0
- package/executor/StorageQueryExecutor.d.ts +14 -0
- package/executor/StorageQueryExecutor.js +111 -0
- package/executor/TxExecutor.d.ts +10 -0
- package/executor/TxExecutor.js +51 -0
- package/executor/index.d.ts +10 -0
- package/executor/index.js +10 -0
- package/executor/v2/RuntimeApiExecutorV2.d.ts +14 -0
- package/executor/v2/RuntimeApiExecutorV2.js +17 -0
- package/executor/v2/StorageQueryExecutorV2.d.ts +17 -0
- package/executor/v2/StorageQueryExecutorV2.js +61 -0
- package/executor/v2/TxExecutorV2.d.ts +11 -0
- package/executor/v2/TxExecutorV2.js +16 -0
- package/extrinsic/extensions/ExtraSignedExtension.d.ts +14 -0
- package/extrinsic/extensions/ExtraSignedExtension.js +60 -0
- package/extrinsic/extensions/SignedExtension.d.ts +40 -0
- package/extrinsic/extensions/SignedExtension.js +37 -0
- package/extrinsic/extensions/index.d.ts +3 -0
- package/extrinsic/extensions/index.js +3 -0
- package/extrinsic/extensions/known/ChargeAssetTxPayment.d.ts +14 -0
- package/extrinsic/extensions/known/ChargeAssetTxPayment.js +39 -0
- package/extrinsic/extensions/known/ChargeTransactionPayment.d.ts +6 -0
- package/extrinsic/extensions/known/ChargeTransactionPayment.js +12 -0
- package/extrinsic/extensions/known/CheckGenesis.d.ts +10 -0
- package/extrinsic/extensions/known/CheckGenesis.js +15 -0
- package/extrinsic/extensions/known/CheckMortality.d.ts +15 -0
- package/extrinsic/extensions/known/CheckMortality.js +86 -0
- package/extrinsic/extensions/known/CheckNonZeroSender.d.ts +6 -0
- package/extrinsic/extensions/known/CheckNonZeroSender.js +6 -0
- package/extrinsic/extensions/known/CheckNonce.d.ts +10 -0
- package/extrinsic/extensions/known/CheckNonce.js +29 -0
- package/extrinsic/extensions/known/CheckSpecVersion.d.ts +9 -0
- package/extrinsic/extensions/known/CheckSpecVersion.js +15 -0
- package/extrinsic/extensions/known/CheckTxVersion.d.ts +9 -0
- package/extrinsic/extensions/known/CheckTxVersion.js +15 -0
- package/extrinsic/extensions/known/CheckWeight.d.ts +6 -0
- package/extrinsic/extensions/known/CheckWeight.js +6 -0
- package/extrinsic/extensions/known/PrevalidateAttests.d.ts +7 -0
- package/extrinsic/extensions/known/PrevalidateAttests.js +7 -0
- package/extrinsic/extensions/known/index.d.ts +3 -0
- package/extrinsic/extensions/known/index.js +22 -0
- package/extrinsic/index.d.ts +2 -0
- package/extrinsic/index.js +2 -0
- package/extrinsic/submittable/BaseSubmittableExtrinsic.d.ts +17 -0
- package/extrinsic/submittable/BaseSubmittableExtrinsic.js +66 -0
- package/extrinsic/submittable/SubmittableExtrinsic.d.ts +12 -0
- package/extrinsic/submittable/SubmittableExtrinsic.js +43 -0
- package/extrinsic/submittable/SubmittableExtrinsicV2.d.ts +15 -0
- package/extrinsic/submittable/SubmittableExtrinsicV2.js +200 -0
- package/extrinsic/submittable/SubmittableResult.d.ts +19 -0
- package/extrinsic/submittable/SubmittableResult.js +29 -0
- package/extrinsic/submittable/errors.d.ts +11 -0
- package/extrinsic/submittable/errors.js +12 -0
- package/extrinsic/submittable/fakeSigner.d.ts +2 -0
- package/extrinsic/submittable/fakeSigner.js +10 -0
- package/extrinsic/submittable/index.d.ts +4 -0
- package/extrinsic/submittable/index.js +4 -0
- package/extrinsic/submittable/utils.d.ts +10 -0
- package/extrinsic/submittable/utils.js +15 -0
- package/index.d.ts +6 -0
- package/index.js +5 -0
- package/json-rpc/JsonRpcClient.d.ts +50 -0
- package/json-rpc/JsonRpcClient.js +160 -0
- package/json-rpc/group/ChainHead/BlockUsage.d.ts +11 -0
- package/json-rpc/group/ChainHead/BlockUsage.js +20 -0
- package/json-rpc/group/ChainHead/ChainHead.d.ts +70 -0
- package/json-rpc/group/ChainHead/ChainHead.js +599 -0
- package/json-rpc/group/ChainHead/error.d.ts +47 -0
- package/json-rpc/group/ChainHead/error.js +48 -0
- package/json-rpc/group/ChainHead/index.d.ts +2 -0
- package/json-rpc/group/ChainHead/index.js +2 -0
- package/json-rpc/group/ChainSpec.d.ts +10 -0
- package/json-rpc/group/ChainSpec.js +15 -0
- package/json-rpc/group/JsonRpcGroup.d.ts +74 -0
- package/json-rpc/group/JsonRpcGroup.js +85 -0
- package/json-rpc/group/Transaction.d.ts +11 -0
- package/json-rpc/group/Transaction.js +21 -0
- package/json-rpc/group/TransactionWatch.d.ts +10 -0
- package/json-rpc/group/TransactionWatch.js +13 -0
- package/json-rpc/group/index.d.ts +5 -0
- package/json-rpc/group/index.js +5 -0
- package/json-rpc/index.d.ts +4 -0
- package/json-rpc/index.js +4 -0
- package/json-rpc/scaledResponses.d.ts +2 -0
- package/json-rpc/scaledResponses.js +12 -0
- package/json-rpc/subscriptionsInfo.d.ts +2 -0
- package/json-rpc/subscriptionsInfo.js +17 -0
- package/package.json +54 -0
- package/proxychain.d.ts +14 -0
- package/proxychain.js +23 -0
- package/storage/QueryableStorage.d.ts +35 -0
- package/storage/QueryableStorage.js +157 -0
- package/storage/index.d.ts +1 -0
- package/storage/index.js +1 -0
- package/types.d.ts +120 -0
- package/types.js +1 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChainSpec = void 0;
|
|
4
|
+
const JsonRpcGroup_js_1 = require("./JsonRpcGroup.js");
|
|
5
|
+
class ChainSpec extends JsonRpcGroup_js_1.JsonRpcGroup {
|
|
6
|
+
constructor(client, options) {
|
|
7
|
+
super(client, { prefix: 'chainSpec', supportedVersions: ['unstable', 'v1'], ...options });
|
|
8
|
+
}
|
|
9
|
+
async chainName() {
|
|
10
|
+
return this.send('chainName');
|
|
11
|
+
}
|
|
12
|
+
async genesisHash() {
|
|
13
|
+
return this.send('genesisHash');
|
|
14
|
+
}
|
|
15
|
+
async properties() {
|
|
16
|
+
return this.send('properties');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.ChainSpec = ChainSpec;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonRpcGroup = void 0;
|
|
4
|
+
const utils_1 = require("@dedot/utils");
|
|
5
|
+
/**
|
|
6
|
+
* @name JsonRpcGroup
|
|
7
|
+
* A group of json-rpc methods with a common prefix.
|
|
8
|
+
*
|
|
9
|
+
* JSON-RPC V2: https://paritytech.github.io/json-rpc-interface-spec/grouping-functions-and-node-capabilities.html#grouping-functions-and-node-capabilities
|
|
10
|
+
*/
|
|
11
|
+
class JsonRpcGroup extends utils_1.EventEmitter {
|
|
12
|
+
client;
|
|
13
|
+
options;
|
|
14
|
+
#detectedVersion;
|
|
15
|
+
constructor(client, options) {
|
|
16
|
+
super();
|
|
17
|
+
this.client = client;
|
|
18
|
+
this.options = options;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Check if the group is supported by the connected JSON-RPC server.
|
|
22
|
+
*/
|
|
23
|
+
async supported() {
|
|
24
|
+
try {
|
|
25
|
+
const detectedVersion = await this.#detectVersion();
|
|
26
|
+
const { supportedVersions } = this.options;
|
|
27
|
+
// if there aren't any specific supported versions, then any detected version is supported
|
|
28
|
+
if (!supportedVersions || supportedVersions.length === 0)
|
|
29
|
+
return true;
|
|
30
|
+
return supportedVersions.includes(detectedVersion);
|
|
31
|
+
}
|
|
32
|
+
catch { }
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Send a json-rpc request, note the method should not contain the prefix and version parts.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const client = await JsonRpcClient.new('wss://rpc.polkadot.io');
|
|
41
|
+
* const achieve = new JsonRpcGroup(client, { prefix: 'archive', supportedVersions: ['unstable'] });
|
|
42
|
+
*
|
|
43
|
+
* const finalizedHeight = await achieve.send<number>('finalizedHeight'); // sending archive_unstable_finalizedHeight
|
|
44
|
+
* console.log(finalizedHeight);
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @param method
|
|
48
|
+
* @param params
|
|
49
|
+
*/
|
|
50
|
+
async send(method, ...params) {
|
|
51
|
+
const rpcMethod = `${this.prefix}_${await this.version()}_${method}`;
|
|
52
|
+
return this.client.rpc[rpcMethod](...params);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The prefix of the group
|
|
56
|
+
*/
|
|
57
|
+
get prefix() {
|
|
58
|
+
return this.options.prefix;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Detect & return the version of the group.
|
|
62
|
+
* This will be used to construct the json-rpc method name.
|
|
63
|
+
*/
|
|
64
|
+
async version() {
|
|
65
|
+
const { fixedVersion, supportedVersions } = this.options;
|
|
66
|
+
if (fixedVersion)
|
|
67
|
+
return fixedVersion;
|
|
68
|
+
const detectedVersion = await this.#detectVersion();
|
|
69
|
+
if (supportedVersions && supportedVersions.length > 0 && !supportedVersions.includes(detectedVersion)) {
|
|
70
|
+
throw new Error(`Detected version ${detectedVersion} is not supported`);
|
|
71
|
+
}
|
|
72
|
+
return detectedVersion;
|
|
73
|
+
}
|
|
74
|
+
async #detectVersion() {
|
|
75
|
+
if (!this.#detectedVersion) {
|
|
76
|
+
this.#detectedVersion = await this.#doDetectVersion();
|
|
77
|
+
}
|
|
78
|
+
return this.#detectedVersion;
|
|
79
|
+
}
|
|
80
|
+
async #doDetectVersion() {
|
|
81
|
+
const rpcMethods = this.options.rpcMethods || (await this.client.rpc.rpc_methods()).methods;
|
|
82
|
+
const prefixedMethods = rpcMethods.filter((method) => method.startsWith(`${this.prefix}_`));
|
|
83
|
+
if (prefixedMethods.length === 0) {
|
|
84
|
+
throw new Error(`No methods found with prefix ${this.prefix}`);
|
|
85
|
+
}
|
|
86
|
+
return prefixedMethods[0].split('_')[1];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.JsonRpcGroup = JsonRpcGroup;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Transaction = void 0;
|
|
4
|
+
const utils_1 = require("@dedot/utils");
|
|
5
|
+
const JsonRpcGroup_js_1 = require("./JsonRpcGroup.js");
|
|
6
|
+
class Transaction extends JsonRpcGroup_js_1.JsonRpcGroup {
|
|
7
|
+
constructor(client, options) {
|
|
8
|
+
super(client, { prefix: 'transaction', supportedVersions: ['unstable', 'v1'], ...options });
|
|
9
|
+
}
|
|
10
|
+
async broadcastTx(tx) {
|
|
11
|
+
const operationId = await this.broadcast(tx);
|
|
12
|
+
return () => {
|
|
13
|
+
return this.stop(operationId);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
async broadcast(tx) {
|
|
17
|
+
const operationId = await this.send('broadcast', tx);
|
|
18
|
+
(0, utils_1.assert)(operationId, 'Maximum number of broadcasted transactions has been reached');
|
|
19
|
+
return operationId;
|
|
20
|
+
}
|
|
21
|
+
stop(operationId) {
|
|
22
|
+
return this.send('stop', operationId);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Transaction = Transaction;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionWatch = void 0;
|
|
4
|
+
const utils_1 = require("@dedot/utils");
|
|
5
|
+
const JsonRpcGroup_js_1 = require("./JsonRpcGroup.js");
|
|
6
|
+
class TransactionWatch extends JsonRpcGroup_js_1.JsonRpcGroup {
|
|
7
|
+
constructor(client, options) {
|
|
8
|
+
super(client, { prefix: 'transactionWatch', supportedVersions: ['unstable'], ...options });
|
|
9
|
+
}
|
|
10
|
+
broadcastTx(tx) {
|
|
11
|
+
return this.submitAndWatch(tx, utils_1.noop);
|
|
12
|
+
}
|
|
13
|
+
async submitAndWatch(tx, callback) {
|
|
14
|
+
return this.send('submitAndWatch', tx, callback);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.TransactionWatch = TransactionWatch;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./JsonRpcGroup.js"), exports);
|
|
18
|
+
__exportStar(require("./ChainSpec.js"), exports);
|
|
19
|
+
__exportStar(require("./Transaction.js"), exports);
|
|
20
|
+
__exportStar(require("./TransactionWatch.js"), exports);
|
|
21
|
+
__exportStar(require("./ChainHead/index.js"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./subscriptionsInfo.js"), exports);
|
|
18
|
+
__exportStar(require("./scaledResponses.js"), exports);
|
|
19
|
+
__exportStar(require("./JsonRpcClient.js"), exports);
|
|
20
|
+
__exportStar(require("./group/index.js"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.scaledResponses = void 0;
|
|
4
|
+
const codecs_1 = require("@dedot/codecs");
|
|
5
|
+
exports.scaledResponses = {
|
|
6
|
+
system_dryRun: codecs_1.$ApplyExtrinsicResult,
|
|
7
|
+
state_getMetadata: codecs_1.$Metadata,
|
|
8
|
+
chain_getHeader: codecs_1.$Header,
|
|
9
|
+
chain_getBlock: codecs_1.$SignedBlock,
|
|
10
|
+
chain_subscribeAllHeads: codecs_1.$Header,
|
|
11
|
+
chain_subscribeNewHeads: codecs_1.$Header,
|
|
12
|
+
chain_subscribeFinalizedHeads: codecs_1.$Header,
|
|
13
|
+
author_submitAndWatchExtrinsic: codecs_1.$TransactionStatus,
|
|
14
|
+
beefy_subscribeJustifications: codecs_1.$VersionedFinalityProof,
|
|
15
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subscriptionsInfo = void 0;
|
|
4
|
+
exports.subscriptionsInfo = {
|
|
5
|
+
author_submitAndWatchExtrinsic: ['author_extrinsicUpdate', 'author_unwatchExtrinsic'],
|
|
6
|
+
state_subscribeRuntimeVersion: ['state_runtimeVersion', 'state_unsubscribeRuntimeVersion'],
|
|
7
|
+
state_subscribeStorage: ['state_storage', 'state_unsubscribeStorage'],
|
|
8
|
+
chain_subscribeAllHeads: ['chain_allHead', 'chain_unsubscribeAllHeads'],
|
|
9
|
+
chain_subscribeNewHeads: ['chain_newHead', 'chain_unsubscribeNewHeads'],
|
|
10
|
+
chain_subscribeFinalizedHeads: ['chain_finalizedHead', 'chain_unsubscribeFinalizedHeads'],
|
|
11
|
+
grandpa_subscribeJustifications: ['grandpa_justifications', 'grandpa_unsubscribeJustifications'],
|
|
12
|
+
beefy_subscribeJustifications: ['beefy_justifications', 'beefy_unsubscribeJustifications'],
|
|
13
|
+
chainHead_unstable_follow: ['chainHead_unstable_followEvent', 'chainHead_unstable_unfollow'],
|
|
14
|
+
chainHead_v1_follow: ['chainHead_v1_followEvent', 'chainHead_v1_unfollow'],
|
|
15
|
+
transactionWatch_unstable_submitAndWatch: [
|
|
16
|
+
'transactionWatch_unstable_watchEvent',
|
|
17
|
+
'transactionWatch_unstable_unwatch',
|
|
18
|
+
],
|
|
19
|
+
transactionWatch_v1_submitAndWatch: ['transactionWatch_v1_watchEvent', 'transactionWatch_v1_unwatch'],
|
|
20
|
+
};
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newProxyChain = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Create a chain of proxy objects
|
|
6
|
+
*
|
|
7
|
+
* @param carrier
|
|
8
|
+
* @param currentLevel
|
|
9
|
+
* @param maxLevel
|
|
10
|
+
*/
|
|
11
|
+
const newProxyChain = (carrier, currentLevel = 1, maxLevel = 3) => {
|
|
12
|
+
const { executor, chain = [] } = carrier;
|
|
13
|
+
if (currentLevel === maxLevel) {
|
|
14
|
+
return executor.execute(...chain);
|
|
15
|
+
}
|
|
16
|
+
return new Proxy(carrier, {
|
|
17
|
+
get(target, property, receiver) {
|
|
18
|
+
if (!target.chain) {
|
|
19
|
+
target.chain = [];
|
|
20
|
+
}
|
|
21
|
+
const { chain } = target;
|
|
22
|
+
chain.push(property.toString());
|
|
23
|
+
return (0, exports.newProxyChain)(target, currentLevel + 1, maxLevel);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
exports.newProxyChain = newProxyChain;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryableStorage = void 0;
|
|
4
|
+
const codecs_1 = require("@dedot/codecs");
|
|
5
|
+
const utils_1 = require("@dedot/utils");
|
|
6
|
+
const utils_2 = require("@dedot/utils");
|
|
7
|
+
// https://github.com/polkadot-js/api/blob/0982f68507942c5bf6f751f662804344e211b289/packages/types/src/primitive/StorageKey.ts#L29-L38
|
|
8
|
+
const HASHER_INFO = {
|
|
9
|
+
blake2_128: [16, false],
|
|
10
|
+
blake2_256: [32, false],
|
|
11
|
+
blake2_128Concat: [16, true],
|
|
12
|
+
twox128: [16, false],
|
|
13
|
+
twox256: [32, false],
|
|
14
|
+
twox64Concat: [8, true],
|
|
15
|
+
identity: [0, true],
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @name QueryableStorage
|
|
19
|
+
* @description A helper to encode key & decode value for a storage entry
|
|
20
|
+
*/
|
|
21
|
+
class QueryableStorage {
|
|
22
|
+
registry;
|
|
23
|
+
palletName;
|
|
24
|
+
storageItem;
|
|
25
|
+
pallet;
|
|
26
|
+
storageEntry;
|
|
27
|
+
constructor(registry, palletName, storageItem) {
|
|
28
|
+
this.registry = registry;
|
|
29
|
+
this.palletName = palletName;
|
|
30
|
+
this.storageItem = storageItem;
|
|
31
|
+
this.pallet = this.#getPallet();
|
|
32
|
+
this.storageEntry = this.#getStorageEntry();
|
|
33
|
+
}
|
|
34
|
+
get prefixKey() {
|
|
35
|
+
return (0, utils_2.u8aToHex)(this.prefixKeyAsU8a);
|
|
36
|
+
}
|
|
37
|
+
get prefixKeyAsU8a() {
|
|
38
|
+
const palletNameHash = (0, utils_2.xxhashAsU8a)(this.pallet.name, 128);
|
|
39
|
+
const storageItemHash = (0, utils_2.xxhashAsU8a)(this.storageEntry.name, 128);
|
|
40
|
+
return (0, utils_2.concatU8a)(palletNameHash, storageItemHash);
|
|
41
|
+
}
|
|
42
|
+
#getStorageMapInfo(type) {
|
|
43
|
+
(0, utils_1.assert)(type.tag === 'Map');
|
|
44
|
+
const { hashers, keyTypeId } = type.value;
|
|
45
|
+
let keyTypeIds = [keyTypeId];
|
|
46
|
+
if (hashers.length > 1) {
|
|
47
|
+
const { type } = this.registry.findType(keyTypeId);
|
|
48
|
+
(0, utils_1.assert)(type.tag === 'Tuple', 'Key type should be a tuple!');
|
|
49
|
+
keyTypeIds = type.value.fields;
|
|
50
|
+
}
|
|
51
|
+
return { hashers, keyTypeIds };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Encode plain key input to raw/bytes storage key
|
|
55
|
+
*
|
|
56
|
+
* @param keyInput
|
|
57
|
+
*/
|
|
58
|
+
encodeKey(keyInput) {
|
|
59
|
+
const { type } = this.storageEntry;
|
|
60
|
+
if (type.tag === 'Plain') {
|
|
61
|
+
return this.prefixKey;
|
|
62
|
+
}
|
|
63
|
+
else if (type.tag === 'Map') {
|
|
64
|
+
const { hashers, keyTypeIds } = this.#getStorageMapInfo(type);
|
|
65
|
+
const extractedInputs = this.#extractRequiredKeyInputs(keyInput, hashers.length);
|
|
66
|
+
const keyParts = keyTypeIds.map((keyId, index) => {
|
|
67
|
+
const input = extractedInputs[index];
|
|
68
|
+
const hasher = utils_1.HASHERS[hashers[index]];
|
|
69
|
+
const $keyCodec = this.registry.findCodec(keyId);
|
|
70
|
+
return hasher($keyCodec.tryEncode(input));
|
|
71
|
+
});
|
|
72
|
+
return (0, utils_2.u8aToHex)((0, utils_2.concatU8a)(this.prefixKeyAsU8a, ...keyParts));
|
|
73
|
+
}
|
|
74
|
+
throw Error(`Invalid storage entry type: ${type}`);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Decode storage key to plain key input
|
|
78
|
+
* Only storage keys that hashed by `twox64Concat`, `blake2_128Concat`, or `identity` can be decoded
|
|
79
|
+
*
|
|
80
|
+
* @param key
|
|
81
|
+
*/
|
|
82
|
+
decodeKey(key) {
|
|
83
|
+
const { type } = this.storageEntry;
|
|
84
|
+
if (type.tag === 'Plain') {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
else if (type.tag === 'Map') {
|
|
88
|
+
const prefix = this.prefixKey;
|
|
89
|
+
if (!key.startsWith(prefix)) {
|
|
90
|
+
throw new Error(`Storage key does not match this storage entry (${this.palletName}.${this.storageItem})`);
|
|
91
|
+
}
|
|
92
|
+
const { hashers, keyTypeIds } = this.#getStorageMapInfo(type);
|
|
93
|
+
let keyData = (0, utils_2.hexToU8a)((0, utils_1.hexAddPrefix)(key.slice(prefix.length)));
|
|
94
|
+
const results = keyTypeIds.map((keyId, index) => {
|
|
95
|
+
const [hashLen, canDecode] = HASHER_INFO[hashers[index]];
|
|
96
|
+
if (!canDecode)
|
|
97
|
+
throw new Error('Cannot decode storage key');
|
|
98
|
+
const $keyCodec = this.registry.findCodec(keyId);
|
|
99
|
+
keyData = keyData.slice(hashLen);
|
|
100
|
+
const result = $keyCodec.tryDecode(keyData);
|
|
101
|
+
const encoded = $keyCodec.tryEncode(result);
|
|
102
|
+
keyData = keyData.slice(encoded.length);
|
|
103
|
+
return result;
|
|
104
|
+
});
|
|
105
|
+
return hashers.length > 1 ? results : results[0];
|
|
106
|
+
}
|
|
107
|
+
throw Error(`Invalid storage entry type: ${type}`);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Decode raw/bytes storage data to plain value
|
|
111
|
+
*
|
|
112
|
+
* @param raw
|
|
113
|
+
*/
|
|
114
|
+
decodeValue(raw) {
|
|
115
|
+
const { modifier, type: { value: { valueTypeId }, }, default: defaultValue, } = this.storageEntry;
|
|
116
|
+
if (raw === null || raw === undefined) {
|
|
117
|
+
if (modifier === 'Optional') {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
else if (modifier === 'Default') {
|
|
121
|
+
return this.registry.findCodec(valueTypeId).tryDecode((0, utils_2.hexToU8a)(defaultValue));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
return this.registry.findCodec(valueTypeId).tryDecode(codecs_1.$StorageData.tryEncode(raw));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
#extractRequiredKeyInputs(keyInput, numberOfValue) {
|
|
129
|
+
if (numberOfValue === 0) {
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
if (keyInput === undefined) {
|
|
134
|
+
throw new Error(`Invalid key inputs, required ${numberOfValue} input(s)`);
|
|
135
|
+
}
|
|
136
|
+
if (numberOfValue === 1) {
|
|
137
|
+
return [keyInput];
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
if (!Array.isArray(keyInput)) {
|
|
141
|
+
throw new Error(`Input should be an array with ${numberOfValue} value(s)`);
|
|
142
|
+
}
|
|
143
|
+
if (keyInput.length !== numberOfValue) {
|
|
144
|
+
throw new Error(`Mismatch key inputs length, required an array of ${numberOfValue} value(s)`);
|
|
145
|
+
}
|
|
146
|
+
return keyInput.slice(0, numberOfValue);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
#getPallet() {
|
|
151
|
+
const targetPallet = this.registry.metadata.pallets.find((p) => (0, utils_2.stringCamelCase)(p.name) === (0, utils_2.stringCamelCase)(this.palletName));
|
|
152
|
+
(0, utils_1.assert)(targetPallet, new utils_1.UnknownApiError(`Pallet not found: ${this.palletName}`));
|
|
153
|
+
return targetPallet;
|
|
154
|
+
}
|
|
155
|
+
#getStorageEntry() {
|
|
156
|
+
const targetEntry = this.pallet.storage?.entries?.find((entry) => (0, utils_2.stringCamelCase)(entry.name) === (0, utils_2.stringCamelCase)(this.storageItem));
|
|
157
|
+
(0, utils_1.assert)(targetEntry, new utils_1.UnknownApiError(`Storage item not found: ${this.storageItem}`));
|
|
158
|
+
return targetEntry;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.QueryableStorage = QueryableStorage;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./QueryableStorage.js"), exports);
|
package/cjs/types.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { BlockHash, Hash, Metadata, PortableRegistry, RuntimeVersion } from '@dedot/codecs';
|
|
2
|
+
import type { JsonRpcProvider } from '@dedot/providers';
|
|
3
|
+
import { type IStorage } from '@dedot/storage';
|
|
4
|
+
import { GenericSubstrateApi, RpcVersion, VersionedGenericSubstrateApi } from '@dedot/types';
|
|
5
|
+
import type { SubstrateApi } from '../chaintypes/index.js';
|
|
6
|
+
import { JsonRpcClient } from '../json-rpc/index.js';
|
|
7
|
+
import type { ApiEvent, ApiOptions, ISubstrateClient, ISubstrateClientAt, JsonRpcClientOptions, MetadataKey, SubstrateRuntimeVersion } from '../types.js';
|
|
8
|
+
export declare function ensurePresence<T>(value: T): NonNullable<T>;
|
|
9
|
+
/**
|
|
10
|
+
* @name BaseSubstrateClient
|
|
11
|
+
* @description Base & shared abstraction for Substrate API Clients
|
|
12
|
+
*/
|
|
13
|
+
export declare abstract class BaseSubstrateClient<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> extends JsonRpcClient<ChainApi[RpcVersion], ApiEvent> implements ISubstrateClient<ChainApi[RpcVersion]> {
|
|
14
|
+
rpcVersion: RpcVersion;
|
|
15
|
+
protected _options: ApiOptions;
|
|
16
|
+
protected _registry?: PortableRegistry;
|
|
17
|
+
protected _metadata?: Metadata;
|
|
18
|
+
protected _genesisHash?: Hash;
|
|
19
|
+
protected _runtimeVersion?: SubstrateRuntimeVersion;
|
|
20
|
+
protected _localCache?: IStorage;
|
|
21
|
+
protected constructor(rpcVersion: RpcVersion, options: JsonRpcClientOptions | JsonRpcProvider);
|
|
22
|
+
protected normalizeOptions(options: ApiOptions | JsonRpcProvider): ApiOptions;
|
|
23
|
+
protected initializeLocalCache(): Promise<void>;
|
|
24
|
+
protected setupMetadata(preloadMetadata: Metadata | undefined): Promise<void>;
|
|
25
|
+
protected setMetadata(metadata: Metadata): void;
|
|
26
|
+
protected getMetadataKey(runtime?: SubstrateRuntimeVersion): MetadataKey;
|
|
27
|
+
get currentMetadataKey(): string;
|
|
28
|
+
protected shouldPreloadMetadata(): Promise<boolean>;
|
|
29
|
+
protected getMetadataFromOptions(runtime?: SubstrateRuntimeVersion): Metadata | undefined;
|
|
30
|
+
protected fetchMetadata(hash?: BlockHash, runtime?: SubstrateRuntimeVersion): Promise<Metadata>;
|
|
31
|
+
protected cleanUp(): void;
|
|
32
|
+
/**
|
|
33
|
+
* @description Clear local cache
|
|
34
|
+
*/
|
|
35
|
+
clearCache(): Promise<void>;
|
|
36
|
+
protected doConnect(): Promise<this>;
|
|
37
|
+
protected onConnected: () => Promise<void>;
|
|
38
|
+
protected onDisconnected: () => Promise<void>;
|
|
39
|
+
protected initialize(): Promise<void>;
|
|
40
|
+
protected doInitialize(): Promise<void>;
|
|
41
|
+
protected beforeDisconnect(): Promise<void>;
|
|
42
|
+
protected afterDisconnect(): Promise<void>;
|
|
43
|
+
protected toSubstrateRuntimeVersion(runtimeVersion: RuntimeVersion): SubstrateRuntimeVersion;
|
|
44
|
+
/**
|
|
45
|
+
* @description Connect to blockchain node
|
|
46
|
+
*/
|
|
47
|
+
connect(): Promise<this>;
|
|
48
|
+
/**
|
|
49
|
+
* @description Disconnect to blockchain node
|
|
50
|
+
*/
|
|
51
|
+
disconnect(): Promise<void>;
|
|
52
|
+
get options(): ApiOptions;
|
|
53
|
+
get metadata(): Metadata;
|
|
54
|
+
get registry(): PortableRegistry;
|
|
55
|
+
get genesisHash(): Hash;
|
|
56
|
+
get runtimeVersion(): SubstrateRuntimeVersion;
|
|
57
|
+
get consts(): ChainApi[RpcVersion]['consts'];
|
|
58
|
+
get errors(): ChainApi[RpcVersion]['errors'];
|
|
59
|
+
get events(): ChainApi[RpcVersion]['events'];
|
|
60
|
+
get query(): ChainApi[RpcVersion]['query'];
|
|
61
|
+
get call(): ChainApi[RpcVersion]['call'];
|
|
62
|
+
protected callAt(hash?: BlockHash): ChainApi[RpcVersion]['call'];
|
|
63
|
+
get tx(): ChainApi[RpcVersion]['tx'];
|
|
64
|
+
at<ChainApiAt extends GenericSubstrateApi = ChainApi[RpcVersion]>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
|
|
65
|
+
}
|