@dedot/api 0.4.1 → 0.5.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.js +1 -0
- package/chaintypes/substrate/errors.js +1 -0
- package/chaintypes/substrate/events.js +1 -0
- package/chaintypes/substrate/index.d.ts +4 -0
- package/chaintypes/substrate/index.js +1 -0
- package/chaintypes/substrate/json-rpc.js +1 -0
- package/chaintypes/substrate/query.js +1 -0
- package/chaintypes/substrate/runtime.js +1 -0
- package/chaintypes/substrate/tx.js +1 -0
- package/chaintypes/substrate/types.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/executor/Executor.js +6 -6
- package/cjs/executor/RuntimeApiExecutor.js +3 -3
- package/cjs/executor/StorageQueryExecutor.js +3 -3
- package/cjs/executor/TxExecutor.js +1 -1
- package/cjs/executor/v2/RuntimeApiExecutorV2.js +3 -3
- package/cjs/executor/v2/StorageQueryExecutorV2.js +3 -3
- package/cjs/executor/v2/TxExecutorV2.js +1 -1
- package/cjs/extrinsic/extensions/ExtraSignedExtension.js +2 -2
- package/cjs/extrinsic/extensions/SignedExtension.js +4 -4
- package/cjs/extrinsic/extensions/known/CheckGenesis.js +1 -1
- package/cjs/extrinsic/extensions/known/CheckMortality.js +8 -8
- package/cjs/extrinsic/extensions/known/CheckNonce.js +2 -2
- package/cjs/extrinsic/extensions/known/CheckSpecVersion.js +1 -1
- package/cjs/extrinsic/extensions/known/CheckTxVersion.js +1 -1
- package/cjs/extrinsic/submittable/BaseSubmittableExtrinsic.js +8 -8
- package/cjs/extrinsic/submittable/SubmittableExtrinsic.js +4 -4
- package/cjs/extrinsic/submittable/SubmittableExtrinsicV2.js +6 -6
- package/cjs/extrinsic/submittable/errors.js +1 -0
- package/cjs/json-rpc/group/ChainHead/error.js +8 -0
- package/executor/Executor.d.ts +2 -2
- package/executor/Executor.js +6 -6
- package/executor/RuntimeApiExecutor.js +3 -3
- package/executor/StorageQueryExecutor.js +3 -3
- package/executor/TxExecutor.js +1 -1
- package/executor/v2/RuntimeApiExecutorV2.d.ts +1 -1
- package/executor/v2/RuntimeApiExecutorV2.js +3 -3
- package/executor/v2/StorageQueryExecutorV2.d.ts +1 -1
- package/executor/v2/StorageQueryExecutorV2.js +3 -3
- package/executor/v2/TxExecutorV2.js +1 -1
- package/extrinsic/extensions/ExtraSignedExtension.js +2 -2
- package/extrinsic/extensions/SignedExtension.d.ts +3 -3
- package/extrinsic/extensions/SignedExtension.js +4 -4
- package/extrinsic/extensions/known/CheckGenesis.js +1 -1
- package/extrinsic/extensions/known/CheckMortality.js +8 -8
- package/extrinsic/extensions/known/CheckNonce.js +2 -2
- package/extrinsic/extensions/known/CheckSpecVersion.js +1 -1
- package/extrinsic/extensions/known/CheckTxVersion.js +1 -1
- package/extrinsic/submittable/BaseSubmittableExtrinsic.d.ts +2 -2
- package/extrinsic/submittable/BaseSubmittableExtrinsic.js +8 -8
- package/extrinsic/submittable/SubmittableExtrinsic.js +4 -4
- package/extrinsic/submittable/SubmittableExtrinsicV2.d.ts +2 -2
- package/extrinsic/submittable/SubmittableExtrinsicV2.js +6 -6
- package/extrinsic/submittable/errors.d.ts +1 -0
- package/extrinsic/submittable/errors.js +1 -0
- package/json-rpc/group/ChainHead/error.d.ts +8 -0
- package/json-rpc/group/ChainHead/error.js +8 -0
- package/package.json +10 -10
|
@@ -16,6 +16,10 @@ export interface VersionedSubstrateApi<Rv extends RpcVersion> extends GenericSub
|
|
|
16
16
|
call: RuntimeApis<Rv>;
|
|
17
17
|
tx: ChainTx<Rv>;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* @name: SubstrateApi
|
|
21
|
+
* @specVersion: 268
|
|
22
|
+
**/
|
|
19
23
|
export interface SubstrateApi {
|
|
20
24
|
legacy: VersionedSubstrateApi<RpcLegacy>;
|
|
21
25
|
v2: VersionedSubstrateApi<RpcV2>;
|
package/cjs/executor/Executor.js
CHANGED
|
@@ -7,17 +7,17 @@ const utils_1 = require("@dedot/utils");
|
|
|
7
7
|
* @description Execution abstraction for a specific action
|
|
8
8
|
*/
|
|
9
9
|
class Executor {
|
|
10
|
-
|
|
10
|
+
client;
|
|
11
11
|
#atBlockHash;
|
|
12
|
-
constructor(
|
|
13
|
-
this.
|
|
12
|
+
constructor(client, atBlockHash) {
|
|
13
|
+
this.client = client;
|
|
14
14
|
this.#atBlockHash = atBlockHash;
|
|
15
15
|
}
|
|
16
16
|
get atBlockHash() {
|
|
17
|
-
return this.#atBlockHash || this.
|
|
17
|
+
return this.#atBlockHash || this.client.atBlockHash;
|
|
18
18
|
}
|
|
19
19
|
get registry() {
|
|
20
|
-
return this.
|
|
20
|
+
return this.client.registry;
|
|
21
21
|
}
|
|
22
22
|
get metadata() {
|
|
23
23
|
return this.registry.metadata;
|
|
@@ -32,7 +32,7 @@ class Executor {
|
|
|
32
32
|
return this.doExecute(...paths);
|
|
33
33
|
}
|
|
34
34
|
catch (e) {
|
|
35
|
-
if (!this.
|
|
35
|
+
if (!this.client.options?.throwOnUnknownApi && e instanceof utils_1.UnknownApiError) {
|
|
36
36
|
return undefined;
|
|
37
37
|
}
|
|
38
38
|
throw e;
|
|
@@ -40,7 +40,7 @@ class RuntimeApiExecutor extends Executor_js_1.Executor {
|
|
|
40
40
|
const args = [func, params];
|
|
41
41
|
if (at)
|
|
42
42
|
args.push(at);
|
|
43
|
-
return this.
|
|
43
|
+
return this.client.rpc.state_call(...args);
|
|
44
44
|
}
|
|
45
45
|
tryDecode(callSpec, raw) {
|
|
46
46
|
const $codec = this.#findCodec(callSpec, `Codec not found to decode respond data for ${this.#callName(callSpec)}`);
|
|
@@ -66,7 +66,7 @@ class RuntimeApiExecutor extends Executor_js_1.Executor {
|
|
|
66
66
|
const targetVersion = this.#findTargetRuntimeApiVersion(runtimeApi);
|
|
67
67
|
if (!(0, utils_1.isNumber)(targetVersion))
|
|
68
68
|
return undefined;
|
|
69
|
-
const userDefinedSpec = this.#findDefinedSpec(this.
|
|
69
|
+
const userDefinedSpec = this.#findDefinedSpec(this.client.options.runtimeApis, runtimeApi, method, targetVersion);
|
|
70
70
|
if (userDefinedSpec)
|
|
71
71
|
return userDefinedSpec;
|
|
72
72
|
const methodDef = this.#findRuntimeApiMethodDef(runtimeApi, method);
|
|
@@ -104,7 +104,7 @@ class RuntimeApiExecutor extends Executor_js_1.Executor {
|
|
|
104
104
|
#findTargetRuntimeApiVersion(runtimeApi) {
|
|
105
105
|
const runtimeApiHash = (0, utils_1.calcRuntimeApiHash)(runtimeApi);
|
|
106
106
|
try {
|
|
107
|
-
return this.
|
|
107
|
+
return this.client.runtimeVersion.apis[runtimeApiHash] || exports.FallbackRuntimeApis[runtimeApiHash];
|
|
108
108
|
}
|
|
109
109
|
catch {
|
|
110
110
|
return exports.FallbackRuntimeApis[runtimeApiHash];
|
|
@@ -80,7 +80,7 @@ class StorageQueryExecutor extends Executor_js_1.Executor {
|
|
|
80
80
|
const rawKeys = async (pagination) => {
|
|
81
81
|
const pageSize = pagination?.pageSize || DEFAULT_KEYS_PAGE_SIZE;
|
|
82
82
|
const startKey = pagination?.startKey || entry.prefixKey;
|
|
83
|
-
return await this.
|
|
83
|
+
return await this.client.rpc.state_getKeysPaged(entry.prefixKey, pageSize, startKey, this.atBlockHash);
|
|
84
84
|
};
|
|
85
85
|
const pagedKeys = async (pagination) => {
|
|
86
86
|
const storageKeys = await rawKeys({ pageSize: DEFAULT_KEYS_PAGE_SIZE, ...pagination });
|
|
@@ -94,7 +94,7 @@ class StorageQueryExecutor extends Executor_js_1.Executor {
|
|
|
94
94
|
return { pagedKeys, pagedEntries };
|
|
95
95
|
}
|
|
96
96
|
async queryStorage(keys, hash) {
|
|
97
|
-
const changeSets = await this.
|
|
97
|
+
const changeSets = await this.client.rpc.state_queryStorageAt(keys, hash);
|
|
98
98
|
return changeSets[0].changes.reduce((o, [key, value]) => {
|
|
99
99
|
o[key] = value ?? undefined;
|
|
100
100
|
return o;
|
|
@@ -102,7 +102,7 @@ class StorageQueryExecutor extends Executor_js_1.Executor {
|
|
|
102
102
|
}
|
|
103
103
|
subscribeStorage(keys, callback) {
|
|
104
104
|
const lastChanges = {};
|
|
105
|
-
return this.
|
|
105
|
+
return this.client.rpc.state_subscribeStorage(keys, (changeSet) => {
|
|
106
106
|
changeSet.changes.forEach(([key, value]) => {
|
|
107
107
|
if (lastChanges[key] !== value) {
|
|
108
108
|
lastChanges[key] = value ?? undefined;
|
|
@@ -49,7 +49,7 @@ class TxExecutor extends Executor_js_1.Executor {
|
|
|
49
49
|
return txCallFn;
|
|
50
50
|
}
|
|
51
51
|
createExtrinsic(call) {
|
|
52
|
-
return new index_js_1.SubmittableExtrinsic(this.
|
|
52
|
+
return new index_js_1.SubmittableExtrinsic(this.client, call);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
exports.TxExecutor = TxExecutor;
|
|
@@ -8,9 +8,9 @@ const RuntimeApiExecutor_js_1 = require("../RuntimeApiExecutor.js");
|
|
|
8
8
|
*/
|
|
9
9
|
class RuntimeApiExecutorV2 extends RuntimeApiExecutor_js_1.RuntimeApiExecutor {
|
|
10
10
|
chainHead;
|
|
11
|
-
constructor(
|
|
12
|
-
(0, utils_1.assert)(
|
|
13
|
-
super(
|
|
11
|
+
constructor(client, chainHead, atBlockHash) {
|
|
12
|
+
(0, utils_1.assert)(client.rpcVersion === 'v2', 'Only supports JSON-RPC v2');
|
|
13
|
+
super(client, atBlockHash);
|
|
14
14
|
this.chainHead = chainHead;
|
|
15
15
|
}
|
|
16
16
|
stateCall(callParams) {
|
|
@@ -8,9 +8,9 @@ const StorageQueryExecutor_js_1 = require("../StorageQueryExecutor.js");
|
|
|
8
8
|
*/
|
|
9
9
|
class StorageQueryExecutorV2 extends StorageQueryExecutor_js_1.StorageQueryExecutor {
|
|
10
10
|
chainHead;
|
|
11
|
-
constructor(
|
|
12
|
-
(0, utils_1.assert)(
|
|
13
|
-
super(
|
|
11
|
+
constructor(client, chainHead, atBlockHash) {
|
|
12
|
+
(0, utils_1.assert)(client.rpcVersion === 'v2', 'Only supports JSON-RPC v2');
|
|
13
|
+
super(client, atBlockHash);
|
|
14
14
|
this.chainHead = chainHead;
|
|
15
15
|
}
|
|
16
16
|
exposeStorageMapMethods(entry) {
|
|
@@ -14,7 +14,7 @@ class TxExecutorV2 extends TxExecutor_js_1.TxExecutor {
|
|
|
14
14
|
super(api);
|
|
15
15
|
}
|
|
16
16
|
createExtrinsic(call) {
|
|
17
|
-
return new index_js_1.SubmittableExtrinsicV2(this.
|
|
17
|
+
return new index_js_1.SubmittableExtrinsicV2(this.client, call);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
exports.TxExecutorV2 = TxExecutorV2;
|
|
@@ -57,11 +57,11 @@ class ExtraSignedExtension extends SignedExtension_js_1.SignedExtension {
|
|
|
57
57
|
}
|
|
58
58
|
#getSignedExtensions() {
|
|
59
59
|
return this.#signedExtensionDefs.map((extDef) => {
|
|
60
|
-
const { signedExtensions: userSignedExtensions = {} } = this.
|
|
60
|
+
const { signedExtensions: userSignedExtensions = {} } = this.client.options;
|
|
61
61
|
const Extension = userSignedExtensions[extDef.ident] ||
|
|
62
62
|
index_js_1.knownSignedExtensions[extDef.ident];
|
|
63
63
|
(0, utils_1.assert)(Extension, `SignedExtension for ${extDef.ident} not found`);
|
|
64
|
-
return new Extension(this.
|
|
64
|
+
return new Extension(this.client, {
|
|
65
65
|
...(0, utils_1.ensurePresence)(this.options),
|
|
66
66
|
def: extDef,
|
|
67
67
|
});
|
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SignedExtension = void 0;
|
|
4
4
|
const utils_1 = require("@dedot/utils");
|
|
5
5
|
class SignedExtension {
|
|
6
|
-
|
|
6
|
+
client;
|
|
7
7
|
options;
|
|
8
8
|
data;
|
|
9
9
|
additionalSigned;
|
|
10
|
-
constructor(
|
|
11
|
-
this.
|
|
10
|
+
constructor(client, options) {
|
|
11
|
+
this.client = client;
|
|
12
12
|
this.options = options;
|
|
13
13
|
this.data = {};
|
|
14
14
|
this.additionalSigned = [];
|
|
@@ -26,7 +26,7 @@ class SignedExtension {
|
|
|
26
26
|
return (0, utils_1.ensurePresence)(this.registry.findCodec(this.signedExtensionDef.additionalSigned));
|
|
27
27
|
}
|
|
28
28
|
get registry() {
|
|
29
|
-
return this.
|
|
29
|
+
return this.client.registry;
|
|
30
30
|
}
|
|
31
31
|
get signedExtensionDef() {
|
|
32
32
|
return (0, utils_1.ensurePresence)(this.options.def);
|
|
@@ -8,7 +8,7 @@ const SignedExtension_js_1 = require("../SignedExtension.js");
|
|
|
8
8
|
*/
|
|
9
9
|
class CheckGenesis extends SignedExtension_js_1.SignedExtension {
|
|
10
10
|
async init() {
|
|
11
|
-
this.additionalSigned = (0, utils_1.ensurePresence)(this.
|
|
11
|
+
this.additionalSigned = (0, utils_1.ensurePresence)(this.client.genesisHash);
|
|
12
12
|
}
|
|
13
13
|
toPayload() {
|
|
14
14
|
return {
|
|
@@ -18,13 +18,13 @@ class CheckMortality extends SignedExtension_js_1.SignedExtension {
|
|
|
18
18
|
this.additionalSigned = this.#signingHeader.hash;
|
|
19
19
|
}
|
|
20
20
|
async #getSigningHeader() {
|
|
21
|
-
if (this.
|
|
21
|
+
if (this.client.rpcVersion === 'v2') {
|
|
22
22
|
return this.#getSigningHeaderRpcV2();
|
|
23
23
|
}
|
|
24
24
|
return this.#getSigningHeaderViaLegacyRpc();
|
|
25
25
|
}
|
|
26
26
|
async #getSigningHeaderRpcV2() {
|
|
27
|
-
const api = this.
|
|
27
|
+
const api = this.client;
|
|
28
28
|
// TODO similar to the legacy, we should account for the case finality is lagging behind
|
|
29
29
|
const finalizedBlock = await api.chainHead.finalizedBlock();
|
|
30
30
|
return {
|
|
@@ -35,8 +35,8 @@ class CheckMortality extends SignedExtension_js_1.SignedExtension {
|
|
|
35
35
|
// Ref: https://github.com/polkadot-js/api/blob/3bdf49b0428a62f16b3222b9a31bfefa43c1ca55/packages/api-derive/src/tx/signingInfo.ts#L34-L64
|
|
36
36
|
async #getSigningHeaderViaLegacyRpc() {
|
|
37
37
|
const [header, finalizedHash] = await Promise.all([
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
38
|
+
this.client.rpc.chain_getHeader(),
|
|
39
|
+
this.client.rpc.chain_getFinalizedHead(),
|
|
40
40
|
]);
|
|
41
41
|
(0, utils_1.assert)(header, 'Current header not found');
|
|
42
42
|
const [currentHeader, finalizedHeader] = await Promise.all([
|
|
@@ -46,10 +46,10 @@ class CheckMortality extends SignedExtension_js_1.SignedExtension {
|
|
|
46
46
|
return header;
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
|
-
return this.
|
|
49
|
+
return this.client.rpc.chain_getHeader(parentHash);
|
|
50
50
|
}
|
|
51
51
|
}),
|
|
52
|
-
this.
|
|
52
|
+
this.client.rpc.chain_getHeader(finalizedHash),
|
|
53
53
|
]);
|
|
54
54
|
(0, utils_1.assert)(currentHeader, 'Cannot determine current header');
|
|
55
55
|
if (!finalizedHeader || currentHeader.number - finalizedHeader.number > exports.MAX_FINALITY_LAG) {
|
|
@@ -59,7 +59,7 @@ class CheckMortality extends SignedExtension_js_1.SignedExtension {
|
|
|
59
59
|
}
|
|
60
60
|
async #toSigningHeader(header) {
|
|
61
61
|
const { number } = header;
|
|
62
|
-
const hash = (await this.
|
|
62
|
+
const hash = (await this.client.rpc.chain_getBlockHash(header.number));
|
|
63
63
|
return { hash, number };
|
|
64
64
|
}
|
|
65
65
|
// Ref: https://github.com/polkadot-js/api/blob/3bdf49b0428a62f16b3222b9a31bfefa43c1ca55/packages/api-derive/src/tx/signingInfo.ts#L83-L93
|
|
@@ -72,7 +72,7 @@ class CheckMortality extends SignedExtension_js_1.SignedExtension {
|
|
|
72
72
|
}
|
|
73
73
|
#getConst(pallet, name) {
|
|
74
74
|
try {
|
|
75
|
-
return this.
|
|
75
|
+
return this.client.consts[pallet][name];
|
|
76
76
|
}
|
|
77
77
|
catch {
|
|
78
78
|
// ignore this on purpose
|
|
@@ -14,11 +14,11 @@ class CheckNonce extends SignedExtension_js_1.SignedExtension {
|
|
|
14
14
|
const { signerAddress } = this.options || {};
|
|
15
15
|
(0, utils_1.assert)(signerAddress, 'Signer address not found');
|
|
16
16
|
try {
|
|
17
|
-
return (await this.
|
|
17
|
+
return (await this.client.query.system.account(signerAddress)).nonce;
|
|
18
18
|
}
|
|
19
19
|
catch { }
|
|
20
20
|
try {
|
|
21
|
-
return await this.
|
|
21
|
+
return await this.client.call.accountNonceApi.accountNonce(signerAddress);
|
|
22
22
|
}
|
|
23
23
|
catch { }
|
|
24
24
|
// TODO fallback to api.rpc.system_accountNextIndex if needed
|
|
@@ -8,7 +8,7 @@ const SignedExtension_js_1 = require("../SignedExtension.js");
|
|
|
8
8
|
*/
|
|
9
9
|
class CheckSpecVersion extends SignedExtension_js_1.SignedExtension {
|
|
10
10
|
async init() {
|
|
11
|
-
this.additionalSigned = this.
|
|
11
|
+
this.additionalSigned = this.client.runtimeVersion.specVersion;
|
|
12
12
|
}
|
|
13
13
|
toPayload() {
|
|
14
14
|
return {
|
|
@@ -8,7 +8,7 @@ const SignedExtension_js_1 = require("../SignedExtension.js");
|
|
|
8
8
|
*/
|
|
9
9
|
class CheckTxVersion extends SignedExtension_js_1.SignedExtension {
|
|
10
10
|
async init() {
|
|
11
|
-
this.additionalSigned = this.
|
|
11
|
+
this.additionalSigned = this.client.runtimeVersion.transactionVersion;
|
|
12
12
|
}
|
|
13
13
|
toPayload() {
|
|
14
14
|
return {
|
|
@@ -7,21 +7,21 @@ const index_js_1 = require("../extensions/index.js");
|
|
|
7
7
|
const fakeSigner_js_1 = require("./fakeSigner.js");
|
|
8
8
|
const utils_js_1 = require("./utils.js");
|
|
9
9
|
class BaseSubmittableExtrinsic extends codecs_1.Extrinsic {
|
|
10
|
-
|
|
10
|
+
client;
|
|
11
11
|
#alterTx;
|
|
12
|
-
constructor(
|
|
13
|
-
super(
|
|
14
|
-
this.
|
|
12
|
+
constructor(client, call) {
|
|
13
|
+
super(client.registry, call);
|
|
14
|
+
this.client = client;
|
|
15
15
|
}
|
|
16
16
|
async paymentInfo(account, options) {
|
|
17
17
|
await this.sign(account, { ...options, signer: fakeSigner_js_1.fakeSigner });
|
|
18
18
|
const txU8a = this.toU8a();
|
|
19
|
-
const api = this.
|
|
19
|
+
const api = this.client;
|
|
20
20
|
return api.call.transactionPaymentApi.queryInfo(txU8a, txU8a.length);
|
|
21
21
|
}
|
|
22
22
|
async sign(fromAccount, options) {
|
|
23
23
|
const address = (0, utils_js_1.isKeyringPair)(fromAccount) ? fromAccount.address : fromAccount.toString();
|
|
24
|
-
const extra = new index_js_1.ExtraSignedExtension(this.
|
|
24
|
+
const extra = new index_js_1.ExtraSignedExtension(this.client, {
|
|
25
25
|
signerAddress: address,
|
|
26
26
|
payloadOptions: options,
|
|
27
27
|
});
|
|
@@ -72,7 +72,7 @@ class BaseSubmittableExtrinsic extends codecs_1.Extrinsic {
|
|
|
72
72
|
throw new Error('Unimplemented!');
|
|
73
73
|
}
|
|
74
74
|
async getSystemEventsAt(hash) {
|
|
75
|
-
const atApi = (await this.
|
|
75
|
+
const atApi = (await this.client.at(hash));
|
|
76
76
|
return await atApi.query.system.events();
|
|
77
77
|
}
|
|
78
78
|
toHex() {
|
|
@@ -97,7 +97,7 @@ class BaseSubmittableExtrinsic extends codecs_1.Extrinsic {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
#getSigner(options) {
|
|
100
|
-
return options?.signer || this.
|
|
100
|
+
return options?.signer || this.client.options.signer;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
exports.BaseSubmittableExtrinsic = BaseSubmittableExtrinsic;
|
|
@@ -11,7 +11,7 @@ const utils_js_1 = require("./utils.js");
|
|
|
11
11
|
*/
|
|
12
12
|
class SubmittableExtrinsic extends BaseSubmittableExtrinsic_js_1.BaseSubmittableExtrinsic {
|
|
13
13
|
async dryRun(account, optionsOrHash) {
|
|
14
|
-
const dryRunFn = this.
|
|
14
|
+
const dryRunFn = this.client.rpc.system_dryRun;
|
|
15
15
|
if ((0, utils_1.isHex)(optionsOrHash)) {
|
|
16
16
|
return dryRunFn(this.toHex(), optionsOrHash);
|
|
17
17
|
}
|
|
@@ -23,11 +23,11 @@ class SubmittableExtrinsic extends BaseSubmittableExtrinsic_js_1.BaseSubmittable
|
|
|
23
23
|
const txHex = this.toHex();
|
|
24
24
|
const txHash = this.hash;
|
|
25
25
|
if (isSubscription) {
|
|
26
|
-
return this.
|
|
26
|
+
return this.client.rpc.author_submitAndWatchExtrinsic(txHex, async (txStatus) => {
|
|
27
27
|
if (txStatus.type === 'InBlock' || txStatus.type === 'Finalized') {
|
|
28
28
|
const blockHash = txStatus.value;
|
|
29
29
|
const [signedBlock, blockEvents] = await Promise.all([
|
|
30
|
-
this.
|
|
30
|
+
this.client.rpc.chain_getBlock(blockHash),
|
|
31
31
|
this.getSystemEventsAt(blockHash),
|
|
32
32
|
]);
|
|
33
33
|
const txIndex = signedBlock.block.extrinsics.indexOf(txHex);
|
|
@@ -44,7 +44,7 @@ class SubmittableExtrinsic extends BaseSubmittableExtrinsic_js_1.BaseSubmittable
|
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
|
-
return this.
|
|
47
|
+
return this.client.rpc.author_submitExtrinsic(txHex);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -10,18 +10,18 @@ const errors_js_1 = require("./errors.js");
|
|
|
10
10
|
* @description Submittable extrinsic based on JSON-RPC v2
|
|
11
11
|
*/
|
|
12
12
|
class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittableExtrinsic {
|
|
13
|
-
|
|
14
|
-
constructor(
|
|
15
|
-
super(
|
|
16
|
-
this.
|
|
13
|
+
client;
|
|
14
|
+
constructor(client, call) {
|
|
15
|
+
super(client, call);
|
|
16
|
+
this.client = client;
|
|
17
17
|
}
|
|
18
18
|
async #send(callback) {
|
|
19
|
-
const api = this.
|
|
19
|
+
const api = this.client;
|
|
20
20
|
const txHex = this.toHex();
|
|
21
21
|
const txHash = this.hash;
|
|
22
22
|
// validate the transaction
|
|
23
23
|
// https://github.com/paritytech/json-rpc-interface-spec/issues/55#issuecomment-1609011150
|
|
24
|
-
const finalizedHash = await this.
|
|
24
|
+
const finalizedHash = await this.client.chainHead.finalizedHash();
|
|
25
25
|
const validateTx = async (hash) => {
|
|
26
26
|
const apiAt = await api.at(hash);
|
|
27
27
|
return apiAt.call.taggedTransactionQueue.validateTransaction('External', txHex, hash);
|
|
@@ -8,6 +8,7 @@ var RetryStrategy;
|
|
|
8
8
|
RetryStrategy["QUEUED"] = "QUEUED";
|
|
9
9
|
})(RetryStrategy || (exports.RetryStrategy = RetryStrategy = {}));
|
|
10
10
|
class ChainHeadError extends utils_1.DedotError {
|
|
11
|
+
name = 'ChainHeadError';
|
|
11
12
|
retryStrategy;
|
|
12
13
|
}
|
|
13
14
|
exports.ChainHeadError = ChainHeadError;
|
|
@@ -17,6 +18,7 @@ exports.ChainHeadError = ChainHeadError;
|
|
|
17
18
|
* Ref: https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_v1_follow.html#operationinaccessible
|
|
18
19
|
*/
|
|
19
20
|
class ChainHeadOperationInaccessibleError extends ChainHeadError {
|
|
21
|
+
name = 'ChainHeadOperationInaccessibleError';
|
|
20
22
|
retryStrategy = RetryStrategy.NOW;
|
|
21
23
|
}
|
|
22
24
|
exports.ChainHeadOperationInaccessibleError = ChainHeadOperationInaccessibleError;
|
|
@@ -26,6 +28,7 @@ exports.ChainHeadOperationInaccessibleError = ChainHeadOperationInaccessibleErro
|
|
|
26
28
|
* Ref: https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_v1_follow.html#stop
|
|
27
29
|
*/
|
|
28
30
|
class ChainHeadStopError extends ChainHeadError {
|
|
31
|
+
name = 'ChainHeadStopError';
|
|
29
32
|
retryStrategy = RetryStrategy.QUEUED;
|
|
30
33
|
}
|
|
31
34
|
exports.ChainHeadStopError = ChainHeadStopError;
|
|
@@ -34,6 +37,7 @@ exports.ChainHeadStopError = ChainHeadStopError;
|
|
|
34
37
|
* Ref: https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_v1_follow.html#operationerror
|
|
35
38
|
*/
|
|
36
39
|
class ChainHeadOperationError extends ChainHeadError {
|
|
40
|
+
name = 'ChainHeadOperationError';
|
|
37
41
|
}
|
|
38
42
|
exports.ChainHeadOperationError = ChainHeadOperationError;
|
|
39
43
|
/**
|
|
@@ -41,6 +45,7 @@ exports.ChainHeadOperationError = ChainHeadOperationError;
|
|
|
41
45
|
* Ref: https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_v1_storage.html#limitreached
|
|
42
46
|
*/
|
|
43
47
|
class ChainHeadLimitReachedError extends ChainHeadError {
|
|
48
|
+
name = 'ChainHeadLimitReachedError';
|
|
44
49
|
retryStrategy = RetryStrategy.QUEUED;
|
|
45
50
|
}
|
|
46
51
|
exports.ChainHeadLimitReachedError = ChainHeadLimitReachedError;
|
|
@@ -49,11 +54,14 @@ exports.ChainHeadLimitReachedError = ChainHeadLimitReachedError;
|
|
|
49
54
|
* Ref: https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_v1_storage.html#limitreached
|
|
50
55
|
*/
|
|
51
56
|
class ChainHeadInvalidRuntimeError extends ChainHeadError {
|
|
57
|
+
name = 'ChainHeadInvalidRuntimeError';
|
|
52
58
|
}
|
|
53
59
|
exports.ChainHeadInvalidRuntimeError = ChainHeadInvalidRuntimeError;
|
|
54
60
|
class ChainHeadBlockNotPinnedError extends ChainHeadError {
|
|
61
|
+
name = 'ChainHeadBlockNotPinnedError';
|
|
55
62
|
}
|
|
56
63
|
exports.ChainHeadBlockNotPinnedError = ChainHeadBlockNotPinnedError;
|
|
57
64
|
class ChainHeadBlockPrunedError extends ChainHeadError {
|
|
65
|
+
name = 'ChainHeadBlockPrunedError';
|
|
58
66
|
}
|
|
59
67
|
exports.ChainHeadBlockPrunedError = ChainHeadBlockPrunedError;
|
package/executor/Executor.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ import { ISubstrateClientAt } from '../types.js';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare abstract class Executor<ChainApi extends GenericSubstrateApi = GenericSubstrateApi> {
|
|
9
9
|
#private;
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
10
|
+
readonly client: ISubstrateClientAt<ChainApi>;
|
|
11
|
+
constructor(client: ISubstrateClientAt<ChainApi>, atBlockHash?: BlockHash);
|
|
12
12
|
get atBlockHash(): `0x${string}` | undefined;
|
|
13
13
|
get registry(): import("@dedot/codecs").PortableRegistry;
|
|
14
14
|
get metadata(): {
|
package/executor/Executor.js
CHANGED
|
@@ -4,17 +4,17 @@ import { assert, stringCamelCase, UnknownApiError } from '@dedot/utils';
|
|
|
4
4
|
* @description Execution abstraction for a specific action
|
|
5
5
|
*/
|
|
6
6
|
export class Executor {
|
|
7
|
-
|
|
7
|
+
client;
|
|
8
8
|
#atBlockHash;
|
|
9
|
-
constructor(
|
|
10
|
-
this.
|
|
9
|
+
constructor(client, atBlockHash) {
|
|
10
|
+
this.client = client;
|
|
11
11
|
this.#atBlockHash = atBlockHash;
|
|
12
12
|
}
|
|
13
13
|
get atBlockHash() {
|
|
14
|
-
return this.#atBlockHash || this.
|
|
14
|
+
return this.#atBlockHash || this.client.atBlockHash;
|
|
15
15
|
}
|
|
16
16
|
get registry() {
|
|
17
|
-
return this.
|
|
17
|
+
return this.client.registry;
|
|
18
18
|
}
|
|
19
19
|
get metadata() {
|
|
20
20
|
return this.registry.metadata;
|
|
@@ -29,7 +29,7 @@ export class Executor {
|
|
|
29
29
|
return this.doExecute(...paths);
|
|
30
30
|
}
|
|
31
31
|
catch (e) {
|
|
32
|
-
if (!this.
|
|
32
|
+
if (!this.client.options?.throwOnUnknownApi && e instanceof UnknownApiError) {
|
|
33
33
|
return undefined;
|
|
34
34
|
}
|
|
35
35
|
throw e;
|
|
@@ -37,7 +37,7 @@ export class RuntimeApiExecutor extends Executor {
|
|
|
37
37
|
const args = [func, params];
|
|
38
38
|
if (at)
|
|
39
39
|
args.push(at);
|
|
40
|
-
return this.
|
|
40
|
+
return this.client.rpc.state_call(...args);
|
|
41
41
|
}
|
|
42
42
|
tryDecode(callSpec, raw) {
|
|
43
43
|
const $codec = this.#findCodec(callSpec, `Codec not found to decode respond data for ${this.#callName(callSpec)}`);
|
|
@@ -63,7 +63,7 @@ export class RuntimeApiExecutor extends Executor {
|
|
|
63
63
|
const targetVersion = this.#findTargetRuntimeApiVersion(runtimeApi);
|
|
64
64
|
if (!isNumber(targetVersion))
|
|
65
65
|
return undefined;
|
|
66
|
-
const userDefinedSpec = this.#findDefinedSpec(this.
|
|
66
|
+
const userDefinedSpec = this.#findDefinedSpec(this.client.options.runtimeApis, runtimeApi, method, targetVersion);
|
|
67
67
|
if (userDefinedSpec)
|
|
68
68
|
return userDefinedSpec;
|
|
69
69
|
const methodDef = this.#findRuntimeApiMethodDef(runtimeApi, method);
|
|
@@ -101,7 +101,7 @@ export class RuntimeApiExecutor extends Executor {
|
|
|
101
101
|
#findTargetRuntimeApiVersion(runtimeApi) {
|
|
102
102
|
const runtimeApiHash = calcRuntimeApiHash(runtimeApi);
|
|
103
103
|
try {
|
|
104
|
-
return this.
|
|
104
|
+
return this.client.runtimeVersion.apis[runtimeApiHash] || FallbackRuntimeApis[runtimeApiHash];
|
|
105
105
|
}
|
|
106
106
|
catch {
|
|
107
107
|
return FallbackRuntimeApis[runtimeApiHash];
|
|
@@ -77,7 +77,7 @@ export class StorageQueryExecutor extends Executor {
|
|
|
77
77
|
const rawKeys = async (pagination) => {
|
|
78
78
|
const pageSize = pagination?.pageSize || DEFAULT_KEYS_PAGE_SIZE;
|
|
79
79
|
const startKey = pagination?.startKey || entry.prefixKey;
|
|
80
|
-
return await this.
|
|
80
|
+
return await this.client.rpc.state_getKeysPaged(entry.prefixKey, pageSize, startKey, this.atBlockHash);
|
|
81
81
|
};
|
|
82
82
|
const pagedKeys = async (pagination) => {
|
|
83
83
|
const storageKeys = await rawKeys({ pageSize: DEFAULT_KEYS_PAGE_SIZE, ...pagination });
|
|
@@ -91,7 +91,7 @@ export class StorageQueryExecutor extends Executor {
|
|
|
91
91
|
return { pagedKeys, pagedEntries };
|
|
92
92
|
}
|
|
93
93
|
async queryStorage(keys, hash) {
|
|
94
|
-
const changeSets = await this.
|
|
94
|
+
const changeSets = await this.client.rpc.state_queryStorageAt(keys, hash);
|
|
95
95
|
return changeSets[0].changes.reduce((o, [key, value]) => {
|
|
96
96
|
o[key] = value ?? undefined;
|
|
97
97
|
return o;
|
|
@@ -99,7 +99,7 @@ export class StorageQueryExecutor extends Executor {
|
|
|
99
99
|
}
|
|
100
100
|
subscribeStorage(keys, callback) {
|
|
101
101
|
const lastChanges = {};
|
|
102
|
-
return this.
|
|
102
|
+
return this.client.rpc.state_subscribeStorage(keys, (changeSet) => {
|
|
103
103
|
changeSet.changes.forEach(([key, value]) => {
|
|
104
104
|
if (lastChanges[key] !== value) {
|
|
105
105
|
lastChanges[key] = value ?? undefined;
|
package/executor/TxExecutor.js
CHANGED
|
@@ -9,6 +9,6 @@ import { RuntimeApiExecutor, StateCallParams } from '../RuntimeApiExecutor.js';
|
|
|
9
9
|
*/
|
|
10
10
|
export declare class RuntimeApiExecutorV2<ChainApi extends GenericSubstrateApi = GenericSubstrateApi> extends RuntimeApiExecutor<ChainApi> {
|
|
11
11
|
chainHead: ChainHead;
|
|
12
|
-
constructor(
|
|
12
|
+
constructor(client: ISubstrateClientAt<ChainApi>, chainHead: ChainHead, atBlockHash?: BlockHash);
|
|
13
13
|
protected stateCall(callParams: StateCallParams): Promise<HexString>;
|
|
14
14
|
}
|
|
@@ -5,9 +5,9 @@ import { RuntimeApiExecutor } from '../RuntimeApiExecutor.js';
|
|
|
5
5
|
*/
|
|
6
6
|
export class RuntimeApiExecutorV2 extends RuntimeApiExecutor {
|
|
7
7
|
chainHead;
|
|
8
|
-
constructor(
|
|
9
|
-
assert(
|
|
10
|
-
super(
|
|
8
|
+
constructor(client, chainHead, atBlockHash) {
|
|
9
|
+
assert(client.rpcVersion === 'v2', 'Only supports JSON-RPC v2');
|
|
10
|
+
super(client, atBlockHash);
|
|
11
11
|
this.chainHead = chainHead;
|
|
12
12
|
}
|
|
13
13
|
stateCall(callParams) {
|
|
@@ -10,7 +10,7 @@ import { StorageQueryExecutor } from '../StorageQueryExecutor.js';
|
|
|
10
10
|
*/
|
|
11
11
|
export declare class StorageQueryExecutorV2<ChainApi extends GenericSubstrateApi = GenericSubstrateApi> extends StorageQueryExecutor<ChainApi> {
|
|
12
12
|
chainHead: ChainHead;
|
|
13
|
-
constructor(
|
|
13
|
+
constructor(client: ISubstrateClientAt<ChainApi>, chainHead: ChainHead, atBlockHash?: BlockHash);
|
|
14
14
|
protected exposeStorageMapMethods(entry: QueryableStorage): Record<string, AsyncMethod>;
|
|
15
15
|
protected queryStorage(keys: StorageKey[], at?: BlockHash): Promise<Record<StorageKey, Option<StorageData>>>;
|
|
16
16
|
protected subscribeStorage(keys: HexString[], callback: Callback<Array<StorageData | undefined>>): Promise<() => Promise<void>>;
|
|
@@ -5,9 +5,9 @@ import { StorageQueryExecutor } from '../StorageQueryExecutor.js';
|
|
|
5
5
|
*/
|
|
6
6
|
export class StorageQueryExecutorV2 extends StorageQueryExecutor {
|
|
7
7
|
chainHead;
|
|
8
|
-
constructor(
|
|
9
|
-
assert(
|
|
10
|
-
super(
|
|
8
|
+
constructor(client, chainHead, atBlockHash) {
|
|
9
|
+
assert(client.rpcVersion === 'v2', 'Only supports JSON-RPC v2');
|
|
10
|
+
super(client, atBlockHash);
|
|
11
11
|
this.chainHead = chainHead;
|
|
12
12
|
}
|
|
13
13
|
exposeStorageMapMethods(entry) {
|
|
@@ -31,11 +31,11 @@ export class ExtraSignedExtension extends SignedExtension {
|
|
|
31
31
|
}
|
|
32
32
|
#getSignedExtensions() {
|
|
33
33
|
return this.#signedExtensionDefs.map((extDef) => {
|
|
34
|
-
const { signedExtensions: userSignedExtensions = {} } = this.
|
|
34
|
+
const { signedExtensions: userSignedExtensions = {} } = this.client.options;
|
|
35
35
|
const Extension = userSignedExtensions[extDef.ident] ||
|
|
36
36
|
knownSignedExtensions[extDef.ident];
|
|
37
37
|
assert(Extension, `SignedExtension for ${extDef.ident} not found`);
|
|
38
|
-
return new Extension(this.
|
|
38
|
+
return new Extension(this.client, {
|
|
39
39
|
...ensurePresence(this.options),
|
|
40
40
|
def: extDef,
|
|
41
41
|
});
|
|
@@ -19,11 +19,11 @@ interface SignedExtensionOptions {
|
|
|
19
19
|
payloadOptions?: Partial<PayloadOptions>;
|
|
20
20
|
}
|
|
21
21
|
export declare abstract class SignedExtension<Data extends any = {}, AdditionalSigned extends any = []> implements ISignedExtension {
|
|
22
|
-
|
|
23
|
-
options?: SignedExtensionOptions | undefined;
|
|
22
|
+
readonly client: ISubstrateClient;
|
|
23
|
+
readonly options?: SignedExtensionOptions | undefined;
|
|
24
24
|
data: Data;
|
|
25
25
|
additionalSigned: AdditionalSigned;
|
|
26
|
-
constructor(
|
|
26
|
+
constructor(client: ISubstrateClient, options?: SignedExtensionOptions | undefined);
|
|
27
27
|
init(): Promise<void>;
|
|
28
28
|
get identifier(): string;
|
|
29
29
|
get $Data(): $.AnyShape;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ensurePresence } from '@dedot/utils';
|
|
2
2
|
export class SignedExtension {
|
|
3
|
-
|
|
3
|
+
client;
|
|
4
4
|
options;
|
|
5
5
|
data;
|
|
6
6
|
additionalSigned;
|
|
7
|
-
constructor(
|
|
8
|
-
this.
|
|
7
|
+
constructor(client, options) {
|
|
8
|
+
this.client = client;
|
|
9
9
|
this.options = options;
|
|
10
10
|
this.data = {};
|
|
11
11
|
this.additionalSigned = [];
|
|
@@ -23,7 +23,7 @@ export class SignedExtension {
|
|
|
23
23
|
return ensurePresence(this.registry.findCodec(this.signedExtensionDef.additionalSigned));
|
|
24
24
|
}
|
|
25
25
|
get registry() {
|
|
26
|
-
return this.
|
|
26
|
+
return this.client.registry;
|
|
27
27
|
}
|
|
28
28
|
get signedExtensionDef() {
|
|
29
29
|
return ensurePresence(this.options.def);
|
|
@@ -5,7 +5,7 @@ import { SignedExtension } from '../SignedExtension.js';
|
|
|
5
5
|
*/
|
|
6
6
|
export class CheckGenesis extends SignedExtension {
|
|
7
7
|
async init() {
|
|
8
|
-
this.additionalSigned = ensurePresence(this.
|
|
8
|
+
this.additionalSigned = ensurePresence(this.client.genesisHash);
|
|
9
9
|
}
|
|
10
10
|
toPayload() {
|
|
11
11
|
return {
|
|
@@ -15,13 +15,13 @@ export class CheckMortality extends SignedExtension {
|
|
|
15
15
|
this.additionalSigned = this.#signingHeader.hash;
|
|
16
16
|
}
|
|
17
17
|
async #getSigningHeader() {
|
|
18
|
-
if (this.
|
|
18
|
+
if (this.client.rpcVersion === 'v2') {
|
|
19
19
|
return this.#getSigningHeaderRpcV2();
|
|
20
20
|
}
|
|
21
21
|
return this.#getSigningHeaderViaLegacyRpc();
|
|
22
22
|
}
|
|
23
23
|
async #getSigningHeaderRpcV2() {
|
|
24
|
-
const api = this.
|
|
24
|
+
const api = this.client;
|
|
25
25
|
// TODO similar to the legacy, we should account for the case finality is lagging behind
|
|
26
26
|
const finalizedBlock = await api.chainHead.finalizedBlock();
|
|
27
27
|
return {
|
|
@@ -32,8 +32,8 @@ export class CheckMortality extends SignedExtension {
|
|
|
32
32
|
// Ref: https://github.com/polkadot-js/api/blob/3bdf49b0428a62f16b3222b9a31bfefa43c1ca55/packages/api-derive/src/tx/signingInfo.ts#L34-L64
|
|
33
33
|
async #getSigningHeaderViaLegacyRpc() {
|
|
34
34
|
const [header, finalizedHash] = await Promise.all([
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
35
|
+
this.client.rpc.chain_getHeader(),
|
|
36
|
+
this.client.rpc.chain_getFinalizedHead(),
|
|
37
37
|
]);
|
|
38
38
|
assert(header, 'Current header not found');
|
|
39
39
|
const [currentHeader, finalizedHeader] = await Promise.all([
|
|
@@ -43,10 +43,10 @@ export class CheckMortality extends SignedExtension {
|
|
|
43
43
|
return header;
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
|
-
return this.
|
|
46
|
+
return this.client.rpc.chain_getHeader(parentHash);
|
|
47
47
|
}
|
|
48
48
|
}),
|
|
49
|
-
this.
|
|
49
|
+
this.client.rpc.chain_getHeader(finalizedHash),
|
|
50
50
|
]);
|
|
51
51
|
assert(currentHeader, 'Cannot determine current header');
|
|
52
52
|
if (!finalizedHeader || currentHeader.number - finalizedHeader.number > MAX_FINALITY_LAG) {
|
|
@@ -56,7 +56,7 @@ export class CheckMortality extends SignedExtension {
|
|
|
56
56
|
}
|
|
57
57
|
async #toSigningHeader(header) {
|
|
58
58
|
const { number } = header;
|
|
59
|
-
const hash = (await this.
|
|
59
|
+
const hash = (await this.client.rpc.chain_getBlockHash(header.number));
|
|
60
60
|
return { hash, number };
|
|
61
61
|
}
|
|
62
62
|
// Ref: https://github.com/polkadot-js/api/blob/3bdf49b0428a62f16b3222b9a31bfefa43c1ca55/packages/api-derive/src/tx/signingInfo.ts#L83-L93
|
|
@@ -69,7 +69,7 @@ export class CheckMortality extends SignedExtension {
|
|
|
69
69
|
}
|
|
70
70
|
#getConst(pallet, name) {
|
|
71
71
|
try {
|
|
72
|
-
return this.
|
|
72
|
+
return this.client.consts[pallet][name];
|
|
73
73
|
}
|
|
74
74
|
catch {
|
|
75
75
|
// ignore this on purpose
|
|
@@ -11,11 +11,11 @@ export class CheckNonce extends SignedExtension {
|
|
|
11
11
|
const { signerAddress } = this.options || {};
|
|
12
12
|
assert(signerAddress, 'Signer address not found');
|
|
13
13
|
try {
|
|
14
|
-
return (await this.
|
|
14
|
+
return (await this.client.query.system.account(signerAddress)).nonce;
|
|
15
15
|
}
|
|
16
16
|
catch { }
|
|
17
17
|
try {
|
|
18
|
-
return await this.
|
|
18
|
+
return await this.client.call.accountNonceApi.accountNonce(signerAddress);
|
|
19
19
|
}
|
|
20
20
|
catch { }
|
|
21
21
|
// TODO fallback to api.rpc.system_accountNextIndex if needed
|
|
@@ -5,7 +5,7 @@ import { SignedExtension } from '../SignedExtension.js';
|
|
|
5
5
|
*/
|
|
6
6
|
export class CheckSpecVersion extends SignedExtension {
|
|
7
7
|
async init() {
|
|
8
|
-
this.additionalSigned = this.
|
|
8
|
+
this.additionalSigned = this.client.runtimeVersion.specVersion;
|
|
9
9
|
}
|
|
10
10
|
toPayload() {
|
|
11
11
|
return {
|
|
@@ -5,7 +5,7 @@ import { SignedExtension } from '../SignedExtension.js';
|
|
|
5
5
|
*/
|
|
6
6
|
export class CheckTxVersion extends SignedExtension {
|
|
7
7
|
async init() {
|
|
8
|
-
this.additionalSigned = this.
|
|
8
|
+
this.additionalSigned = this.client.runtimeVersion.transactionVersion;
|
|
9
9
|
}
|
|
10
10
|
toPayload() {
|
|
11
11
|
return {
|
|
@@ -5,8 +5,8 @@ import type { FrameSystemEventRecord } from '../../chaintypes/index.js';
|
|
|
5
5
|
import type { ISubstrateClient } from '../../types.js';
|
|
6
6
|
export declare abstract class BaseSubmittableExtrinsic extends Extrinsic implements ISubmittableExtrinsic {
|
|
7
7
|
#private;
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
8
|
+
readonly client: ISubstrateClient;
|
|
9
|
+
constructor(client: ISubstrateClient, call: IRuntimeTxCall);
|
|
10
10
|
paymentInfo(account: AddressOrPair, options?: Partial<PayloadOptions>): Promise<TxPaymentInfo>;
|
|
11
11
|
sign(fromAccount: AddressOrPair, options?: Partial<SignerOptions>): Promise<this>;
|
|
12
12
|
signAndSend(account: AddressOrPair, options?: Partial<SignerOptions>): Promise<Hash>;
|
|
@@ -4,21 +4,21 @@ import { ExtraSignedExtension } from '../extensions/index.js';
|
|
|
4
4
|
import { fakeSigner } from './fakeSigner.js';
|
|
5
5
|
import { isKeyringPair, signRaw } from './utils.js';
|
|
6
6
|
export class BaseSubmittableExtrinsic extends Extrinsic {
|
|
7
|
-
|
|
7
|
+
client;
|
|
8
8
|
#alterTx;
|
|
9
|
-
constructor(
|
|
10
|
-
super(
|
|
11
|
-
this.
|
|
9
|
+
constructor(client, call) {
|
|
10
|
+
super(client.registry, call);
|
|
11
|
+
this.client = client;
|
|
12
12
|
}
|
|
13
13
|
async paymentInfo(account, options) {
|
|
14
14
|
await this.sign(account, { ...options, signer: fakeSigner });
|
|
15
15
|
const txU8a = this.toU8a();
|
|
16
|
-
const api = this.
|
|
16
|
+
const api = this.client;
|
|
17
17
|
return api.call.transactionPaymentApi.queryInfo(txU8a, txU8a.length);
|
|
18
18
|
}
|
|
19
19
|
async sign(fromAccount, options) {
|
|
20
20
|
const address = isKeyringPair(fromAccount) ? fromAccount.address : fromAccount.toString();
|
|
21
|
-
const extra = new ExtraSignedExtension(this.
|
|
21
|
+
const extra = new ExtraSignedExtension(this.client, {
|
|
22
22
|
signerAddress: address,
|
|
23
23
|
payloadOptions: options,
|
|
24
24
|
});
|
|
@@ -69,7 +69,7 @@ export class BaseSubmittableExtrinsic extends Extrinsic {
|
|
|
69
69
|
throw new Error('Unimplemented!');
|
|
70
70
|
}
|
|
71
71
|
async getSystemEventsAt(hash) {
|
|
72
|
-
const atApi = (await this.
|
|
72
|
+
const atApi = (await this.client.at(hash));
|
|
73
73
|
return await atApi.query.system.events();
|
|
74
74
|
}
|
|
75
75
|
toHex() {
|
|
@@ -94,6 +94,6 @@ export class BaseSubmittableExtrinsic extends Extrinsic {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
#getSigner(options) {
|
|
97
|
-
return options?.signer || this.
|
|
97
|
+
return options?.signer || this.client.options.signer;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
@@ -8,7 +8,7 @@ import { toTxStatus } from './utils.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export class SubmittableExtrinsic extends BaseSubmittableExtrinsic {
|
|
10
10
|
async dryRun(account, optionsOrHash) {
|
|
11
|
-
const dryRunFn = this.
|
|
11
|
+
const dryRunFn = this.client.rpc.system_dryRun;
|
|
12
12
|
if (isHex(optionsOrHash)) {
|
|
13
13
|
return dryRunFn(this.toHex(), optionsOrHash);
|
|
14
14
|
}
|
|
@@ -20,11 +20,11 @@ export class SubmittableExtrinsic extends BaseSubmittableExtrinsic {
|
|
|
20
20
|
const txHex = this.toHex();
|
|
21
21
|
const txHash = this.hash;
|
|
22
22
|
if (isSubscription) {
|
|
23
|
-
return this.
|
|
23
|
+
return this.client.rpc.author_submitAndWatchExtrinsic(txHex, async (txStatus) => {
|
|
24
24
|
if (txStatus.type === 'InBlock' || txStatus.type === 'Finalized') {
|
|
25
25
|
const blockHash = txStatus.value;
|
|
26
26
|
const [signedBlock, blockEvents] = await Promise.all([
|
|
27
|
-
this.
|
|
27
|
+
this.client.rpc.chain_getBlock(blockHash),
|
|
28
28
|
this.getSystemEventsAt(blockHash),
|
|
29
29
|
]);
|
|
30
30
|
const txIndex = signedBlock.block.extrinsics.indexOf(txHex);
|
|
@@ -41,7 +41,7 @@ export class SubmittableExtrinsic extends BaseSubmittableExtrinsic {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
|
-
return this.
|
|
44
|
+
return this.client.rpc.author_submitExtrinsic(txHex);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -8,8 +8,8 @@ import { BaseSubmittableExtrinsic } from './BaseSubmittableExtrinsic.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic {
|
|
10
10
|
#private;
|
|
11
|
-
|
|
12
|
-
constructor(
|
|
11
|
+
client: DedotClient;
|
|
12
|
+
constructor(client: DedotClient, call: IRuntimeTxCall);
|
|
13
13
|
send(): Promise<Hash>;
|
|
14
14
|
send(callback: Callback): Promise<Unsub>;
|
|
15
15
|
}
|
|
@@ -7,18 +7,18 @@ import { InvalidTxError } from './errors.js';
|
|
|
7
7
|
* @description Submittable extrinsic based on JSON-RPC v2
|
|
8
8
|
*/
|
|
9
9
|
export class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic {
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
12
|
-
super(
|
|
13
|
-
this.
|
|
10
|
+
client;
|
|
11
|
+
constructor(client, call) {
|
|
12
|
+
super(client, call);
|
|
13
|
+
this.client = client;
|
|
14
14
|
}
|
|
15
15
|
async #send(callback) {
|
|
16
|
-
const api = this.
|
|
16
|
+
const api = this.client;
|
|
17
17
|
const txHex = this.toHex();
|
|
18
18
|
const txHash = this.hash;
|
|
19
19
|
// validate the transaction
|
|
20
20
|
// https://github.com/paritytech/json-rpc-interface-spec/issues/55#issuecomment-1609011150
|
|
21
|
-
const finalizedHash = await this.
|
|
21
|
+
const finalizedHash = await this.client.chainHead.finalizedHash();
|
|
22
22
|
const validateTx = async (hash) => {
|
|
23
23
|
const apiAt = await api.at(hash);
|
|
24
24
|
return apiAt.call.taggedTransactionQueue.validateTransaction('External', txHex, hash);
|
|
@@ -7,5 +7,6 @@ import type { SpRuntimeTransactionValidityTransactionValidityError, SpRuntimeTra
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class InvalidTxError extends DedotError {
|
|
9
9
|
data: Result<SpRuntimeTransactionValidityValidTransaction, SpRuntimeTransactionValidityTransactionValidityError>;
|
|
10
|
+
name: string;
|
|
10
11
|
constructor(message: string, data: Result<SpRuntimeTransactionValidityValidTransaction, SpRuntimeTransactionValidityTransactionValidityError>);
|
|
11
12
|
}
|
|
@@ -4,6 +4,7 @@ export declare enum RetryStrategy {
|
|
|
4
4
|
QUEUED = "QUEUED"
|
|
5
5
|
}
|
|
6
6
|
export declare class ChainHeadError extends DedotError {
|
|
7
|
+
name: string;
|
|
7
8
|
retryStrategy?: RetryStrategy | undefined;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
@@ -12,6 +13,7 @@ export declare class ChainHeadError extends DedotError {
|
|
|
12
13
|
* Ref: https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_v1_follow.html#operationinaccessible
|
|
13
14
|
*/
|
|
14
15
|
export declare class ChainHeadOperationInaccessibleError extends ChainHeadError {
|
|
16
|
+
name: string;
|
|
15
17
|
retryStrategy: RetryStrategy;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
@@ -20,6 +22,7 @@ export declare class ChainHeadOperationInaccessibleError extends ChainHeadError
|
|
|
20
22
|
* Ref: https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_v1_follow.html#stop
|
|
21
23
|
*/
|
|
22
24
|
export declare class ChainHeadStopError extends ChainHeadError {
|
|
25
|
+
name: string;
|
|
23
26
|
retryStrategy: RetryStrategy;
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
@@ -27,12 +30,14 @@ export declare class ChainHeadStopError extends ChainHeadError {
|
|
|
27
30
|
* Ref: https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_v1_follow.html#operationerror
|
|
28
31
|
*/
|
|
29
32
|
export declare class ChainHeadOperationError extends ChainHeadError {
|
|
33
|
+
name: string;
|
|
30
34
|
}
|
|
31
35
|
/**
|
|
32
36
|
* Limit Reached Error
|
|
33
37
|
* Ref: https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_v1_storage.html#limitreached
|
|
34
38
|
*/
|
|
35
39
|
export declare class ChainHeadLimitReachedError extends ChainHeadError {
|
|
40
|
+
name: string;
|
|
36
41
|
retryStrategy: RetryStrategy;
|
|
37
42
|
}
|
|
38
43
|
/**
|
|
@@ -40,8 +45,11 @@ export declare class ChainHeadLimitReachedError extends ChainHeadError {
|
|
|
40
45
|
* Ref: https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_v1_storage.html#limitreached
|
|
41
46
|
*/
|
|
42
47
|
export declare class ChainHeadInvalidRuntimeError extends ChainHeadError {
|
|
48
|
+
name: string;
|
|
43
49
|
}
|
|
44
50
|
export declare class ChainHeadBlockNotPinnedError extends ChainHeadError {
|
|
51
|
+
name: string;
|
|
45
52
|
}
|
|
46
53
|
export declare class ChainHeadBlockPrunedError extends ChainHeadError {
|
|
54
|
+
name: string;
|
|
47
55
|
}
|
|
@@ -5,6 +5,7 @@ export var RetryStrategy;
|
|
|
5
5
|
RetryStrategy["QUEUED"] = "QUEUED";
|
|
6
6
|
})(RetryStrategy || (RetryStrategy = {}));
|
|
7
7
|
export class ChainHeadError extends DedotError {
|
|
8
|
+
name = 'ChainHeadError';
|
|
8
9
|
retryStrategy;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
@@ -13,6 +14,7 @@ export class ChainHeadError extends DedotError {
|
|
|
13
14
|
* Ref: https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_v1_follow.html#operationinaccessible
|
|
14
15
|
*/
|
|
15
16
|
export class ChainHeadOperationInaccessibleError extends ChainHeadError {
|
|
17
|
+
name = 'ChainHeadOperationInaccessibleError';
|
|
16
18
|
retryStrategy = RetryStrategy.NOW;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
@@ -21,6 +23,7 @@ export class ChainHeadOperationInaccessibleError extends ChainHeadError {
|
|
|
21
23
|
* Ref: https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_v1_follow.html#stop
|
|
22
24
|
*/
|
|
23
25
|
export class ChainHeadStopError extends ChainHeadError {
|
|
26
|
+
name = 'ChainHeadStopError';
|
|
24
27
|
retryStrategy = RetryStrategy.QUEUED;
|
|
25
28
|
}
|
|
26
29
|
/**
|
|
@@ -28,12 +31,14 @@ export class ChainHeadStopError extends ChainHeadError {
|
|
|
28
31
|
* Ref: https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_v1_follow.html#operationerror
|
|
29
32
|
*/
|
|
30
33
|
export class ChainHeadOperationError extends ChainHeadError {
|
|
34
|
+
name = 'ChainHeadOperationError';
|
|
31
35
|
}
|
|
32
36
|
/**
|
|
33
37
|
* Limit Reached Error
|
|
34
38
|
* Ref: https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_v1_storage.html#limitreached
|
|
35
39
|
*/
|
|
36
40
|
export class ChainHeadLimitReachedError extends ChainHeadError {
|
|
41
|
+
name = 'ChainHeadLimitReachedError';
|
|
37
42
|
retryStrategy = RetryStrategy.QUEUED;
|
|
38
43
|
}
|
|
39
44
|
/**
|
|
@@ -41,8 +46,11 @@ export class ChainHeadLimitReachedError extends ChainHeadError {
|
|
|
41
46
|
* Ref: https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_v1_storage.html#limitreached
|
|
42
47
|
*/
|
|
43
48
|
export class ChainHeadInvalidRuntimeError extends ChainHeadError {
|
|
49
|
+
name = 'ChainHeadInvalidRuntimeError';
|
|
44
50
|
}
|
|
45
51
|
export class ChainHeadBlockNotPinnedError extends ChainHeadError {
|
|
52
|
+
name = 'ChainHeadBlockNotPinnedError';
|
|
46
53
|
}
|
|
47
54
|
export class ChainHeadBlockPrunedError extends ChainHeadError {
|
|
55
|
+
name = 'ChainHeadBlockPrunedError';
|
|
48
56
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
|
|
5
5
|
"author": "Thang X. Vu <thang@coongcrafts.io>",
|
|
6
6
|
"homepage": "https://github.com/dedotdev/dedot/tree/main/packages/api",
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@dedot/codecs": "0.
|
|
17
|
-
"@dedot/providers": "0.
|
|
18
|
-
"@dedot/runtime-specs": "0.
|
|
19
|
-
"@dedot/shape": "0.
|
|
20
|
-
"@dedot/storage": "0.
|
|
21
|
-
"@dedot/types": "0.
|
|
22
|
-
"@dedot/utils": "0.
|
|
16
|
+
"@dedot/codecs": "0.5.0",
|
|
17
|
+
"@dedot/providers": "0.5.0",
|
|
18
|
+
"@dedot/runtime-specs": "0.5.0",
|
|
19
|
+
"@dedot/shape": "0.5.0",
|
|
20
|
+
"@dedot/storage": "0.5.0",
|
|
21
|
+
"@dedot/types": "0.5.0",
|
|
22
|
+
"@dedot/utils": "0.5.0"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsc --project tsconfig.build.json && tsc --project tsconfig.build.cjs.json",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
},
|
|
47
47
|
"license": "Apache-2.0",
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@polkadot/types": "^12.
|
|
49
|
+
"@polkadot/types": "^12.3.1"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "968148ade63e07644094fc033be719b320e18a18",
|
|
52
52
|
"module": "./index.js",
|
|
53
53
|
"types": "./index.d.ts"
|
|
54
54
|
}
|