dedot 0.0.1-next.fecbe32d.13 → 0.1.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/README.md +80 -86
- package/bin/dedot +3 -0
- package/chaintypes/index.d.ts +1 -1
- package/chaintypes/index.js +1 -1
- package/cjs/chaintypes/index.js +1 -1
- package/cjs/{json-rpc → codecs}/index.js +1 -1
- package/cjs/{storage → contracts}/index.js +1 -1
- package/cjs/index.js +6 -15
- package/cjs/runtime-specs/index.js +17 -0
- package/cjs/{chaintypes/substrate → shape}/index.js +1 -1
- package/cjs/{client → types}/index.js +1 -1
- package/cjs/types/json-rpc/index.js +17 -0
- package/cjs/utils/index.js +17 -0
- package/codecs/index.d.ts +1 -0
- package/codecs/index.js +1 -0
- package/contracts/index.d.ts +1 -0
- package/contracts/index.js +1 -0
- package/index.d.ts +2 -9
- package/index.js +2 -9
- package/package.json +76 -36
- package/runtime-specs/index.d.ts +1 -0
- package/runtime-specs/index.js +1 -0
- package/shape/index.d.ts +1 -0
- package/shape/index.js +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/json-rpc/index.d.ts +1 -0
- package/types/json-rpc/index.js +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/chaintypes/substrate/consts.d.ts +0 -1971
- package/chaintypes/substrate/consts.js +0 -1
- package/chaintypes/substrate/errors.d.ts +0 -3337
- package/chaintypes/substrate/errors.js +0 -1
- package/chaintypes/substrate/events.d.ts +0 -4777
- package/chaintypes/substrate/events.js +0 -1
- package/chaintypes/substrate/index.d.ts +0 -18
- package/chaintypes/substrate/index.js +0 -1
- package/chaintypes/substrate/json-rpc.d.ts +0 -3
- package/chaintypes/substrate/json-rpc.js +0 -1
- package/chaintypes/substrate/query.d.ts +0 -3447
- package/chaintypes/substrate/query.js +0 -1
- package/chaintypes/substrate/runtime.d.ts +0 -708
- package/chaintypes/substrate/runtime.js +0 -1
- package/chaintypes/substrate/tx.d.ts +0 -8800
- package/chaintypes/substrate/tx.js +0 -1
- package/chaintypes/substrate/types.d.ts +0 -20332
- package/chaintypes/substrate/types.js +0 -1
- package/cjs/chaintypes/substrate/consts.js +0 -2
- package/cjs/chaintypes/substrate/errors.js +0 -2
- package/cjs/chaintypes/substrate/events.js +0 -2
- package/cjs/chaintypes/substrate/json-rpc.js +0 -2
- package/cjs/chaintypes/substrate/query.js +0 -2
- package/cjs/chaintypes/substrate/runtime.js +0 -2
- package/cjs/chaintypes/substrate/tx.js +0 -2
- package/cjs/chaintypes/substrate/types.js +0 -2
- package/cjs/client/BaseSubstrateClient.js +0 -247
- package/cjs/client/Dedot.js +0 -257
- package/cjs/executor/ConstantExecutor.js +0 -20
- package/cjs/executor/ErrorExecutor.js +0 -46
- package/cjs/executor/EventExecutor.js +0 -52
- package/cjs/executor/Executor.js +0 -45
- package/cjs/executor/RuntimeApiExecutor.js +0 -113
- package/cjs/executor/StorageQueryExecutor.js +0 -109
- package/cjs/executor/TxExecutor.js +0 -158
- package/cjs/executor/index.js +0 -23
- package/cjs/extrinsic/SubmittableResult.js +0 -33
- package/cjs/extrinsic/extensions/ExtraSignedExtension.js +0 -87
- package/cjs/extrinsic/extensions/SignedExtension.js +0 -41
- package/cjs/extrinsic/extensions/index.js +0 -19
- package/cjs/extrinsic/extensions/known/ChargeAssetTxPayment.js +0 -43
- package/cjs/extrinsic/extensions/known/ChargeTransactionPayment.js +0 -16
- package/cjs/extrinsic/extensions/known/CheckGenesis.js +0 -19
- package/cjs/extrinsic/extensions/known/CheckMortality.js +0 -70
- package/cjs/extrinsic/extensions/known/CheckNonZeroSender.js +0 -10
- package/cjs/extrinsic/extensions/known/CheckNonce.js +0 -33
- package/cjs/extrinsic/extensions/known/CheckSpecVersion.js +0 -19
- package/cjs/extrinsic/extensions/known/CheckTxVersion.js +0 -19
- package/cjs/extrinsic/extensions/known/CheckWeight.js +0 -10
- package/cjs/extrinsic/extensions/known/PrevalidateAttests.js +0 -11
- package/cjs/extrinsic/extensions/known/index.js +0 -25
- package/cjs/extrinsic/index.js +0 -18
- package/cjs/json-rpc/JsonRpcClient.js +0 -157
- package/cjs/proxychain.js +0 -27
- package/cjs/storage/QueryableStorage.js +0 -161
- package/cjs/types.js +0 -2
- package/client/BaseSubstrateClient.d.ts +0 -65
- package/client/BaseSubstrateClient.js +0 -242
- package/client/Dedot.d.ts +0 -130
- package/client/Dedot.js +0 -253
- package/client/index.d.ts +0 -1
- package/client/index.js +0 -1
- package/executor/ConstantExecutor.d.ts +0 -11
- package/executor/ConstantExecutor.js +0 -16
- package/executor/ErrorExecutor.d.ts +0 -11
- package/executor/ErrorExecutor.js +0 -42
- package/executor/EventExecutor.d.ts +0 -11
- package/executor/EventExecutor.js +0 -48
- package/executor/Executor.d.ts +0 -150
- package/executor/Executor.js +0 -41
- package/executor/RuntimeApiExecutor.d.ts +0 -19
- package/executor/RuntimeApiExecutor.js +0 -109
- package/executor/StorageQueryExecutor.d.ts +0 -13
- package/executor/StorageQueryExecutor.js +0 -105
- package/executor/TxExecutor.d.ts +0 -48
- package/executor/TxExecutor.js +0 -152
- package/executor/index.d.ts +0 -7
- package/executor/index.js +0 -7
- package/extrinsic/SubmittableResult.d.ts +0 -19
- package/extrinsic/SubmittableResult.js +0 -29
- package/extrinsic/extensions/ExtraSignedExtension.d.ts +0 -14
- package/extrinsic/extensions/ExtraSignedExtension.js +0 -60
- package/extrinsic/extensions/SignedExtension.d.ts +0 -40
- package/extrinsic/extensions/SignedExtension.js +0 -37
- package/extrinsic/extensions/index.d.ts +0 -3
- package/extrinsic/extensions/index.js +0 -3
- package/extrinsic/extensions/known/ChargeAssetTxPayment.d.ts +0 -14
- package/extrinsic/extensions/known/ChargeAssetTxPayment.js +0 -39
- package/extrinsic/extensions/known/ChargeTransactionPayment.d.ts +0 -6
- package/extrinsic/extensions/known/ChargeTransactionPayment.js +0 -12
- package/extrinsic/extensions/known/CheckGenesis.d.ts +0 -10
- package/extrinsic/extensions/known/CheckGenesis.js +0 -15
- package/extrinsic/extensions/known/CheckMortality.d.ts +0 -15
- package/extrinsic/extensions/known/CheckMortality.js +0 -66
- package/extrinsic/extensions/known/CheckNonZeroSender.d.ts +0 -6
- package/extrinsic/extensions/known/CheckNonZeroSender.js +0 -6
- package/extrinsic/extensions/known/CheckNonce.d.ts +0 -10
- package/extrinsic/extensions/known/CheckNonce.js +0 -29
- package/extrinsic/extensions/known/CheckSpecVersion.d.ts +0 -9
- package/extrinsic/extensions/known/CheckSpecVersion.js +0 -15
- package/extrinsic/extensions/known/CheckTxVersion.d.ts +0 -9
- package/extrinsic/extensions/known/CheckTxVersion.js +0 -15
- package/extrinsic/extensions/known/CheckWeight.d.ts +0 -6
- package/extrinsic/extensions/known/CheckWeight.js +0 -6
- package/extrinsic/extensions/known/PrevalidateAttests.d.ts +0 -7
- package/extrinsic/extensions/known/PrevalidateAttests.js +0 -7
- package/extrinsic/extensions/known/index.d.ts +0 -3
- package/extrinsic/extensions/known/index.js +0 -22
- package/extrinsic/index.d.ts +0 -2
- package/extrinsic/index.js +0 -2
- package/json-rpc/JsonRpcClient.d.ts +0 -49
- package/json-rpc/JsonRpcClient.js +0 -153
- package/json-rpc/index.d.ts +0 -1
- package/json-rpc/index.js +0 -1
- package/proxychain.d.ts +0 -14
- package/proxychain.js +0 -23
- package/storage/QueryableStorage.d.ts +0 -35
- package/storage/QueryableStorage.js +0 -157
- package/storage/index.d.ts +0 -1
- package/storage/index.js +0 -1
- package/types.d.ts +0 -103
- package/types.js +0 -1
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChargeTransactionPayment = void 0;
|
|
4
|
-
const utils_1 = require("@dedot/utils");
|
|
5
|
-
const SignedExtension_js_1 = require("../SignedExtension.js");
|
|
6
|
-
class ChargeTransactionPayment extends SignedExtension_js_1.SignedExtension {
|
|
7
|
-
async init() {
|
|
8
|
-
this.data = this.payloadOptions.tip || 0n;
|
|
9
|
-
}
|
|
10
|
-
toPayload() {
|
|
11
|
-
return {
|
|
12
|
-
tip: (0, utils_1.bnToHex)(this.data),
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.ChargeTransactionPayment = ChargeTransactionPayment;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CheckGenesis = void 0;
|
|
4
|
-
const utils_1 = require("@dedot/utils");
|
|
5
|
-
const SignedExtension_js_1 = require("../SignedExtension.js");
|
|
6
|
-
/**
|
|
7
|
-
* @description Genesis hash check to provide replay protection between different networks.
|
|
8
|
-
*/
|
|
9
|
-
class CheckGenesis extends SignedExtension_js_1.SignedExtension {
|
|
10
|
-
async init() {
|
|
11
|
-
this.additionalSigned = (0, utils_1.ensurePresence)(this.api.genesisHash);
|
|
12
|
-
}
|
|
13
|
-
toPayload() {
|
|
14
|
-
return {
|
|
15
|
-
genesisHash: this.additionalSigned,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.CheckGenesis = CheckGenesis;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CheckMortality = exports.MORTAL_PERIOD = exports.FALLBACK_PERIOD = exports.FALLBACK_MAX_HASH_COUNT = exports.MAX_FINALITY_LAG = void 0;
|
|
4
|
-
const utils_1 = require("@dedot/utils");
|
|
5
|
-
const SignedExtension_js_1 = require("../SignedExtension.js");
|
|
6
|
-
exports.MAX_FINALITY_LAG = 5;
|
|
7
|
-
exports.FALLBACK_MAX_HASH_COUNT = 250;
|
|
8
|
-
exports.FALLBACK_PERIOD = 6 * 1000;
|
|
9
|
-
exports.MORTAL_PERIOD = 5 * 60 * 1000;
|
|
10
|
-
/**
|
|
11
|
-
* @description Check for transaction mortality.
|
|
12
|
-
*/
|
|
13
|
-
class CheckMortality extends SignedExtension_js_1.SignedExtension {
|
|
14
|
-
#signingHeader;
|
|
15
|
-
async init() {
|
|
16
|
-
this.#signingHeader = await this.#determineSigningHeader();
|
|
17
|
-
this.data = { period: this.#calculateMortalLength(), current: BigInt(this.#signingHeader.number) };
|
|
18
|
-
this.additionalSigned = (await this.api.rpc.chain_getBlockHash(this.#signingHeader.number));
|
|
19
|
-
}
|
|
20
|
-
// Ref: https://github.com/polkadot-js/api/blob/3bdf49b0428a62f16b3222b9a31bfefa43c1ca55/packages/api-derive/src/tx/signingInfo.ts#L34-L64
|
|
21
|
-
async #determineSigningHeader() {
|
|
22
|
-
const [header, finalizedHash] = await Promise.all([
|
|
23
|
-
this.api.rpc.chain_getHeader(),
|
|
24
|
-
this.api.rpc.chain_getFinalizedHead(),
|
|
25
|
-
]);
|
|
26
|
-
(0, utils_1.assert)(header, 'Current header not found');
|
|
27
|
-
const [currentHeader, finalizedHeader] = await Promise.all([
|
|
28
|
-
Promise.resolve(header).then((header) => {
|
|
29
|
-
const { parentHash } = header;
|
|
30
|
-
if (parentHash.length === 0 || (0, utils_1.isZeroHex)(parentHash)) {
|
|
31
|
-
return header;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
return this.api.rpc.chain_getHeader(parentHash);
|
|
35
|
-
}
|
|
36
|
-
}),
|
|
37
|
-
this.api.rpc.chain_getHeader(finalizedHash),
|
|
38
|
-
]);
|
|
39
|
-
(0, utils_1.assert)(currentHeader, 'Cannot determine current header');
|
|
40
|
-
if (!finalizedHeader || currentHeader.number - finalizedHeader.number > exports.MAX_FINALITY_LAG) {
|
|
41
|
-
return currentHeader;
|
|
42
|
-
}
|
|
43
|
-
return finalizedHeader;
|
|
44
|
-
}
|
|
45
|
-
// Ref: https://github.com/polkadot-js/api/blob/3bdf49b0428a62f16b3222b9a31bfefa43c1ca55/packages/api-derive/src/tx/signingInfo.ts#L83-L93
|
|
46
|
-
#calculateMortalLength() {
|
|
47
|
-
return (0, utils_1.bnMin)(BigInt(this.#getConst('system', 'blockHashCount') || exports.FALLBACK_MAX_HASH_COUNT), BigInt(exports.MORTAL_PERIOD) /
|
|
48
|
-
BigInt(this.#getConst('babe', 'expectedBlockTime') ||
|
|
49
|
-
BigInt(this.#getConst('timestamp', 'minimumPeriod') || 0) * 2n ||
|
|
50
|
-
exports.FALLBACK_PERIOD) +
|
|
51
|
-
BigInt(exports.MAX_FINALITY_LAG));
|
|
52
|
-
}
|
|
53
|
-
#getConst(pallet, name) {
|
|
54
|
-
try {
|
|
55
|
-
return this.api.consts[pallet][name];
|
|
56
|
-
}
|
|
57
|
-
catch {
|
|
58
|
-
// ignore this on purpose
|
|
59
|
-
}
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
toPayload() {
|
|
63
|
-
return {
|
|
64
|
-
era: (0, utils_1.u8aToHex)(this.dataCodec.tryEncode(this.data)),
|
|
65
|
-
blockHash: this.additionalSigned,
|
|
66
|
-
blockNumber: (0, utils_1.numberToHex)(this.#signingHeader.number),
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.CheckMortality = CheckMortality;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CheckNonZeroSender = void 0;
|
|
4
|
-
const SignedExtension_js_1 = require("../SignedExtension.js");
|
|
5
|
-
/**
|
|
6
|
-
* @description Check to ensure that the sender is not the zero address
|
|
7
|
-
*/
|
|
8
|
-
class CheckNonZeroSender extends SignedExtension_js_1.SignedExtension {
|
|
9
|
-
}
|
|
10
|
-
exports.CheckNonZeroSender = CheckNonZeroSender;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CheckNonce = void 0;
|
|
4
|
-
const utils_1 = require("@dedot/utils");
|
|
5
|
-
const SignedExtension_js_1 = require("../SignedExtension.js");
|
|
6
|
-
/**
|
|
7
|
-
* @description Nonce check and increment to give replay protection for transactions.
|
|
8
|
-
*/
|
|
9
|
-
class CheckNonce extends SignedExtension_js_1.SignedExtension {
|
|
10
|
-
async init() {
|
|
11
|
-
this.data = this.payloadOptions.nonce || (await this.#getNonce());
|
|
12
|
-
}
|
|
13
|
-
async #getNonce() {
|
|
14
|
-
const { signerAddress } = this.options || {};
|
|
15
|
-
(0, utils_1.assert)(signerAddress, 'Signer address not found');
|
|
16
|
-
try {
|
|
17
|
-
return (await this.api.query.system.account(signerAddress)).nonce;
|
|
18
|
-
}
|
|
19
|
-
catch { }
|
|
20
|
-
try {
|
|
21
|
-
return await this.api.call.accountNonceApi.accountNonce(signerAddress);
|
|
22
|
-
}
|
|
23
|
-
catch { }
|
|
24
|
-
// TODO fallback to api.rpc.system_accountNextIndex if needed
|
|
25
|
-
return 0;
|
|
26
|
-
}
|
|
27
|
-
toPayload() {
|
|
28
|
-
return {
|
|
29
|
-
nonce: (0, utils_1.numberToHex)(this.data),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.CheckNonce = CheckNonce;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CheckSpecVersion = void 0;
|
|
4
|
-
const utils_1 = require("@dedot/utils");
|
|
5
|
-
const SignedExtension_js_1 = require("../SignedExtension.js");
|
|
6
|
-
/**
|
|
7
|
-
* @description Ensure the runtime version registered in the transaction is the same as at present.
|
|
8
|
-
*/
|
|
9
|
-
class CheckSpecVersion extends SignedExtension_js_1.SignedExtension {
|
|
10
|
-
async init() {
|
|
11
|
-
this.additionalSigned = this.api.runtimeVersion.specVersion;
|
|
12
|
-
}
|
|
13
|
-
toPayload() {
|
|
14
|
-
return {
|
|
15
|
-
specVersion: (0, utils_1.numberToHex)(this.additionalSigned),
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.CheckSpecVersion = CheckSpecVersion;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CheckTxVersion = void 0;
|
|
4
|
-
const utils_1 = require("@dedot/utils");
|
|
5
|
-
const SignedExtension_js_1 = require("../SignedExtension.js");
|
|
6
|
-
/**
|
|
7
|
-
* @description Ensure the transaction version registered in the transaction is the same as at present.
|
|
8
|
-
*/
|
|
9
|
-
class CheckTxVersion extends SignedExtension_js_1.SignedExtension {
|
|
10
|
-
async init() {
|
|
11
|
-
this.additionalSigned = this.api.runtimeVersion.transactionVersion;
|
|
12
|
-
}
|
|
13
|
-
toPayload() {
|
|
14
|
-
return {
|
|
15
|
-
transactionVersion: (0, utils_1.numberToHex)(this.additionalSigned),
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.CheckTxVersion = CheckTxVersion;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CheckWeight = void 0;
|
|
4
|
-
const SignedExtension_js_1 = require("../SignedExtension.js");
|
|
5
|
-
/**
|
|
6
|
-
* @description Block resource (weight) limit check.
|
|
7
|
-
*/
|
|
8
|
-
class CheckWeight extends SignedExtension_js_1.SignedExtension {
|
|
9
|
-
}
|
|
10
|
-
exports.CheckWeight = CheckWeight;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PrevalidateAttests = void 0;
|
|
4
|
-
const SignedExtension_js_1 = require("../SignedExtension.js");
|
|
5
|
-
/**
|
|
6
|
-
* @description Validate `attest` calls prior to execution.
|
|
7
|
-
* Needed to avoid a DoS attack since they are otherwise free to place on chain.
|
|
8
|
-
*/
|
|
9
|
-
class PrevalidateAttests extends SignedExtension_js_1.SignedExtension {
|
|
10
|
-
}
|
|
11
|
-
exports.PrevalidateAttests = PrevalidateAttests;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.knownSignedExtensions = void 0;
|
|
4
|
-
const ChargeAssetTxPayment_js_1 = require("./ChargeAssetTxPayment.js");
|
|
5
|
-
const ChargeTransactionPayment_js_1 = require("./ChargeTransactionPayment.js");
|
|
6
|
-
const CheckGenesis_js_1 = require("./CheckGenesis.js");
|
|
7
|
-
const CheckMortality_js_1 = require("./CheckMortality.js");
|
|
8
|
-
const CheckNonZeroSender_js_1 = require("./CheckNonZeroSender.js");
|
|
9
|
-
const CheckNonce_js_1 = require("./CheckNonce.js");
|
|
10
|
-
const CheckSpecVersion_js_1 = require("./CheckSpecVersion.js");
|
|
11
|
-
const CheckTxVersion_js_1 = require("./CheckTxVersion.js");
|
|
12
|
-
const CheckWeight_js_1 = require("./CheckWeight.js");
|
|
13
|
-
const PrevalidateAttests_js_1 = require("./PrevalidateAttests.js");
|
|
14
|
-
exports.knownSignedExtensions = {
|
|
15
|
-
CheckNonZeroSender: CheckNonZeroSender_js_1.CheckNonZeroSender,
|
|
16
|
-
CheckSpecVersion: CheckSpecVersion_js_1.CheckSpecVersion,
|
|
17
|
-
CheckTxVersion: CheckTxVersion_js_1.CheckTxVersion,
|
|
18
|
-
CheckGenesis: CheckGenesis_js_1.CheckGenesis,
|
|
19
|
-
CheckMortality: CheckMortality_js_1.CheckMortality,
|
|
20
|
-
CheckNonce: CheckNonce_js_1.CheckNonce,
|
|
21
|
-
CheckWeight: CheckWeight_js_1.CheckWeight,
|
|
22
|
-
ChargeTransactionPayment: ChargeTransactionPayment_js_1.ChargeTransactionPayment,
|
|
23
|
-
PrevalidateAttests: PrevalidateAttests_js_1.PrevalidateAttests,
|
|
24
|
-
ChargeAssetTxPayment: ChargeAssetTxPayment_js_1.ChargeAssetTxPayment,
|
|
25
|
-
};
|
package/cjs/extrinsic/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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("./extensions/index.js"), exports);
|
|
18
|
-
__exportStar(require("./SubmittableResult.js"), exports);
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JsonRpcClient = void 0;
|
|
4
|
-
const providers_1 = require("@dedot/providers");
|
|
5
|
-
const specs_1 = require("@dedot/specs");
|
|
6
|
-
const utils_1 = require("@dedot/utils");
|
|
7
|
-
class JsonRpcClient extends utils_1.EventEmitter {
|
|
8
|
-
#options;
|
|
9
|
-
#provider;
|
|
10
|
-
constructor(options) {
|
|
11
|
-
super();
|
|
12
|
-
this.#options = typeof options === 'string' ? { endpoint: options } : options;
|
|
13
|
-
this.#provider = this.#getProvider();
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Factory method to create a new JsonRpcClient instance
|
|
17
|
-
*
|
|
18
|
-
* @param options
|
|
19
|
-
*/
|
|
20
|
-
static async create(options) {
|
|
21
|
-
return new JsonRpcClient(options).connect();
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Alias for __JsonRpcClient.create__
|
|
25
|
-
*
|
|
26
|
-
* @param options
|
|
27
|
-
*/
|
|
28
|
-
static async new(options) {
|
|
29
|
-
return JsonRpcClient.create(options);
|
|
30
|
-
}
|
|
31
|
-
get options() {
|
|
32
|
-
return this.#options;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* @description Check connection status of the api instance
|
|
36
|
-
*/
|
|
37
|
-
get status() {
|
|
38
|
-
return this.provider.status;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* @description Get the JSON-RPC provider instance
|
|
42
|
-
*/
|
|
43
|
-
get provider() {
|
|
44
|
-
return this.#provider;
|
|
45
|
-
}
|
|
46
|
-
connect() {
|
|
47
|
-
return this.#doConnect();
|
|
48
|
-
}
|
|
49
|
-
async #doConnect() {
|
|
50
|
-
this.provider.on('connected', this.#onConnected);
|
|
51
|
-
this.provider.on('disconnected', this.#onDisconnected);
|
|
52
|
-
this.provider.on('reconnecting', this.#onReconnecting);
|
|
53
|
-
this.provider.on('error', this.#onError);
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
this.once('connected', () => {
|
|
57
|
-
resolve(this);
|
|
58
|
-
});
|
|
59
|
-
if (this.status === 'connected') {
|
|
60
|
-
this.#onConnected().catch(reject);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
this.provider.connect().catch(reject);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
#onConnected = async () => {
|
|
68
|
-
// @ts-ignore
|
|
69
|
-
this.emit('connected');
|
|
70
|
-
};
|
|
71
|
-
#onDisconnected = async () => {
|
|
72
|
-
// @ts-ignore
|
|
73
|
-
this.emit('disconnected');
|
|
74
|
-
};
|
|
75
|
-
#onReconnecting = async () => {
|
|
76
|
-
// @ts-ignore
|
|
77
|
-
this.emit('reconnecting');
|
|
78
|
-
};
|
|
79
|
-
#onError = async (e) => {
|
|
80
|
-
// @ts-ignore
|
|
81
|
-
this.emit('error', e);
|
|
82
|
-
};
|
|
83
|
-
async disconnect() {
|
|
84
|
-
await this.#provider.disconnect();
|
|
85
|
-
}
|
|
86
|
-
#getProvider() {
|
|
87
|
-
const { provider, endpoint } = this.#options;
|
|
88
|
-
if (provider)
|
|
89
|
-
return provider;
|
|
90
|
-
if (endpoint)
|
|
91
|
-
return new providers_1.WsProvider(endpoint);
|
|
92
|
-
// TODO support light-client
|
|
93
|
-
return new providers_1.WsProvider('ws://127.0.0.1:9944');
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* @description Entry-point for executing JSON-RPCs to blockchain node.
|
|
97
|
-
*
|
|
98
|
-
* ```typescript
|
|
99
|
-
* const client = new JsonRpcClient('wss://rpc.polkadot.io');
|
|
100
|
-
* await client.connect();
|
|
101
|
-
*
|
|
102
|
-
* // Subscribe to new heads
|
|
103
|
-
* client.rpc.chain_subscribeNewHeads((header) => {
|
|
104
|
-
* console.log(header);
|
|
105
|
-
* });
|
|
106
|
-
*
|
|
107
|
-
* // Execute arbitrary rpc method: `module_rpc_name`
|
|
108
|
-
* const result = await client.rpc.module_rpc_name();
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
get rpc() {
|
|
112
|
-
return new Proxy(this, {
|
|
113
|
-
get(target, property, receiver) {
|
|
114
|
-
const rpcMethod = property.toString();
|
|
115
|
-
return target.#doExecute(rpcMethod);
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
#doExecute(rpcName) {
|
|
120
|
-
const subscriptionInfo = this.options.subscriptions?.[rpcName] || specs_1.subscriptionsInfo[rpcName];
|
|
121
|
-
const isSubscription = !!subscriptionInfo;
|
|
122
|
-
const fnRpc = async (...args) => {
|
|
123
|
-
const result = await this.provider.send(rpcName, args);
|
|
124
|
-
return this.#tryDecode(rpcName, result);
|
|
125
|
-
};
|
|
126
|
-
const fnSubRpc = async (...args) => {
|
|
127
|
-
const inArgs = args.slice();
|
|
128
|
-
const callback = inArgs.pop();
|
|
129
|
-
(0, utils_1.assert)((0, utils_1.isFunction)(callback), 'A callback is required for subscription');
|
|
130
|
-
const onNewMessage = (error, result, subscription) => {
|
|
131
|
-
if (error) {
|
|
132
|
-
console.error(error);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
callback(this.#tryDecode(rpcName, result), subscription);
|
|
136
|
-
};
|
|
137
|
-
const [subname, unsubscribe] = subscriptionInfo;
|
|
138
|
-
const subscription = await this.provider.subscribe({ subname, subscribe: rpcName, params: inArgs, unsubscribe }, onNewMessage);
|
|
139
|
-
return async () => {
|
|
140
|
-
await subscription.unsubscribe();
|
|
141
|
-
};
|
|
142
|
-
};
|
|
143
|
-
return isSubscription ? fnSubRpc : fnRpc;
|
|
144
|
-
}
|
|
145
|
-
#tryDecode(rpcName, raw) {
|
|
146
|
-
if (raw === null) {
|
|
147
|
-
// We use `undefined` to represent Option::None in the client
|
|
148
|
-
return undefined;
|
|
149
|
-
}
|
|
150
|
-
const $maybeCodec = this.options.scaledResponses?.[rpcName] || specs_1.scaledResponses[rpcName];
|
|
151
|
-
if ($maybeCodec) {
|
|
152
|
-
return $maybeCodec.tryDecode(raw);
|
|
153
|
-
}
|
|
154
|
-
return raw;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
exports.JsonRpcClient = JsonRpcClient;
|
package/cjs/proxychain.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
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;
|
|
@@ -1,161 +0,0 @@
|
|
|
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;
|
package/cjs/types.js
DELETED