@dedot/api 0.0.1-alpha.34 → 0.0.1-next.04c158c0.11
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.js +1 -0
- package/chaintypes/substrate/json-rpc.d.ts +1 -1
- 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.d.ts +377 -377
- 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/client/LegacyClient.js +3 -3
- package/cjs/executor/ErrorExecutor.js +3 -3
- package/cjs/executor/EventExecutor.js +2 -2
- package/cjs/executor/StorageQueryExecutor.js +1 -1
- package/cjs/executor/TxExecutor.js +3 -3
- package/cjs/extrinsic/extensions/known/ChargeAssetTxPayment.js +2 -2
- package/cjs/extrinsic/extensions/known/StorageWeightReclaim.js +10 -0
- package/cjs/extrinsic/extensions/known/index.js +2 -0
- package/cjs/extrinsic/submittable/SubmittableExtrinsic.js +2 -2
- package/cjs/extrinsic/submittable/SubmittableExtrinsicV2.js +11 -11
- package/cjs/storage/QueryableStorage.js +17 -17
- package/client/LegacyClient.d.ts +3 -3
- package/client/LegacyClient.js +3 -3
- package/executor/ErrorExecutor.js +3 -3
- package/executor/EventExecutor.js +2 -2
- package/executor/Executor.d.ts +12 -12
- package/executor/StorageQueryExecutor.js +1 -1
- package/executor/TxExecutor.js +3 -3
- package/extrinsic/extensions/known/ChargeAssetTxPayment.js +2 -2
- package/extrinsic/extensions/known/StorageWeightReclaim.d.ts +6 -0
- package/extrinsic/extensions/known/StorageWeightReclaim.js +6 -0
- package/extrinsic/extensions/known/index.js +2 -0
- package/extrinsic/submittable/SubmittableExtrinsic.js +2 -2
- package/extrinsic/submittable/SubmittableExtrinsicV2.js +11 -11
- package/package.json +10 -10
- package/storage/QueryableStorage.js +17 -17
|
@@ -16,7 +16,7 @@ const KEEP_ALIVE_INTERVAL = 10_000; // in ms
|
|
|
16
16
|
* import type { PolkadotApi } from '@dedot/chaintypes/polkadot';
|
|
17
17
|
*
|
|
18
18
|
* const run = async () => {
|
|
19
|
-
* const api = await
|
|
19
|
+
* const api = await LegacyClient.new<PolkadotApi>('wss://rpc.polkadot.io');
|
|
20
20
|
*
|
|
21
21
|
* // Call rpc `state_getMetadata` to fetch raw scale-encoded metadata and decode it.
|
|
22
22
|
* const metadata = await api.rpc.state.getMetadata();
|
|
@@ -65,7 +65,7 @@ class LegacyClient extends BaseSubstrateClient_js_1.BaseSubstrateClient {
|
|
|
65
65
|
return new LegacyClient(options).connect();
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
|
-
* Alias for
|
|
68
|
+
* Alias for __LegacyClient.create__
|
|
69
69
|
*
|
|
70
70
|
* @param options
|
|
71
71
|
*/
|
|
@@ -205,7 +205,7 @@ class LegacyClient extends BaseSubstrateClient_js_1.BaseSubstrateClient {
|
|
|
205
205
|
* // Make a transfer balance transaction
|
|
206
206
|
* api.tx.balances.transferKeepAlive(<address>, <amount>)
|
|
207
207
|
* .signAndSend(<keyPair|address>, { signer }, ({ status }) => {
|
|
208
|
-
* console.log('Transaction status', status.
|
|
208
|
+
* console.log('Transaction status', status.type);
|
|
209
209
|
* });
|
|
210
210
|
* ```
|
|
211
211
|
*/
|
|
@@ -20,7 +20,7 @@ class ErrorExecutor extends Executor_js_1.Executor {
|
|
|
20
20
|
palletIndex: targetPallet.index,
|
|
21
21
|
},
|
|
22
22
|
is: (errorInfo) => {
|
|
23
|
-
if ((0, utils_1.isObject)(errorInfo) && errorInfo.
|
|
23
|
+
if ((0, utils_1.isObject)(errorInfo) && errorInfo.type === 'Module') {
|
|
24
24
|
errorInfo = errorInfo.value;
|
|
25
25
|
}
|
|
26
26
|
if ((0, utils_1.isObject)(errorInfo) && (0, utils_1.isNumber)(errorInfo.index) && (0, utils_1.isHex)(errorInfo.error)) {
|
|
@@ -33,8 +33,8 @@ class ErrorExecutor extends Executor_js_1.Executor {
|
|
|
33
33
|
#getErrorDef(errorTypeId, errorName) {
|
|
34
34
|
const def = this.metadata.types[errorTypeId];
|
|
35
35
|
(0, utils_1.assert)(def, new utils_1.UnknownApiError(`Error def not found for id ${errorTypeId}`));
|
|
36
|
-
const {
|
|
37
|
-
(0, utils_1.assert)(
|
|
36
|
+
const { type, value } = def.typeDef;
|
|
37
|
+
(0, utils_1.assert)(type === 'Enum', new utils_1.UnknownApiError(`Error type should be an enum, found: ${type}`));
|
|
38
38
|
const errorDef = value.members.find(({ name }) => (0, utils_1.stringPascalCase)(name) === errorName);
|
|
39
39
|
(0, utils_1.assert)(errorDef, new utils_1.UnknownApiError(`Error def not found for ${errorName}`));
|
|
40
40
|
return {
|
|
@@ -39,8 +39,8 @@ class EventExecutor extends Executor_js_1.Executor {
|
|
|
39
39
|
#getEventDef(eventTypeId, errorName) {
|
|
40
40
|
const def = this.metadata.types[eventTypeId];
|
|
41
41
|
(0, utils_1.assert)(def, new utils_1.UnknownApiError(`Event def not found for id ${eventTypeId}`));
|
|
42
|
-
const {
|
|
43
|
-
(0, utils_1.assert)(
|
|
42
|
+
const { type, value } = def.typeDef;
|
|
43
|
+
(0, utils_1.assert)(type === 'Enum', new utils_1.UnknownApiError(`Event type should be an enum, found: ${type}`));
|
|
44
44
|
const eventDef = value.members.find(({ name }) => (0, utils_1.stringPascalCase)(name) === errorName);
|
|
45
45
|
(0, utils_1.assert)(eventDef, new utils_1.UnknownApiError(`Event def not found for ${errorName}`));
|
|
46
46
|
return {
|
|
@@ -52,7 +52,7 @@ class StorageQueryExecutor extends Executor_js_1.Executor {
|
|
|
52
52
|
palletIndex: entry.pallet.index,
|
|
53
53
|
...entry.storageEntry,
|
|
54
54
|
};
|
|
55
|
-
const isMap = entry.storageEntry.type
|
|
55
|
+
const isMap = entry.storageEntry.storageType.type === 'Map';
|
|
56
56
|
if (isMap) {
|
|
57
57
|
const queryMultiFn = async (...args) => {
|
|
58
58
|
const [inArgs, callback] = extractArgs(args);
|
|
@@ -13,9 +13,9 @@ class TxExecutor extends Executor_js_1.Executor {
|
|
|
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
15
|
const txType = this.metadata.types[targetPallet.calls];
|
|
16
|
-
(0, utils_1.assert)(txType.type
|
|
17
|
-
const isFlatEnum = txType.
|
|
18
|
-
const txCallDef = txType.
|
|
16
|
+
(0, utils_1.assert)(txType.typeDef.type === 'Enum', new utils_1.UnknownApiError('Tx type defs should be enum'));
|
|
17
|
+
const isFlatEnum = txType.typeDef.value.members.every((m) => m.fields.length === 0);
|
|
18
|
+
const txCallDef = txType.typeDef.value.members.find((m) => (0, utils_1.stringCamelCase)(m.name) === functionName);
|
|
19
19
|
(0, utils_1.assert)(txCallDef, new utils_1.UnknownApiError(`Tx call spec not found for ${pallet}.${functionName}`));
|
|
20
20
|
const txCallFn = (...args) => {
|
|
21
21
|
let call;
|
|
@@ -30,8 +30,8 @@ class ChargeAssetTxPayment extends SignedExtension_js_1.SignedExtension {
|
|
|
30
30
|
}
|
|
31
31
|
$AssetId() {
|
|
32
32
|
const extensionTypeDef = this.registry.findType(this.signedExtensionDef.typeId);
|
|
33
|
-
(0, utils_1.assert)(extensionTypeDef.type
|
|
34
|
-
const assetIdTypeDef = extensionTypeDef.
|
|
33
|
+
(0, utils_1.assert)(extensionTypeDef.typeDef.type === 'Struct');
|
|
34
|
+
const assetIdTypeDef = extensionTypeDef.typeDef.value.fields.find((f) => f.name === 'asset_id');
|
|
35
35
|
const $codec = this.registry.findCodec(assetIdTypeDef.typeId);
|
|
36
36
|
const codecMetadata = $codec.metadata[0];
|
|
37
37
|
if (codecMetadata.name === '$.option') {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StorageWeightReclaim = void 0;
|
|
4
|
+
const SignedExtension_js_1 = require("../SignedExtension.js");
|
|
5
|
+
/**
|
|
6
|
+
* @description Storage weight reclaim mechanism.
|
|
7
|
+
*/
|
|
8
|
+
class StorageWeightReclaim extends SignedExtension_js_1.SignedExtension {
|
|
9
|
+
}
|
|
10
|
+
exports.StorageWeightReclaim = StorageWeightReclaim;
|
|
@@ -12,6 +12,7 @@ const CheckSpecVersion_js_1 = require("./CheckSpecVersion.js");
|
|
|
12
12
|
const CheckTxVersion_js_1 = require("./CheckTxVersion.js");
|
|
13
13
|
const CheckWeight_js_1 = require("./CheckWeight.js");
|
|
14
14
|
const PrevalidateAttests_js_1 = require("./PrevalidateAttests.js");
|
|
15
|
+
const StorageWeightReclaim_js_1 = require("./StorageWeightReclaim.js");
|
|
15
16
|
exports.knownSignedExtensions = {
|
|
16
17
|
CheckNonZeroSender: CheckNonZeroSender_js_1.CheckNonZeroSender,
|
|
17
18
|
CheckSpecVersion: CheckSpecVersion_js_1.CheckSpecVersion,
|
|
@@ -24,4 +25,5 @@ exports.knownSignedExtensions = {
|
|
|
24
25
|
PrevalidateAttests: PrevalidateAttests_js_1.PrevalidateAttests,
|
|
25
26
|
ChargeAssetTxPayment: ChargeAssetTxPayment_js_1.ChargeAssetTxPayment,
|
|
26
27
|
CheckMetadataHash: CheckMetadataHash_js_1.CheckMetadataHash,
|
|
28
|
+
StorageWeightReclaim: StorageWeightReclaim_js_1.StorageWeightReclaim,
|
|
27
29
|
};
|
|
@@ -23,7 +23,7 @@ class SubmittableExtrinsic extends BaseSubmittableExtrinsic_js_1.BaseSubmittable
|
|
|
23
23
|
const txHash = this.hash;
|
|
24
24
|
if (isSubscription) {
|
|
25
25
|
return this.api.rpc.author_submitAndWatchExtrinsic(txHex, async (status) => {
|
|
26
|
-
if (status.
|
|
26
|
+
if (status.type === 'InBlock' || status.type === 'Finalized') {
|
|
27
27
|
const blockHash = status.value;
|
|
28
28
|
const [signedBlock, blockEvents] = await Promise.all([
|
|
29
29
|
this.api.rpc.chain_getBlock(blockHash),
|
|
@@ -31,7 +31,7 @@ class SubmittableExtrinsic extends BaseSubmittableExtrinsic_js_1.BaseSubmittable
|
|
|
31
31
|
]);
|
|
32
32
|
const txIndex = signedBlock.block.extrinsics.indexOf(txHex);
|
|
33
33
|
(0, utils_1.assert)(txIndex >= 0, 'Extrinsic not found!');
|
|
34
|
-
const events = blockEvents.filter(({ phase }) => phase.
|
|
34
|
+
const events = blockEvents.filter(({ phase }) => phase.type === 'ApplyExtrinsic' && phase.value === txIndex);
|
|
35
35
|
return callback(new SubmittableResult_js_1.SubmittableResult({ status, txHash, events, txIndex }));
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
@@ -28,10 +28,10 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
|
|
|
28
28
|
};
|
|
29
29
|
const validation = await validateTx(finalizedHash);
|
|
30
30
|
if (validation.isOk) {
|
|
31
|
-
callback(new SubmittableResult_js_1.SubmittableResult({ status: {
|
|
31
|
+
callback(new SubmittableResult_js_1.SubmittableResult({ status: { type: 'Validated' }, txHash }));
|
|
32
32
|
}
|
|
33
33
|
else if (validation.isErr) {
|
|
34
|
-
throw new errors_js_1.InvalidTxError(`Invalid Tx: ${validation.err.
|
|
34
|
+
throw new errors_js_1.InvalidTxError(`Invalid Tx: ${validation.err.type} - ${validation.err.value.type}`, validation);
|
|
35
35
|
}
|
|
36
36
|
const checkTxIsOnChain = async (blockHash) => {
|
|
37
37
|
if (blockHash === finalizedHash)
|
|
@@ -42,7 +42,7 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
|
|
|
42
42
|
return checkTxIsOnChain(api.chainHead.findBlock(blockHash).parent);
|
|
43
43
|
}
|
|
44
44
|
const events = await this.getSystemEventsAt(blockHash);
|
|
45
|
-
const txEvents = events.filter(({ phase }) => phase.
|
|
45
|
+
const txEvents = events.filter(({ phase }) => phase.type == 'ApplyExtrinsic' && phase.value === txIndex);
|
|
46
46
|
return {
|
|
47
47
|
blockHash,
|
|
48
48
|
index: txIndex,
|
|
@@ -88,7 +88,7 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
|
|
|
88
88
|
if (txFound && bestChainChanged) {
|
|
89
89
|
txFound = undefined;
|
|
90
90
|
callback(new SubmittableResult_js_1.SubmittableResult({
|
|
91
|
-
status: {
|
|
91
|
+
status: { type: 'NoLongerInBestChain' },
|
|
92
92
|
txHash,
|
|
93
93
|
}));
|
|
94
94
|
}
|
|
@@ -101,7 +101,7 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
|
|
|
101
101
|
txFound = inBlock;
|
|
102
102
|
const { index: txIndex, events, blockHash } = inBlock;
|
|
103
103
|
callback(new SubmittableResult_js_1.SubmittableResult({
|
|
104
|
-
status: {
|
|
104
|
+
status: { type: 'BestChainBlockIncluded', value: { blockHash, txIndex } },
|
|
105
105
|
txHash,
|
|
106
106
|
events,
|
|
107
107
|
txIndex,
|
|
@@ -134,7 +134,7 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
|
|
|
134
134
|
if (inBlock) {
|
|
135
135
|
const { index: txIndex, events, blockHash } = inBlock;
|
|
136
136
|
callback(new SubmittableResult_js_1.SubmittableResult({
|
|
137
|
-
status: {
|
|
137
|
+
status: { type: 'Finalized', value: { blockHash, txIndex } },
|
|
138
138
|
txHash,
|
|
139
139
|
events,
|
|
140
140
|
txIndex,
|
|
@@ -148,8 +148,8 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
|
|
|
148
148
|
return;
|
|
149
149
|
callback(new SubmittableResult_js_1.SubmittableResult({
|
|
150
150
|
status: {
|
|
151
|
-
|
|
152
|
-
value: { error: `Invalid Tx: ${validation.err.
|
|
151
|
+
type: 'Invalid',
|
|
152
|
+
value: { error: `Invalid Tx: ${validation.err.type} - ${validation.err.value.type}` },
|
|
153
153
|
},
|
|
154
154
|
txHash,
|
|
155
155
|
}));
|
|
@@ -158,7 +158,7 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
|
|
|
158
158
|
};
|
|
159
159
|
stopBroadcastFn = await api.txBroadcaster.broadcastTx(txHex);
|
|
160
160
|
callback(new SubmittableResult_js_1.SubmittableResult({
|
|
161
|
-
status: {
|
|
161
|
+
status: { type: 'Broadcasting' },
|
|
162
162
|
txHash,
|
|
163
163
|
}));
|
|
164
164
|
const stopBestBlockTrackingFn = api.chainHead.on('bestBlock', checkBestBlockIncluded);
|
|
@@ -184,11 +184,11 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
|
|
|
184
184
|
try {
|
|
185
185
|
// TODO handle timeout for this with the Drop status, just in-case we somehow can't find the tx in any block
|
|
186
186
|
const unsub = await this.#send(({ status, txHash }) => {
|
|
187
|
-
if (status.
|
|
187
|
+
if (status.type === 'BestChainBlockIncluded' || status.type === 'Finalized') {
|
|
188
188
|
defer.resolve(txHash);
|
|
189
189
|
unsub().catch(utils_1.noop);
|
|
190
190
|
}
|
|
191
|
-
else if (status.
|
|
191
|
+
else if (status.type === 'Invalid' || status.type === 'Drop') {
|
|
192
192
|
defer.reject(new Error(status.value.error));
|
|
193
193
|
unsub().catch(utils_1.noop);
|
|
194
194
|
}
|
|
@@ -39,14 +39,14 @@ class QueryableStorage {
|
|
|
39
39
|
const storageItemHash = (0, utils_2.xxhashAsU8a)(this.storageEntry.name, 128);
|
|
40
40
|
return (0, utils_2.concatU8a)(palletNameHash, storageItemHash);
|
|
41
41
|
}
|
|
42
|
-
#getStorageMapInfo(
|
|
43
|
-
(0, utils_1.assert)(type
|
|
44
|
-
const { hashers, keyTypeId } =
|
|
42
|
+
#getStorageMapInfo(storageType) {
|
|
43
|
+
(0, utils_1.assert)(storageType.type === 'Map');
|
|
44
|
+
const { hashers, keyTypeId } = storageType.value;
|
|
45
45
|
let keyTypeIds = [keyTypeId];
|
|
46
46
|
if (hashers.length > 1) {
|
|
47
|
-
const {
|
|
48
|
-
(0, utils_1.assert)(type
|
|
49
|
-
keyTypeIds =
|
|
47
|
+
const { typeDef } = this.registry.findType(keyTypeId);
|
|
48
|
+
(0, utils_1.assert)(typeDef.type === 'Tuple', 'Key type should be a tuple!');
|
|
49
|
+
keyTypeIds = typeDef.value.fields;
|
|
50
50
|
}
|
|
51
51
|
return { hashers, keyTypeIds };
|
|
52
52
|
}
|
|
@@ -56,12 +56,12 @@ class QueryableStorage {
|
|
|
56
56
|
* @param keyInput
|
|
57
57
|
*/
|
|
58
58
|
encodeKey(keyInput) {
|
|
59
|
-
const {
|
|
60
|
-
if (type
|
|
59
|
+
const { storageType } = this.storageEntry;
|
|
60
|
+
if (storageType.type === 'Plain') {
|
|
61
61
|
return this.prefixKey;
|
|
62
62
|
}
|
|
63
|
-
else if (type
|
|
64
|
-
const { hashers, keyTypeIds } = this.#getStorageMapInfo(
|
|
63
|
+
else if (storageType.type === 'Map') {
|
|
64
|
+
const { hashers, keyTypeIds } = this.#getStorageMapInfo(storageType);
|
|
65
65
|
const extractedInputs = this.#extractRequiredKeyInputs(keyInput, hashers.length);
|
|
66
66
|
const keyParts = keyTypeIds.map((keyId, index) => {
|
|
67
67
|
const input = extractedInputs[index];
|
|
@@ -71,7 +71,7 @@ class QueryableStorage {
|
|
|
71
71
|
});
|
|
72
72
|
return (0, utils_2.u8aToHex)((0, utils_2.concatU8a)(this.prefixKeyAsU8a, ...keyParts));
|
|
73
73
|
}
|
|
74
|
-
throw Error(`Invalid storage entry type: ${
|
|
74
|
+
throw Error(`Invalid storage entry type: ${JSON.stringify(storageType)}`);
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* Decode storage key to plain key input
|
|
@@ -80,16 +80,16 @@ class QueryableStorage {
|
|
|
80
80
|
* @param key
|
|
81
81
|
*/
|
|
82
82
|
decodeKey(key) {
|
|
83
|
-
const {
|
|
84
|
-
if (type
|
|
83
|
+
const { storageType } = this.storageEntry;
|
|
84
|
+
if (storageType.type === 'Plain') {
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
|
-
else if (type
|
|
87
|
+
else if (storageType.type === 'Map') {
|
|
88
88
|
const prefix = this.prefixKey;
|
|
89
89
|
if (!key.startsWith(prefix)) {
|
|
90
90
|
throw new Error(`Storage key does not match this storage entry (${this.palletName}.${this.storageItem})`);
|
|
91
91
|
}
|
|
92
|
-
const { hashers, keyTypeIds } = this.#getStorageMapInfo(
|
|
92
|
+
const { hashers, keyTypeIds } = this.#getStorageMapInfo(storageType);
|
|
93
93
|
let keyData = (0, utils_2.hexToU8a)((0, utils_1.hexAddPrefix)(key.slice(prefix.length)));
|
|
94
94
|
const results = keyTypeIds.map((keyId, index) => {
|
|
95
95
|
const [hashLen, canDecode] = HASHER_INFO[hashers[index]];
|
|
@@ -104,7 +104,7 @@ class QueryableStorage {
|
|
|
104
104
|
});
|
|
105
105
|
return hashers.length > 1 ? results : results[0];
|
|
106
106
|
}
|
|
107
|
-
throw Error(`Invalid storage entry type: ${
|
|
107
|
+
throw Error(`Invalid storage entry type: ${JSON.stringify(storageType)}`);
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
110
|
* Decode raw/bytes storage data to plain value
|
|
@@ -112,7 +112,7 @@ class QueryableStorage {
|
|
|
112
112
|
* @param raw
|
|
113
113
|
*/
|
|
114
114
|
decodeValue(raw) {
|
|
115
|
-
const { modifier,
|
|
115
|
+
const { modifier, storageType: { value: { valueTypeId }, }, default: defaultValue, } = this.storageEntry;
|
|
116
116
|
if (raw === null || raw === undefined) {
|
|
117
117
|
if (modifier === 'Optional') {
|
|
118
118
|
return undefined;
|
package/client/LegacyClient.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { BaseSubstrateClient } from './BaseSubstrateClient.js';
|
|
|
14
14
|
* import type { PolkadotApi } from '@dedot/chaintypes/polkadot';
|
|
15
15
|
*
|
|
16
16
|
* const run = async () => {
|
|
17
|
-
* const api = await
|
|
17
|
+
* const api = await LegacyClient.new<PolkadotApi>('wss://rpc.polkadot.io');
|
|
18
18
|
*
|
|
19
19
|
* // Call rpc `state_getMetadata` to fetch raw scale-encoded metadata and decode it.
|
|
20
20
|
* const metadata = await api.rpc.state.getMetadata();
|
|
@@ -57,7 +57,7 @@ export declare class LegacyClient<ChainApi extends VersionedGenericSubstrateApi
|
|
|
57
57
|
*/
|
|
58
58
|
static create<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>(options: ApiOptions | JsonRpcProvider): Promise<LegacyClient<ChainApi>>;
|
|
59
59
|
/**
|
|
60
|
-
* Alias for
|
|
60
|
+
* Alias for __LegacyClient.create__
|
|
61
61
|
*
|
|
62
62
|
* @param options
|
|
63
63
|
*/
|
|
@@ -116,7 +116,7 @@ export declare class LegacyClient<ChainApi extends VersionedGenericSubstrateApi
|
|
|
116
116
|
* // Make a transfer balance transaction
|
|
117
117
|
* api.tx.balances.transferKeepAlive(<address>, <amount>)
|
|
118
118
|
* .signAndSend(<keyPair|address>, { signer }, ({ status }) => {
|
|
119
|
-
* console.log('Transaction status', status.
|
|
119
|
+
* console.log('Transaction status', status.type);
|
|
120
120
|
* });
|
|
121
121
|
* ```
|
|
122
122
|
*/
|
package/client/LegacyClient.js
CHANGED
|
@@ -13,7 +13,7 @@ const KEEP_ALIVE_INTERVAL = 10_000; // in ms
|
|
|
13
13
|
* import type { PolkadotApi } from '@dedot/chaintypes/polkadot';
|
|
14
14
|
*
|
|
15
15
|
* const run = async () => {
|
|
16
|
-
* const api = await
|
|
16
|
+
* const api = await LegacyClient.new<PolkadotApi>('wss://rpc.polkadot.io');
|
|
17
17
|
*
|
|
18
18
|
* // Call rpc `state_getMetadata` to fetch raw scale-encoded metadata and decode it.
|
|
19
19
|
* const metadata = await api.rpc.state.getMetadata();
|
|
@@ -62,7 +62,7 @@ export class LegacyClient extends BaseSubstrateClient {
|
|
|
62
62
|
return new LegacyClient(options).connect();
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
|
-
* Alias for
|
|
65
|
+
* Alias for __LegacyClient.create__
|
|
66
66
|
*
|
|
67
67
|
* @param options
|
|
68
68
|
*/
|
|
@@ -202,7 +202,7 @@ export class LegacyClient extends BaseSubstrateClient {
|
|
|
202
202
|
* // Make a transfer balance transaction
|
|
203
203
|
* api.tx.balances.transferKeepAlive(<address>, <amount>)
|
|
204
204
|
* .signAndSend(<keyPair|address>, { signer }, ({ status }) => {
|
|
205
|
-
* console.log('Transaction status', status.
|
|
205
|
+
* console.log('Transaction status', status.type);
|
|
206
206
|
* });
|
|
207
207
|
* ```
|
|
208
208
|
*/
|
|
@@ -17,7 +17,7 @@ export class ErrorExecutor extends Executor {
|
|
|
17
17
|
palletIndex: targetPallet.index,
|
|
18
18
|
},
|
|
19
19
|
is: (errorInfo) => {
|
|
20
|
-
if (isObject(errorInfo) && errorInfo.
|
|
20
|
+
if (isObject(errorInfo) && errorInfo.type === 'Module') {
|
|
21
21
|
errorInfo = errorInfo.value;
|
|
22
22
|
}
|
|
23
23
|
if (isObject(errorInfo) && isNumber(errorInfo.index) && isHex(errorInfo.error)) {
|
|
@@ -30,8 +30,8 @@ export class ErrorExecutor extends Executor {
|
|
|
30
30
|
#getErrorDef(errorTypeId, errorName) {
|
|
31
31
|
const def = this.metadata.types[errorTypeId];
|
|
32
32
|
assert(def, new UnknownApiError(`Error def not found for id ${errorTypeId}`));
|
|
33
|
-
const {
|
|
34
|
-
assert(
|
|
33
|
+
const { type, value } = def.typeDef;
|
|
34
|
+
assert(type === 'Enum', new UnknownApiError(`Error type should be an enum, found: ${type}`));
|
|
35
35
|
const errorDef = value.members.find(({ name }) => stringPascalCase(name) === errorName);
|
|
36
36
|
assert(errorDef, new UnknownApiError(`Error def not found for ${errorName}`));
|
|
37
37
|
return {
|
|
@@ -36,8 +36,8 @@ export class EventExecutor extends Executor {
|
|
|
36
36
|
#getEventDef(eventTypeId, errorName) {
|
|
37
37
|
const def = this.metadata.types[eventTypeId];
|
|
38
38
|
assert(def, new UnknownApiError(`Event def not found for id ${eventTypeId}`));
|
|
39
|
-
const {
|
|
40
|
-
assert(
|
|
39
|
+
const { type, value } = def.typeDef;
|
|
40
|
+
assert(type === 'Enum', new UnknownApiError(`Event type should be an enum, found: ${type}`));
|
|
41
41
|
const eventDef = value.members.find(({ name }) => stringPascalCase(name) === errorName);
|
|
42
42
|
assert(eventDef, new UnknownApiError(`Event def not found for ${errorName}`));
|
|
43
43
|
return {
|
package/executor/Executor.d.ts
CHANGED
|
@@ -19,13 +19,13 @@ export declare abstract class Executor<ChainApi extends GenericSubstrateApi = Ge
|
|
|
19
19
|
name: string;
|
|
20
20
|
typeId: number | undefined;
|
|
21
21
|
}[];
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
typeDef: {
|
|
23
|
+
type: "Struct";
|
|
24
24
|
value: {
|
|
25
25
|
fields: import("@dedot/codecs").Field[];
|
|
26
26
|
};
|
|
27
27
|
} | {
|
|
28
|
-
|
|
28
|
+
type: "Enum";
|
|
29
29
|
value: {
|
|
30
30
|
members: {
|
|
31
31
|
name: string;
|
|
@@ -35,33 +35,33 @@ export declare abstract class Executor<ChainApi extends GenericSubstrateApi = Ge
|
|
|
35
35
|
}[];
|
|
36
36
|
};
|
|
37
37
|
} | {
|
|
38
|
-
|
|
38
|
+
type: "Sequence";
|
|
39
39
|
value: {
|
|
40
40
|
typeParam: number;
|
|
41
41
|
};
|
|
42
42
|
} | {
|
|
43
|
-
|
|
43
|
+
type: "SizedVec";
|
|
44
44
|
value: {
|
|
45
45
|
len: number;
|
|
46
46
|
typeParam: number;
|
|
47
47
|
};
|
|
48
48
|
} | {
|
|
49
|
-
|
|
49
|
+
type: "Tuple";
|
|
50
50
|
value: {
|
|
51
51
|
fields: number[];
|
|
52
52
|
};
|
|
53
53
|
} | {
|
|
54
|
-
|
|
54
|
+
type: "Primitive";
|
|
55
55
|
value: {
|
|
56
56
|
kind: "bool" | "char" | "str" | "u8" | "u16" | "u32" | "u64" | "u128" | "u256" | "i8" | "i16" | "i32" | "i64" | "i128" | "i256";
|
|
57
57
|
};
|
|
58
58
|
} | {
|
|
59
|
-
|
|
59
|
+
type: "Compact";
|
|
60
60
|
value: {
|
|
61
61
|
typeParam: number;
|
|
62
62
|
};
|
|
63
63
|
} | {
|
|
64
|
-
|
|
64
|
+
type: "BitSequence";
|
|
65
65
|
value: {
|
|
66
66
|
bitOrderType: number;
|
|
67
67
|
bitStoreType: number;
|
|
@@ -76,13 +76,13 @@ export declare abstract class Executor<ChainApi extends GenericSubstrateApi = Ge
|
|
|
76
76
|
entries: {
|
|
77
77
|
name: string;
|
|
78
78
|
modifier: string;
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
storageType: {
|
|
80
|
+
type: "Plain";
|
|
81
81
|
value: {
|
|
82
82
|
valueTypeId: number;
|
|
83
83
|
};
|
|
84
84
|
} | {
|
|
85
|
-
|
|
85
|
+
type: "Map";
|
|
86
86
|
value: {
|
|
87
87
|
hashers: ("identity" | "blake2_128" | "blake2_256" | "blake2_128Concat" | "twox128" | "twox256" | "twox64Concat")[];
|
|
88
88
|
keyTypeId: number;
|
|
@@ -49,7 +49,7 @@ export class StorageQueryExecutor extends Executor {
|
|
|
49
49
|
palletIndex: entry.pallet.index,
|
|
50
50
|
...entry.storageEntry,
|
|
51
51
|
};
|
|
52
|
-
const isMap = entry.storageEntry.type
|
|
52
|
+
const isMap = entry.storageEntry.storageType.type === 'Map';
|
|
53
53
|
if (isMap) {
|
|
54
54
|
const queryMultiFn = async (...args) => {
|
|
55
55
|
const [inArgs, callback] = extractArgs(args);
|
package/executor/TxExecutor.js
CHANGED
|
@@ -10,9 +10,9 @@ export class TxExecutor extends Executor {
|
|
|
10
10
|
const targetPallet = this.getPallet(pallet);
|
|
11
11
|
assert(targetPallet.calls, new UnknownApiError(`Tx calls are not available for pallet ${targetPallet.name}`));
|
|
12
12
|
const txType = this.metadata.types[targetPallet.calls];
|
|
13
|
-
assert(txType.type
|
|
14
|
-
const isFlatEnum = txType.
|
|
15
|
-
const txCallDef = txType.
|
|
13
|
+
assert(txType.typeDef.type === 'Enum', new UnknownApiError('Tx type defs should be enum'));
|
|
14
|
+
const isFlatEnum = txType.typeDef.value.members.every((m) => m.fields.length === 0);
|
|
15
|
+
const txCallDef = txType.typeDef.value.members.find((m) => stringCamelCase(m.name) === functionName);
|
|
16
16
|
assert(txCallDef, new UnknownApiError(`Tx call spec not found for ${pallet}.${functionName}`));
|
|
17
17
|
const txCallFn = (...args) => {
|
|
18
18
|
let call;
|
|
@@ -27,8 +27,8 @@ export class ChargeAssetTxPayment extends SignedExtension {
|
|
|
27
27
|
}
|
|
28
28
|
$AssetId() {
|
|
29
29
|
const extensionTypeDef = this.registry.findType(this.signedExtensionDef.typeId);
|
|
30
|
-
assert(extensionTypeDef.type
|
|
31
|
-
const assetIdTypeDef = extensionTypeDef.
|
|
30
|
+
assert(extensionTypeDef.typeDef.type === 'Struct');
|
|
31
|
+
const assetIdTypeDef = extensionTypeDef.typeDef.value.fields.find((f) => f.name === 'asset_id');
|
|
32
32
|
const $codec = this.registry.findCodec(assetIdTypeDef.typeId);
|
|
33
33
|
const codecMetadata = $codec.metadata[0];
|
|
34
34
|
if (codecMetadata.name === '$.option') {
|
|
@@ -9,6 +9,7 @@ import { CheckSpecVersion } from './CheckSpecVersion.js';
|
|
|
9
9
|
import { CheckTxVersion } from './CheckTxVersion.js';
|
|
10
10
|
import { CheckWeight } from './CheckWeight.js';
|
|
11
11
|
import { PrevalidateAttests } from './PrevalidateAttests.js';
|
|
12
|
+
import { StorageWeightReclaim } from './StorageWeightReclaim.js';
|
|
12
13
|
export const knownSignedExtensions = {
|
|
13
14
|
CheckNonZeroSender,
|
|
14
15
|
CheckSpecVersion,
|
|
@@ -21,4 +22,5 @@ export const knownSignedExtensions = {
|
|
|
21
22
|
PrevalidateAttests,
|
|
22
23
|
ChargeAssetTxPayment,
|
|
23
24
|
CheckMetadataHash,
|
|
25
|
+
StorageWeightReclaim,
|
|
24
26
|
};
|
|
@@ -20,7 +20,7 @@ export class SubmittableExtrinsic extends BaseSubmittableExtrinsic {
|
|
|
20
20
|
const txHash = this.hash;
|
|
21
21
|
if (isSubscription) {
|
|
22
22
|
return this.api.rpc.author_submitAndWatchExtrinsic(txHex, async (status) => {
|
|
23
|
-
if (status.
|
|
23
|
+
if (status.type === 'InBlock' || status.type === 'Finalized') {
|
|
24
24
|
const blockHash = status.value;
|
|
25
25
|
const [signedBlock, blockEvents] = await Promise.all([
|
|
26
26
|
this.api.rpc.chain_getBlock(blockHash),
|
|
@@ -28,7 +28,7 @@ export class SubmittableExtrinsic extends BaseSubmittableExtrinsic {
|
|
|
28
28
|
]);
|
|
29
29
|
const txIndex = signedBlock.block.extrinsics.indexOf(txHex);
|
|
30
30
|
assert(txIndex >= 0, 'Extrinsic not found!');
|
|
31
|
-
const events = blockEvents.filter(({ phase }) => phase.
|
|
31
|
+
const events = blockEvents.filter(({ phase }) => phase.type === 'ApplyExtrinsic' && phase.value === txIndex);
|
|
32
32
|
return callback(new SubmittableResult({ status, txHash, events, txIndex }));
|
|
33
33
|
}
|
|
34
34
|
else {
|