@dedot/api 0.12.1-next.f19f185a.2 → 0.13.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/cjs/executor/ErrorExecutor.js +1 -1
- package/cjs/executor/EventExecutor.js +1 -1
- package/cjs/executor/TxExecutor.js +1 -1
- package/cjs/extrinsic/extensions/ExtraSignedExtension.js +12 -4
- package/cjs/extrinsic/extensions/FallbackSignedExtension.js +4 -0
- package/cjs/extrinsic/extensions/SignedExtension.js +4 -1
- package/cjs/extrinsic/extensions/known/ChargeAssetTxPayment.js +14 -0
- package/cjs/extrinsic/extensions/known/ChargeTransactionPayment.js +4 -0
- package/cjs/extrinsic/extensions/known/CheckGenesis.js +3 -0
- package/cjs/extrinsic/extensions/known/CheckMetadataHash.js +12 -0
- package/cjs/extrinsic/extensions/known/CheckMortality.js +6 -0
- package/cjs/extrinsic/extensions/known/CheckNonce.js +4 -0
- package/cjs/extrinsic/extensions/known/CheckSpecVersion.js +4 -0
- package/cjs/extrinsic/extensions/known/CheckTxVersion.js +4 -0
- package/cjs/extrinsic/submittable/BaseSubmittableExtrinsic.js +1 -1
- package/cjs/extrinsic/submittable/index.js +3 -0
- package/cjs/extrinsic/submittable/utils.js +3 -3
- package/cjs/json-rpc/group/ChainHead/ChainHead.js +3 -2
- package/executor/ErrorExecutor.js +1 -1
- package/executor/EventExecutor.js +1 -1
- package/executor/Executor.d.ts +121 -7
- package/executor/TxExecutor.js +1 -1
- package/extrinsic/extensions/ExtraSignedExtension.d.ts +3 -2
- package/extrinsic/extensions/ExtraSignedExtension.js +13 -5
- package/extrinsic/extensions/FallbackSignedExtension.d.ts +2 -1
- package/extrinsic/extensions/FallbackSignedExtension.js +4 -0
- package/extrinsic/extensions/SignedExtension.d.ts +2 -0
- package/extrinsic/extensions/SignedExtension.js +5 -2
- package/extrinsic/extensions/known/ChargeAssetTxPayment.d.ts +1 -0
- package/extrinsic/extensions/known/ChargeAssetTxPayment.js +15 -1
- package/extrinsic/extensions/known/ChargeTransactionPayment.d.ts +1 -0
- package/extrinsic/extensions/known/ChargeTransactionPayment.js +5 -1
- package/extrinsic/extensions/known/CheckGenesis.d.ts +1 -0
- package/extrinsic/extensions/known/CheckGenesis.js +3 -0
- package/extrinsic/extensions/known/CheckMetadataHash.d.ts +1 -0
- package/extrinsic/extensions/known/CheckMetadataHash.js +12 -0
- package/extrinsic/extensions/known/CheckMortality.d.ts +1 -0
- package/extrinsic/extensions/known/CheckMortality.js +7 -1
- package/extrinsic/extensions/known/CheckNonce.d.ts +1 -0
- package/extrinsic/extensions/known/CheckNonce.js +5 -1
- package/extrinsic/extensions/known/CheckSpecVersion.d.ts +1 -0
- package/extrinsic/extensions/known/CheckSpecVersion.js +5 -1
- package/extrinsic/extensions/known/CheckTxVersion.d.ts +1 -0
- package/extrinsic/extensions/known/CheckTxVersion.js +5 -1
- package/extrinsic/submittable/BaseSubmittableExtrinsic.js +2 -2
- package/extrinsic/submittable/index.d.ts +1 -0
- package/extrinsic/submittable/index.js +1 -0
- package/extrinsic/submittable/utils.d.ts +1 -1
- package/extrinsic/submittable/utils.js +1 -1
- package/json-rpc/group/ChainHead/ChainHead.js +3 -2
- package/package.json +9 -9
|
@@ -12,7 +12,7 @@ class ErrorExecutor extends Executor_js_1.Executor {
|
|
|
12
12
|
const targetPallet = this.getPallet(pallet);
|
|
13
13
|
const errorTypeId = targetPallet.error;
|
|
14
14
|
(0, utils_1.assert)(errorTypeId, new utils_1.UnknownApiError(`Not found error with id ${errorTypeId} in pallet ${pallet}`));
|
|
15
|
-
const errorDef = this.#getErrorDef(errorTypeId, errorName);
|
|
15
|
+
const errorDef = this.#getErrorDef(errorTypeId.typeId, errorName);
|
|
16
16
|
return {
|
|
17
17
|
meta: {
|
|
18
18
|
...errorDef,
|
|
@@ -13,7 +13,7 @@ class EventExecutor extends Executor_js_1.Executor {
|
|
|
13
13
|
const targetPallet = this.getPallet(pallet);
|
|
14
14
|
const eventTypeId = targetPallet.event;
|
|
15
15
|
(0, utils_1.assert)(eventTypeId, new utils_1.UnknownApiError(`Not found event with id ${eventTypeId} in pallet ${pallet}`));
|
|
16
|
-
const eventDef = this.#getEventDef(eventTypeId, eventName);
|
|
16
|
+
const eventDef = this.#getEventDef(eventTypeId.typeId, eventName);
|
|
17
17
|
const is = (event) => {
|
|
18
18
|
if ((0, utils_js_1.isEventRecord)(event)) {
|
|
19
19
|
event = event.event;
|
|
@@ -12,7 +12,7 @@ class TxExecutor extends Executor_js_1.Executor {
|
|
|
12
12
|
doExecute(pallet, functionName) {
|
|
13
13
|
const targetPallet = this.getPallet(pallet);
|
|
14
14
|
(0, utils_1.assert)(targetPallet.calls, new utils_1.UnknownApiError(`Tx calls are not available for pallet ${targetPallet.name}`));
|
|
15
|
-
const txType = this.metadata.types[targetPallet.calls];
|
|
15
|
+
const txType = this.metadata.types[targetPallet.calls.typeId];
|
|
16
16
|
(0, utils_1.assert)(txType.typeDef.type === 'Enum', new utils_1.UnknownApiError('Tx type defs should be enum'));
|
|
17
17
|
const isFlatEnum = txType.typeDef.value.members.every((m) => m.fields.length === 0);
|
|
18
18
|
const txCallDef = txType.typeDef.value.members.find((m) => (0, utils_1.stringCamelCase)(m.name) === functionName);
|
|
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.ExtraSignedExtension = void 0;
|
|
27
|
+
const codecs_1 = require("@dedot/codecs");
|
|
27
28
|
const $ = __importStar(require("@dedot/shape"));
|
|
28
29
|
const utils_1 = require("@dedot/utils");
|
|
29
30
|
const FallbackSignedExtension_js_1 = require("./FallbackSignedExtension.js");
|
|
@@ -37,12 +38,17 @@ class ExtraSignedExtension extends SignedExtension_js_1.SignedExtension {
|
|
|
37
38
|
this.data = this.#signedExtensions.map((se) => se.data);
|
|
38
39
|
this.additionalSigned = this.#signedExtensions.map((se) => se.additionalSigned);
|
|
39
40
|
}
|
|
41
|
+
async fromPayload(payload) {
|
|
42
|
+
this.#signedExtensions = this.#getSignedExtensions();
|
|
43
|
+
await Promise.all(this.#signedExtensions.map((se) => se.fromPayload(payload)));
|
|
44
|
+
this.data = this.#signedExtensions.map((se) => se.data);
|
|
45
|
+
this.additionalSigned = this.#signedExtensions.map((se) => se.additionalSigned);
|
|
46
|
+
}
|
|
40
47
|
get identifier() {
|
|
41
48
|
return 'ExtraSignedExtension';
|
|
42
49
|
}
|
|
43
50
|
get $Data() {
|
|
44
|
-
|
|
45
|
-
return (0, utils_1.ensurePresence)(this.registry.findCodec(extraTypeId));
|
|
51
|
+
return (0, utils_1.ensurePresence)(this.registry.$Extra());
|
|
46
52
|
}
|
|
47
53
|
get $AdditionalSigned() {
|
|
48
54
|
const $AdditionalSignedCodecs = this.#signedExtensionDefs.map((se) => this.registry.findCodec(se.additionalSigned));
|
|
@@ -88,12 +94,14 @@ class ExtraSignedExtension extends SignedExtension_js_1.SignedExtension {
|
|
|
88
94
|
}
|
|
89
95
|
toPayload(call = '0x') {
|
|
90
96
|
const signedExtensions = this.#signedExtensions.map((se) => se.identifier);
|
|
91
|
-
const {
|
|
97
|
+
const { versions } = this.registry.metadata.extrinsic;
|
|
92
98
|
const { signerAddress } = this.options;
|
|
99
|
+
(0, utils_1.assert)(versions.includes(codecs_1.DEFAULT_EXTRINSIC_VERSION), // --
|
|
100
|
+
'Extrinsic Version 4 Not Found');
|
|
93
101
|
return Object.assign({
|
|
94
102
|
address: signerAddress,
|
|
95
103
|
signedExtensions,
|
|
96
|
-
version,
|
|
104
|
+
version: codecs_1.DEFAULT_EXTRINSIC_VERSION,
|
|
97
105
|
method: call,
|
|
98
106
|
withSignedTransaction: true, // allow signer/wallet to alter transaction by default
|
|
99
107
|
}, ...this.#signedExtensions.map((se) => se.toPayload()));
|
|
@@ -30,6 +30,10 @@ class FallbackSignedExtension extends SignedExtension_js_1.SignedExtension {
|
|
|
30
30
|
this.data = {};
|
|
31
31
|
this.additionalSigned = [];
|
|
32
32
|
}
|
|
33
|
+
async fromPayload(_) {
|
|
34
|
+
this.data = {};
|
|
35
|
+
this.additionalSigned = [];
|
|
36
|
+
}
|
|
33
37
|
toPayload() {
|
|
34
38
|
return {}; // No payload contribution
|
|
35
39
|
}
|
|
@@ -14,7 +14,10 @@ class SignedExtension {
|
|
|
14
14
|
this.additionalSigned = [];
|
|
15
15
|
}
|
|
16
16
|
async init() {
|
|
17
|
-
|
|
17
|
+
throw new utils_1.DedotError('Unimplemented');
|
|
18
|
+
}
|
|
19
|
+
async fromPayload(payload) {
|
|
20
|
+
throw new utils_1.DedotError('Unimplemented');
|
|
18
21
|
}
|
|
19
22
|
get identifier() {
|
|
20
23
|
return this.signedExtensionDef.ident;
|
|
@@ -14,6 +14,13 @@ class ChargeAssetTxPayment extends SignedExtension_js_1.SignedExtension {
|
|
|
14
14
|
assetId,
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
+
async fromPayload(payload) {
|
|
18
|
+
const { tip, assetId } = payload;
|
|
19
|
+
this.data = {
|
|
20
|
+
tip: (0, utils_1.hexToBn)(tip) || 0n,
|
|
21
|
+
assetId: this.#decodeAssetId(assetId),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
17
24
|
toPayload() {
|
|
18
25
|
const { tip, assetId } = this.data;
|
|
19
26
|
return {
|
|
@@ -28,6 +35,13 @@ class ChargeAssetTxPayment extends SignedExtension_js_1.SignedExtension {
|
|
|
28
35
|
}
|
|
29
36
|
return (0, utils_1.u8aToHex)(this.$AssetId().tryEncode(assetId));
|
|
30
37
|
}
|
|
38
|
+
#decodeAssetId(assetId) {
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
if (assetId === null || assetId === undefined || assetId === '' || assetId === '0x') {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return this.$AssetId().tryDecode(assetId);
|
|
44
|
+
}
|
|
31
45
|
$AssetId() {
|
|
32
46
|
const extensionTypeDef = this.registry.findType(this.signedExtensionDef.typeId);
|
|
33
47
|
(0, utils_1.assert)(extensionTypeDef.typeDef.type === 'Struct');
|
|
@@ -7,6 +7,10 @@ class ChargeTransactionPayment extends SignedExtension_js_1.SignedExtension {
|
|
|
7
7
|
async init() {
|
|
8
8
|
this.data = this.payloadOptions.tip || 0n;
|
|
9
9
|
}
|
|
10
|
+
async fromPayload(payload) {
|
|
11
|
+
const { tip } = payload;
|
|
12
|
+
this.data = (0, utils_1.hexToBn)(tip) || 0n;
|
|
13
|
+
}
|
|
10
14
|
toPayload() {
|
|
11
15
|
return {
|
|
12
16
|
tip: (0, utils_1.bnToHex)(this.data),
|
|
@@ -10,6 +10,9 @@ class CheckGenesis extends SignedExtension_js_1.SignedExtension {
|
|
|
10
10
|
async init() {
|
|
11
11
|
this.additionalSigned = (0, utils_1.ensurePresence)(this.client.genesisHash);
|
|
12
12
|
}
|
|
13
|
+
async fromPayload(payload) {
|
|
14
|
+
this.additionalSigned = (0, utils_1.ensurePresence)(payload.genesisHash, 'Genesis hash not found in the payload');
|
|
15
|
+
}
|
|
13
16
|
toPayload() {
|
|
14
17
|
return {
|
|
15
18
|
genesisHash: this.additionalSigned,
|
|
@@ -19,6 +19,18 @@ class CheckMetadataHash extends SignedExtension_js_1.SignedExtension {
|
|
|
19
19
|
this.additionalSigned = undefined;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
async fromPayload(payload) {
|
|
23
|
+
const { mode, metadataHash } = payload;
|
|
24
|
+
if (mode) {
|
|
25
|
+
(0, utils_1.assert)((0, utils_1.isHex)(metadataHash), 'Metadata hash is not a valid hex string');
|
|
26
|
+
this.data = { mode: 'Enabled' };
|
|
27
|
+
this.additionalSigned = metadataHash;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.data = { mode: 'Disabled' };
|
|
31
|
+
this.additionalSigned = undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
22
34
|
toPayload() {
|
|
23
35
|
// Ref: https://github.com/paritytech/polkadot-sdk/blob/8dbe4ee80734bba6644c7e5f879a363ce7c0a19f/substrate/frame/metadata-hash-extension/src/lib.rs#L55-L58
|
|
24
36
|
let enabled = this.data.mode === 'Enabled';
|
|
@@ -17,6 +17,12 @@ class CheckMortality extends SignedExtension_js_1.SignedExtension {
|
|
|
17
17
|
this.data = { period: this.#calculateMortalLength(), current: BigInt(this.#signingHeader.number) };
|
|
18
18
|
this.additionalSigned = this.#signingHeader.hash;
|
|
19
19
|
}
|
|
20
|
+
async fromPayload(payload) {
|
|
21
|
+
const { era, blockHash, blockNumber } = payload;
|
|
22
|
+
this.#signingHeader = { hash: blockHash, number: (0, utils_1.hexToNumber)(blockNumber) };
|
|
23
|
+
this.data = this.$Data.tryDecode(era);
|
|
24
|
+
this.additionalSigned = blockHash;
|
|
25
|
+
}
|
|
20
26
|
async #getSigningHeader() {
|
|
21
27
|
if (this.client.rpcVersion === 'v2') {
|
|
22
28
|
return this.#getSigningHeaderRpcV2();
|
|
@@ -10,6 +10,10 @@ class CheckNonce extends SignedExtension_js_1.SignedExtension {
|
|
|
10
10
|
async init() {
|
|
11
11
|
this.data = this.payloadOptions.nonce || (await this.#getNonce());
|
|
12
12
|
}
|
|
13
|
+
async fromPayload(payload) {
|
|
14
|
+
const { nonce } = payload;
|
|
15
|
+
this.data = (0, utils_1.hexToNumber)(nonce);
|
|
16
|
+
}
|
|
13
17
|
async #getNonce() {
|
|
14
18
|
const { signerAddress } = this.options || {};
|
|
15
19
|
(0, utils_1.assert)(signerAddress, 'Signer address not found');
|
|
@@ -10,6 +10,10 @@ class CheckSpecVersion extends SignedExtension_js_1.SignedExtension {
|
|
|
10
10
|
async init() {
|
|
11
11
|
this.additionalSigned = this.client.runtimeVersion.specVersion;
|
|
12
12
|
}
|
|
13
|
+
async fromPayload(payload) {
|
|
14
|
+
const { specVersion } = payload;
|
|
15
|
+
this.additionalSigned = (0, utils_1.hexToNumber)(specVersion);
|
|
16
|
+
}
|
|
13
17
|
toPayload() {
|
|
14
18
|
return {
|
|
15
19
|
specVersion: (0, utils_1.numberToHex)(this.additionalSigned),
|
|
@@ -10,6 +10,10 @@ class CheckTxVersion extends SignedExtension_js_1.SignedExtension {
|
|
|
10
10
|
async init() {
|
|
11
11
|
this.additionalSigned = this.client.runtimeVersion.transactionVersion;
|
|
12
12
|
}
|
|
13
|
+
async fromPayload(payload) {
|
|
14
|
+
const { transactionVersion } = payload;
|
|
15
|
+
this.additionalSigned = (0, utils_1.hexToNumber)(transactionVersion);
|
|
16
|
+
}
|
|
13
17
|
toPayload() {
|
|
14
18
|
return {
|
|
15
19
|
transactionVersion: (0, utils_1.numberToHex)(this.additionalSigned),
|
|
@@ -29,7 +29,7 @@ class BaseSubmittableExtrinsic extends codecs_1.Extrinsic {
|
|
|
29
29
|
const signer = this.#getSigner(options);
|
|
30
30
|
let signature, alteredTx;
|
|
31
31
|
if ((0, utils_js_1.isKeyringPair)(fromAccount)) {
|
|
32
|
-
signature = (0, utils_1.u8aToHex)((0, utils_js_1.
|
|
32
|
+
signature = (0, utils_1.u8aToHex)((0, utils_js_1.signRawMessage)(fromAccount, extra.toRawPayload(this.callHex).data));
|
|
33
33
|
}
|
|
34
34
|
else if (signer?.signPayload) {
|
|
35
35
|
const result = await signer.signPayload(extra.toPayload(this.callHex));
|
|
@@ -14,7 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.signRawMessage = void 0;
|
|
17
18
|
__exportStar(require("./errors.js"), exports);
|
|
18
19
|
__exportStar(require("./SubmittableResult.js"), exports);
|
|
19
20
|
__exportStar(require("./SubmittableExtrinsic.js"), exports);
|
|
20
21
|
__exportStar(require("./SubmittableExtrinsicV2.js"), exports);
|
|
22
|
+
var utils_js_1 = require("./utils.js");
|
|
23
|
+
Object.defineProperty(exports, "signRawMessage", { enumerable: true, get: function () { return utils_js_1.signRawMessage; } });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.txDefer = exports.toTxStatus = exports.
|
|
3
|
+
exports.txDefer = exports.toTxStatus = exports.signRawMessage = exports.isKeyringPair = void 0;
|
|
4
4
|
const utils_1 = require("@dedot/utils");
|
|
5
5
|
const errors_js_1 = require("./errors.js");
|
|
6
6
|
function isKeyringPair(account) {
|
|
@@ -12,13 +12,13 @@ exports.isKeyringPair = isKeyringPair;
|
|
|
12
12
|
* @param signerPair
|
|
13
13
|
* @param raw
|
|
14
14
|
*/
|
|
15
|
-
function
|
|
15
|
+
function signRawMessage(signerPair, raw) {
|
|
16
16
|
const u8a = (0, utils_1.hexToU8a)(raw);
|
|
17
17
|
// Ref: https://github.com/paritytech/polkadot-sdk/blob/943697fa693a4da6ef481ef93df522accb7d0583/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs#L234-L238
|
|
18
18
|
const toSignRaw = u8a.length > 256 ? (0, utils_1.blake2AsU8a)(u8a, 256) : u8a;
|
|
19
19
|
return signerPair.sign(toSignRaw, { withType: true });
|
|
20
20
|
}
|
|
21
|
-
exports.
|
|
21
|
+
exports.signRawMessage = signRawMessage;
|
|
22
22
|
/**
|
|
23
23
|
* Convert transaction status to transaction event
|
|
24
24
|
*
|
|
@@ -83,18 +83,19 @@ class ChainHead extends JsonRpcGroup_js_1.JsonRpcGroup {
|
|
|
83
83
|
const defer = (0, utils_1.deferred)();
|
|
84
84
|
try {
|
|
85
85
|
this.#unsub && this.#unsub().catch(utils_1.noop); // ensure unfollowed
|
|
86
|
+
const SIGNAL_THRESHOLD = this.#__unsafe__isSmoldot() ? 2 : 1;
|
|
86
87
|
let signals = 0;
|
|
87
88
|
this.#unsub = await this.send('follow', true, (event, subscription) => {
|
|
88
89
|
this.#followResponseQueue
|
|
89
90
|
.enqueue(async () => {
|
|
90
91
|
await this.#onFollowEvent(event, subscription);
|
|
91
|
-
if (signals >=
|
|
92
|
+
if (signals >= SIGNAL_THRESHOLD)
|
|
92
93
|
return;
|
|
93
94
|
signals += 1;
|
|
94
95
|
// Sometime smoldot send a `stop` event right after `initialized`
|
|
95
96
|
// So requests sending between `initialized` and `stop` will be on pruned hashes -> throwing out errors
|
|
96
97
|
// Here we make sure to receive at least the first 2 signals to resolve
|
|
97
|
-
if (signals >=
|
|
98
|
+
if (signals >= SIGNAL_THRESHOLD) {
|
|
98
99
|
defer.resolve();
|
|
99
100
|
}
|
|
100
101
|
})
|
|
@@ -9,7 +9,7 @@ export class ErrorExecutor extends Executor {
|
|
|
9
9
|
const targetPallet = this.getPallet(pallet);
|
|
10
10
|
const errorTypeId = targetPallet.error;
|
|
11
11
|
assert(errorTypeId, new UnknownApiError(`Not found error with id ${errorTypeId} in pallet ${pallet}`));
|
|
12
|
-
const errorDef = this.#getErrorDef(errorTypeId, errorName);
|
|
12
|
+
const errorDef = this.#getErrorDef(errorTypeId.typeId, errorName);
|
|
13
13
|
return {
|
|
14
14
|
meta: {
|
|
15
15
|
...errorDef,
|
|
@@ -10,7 +10,7 @@ export class EventExecutor extends Executor {
|
|
|
10
10
|
const targetPallet = this.getPallet(pallet);
|
|
11
11
|
const eventTypeId = targetPallet.event;
|
|
12
12
|
assert(eventTypeId, new UnknownApiError(`Not found event with id ${eventTypeId} in pallet ${pallet}`));
|
|
13
|
-
const eventDef = this.#getEventDef(eventTypeId, eventName);
|
|
13
|
+
const eventDef = this.#getEventDef(eventTypeId.typeId, eventName);
|
|
14
14
|
const is = (event) => {
|
|
15
15
|
if (isEventRecord(event)) {
|
|
16
16
|
event = event.event;
|
package/executor/Executor.d.ts
CHANGED
|
@@ -91,33 +91,124 @@ export declare abstract class Executor<ChainApi extends GenericSubstrateApi = Ge
|
|
|
91
91
|
};
|
|
92
92
|
default: `0x${string}`;
|
|
93
93
|
docs: string[];
|
|
94
|
+
deprecationInfo: {
|
|
95
|
+
type: "NotDeprecated";
|
|
96
|
+
} | {
|
|
97
|
+
type: "DeprecatedWithoutNote";
|
|
98
|
+
} | {
|
|
99
|
+
type: "Deprecated";
|
|
100
|
+
value: {
|
|
101
|
+
note: string;
|
|
102
|
+
since: string | undefined;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
94
105
|
}[];
|
|
95
106
|
} | undefined;
|
|
96
|
-
calls:
|
|
97
|
-
|
|
107
|
+
calls: {
|
|
108
|
+
typeId: number;
|
|
109
|
+
deprecationInfo: readonly [ReadonlyMap<number, {
|
|
110
|
+
type: "DeprecatedWithoutNote";
|
|
111
|
+
} | {
|
|
112
|
+
type: "Deprecated";
|
|
113
|
+
value: {
|
|
114
|
+
note: string;
|
|
115
|
+
since: string | undefined;
|
|
116
|
+
};
|
|
117
|
+
}>];
|
|
118
|
+
} | undefined;
|
|
119
|
+
event: {
|
|
120
|
+
typeId: number;
|
|
121
|
+
deprecationInfo: readonly [ReadonlyMap<number, {
|
|
122
|
+
type: "DeprecatedWithoutNote";
|
|
123
|
+
} | {
|
|
124
|
+
type: "Deprecated";
|
|
125
|
+
value: {
|
|
126
|
+
note: string;
|
|
127
|
+
since: string | undefined;
|
|
128
|
+
};
|
|
129
|
+
}>];
|
|
130
|
+
} | undefined;
|
|
98
131
|
constants: {
|
|
99
132
|
name: string;
|
|
100
133
|
typeId: number;
|
|
101
134
|
value: `0x${string}`;
|
|
102
135
|
docs: string[];
|
|
136
|
+
deprecationInfo: {
|
|
137
|
+
type: "NotDeprecated";
|
|
138
|
+
} | {
|
|
139
|
+
type: "DeprecatedWithoutNote";
|
|
140
|
+
} | {
|
|
141
|
+
type: "Deprecated";
|
|
142
|
+
value: {
|
|
143
|
+
note: string;
|
|
144
|
+
since: string | undefined;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
}[];
|
|
148
|
+
error: {
|
|
149
|
+
typeId: number;
|
|
150
|
+
deprecationInfo: readonly [ReadonlyMap<number, {
|
|
151
|
+
type: "DeprecatedWithoutNote";
|
|
152
|
+
} | {
|
|
153
|
+
type: "Deprecated";
|
|
154
|
+
value: {
|
|
155
|
+
note: string;
|
|
156
|
+
since: string | undefined;
|
|
157
|
+
};
|
|
158
|
+
}>];
|
|
159
|
+
} | undefined;
|
|
160
|
+
associatedTypes: {
|
|
161
|
+
name: string;
|
|
162
|
+
typeId: number;
|
|
163
|
+
docs: string[];
|
|
164
|
+
}[];
|
|
165
|
+
viewFunctions: {
|
|
166
|
+
id: readonly [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number];
|
|
167
|
+
name: string;
|
|
168
|
+
inputs: {
|
|
169
|
+
name: string;
|
|
170
|
+
typeId: number;
|
|
171
|
+
}[];
|
|
172
|
+
output: number;
|
|
173
|
+
docs: string[];
|
|
174
|
+
deprecationInfo: {
|
|
175
|
+
type: "NotDeprecated";
|
|
176
|
+
} | {
|
|
177
|
+
type: "DeprecatedWithoutNote";
|
|
178
|
+
} | {
|
|
179
|
+
type: "Deprecated";
|
|
180
|
+
value: {
|
|
181
|
+
note: string;
|
|
182
|
+
since: string | undefined;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
103
185
|
}[];
|
|
104
|
-
error: number | undefined;
|
|
105
186
|
index: number;
|
|
106
187
|
docs: string[];
|
|
188
|
+
deprecationInfo: {
|
|
189
|
+
type: "NotDeprecated";
|
|
190
|
+
} | {
|
|
191
|
+
type: "DeprecatedWithoutNote";
|
|
192
|
+
} | {
|
|
193
|
+
type: "Deprecated";
|
|
194
|
+
value: {
|
|
195
|
+
note: string;
|
|
196
|
+
since: string | undefined;
|
|
197
|
+
};
|
|
198
|
+
};
|
|
107
199
|
}[];
|
|
108
200
|
extrinsic: {
|
|
109
|
-
|
|
201
|
+
versions: number[];
|
|
110
202
|
addressTypeId: number;
|
|
111
|
-
callTypeId: number;
|
|
112
203
|
signatureTypeId: number;
|
|
113
|
-
|
|
204
|
+
callTypeId: number;
|
|
205
|
+
signedExtensionsByVersion: ReadonlyMap<number, number[]>;
|
|
114
206
|
signedExtensions: {
|
|
115
207
|
ident: string;
|
|
116
208
|
typeId: number;
|
|
117
209
|
additionalSigned: number;
|
|
118
210
|
}[];
|
|
119
211
|
};
|
|
120
|
-
runtimeType: number;
|
|
121
212
|
apis: {
|
|
122
213
|
name: string;
|
|
123
214
|
methods: {
|
|
@@ -128,8 +219,31 @@ export declare abstract class Executor<ChainApi extends GenericSubstrateApi = Ge
|
|
|
128
219
|
}[];
|
|
129
220
|
output: number;
|
|
130
221
|
docs: string[];
|
|
222
|
+
deprecationInfo: {
|
|
223
|
+
type: "NotDeprecated";
|
|
224
|
+
} | {
|
|
225
|
+
type: "DeprecatedWithoutNote";
|
|
226
|
+
} | {
|
|
227
|
+
type: "Deprecated";
|
|
228
|
+
value: {
|
|
229
|
+
note: string;
|
|
230
|
+
since: string | undefined;
|
|
231
|
+
};
|
|
232
|
+
};
|
|
131
233
|
}[];
|
|
132
234
|
docs: string[];
|
|
235
|
+
version: number;
|
|
236
|
+
deprecationInfo: {
|
|
237
|
+
type: "NotDeprecated";
|
|
238
|
+
} | {
|
|
239
|
+
type: "DeprecatedWithoutNote";
|
|
240
|
+
} | {
|
|
241
|
+
type: "Deprecated";
|
|
242
|
+
value: {
|
|
243
|
+
note: string;
|
|
244
|
+
since: string | undefined;
|
|
245
|
+
};
|
|
246
|
+
};
|
|
133
247
|
}[];
|
|
134
248
|
outerEnums: {
|
|
135
249
|
callEnumTypeId: number;
|
package/executor/TxExecutor.js
CHANGED
|
@@ -9,7 +9,7 @@ export class TxExecutor extends Executor {
|
|
|
9
9
|
doExecute(pallet, functionName) {
|
|
10
10
|
const targetPallet = this.getPallet(pallet);
|
|
11
11
|
assert(targetPallet.calls, new UnknownApiError(`Tx calls are not available for pallet ${targetPallet.name}`));
|
|
12
|
-
const txType = this.metadata.types[targetPallet.calls];
|
|
12
|
+
const txType = this.metadata.types[targetPallet.calls.typeId];
|
|
13
13
|
assert(txType.typeDef.type === 'Enum', new UnknownApiError('Tx type defs should be enum'));
|
|
14
14
|
const isFlatEnum = txType.typeDef.value.members.every((m) => m.fields.length === 0);
|
|
15
15
|
const txCallDef = txType.typeDef.value.members.find((m) => stringCamelCase(m.name) === functionName);
|
|
@@ -5,6 +5,7 @@ import { SignedExtension } from './SignedExtension.js';
|
|
|
5
5
|
export declare class ExtraSignedExtension extends SignedExtension<any[], any[]> {
|
|
6
6
|
#private;
|
|
7
7
|
init(): Promise<void>;
|
|
8
|
+
fromPayload(payload: SignerPayloadJSON): Promise<void>;
|
|
8
9
|
get identifier(): string;
|
|
9
10
|
get $Data(): $.AnyShape;
|
|
10
11
|
get $AdditionalSigned(): $.AnyShape;
|
|
@@ -15,6 +16,6 @@ export declare class ExtraSignedExtension extends SignedExtension<any[], any[]>
|
|
|
15
16
|
* @returns boolean
|
|
16
17
|
*/
|
|
17
18
|
private isRequireNoExternalInputs;
|
|
18
|
-
toPayload(call?: HexString): SignerPayloadJSON;
|
|
19
|
-
toRawPayload(call?: HexString): SignerPayloadRaw;
|
|
19
|
+
toPayload(call?: HexString | string): SignerPayloadJSON;
|
|
20
|
+
toRawPayload(call?: HexString | string): SignerPayloadRaw;
|
|
20
21
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { DEFAULT_EXTRINSIC_VERSION } from '@dedot/codecs';
|
|
1
2
|
import * as $ from '@dedot/shape';
|
|
2
|
-
import { ensurePresence, u8aToHex } from '@dedot/utils';
|
|
3
|
+
import { assert, ensurePresence, u8aToHex } from '@dedot/utils';
|
|
3
4
|
import { FallbackSignedExtension, isEmptyStructOrTuple } from './FallbackSignedExtension.js';
|
|
4
5
|
import { SignedExtension } from './SignedExtension.js';
|
|
5
6
|
import { knownSignedExtensions } from './known/index.js';
|
|
@@ -11,12 +12,17 @@ export class ExtraSignedExtension extends SignedExtension {
|
|
|
11
12
|
this.data = this.#signedExtensions.map((se) => se.data);
|
|
12
13
|
this.additionalSigned = this.#signedExtensions.map((se) => se.additionalSigned);
|
|
13
14
|
}
|
|
15
|
+
async fromPayload(payload) {
|
|
16
|
+
this.#signedExtensions = this.#getSignedExtensions();
|
|
17
|
+
await Promise.all(this.#signedExtensions.map((se) => se.fromPayload(payload)));
|
|
18
|
+
this.data = this.#signedExtensions.map((se) => se.data);
|
|
19
|
+
this.additionalSigned = this.#signedExtensions.map((se) => se.additionalSigned);
|
|
20
|
+
}
|
|
14
21
|
get identifier() {
|
|
15
22
|
return 'ExtraSignedExtension';
|
|
16
23
|
}
|
|
17
24
|
get $Data() {
|
|
18
|
-
|
|
19
|
-
return ensurePresence(this.registry.findCodec(extraTypeId));
|
|
25
|
+
return ensurePresence(this.registry.$Extra());
|
|
20
26
|
}
|
|
21
27
|
get $AdditionalSigned() {
|
|
22
28
|
const $AdditionalSignedCodecs = this.#signedExtensionDefs.map((se) => this.registry.findCodec(se.additionalSigned));
|
|
@@ -62,12 +68,14 @@ export class ExtraSignedExtension extends SignedExtension {
|
|
|
62
68
|
}
|
|
63
69
|
toPayload(call = '0x') {
|
|
64
70
|
const signedExtensions = this.#signedExtensions.map((se) => se.identifier);
|
|
65
|
-
const {
|
|
71
|
+
const { versions } = this.registry.metadata.extrinsic;
|
|
66
72
|
const { signerAddress } = this.options;
|
|
73
|
+
assert(versions.includes(DEFAULT_EXTRINSIC_VERSION), // --
|
|
74
|
+
'Extrinsic Version 4 Not Found');
|
|
67
75
|
return Object.assign({
|
|
68
76
|
address: signerAddress,
|
|
69
77
|
signedExtensions,
|
|
70
|
-
version,
|
|
78
|
+
version: DEFAULT_EXTRINSIC_VERSION,
|
|
71
79
|
method: call,
|
|
72
80
|
withSignedTransaction: true, // allow signer/wallet to alter transaction by default
|
|
73
81
|
}, ...this.#signedExtensions.map((se) => se.toPayload()));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PortableRegistry } from '@dedot/codecs';
|
|
2
2
|
import { SignerPayloadJSON } from '@dedot/types';
|
|
3
|
-
import { SignedExtension } from './SignedExtension.js';
|
|
4
3
|
import { ISubstrateClient } from '../../types.js';
|
|
4
|
+
import { SignedExtension } from './SignedExtension.js';
|
|
5
5
|
/**
|
|
6
6
|
* A fallback signed extension that can be used for extensions
|
|
7
7
|
* that don't require external input.
|
|
@@ -21,6 +21,7 @@ export declare class FallbackSignedExtension extends SignedExtension {
|
|
|
21
21
|
constructor(client: ISubstrateClient, options: any, extensionIdent: string);
|
|
22
22
|
get identifier(): string;
|
|
23
23
|
init(): Promise<void>;
|
|
24
|
+
fromPayload(_: SignerPayloadJSON): Promise<void>;
|
|
24
25
|
toPayload(): Partial<SignerPayloadJSON>;
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
@@ -27,6 +27,10 @@ export class FallbackSignedExtension extends SignedExtension {
|
|
|
27
27
|
this.data = {};
|
|
28
28
|
this.additionalSigned = [];
|
|
29
29
|
}
|
|
30
|
+
async fromPayload(_) {
|
|
31
|
+
this.data = {};
|
|
32
|
+
this.additionalSigned = [];
|
|
33
|
+
}
|
|
30
34
|
toPayload() {
|
|
31
35
|
return {}; // No payload contribution
|
|
32
36
|
}
|
|
@@ -9,6 +9,7 @@ export interface ISignedExtension {
|
|
|
9
9
|
data: any;
|
|
10
10
|
additionalSigned: any;
|
|
11
11
|
init(): Promise<void>;
|
|
12
|
+
fromPayload(payload: SignerPayloadJSON): Promise<void>;
|
|
12
13
|
registry: PortableRegistry;
|
|
13
14
|
toPayload(...additional: any[]): Partial<SignerPayloadJSON>;
|
|
14
15
|
}
|
|
@@ -24,6 +25,7 @@ export declare abstract class SignedExtension<Data extends any = {}, AdditionalS
|
|
|
24
25
|
additionalSigned: AdditionalSigned;
|
|
25
26
|
constructor(client: ISubstrateClient, options?: SignedExtensionOptions | undefined);
|
|
26
27
|
init(): Promise<void>;
|
|
28
|
+
fromPayload(payload: SignerPayloadJSON): Promise<void>;
|
|
27
29
|
get identifier(): string;
|
|
28
30
|
get $Data(): $.AnyShape;
|
|
29
31
|
get $AdditionalSigned(): $.AnyShape;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ensurePresence } from '@dedot/utils';
|
|
1
|
+
import { DedotError, ensurePresence } from '@dedot/utils';
|
|
2
2
|
export class SignedExtension {
|
|
3
3
|
client;
|
|
4
4
|
options;
|
|
@@ -11,7 +11,10 @@ export class SignedExtension {
|
|
|
11
11
|
this.additionalSigned = [];
|
|
12
12
|
}
|
|
13
13
|
async init() {
|
|
14
|
-
|
|
14
|
+
throw new DedotError('Unimplemented');
|
|
15
|
+
}
|
|
16
|
+
async fromPayload(payload) {
|
|
17
|
+
throw new DedotError('Unimplemented');
|
|
15
18
|
}
|
|
16
19
|
get identifier() {
|
|
17
20
|
return this.signedExtensionDef.ident;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assert, bnToHex, u8aToHex } from '@dedot/utils';
|
|
1
|
+
import { assert, bnToHex, hexToBn, u8aToHex } from '@dedot/utils';
|
|
2
2
|
import { SignedExtension } from '../SignedExtension.js';
|
|
3
3
|
/**
|
|
4
4
|
* @name ChargeAssetTxPayment
|
|
@@ -11,6 +11,13 @@ export class ChargeAssetTxPayment extends SignedExtension {
|
|
|
11
11
|
assetId,
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
+
async fromPayload(payload) {
|
|
15
|
+
const { tip, assetId } = payload;
|
|
16
|
+
this.data = {
|
|
17
|
+
tip: hexToBn(tip) || 0n,
|
|
18
|
+
assetId: this.#decodeAssetId(assetId),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
14
21
|
toPayload() {
|
|
15
22
|
const { tip, assetId } = this.data;
|
|
16
23
|
return {
|
|
@@ -25,6 +32,13 @@ export class ChargeAssetTxPayment extends SignedExtension {
|
|
|
25
32
|
}
|
|
26
33
|
return u8aToHex(this.$AssetId().tryEncode(assetId));
|
|
27
34
|
}
|
|
35
|
+
#decodeAssetId(assetId) {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
if (assetId === null || assetId === undefined || assetId === '' || assetId === '0x') {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return this.$AssetId().tryDecode(assetId);
|
|
41
|
+
}
|
|
28
42
|
$AssetId() {
|
|
29
43
|
const extensionTypeDef = this.registry.findType(this.signedExtensionDef.typeId);
|
|
30
44
|
assert(extensionTypeDef.typeDef.type === 'Struct');
|
|
@@ -2,5 +2,6 @@ import { SignerPayloadJSON } from '@dedot/types';
|
|
|
2
2
|
import { SignedExtension } from '../SignedExtension.js';
|
|
3
3
|
export declare class ChargeTransactionPayment extends SignedExtension<bigint> {
|
|
4
4
|
init(): Promise<void>;
|
|
5
|
+
fromPayload(payload: SignerPayloadJSON): Promise<void>;
|
|
5
6
|
toPayload(): Partial<SignerPayloadJSON>;
|
|
6
7
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { bnToHex } from '@dedot/utils';
|
|
1
|
+
import { bnToHex, hexToBn } from '@dedot/utils';
|
|
2
2
|
import { SignedExtension } from '../SignedExtension.js';
|
|
3
3
|
export class ChargeTransactionPayment extends SignedExtension {
|
|
4
4
|
async init() {
|
|
5
5
|
this.data = this.payloadOptions.tip || 0n;
|
|
6
6
|
}
|
|
7
|
+
async fromPayload(payload) {
|
|
8
|
+
const { tip } = payload;
|
|
9
|
+
this.data = hexToBn(tip) || 0n;
|
|
10
|
+
}
|
|
7
11
|
toPayload() {
|
|
8
12
|
return {
|
|
9
13
|
tip: bnToHex(this.data),
|
|
@@ -7,6 +7,9 @@ export class CheckGenesis extends SignedExtension {
|
|
|
7
7
|
async init() {
|
|
8
8
|
this.additionalSigned = ensurePresence(this.client.genesisHash);
|
|
9
9
|
}
|
|
10
|
+
async fromPayload(payload) {
|
|
11
|
+
this.additionalSigned = ensurePresence(payload.genesisHash, 'Genesis hash not found in the payload');
|
|
12
|
+
}
|
|
10
13
|
toPayload() {
|
|
11
14
|
return {
|
|
12
15
|
genesisHash: this.additionalSigned,
|
|
@@ -16,6 +16,18 @@ export class CheckMetadataHash extends SignedExtension {
|
|
|
16
16
|
this.additionalSigned = undefined;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
async fromPayload(payload) {
|
|
20
|
+
const { mode, metadataHash } = payload;
|
|
21
|
+
if (mode) {
|
|
22
|
+
assert(isHex(metadataHash), 'Metadata hash is not a valid hex string');
|
|
23
|
+
this.data = { mode: 'Enabled' };
|
|
24
|
+
this.additionalSigned = metadataHash;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.data = { mode: 'Disabled' };
|
|
28
|
+
this.additionalSigned = undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
19
31
|
toPayload() {
|
|
20
32
|
// Ref: https://github.com/paritytech/polkadot-sdk/blob/8dbe4ee80734bba6644c7e5f879a363ce7c0a19f/substrate/frame/metadata-hash-extension/src/lib.rs#L55-L58
|
|
21
33
|
let enabled = this.data.mode === 'Enabled';
|
|
@@ -11,5 +11,6 @@ export declare const MORTAL_PERIOD: number;
|
|
|
11
11
|
export declare class CheckMortality extends SignedExtension<EraLike, Hash> {
|
|
12
12
|
#private;
|
|
13
13
|
init(): Promise<void>;
|
|
14
|
+
fromPayload(payload: SignerPayloadJSON): Promise<void>;
|
|
14
15
|
toPayload(): Partial<SignerPayloadJSON>;
|
|
15
16
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assert, bnMin, isZeroHex, numberToHex, u8aToHex } from '@dedot/utils';
|
|
1
|
+
import { assert, bnMin, hexToNumber, isZeroHex, numberToHex, u8aToHex } from '@dedot/utils';
|
|
2
2
|
import { SignedExtension } from '../SignedExtension.js';
|
|
3
3
|
export const MAX_FINALITY_LAG = 5;
|
|
4
4
|
export const FALLBACK_MAX_HASH_COUNT = 250;
|
|
@@ -14,6 +14,12 @@ export class CheckMortality extends SignedExtension {
|
|
|
14
14
|
this.data = { period: this.#calculateMortalLength(), current: BigInt(this.#signingHeader.number) };
|
|
15
15
|
this.additionalSigned = this.#signingHeader.hash;
|
|
16
16
|
}
|
|
17
|
+
async fromPayload(payload) {
|
|
18
|
+
const { era, blockHash, blockNumber } = payload;
|
|
19
|
+
this.#signingHeader = { hash: blockHash, number: hexToNumber(blockNumber) };
|
|
20
|
+
this.data = this.$Data.tryDecode(era);
|
|
21
|
+
this.additionalSigned = blockHash;
|
|
22
|
+
}
|
|
17
23
|
async #getSigningHeader() {
|
|
18
24
|
if (this.client.rpcVersion === 'v2') {
|
|
19
25
|
return this.#getSigningHeaderRpcV2();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assert, numberToHex } from '@dedot/utils';
|
|
1
|
+
import { assert, hexToNumber, numberToHex } from '@dedot/utils';
|
|
2
2
|
import { SignedExtension } from '../SignedExtension.js';
|
|
3
3
|
/**
|
|
4
4
|
* @description Nonce check and increment to give replay protection for transactions.
|
|
@@ -7,6 +7,10 @@ export class CheckNonce extends SignedExtension {
|
|
|
7
7
|
async init() {
|
|
8
8
|
this.data = this.payloadOptions.nonce || (await this.#getNonce());
|
|
9
9
|
}
|
|
10
|
+
async fromPayload(payload) {
|
|
11
|
+
const { nonce } = payload;
|
|
12
|
+
this.data = hexToNumber(nonce);
|
|
13
|
+
}
|
|
10
14
|
async #getNonce() {
|
|
11
15
|
const { signerAddress } = this.options || {};
|
|
12
16
|
assert(signerAddress, 'Signer address not found');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { numberToHex } from '@dedot/utils';
|
|
1
|
+
import { hexToNumber, numberToHex } from '@dedot/utils';
|
|
2
2
|
import { SignedExtension } from '../SignedExtension.js';
|
|
3
3
|
/**
|
|
4
4
|
* @description Ensure the runtime version registered in the transaction is the same as at present.
|
|
@@ -7,6 +7,10 @@ export class CheckSpecVersion extends SignedExtension {
|
|
|
7
7
|
async init() {
|
|
8
8
|
this.additionalSigned = this.client.runtimeVersion.specVersion;
|
|
9
9
|
}
|
|
10
|
+
async fromPayload(payload) {
|
|
11
|
+
const { specVersion } = payload;
|
|
12
|
+
this.additionalSigned = hexToNumber(specVersion);
|
|
13
|
+
}
|
|
10
14
|
toPayload() {
|
|
11
15
|
return {
|
|
12
16
|
specVersion: numberToHex(this.additionalSigned),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { numberToHex } from '@dedot/utils';
|
|
1
|
+
import { hexToNumber, numberToHex } from '@dedot/utils';
|
|
2
2
|
import { SignedExtension } from '../SignedExtension.js';
|
|
3
3
|
/**
|
|
4
4
|
* @description Ensure the transaction version registered in the transaction is the same as at present.
|
|
@@ -7,6 +7,10 @@ export class CheckTxVersion extends SignedExtension {
|
|
|
7
7
|
async init() {
|
|
8
8
|
this.additionalSigned = this.client.runtimeVersion.transactionVersion;
|
|
9
9
|
}
|
|
10
|
+
async fromPayload(payload) {
|
|
11
|
+
const { transactionVersion } = payload;
|
|
12
|
+
this.additionalSigned = hexToNumber(transactionVersion);
|
|
13
|
+
}
|
|
10
14
|
toPayload() {
|
|
11
15
|
return {
|
|
12
16
|
transactionVersion: numberToHex(this.additionalSigned),
|
|
@@ -2,7 +2,7 @@ import { Extrinsic } from '@dedot/codecs';
|
|
|
2
2
|
import { DedotError, isFunction, toHex, u8aToHex } from '@dedot/utils';
|
|
3
3
|
import { ExtraSignedExtension } from '../extensions/index.js';
|
|
4
4
|
import { fakeSigner } from './fakeSigner.js';
|
|
5
|
-
import { isKeyringPair,
|
|
5
|
+
import { isKeyringPair, signRawMessage, txDefer } from './utils.js';
|
|
6
6
|
export class BaseSubmittableExtrinsic extends Extrinsic {
|
|
7
7
|
client;
|
|
8
8
|
#alterTx;
|
|
@@ -26,7 +26,7 @@ export class BaseSubmittableExtrinsic extends Extrinsic {
|
|
|
26
26
|
const signer = this.#getSigner(options);
|
|
27
27
|
let signature, alteredTx;
|
|
28
28
|
if (isKeyringPair(fromAccount)) {
|
|
29
|
-
signature = u8aToHex(
|
|
29
|
+
signature = u8aToHex(signRawMessage(fromAccount, extra.toRawPayload(this.callHex).data));
|
|
30
30
|
}
|
|
31
31
|
else if (signer?.signPayload) {
|
|
32
32
|
const result = await signer.signPayload(extra.toPayload(this.callHex));
|
|
@@ -7,7 +7,7 @@ export declare function isKeyringPair(account: AddressOrPair): account is IKeyri
|
|
|
7
7
|
* @param signerPair
|
|
8
8
|
* @param raw
|
|
9
9
|
*/
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function signRawMessage(signerPair: IKeyringPair, raw: HexString | string): Uint8Array;
|
|
11
11
|
type TxInfo = {
|
|
12
12
|
txIndex: number;
|
|
13
13
|
blockNumber: number;
|
|
@@ -8,7 +8,7 @@ export function isKeyringPair(account) {
|
|
|
8
8
|
* @param signerPair
|
|
9
9
|
* @param raw
|
|
10
10
|
*/
|
|
11
|
-
export function
|
|
11
|
+
export function signRawMessage(signerPair, raw) {
|
|
12
12
|
const u8a = hexToU8a(raw);
|
|
13
13
|
// Ref: https://github.com/paritytech/polkadot-sdk/blob/943697fa693a4da6ef481ef93df522accb7d0583/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs#L234-L238
|
|
14
14
|
const toSignRaw = u8a.length > 256 ? blake2AsU8a(u8a, 256) : u8a;
|
|
@@ -80,18 +80,19 @@ export class ChainHead extends JsonRpcGroup {
|
|
|
80
80
|
const defer = deferred();
|
|
81
81
|
try {
|
|
82
82
|
this.#unsub && this.#unsub().catch(noop); // ensure unfollowed
|
|
83
|
+
const SIGNAL_THRESHOLD = this.#__unsafe__isSmoldot() ? 2 : 1;
|
|
83
84
|
let signals = 0;
|
|
84
85
|
this.#unsub = await this.send('follow', true, (event, subscription) => {
|
|
85
86
|
this.#followResponseQueue
|
|
86
87
|
.enqueue(async () => {
|
|
87
88
|
await this.#onFollowEvent(event, subscription);
|
|
88
|
-
if (signals >=
|
|
89
|
+
if (signals >= SIGNAL_THRESHOLD)
|
|
89
90
|
return;
|
|
90
91
|
signals += 1;
|
|
91
92
|
// Sometime smoldot send a `stop` event right after `initialized`
|
|
92
93
|
// So requests sending between `initialized` and `stop` will be on pruned hashes -> throwing out errors
|
|
93
94
|
// Here we make sure to receive at least the first 2 signals to resolve
|
|
94
|
-
if (signals >=
|
|
95
|
+
if (signals >= SIGNAL_THRESHOLD) {
|
|
95
96
|
defer.resolve();
|
|
96
97
|
}
|
|
97
98
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
|
|
5
5
|
"author": "Thang X. Vu <thang@dedot.dev>",
|
|
6
6
|
"homepage": "https://dedot.dev",
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@dedot/codecs": "0.
|
|
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.13.0",
|
|
17
|
+
"@dedot/providers": "0.13.0",
|
|
18
|
+
"@dedot/runtime-specs": "0.13.0",
|
|
19
|
+
"@dedot/shape": "0.13.0",
|
|
20
|
+
"@dedot/storage": "0.13.0",
|
|
21
|
+
"@dedot/types": "0.13.0",
|
|
22
|
+
"@dedot/utils": "0.13.0"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsc --project tsconfig.build.json && tsc --project tsconfig.build.cjs.json",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"node": ">=18"
|
|
49
49
|
},
|
|
50
50
|
"license": "Apache-2.0",
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "b9193d170fc63ebd64b75f37f8276a7159e2af55",
|
|
52
52
|
"module": "./index.js",
|
|
53
53
|
"types": "./index.d.ts"
|
|
54
54
|
}
|