@acala-network/chopsticks-core 0.8.5-1 → 0.8.5-2
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/lib/api.js +55 -79
- package/lib/blockchain/block-builder.js +57 -59
- package/lib/blockchain/block.d.ts +3 -1
- package/lib/blockchain/block.js +88 -81
- package/lib/blockchain/head-state.js +31 -46
- package/lib/blockchain/index.js +214 -262
- package/lib/blockchain/inherent/index.js +9 -22
- package/lib/blockchain/inherent/para-enter.js +24 -32
- package/lib/blockchain/inherent/parachain/babe-randomness.js +6 -18
- package/lib/blockchain/inherent/parachain/nimbus-author-inherent.js +6 -18
- package/lib/blockchain/inherent/parachain/validation-data.js +124 -124
- package/lib/blockchain/storage-layer.js +112 -140
- package/lib/blockchain/txpool.js +88 -111
- package/lib/chopsticks-provider.js +28 -37
- package/lib/genesis-provider.d.ts +12 -3
- package/lib/genesis-provider.js +39 -39
- package/lib/offchain.js +18 -31
- package/lib/rpc/index.js +7 -15
- package/lib/rpc/substrate/author.js +13 -22
- package/lib/rpc/substrate/chain.js +26 -35
- package/lib/rpc/substrate/index.js +7 -1
- package/lib/rpc/substrate/payment.js +10 -19
- package/lib/rpc/substrate/state.js +52 -59
- package/lib/rpc/substrate/system.js +22 -31
- package/lib/setup.js +14 -20
- package/lib/utils/decoder.d.ts +1 -1
- package/lib/utils/decoder.js +6 -15
- package/lib/utils/index.js +26 -38
- package/lib/utils/key-cache.js +13 -24
- package/lib/utils/set-storage.js +4 -13
- package/lib/utils/time-travel.d.ts +1 -1
- package/lib/utils/time-travel.js +19 -28
- package/lib/wasm-executor/browser-wasm-executor.mjs +2 -7
- package/lib/wasm-executor/browser-worker.js +4 -13
- package/lib/wasm-executor/index.d.ts +24 -8
- package/lib/wasm-executor/index.js +79 -111
- package/lib/wasm-executor/node-wasm-executor.mjs +2 -7
- package/lib/wasm-executor/node-worker.js +5 -14
- package/lib/xcm/downward.js +8 -17
- package/lib/xcm/horizontal.js +6 -15
- package/lib/xcm/index.js +9 -18
- package/lib/xcm/upward.js +7 -16
- package/package.json +5 -4
package/lib/api.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
3
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
4
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -44,10 +35,8 @@ class Api {
|
|
|
44
35
|
__classPrivateFieldSet(this, _Api_provider, provider, "f");
|
|
45
36
|
this.signedExtensions = signedExtensions || {};
|
|
46
37
|
}
|
|
47
|
-
disconnect() {
|
|
48
|
-
return
|
|
49
|
-
return __classPrivateFieldGet(this, _Api_provider, "f").disconnect();
|
|
50
|
-
});
|
|
38
|
+
async disconnect() {
|
|
39
|
+
return __classPrivateFieldGet(this, _Api_provider, "f").disconnect();
|
|
51
40
|
}
|
|
52
41
|
get isReady() {
|
|
53
42
|
if (!__classPrivateFieldGet(this, _Api_ready, "f")) {
|
|
@@ -56,10 +45,13 @@ class Api {
|
|
|
56
45
|
}
|
|
57
46
|
else {
|
|
58
47
|
__classPrivateFieldSet(this, _Api_ready, new Promise((resolve) => {
|
|
59
|
-
__classPrivateFieldGet(this, _Api_provider, "f").
|
|
48
|
+
if (__classPrivateFieldGet(this, _Api_provider, "f").hasSubscriptions) {
|
|
49
|
+
__classPrivateFieldGet(this, _Api_provider, "f").on('connected', resolve);
|
|
50
|
+
__classPrivateFieldGet(this, _Api_provider, "f").connect();
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
60
53
|
resolve();
|
|
61
|
-
}
|
|
62
|
-
__classPrivateFieldGet(this, _Api_provider, "f").connect();
|
|
54
|
+
}
|
|
63
55
|
}), "f");
|
|
64
56
|
}
|
|
65
57
|
}
|
|
@@ -77,76 +69,60 @@ class Api {
|
|
|
77
69
|
}
|
|
78
70
|
return __classPrivateFieldGet(this, _Api_chainProperties, "f");
|
|
79
71
|
}
|
|
80
|
-
getSystemName() {
|
|
81
|
-
return
|
|
82
|
-
return __classPrivateFieldGet(this, _Api_provider, "f").send('system_name', []);
|
|
83
|
-
});
|
|
72
|
+
async getSystemName() {
|
|
73
|
+
return __classPrivateFieldGet(this, _Api_provider, "f").send('system_name', []);
|
|
84
74
|
}
|
|
85
|
-
getSystemProperties() {
|
|
86
|
-
return
|
|
87
|
-
return __classPrivateFieldGet(this, _Api_provider, "f").send('system_properties', []);
|
|
88
|
-
});
|
|
75
|
+
async getSystemProperties() {
|
|
76
|
+
return __classPrivateFieldGet(this, _Api_provider, "f").send('system_properties', []);
|
|
89
77
|
}
|
|
90
|
-
getSystemChain() {
|
|
91
|
-
return
|
|
92
|
-
return __classPrivateFieldGet(this, _Api_provider, "f").send('system_chain', []);
|
|
93
|
-
});
|
|
78
|
+
async getSystemChain() {
|
|
79
|
+
return __classPrivateFieldGet(this, _Api_provider, "f").send('system_chain', []);
|
|
94
80
|
}
|
|
95
|
-
getBlockHash(blockNumber) {
|
|
96
|
-
return
|
|
97
|
-
return __classPrivateFieldGet(this, _Api_provider, "f").send('chain_getBlockHash', Number.isInteger(blockNumber) ? [blockNumber] : []);
|
|
98
|
-
});
|
|
81
|
+
async getBlockHash(blockNumber) {
|
|
82
|
+
return __classPrivateFieldGet(this, _Api_provider, "f").send('chain_getBlockHash', Number.isInteger(blockNumber) ? [blockNumber] : []);
|
|
99
83
|
}
|
|
100
|
-
getHeader(hash) {
|
|
101
|
-
return
|
|
102
|
-
return __classPrivateFieldGet(this, _Api_provider, "f").send('chain_getHeader', hash ? [hash] : []);
|
|
103
|
-
});
|
|
84
|
+
async getHeader(hash) {
|
|
85
|
+
return __classPrivateFieldGet(this, _Api_provider, "f").send('chain_getHeader', hash ? [hash] : []);
|
|
104
86
|
}
|
|
105
|
-
getBlock(hash) {
|
|
106
|
-
return
|
|
107
|
-
return __classPrivateFieldGet(this, _Api_provider, "f").send('chain_getBlock', hash ? [hash] : []);
|
|
108
|
-
});
|
|
87
|
+
async getBlock(hash) {
|
|
88
|
+
return __classPrivateFieldGet(this, _Api_provider, "f").send('chain_getBlock', hash ? [hash] : []);
|
|
109
89
|
}
|
|
110
|
-
getStorage(key, hash) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
});
|
|
90
|
+
async getStorage(key, hash) {
|
|
91
|
+
const [child, storageKey] = (0, utils_1.splitChildKey)(key);
|
|
92
|
+
if (child) {
|
|
93
|
+
// child storage key, use childstate_getStorage
|
|
94
|
+
const params = [child, storageKey];
|
|
95
|
+
if (hash)
|
|
96
|
+
params.push(hash);
|
|
97
|
+
return __classPrivateFieldGet(this, _Api_provider, "f").send('childstate_getStorage', params);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// main storage key, use state_getStorage
|
|
101
|
+
const params = [key];
|
|
102
|
+
if (hash)
|
|
103
|
+
params.push(hash);
|
|
104
|
+
return __classPrivateFieldGet(this, _Api_provider, "f").send('state_getStorage', params);
|
|
105
|
+
}
|
|
128
106
|
}
|
|
129
|
-
getKeysPaged(prefix, pageSize, startKey, hash) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
});
|
|
107
|
+
async getKeysPaged(prefix, pageSize, startKey, hash) {
|
|
108
|
+
const [child, storageKey] = (0, utils_1.splitChildKey)(prefix);
|
|
109
|
+
if (child) {
|
|
110
|
+
// child storage key, use childstate_getKeysPaged
|
|
111
|
+
// strip child prefix from startKey
|
|
112
|
+
const params = [child, storageKey, pageSize, (0, utils_1.stripChildPrefix)(startKey)];
|
|
113
|
+
if (hash)
|
|
114
|
+
params.push(hash);
|
|
115
|
+
return __classPrivateFieldGet(this, _Api_provider, "f")
|
|
116
|
+
.send('childstate_getKeysPaged', params)
|
|
117
|
+
.then((keys) => keys.map((key) => (0, utils_1.prefixedChildKey)(child, key)));
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// main storage key, use state_getKeysPaged
|
|
121
|
+
const params = [prefix, pageSize, startKey];
|
|
122
|
+
if (hash)
|
|
123
|
+
params.push(hash);
|
|
124
|
+
return __classPrivateFieldGet(this, _Api_provider, "f").send('state_getKeysPaged', params);
|
|
125
|
+
}
|
|
150
126
|
}
|
|
151
127
|
}
|
|
152
128
|
exports.Api = Api;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.dryRunInherents = exports.dryRunExtrinsic = exports.buildBlock = exports.newHeader = void 0;
|
|
13
4
|
const block_1 = require("./block");
|
|
@@ -27,47 +18,56 @@ const getConsensus = (header) => {
|
|
|
27
18
|
const getNewSlot = (digest, slotNumber) => {
|
|
28
19
|
if (digest.isPrimary) {
|
|
29
20
|
return {
|
|
30
|
-
primary:
|
|
21
|
+
primary: {
|
|
22
|
+
...digest.asPrimary.toJSON(),
|
|
23
|
+
slotNumber,
|
|
24
|
+
},
|
|
31
25
|
};
|
|
32
26
|
}
|
|
33
27
|
if (digest.isSecondaryPlain) {
|
|
34
28
|
return {
|
|
35
|
-
secondaryPlain:
|
|
29
|
+
secondaryPlain: {
|
|
30
|
+
...digest.asSecondaryPlain.toJSON(),
|
|
31
|
+
slotNumber,
|
|
32
|
+
},
|
|
36
33
|
};
|
|
37
34
|
}
|
|
38
35
|
if (digest.isSecondaryVRF) {
|
|
39
36
|
return {
|
|
40
|
-
secondaryVRF:
|
|
37
|
+
secondaryVRF: {
|
|
38
|
+
...digest.asSecondaryVRF.toJSON(),
|
|
39
|
+
slotNumber,
|
|
40
|
+
},
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
return digest.toJSON();
|
|
44
44
|
};
|
|
45
|
-
const newHeader = (head, unsafeBlockHeight) =>
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
const parentHeader = yield head.header;
|
|
45
|
+
const newHeader = async (head, unsafeBlockHeight) => {
|
|
46
|
+
const meta = await head.meta;
|
|
47
|
+
const parentHeader = await head.header;
|
|
49
48
|
let newLogs = parentHeader.digest.logs;
|
|
50
49
|
const consensus = getConsensus(parentHeader);
|
|
51
|
-
if (consensus
|
|
52
|
-
const slot =
|
|
50
|
+
if (consensus?.consensusEngine.isAura) {
|
|
51
|
+
const slot = await (0, time_travel_1.getCurrentSlot)(head.chain);
|
|
53
52
|
const newSlot = (0, util_1.compactAddLength)(meta.registry.createType('Slot', slot + 1).toU8a());
|
|
54
53
|
newLogs = [{ PreRuntime: [consensus.consensusEngine, newSlot] }, ...consensus.rest];
|
|
55
54
|
}
|
|
56
|
-
else if (consensus
|
|
57
|
-
const slot =
|
|
55
|
+
else if (consensus?.consensusEngine.isBabe) {
|
|
56
|
+
const slot = await (0, time_travel_1.getCurrentSlot)(head.chain);
|
|
58
57
|
const digest = meta.registry.createType('RawBabePreDigest', consensus.slot);
|
|
59
58
|
const newSlot = (0, util_1.compactAddLength)(meta.registry.createType('RawBabePreDigest', getNewSlot(digest, slot + 1)).toU8a());
|
|
60
59
|
newLogs = [{ PreRuntime: [consensus.consensusEngine, newSlot] }, ...consensus.rest];
|
|
61
60
|
}
|
|
62
|
-
else if (
|
|
61
|
+
else if (consensus?.consensusEngine?.toString() == 'nmbs') {
|
|
63
62
|
const nmbsKey = (0, util_1.stringToHex)('nmbs');
|
|
64
63
|
newLogs = [
|
|
65
64
|
{
|
|
66
65
|
// Using previous block author
|
|
67
66
|
PreRuntime: [
|
|
68
67
|
consensus.consensusEngine,
|
|
69
|
-
|
|
70
|
-
.find((log) => log.isPreRuntime && log.asPreRuntime[0].toHex() == nmbsKey)
|
|
68
|
+
parentHeader.digest.logs
|
|
69
|
+
.find((log) => log.isPreRuntime && log.asPreRuntime[0].toHex() == nmbsKey)
|
|
70
|
+
?.asPreRuntime[1].toHex(),
|
|
71
71
|
],
|
|
72
72
|
},
|
|
73
73
|
...consensus.rest,
|
|
@@ -80,7 +80,7 @@ const newHeader = (head, unsafeBlockHeight) => __awaiter(void 0, void 0, void 0,
|
|
|
80
80
|
}
|
|
81
81
|
const header = meta.registry.createType('Header', {
|
|
82
82
|
parentHash: head.hash,
|
|
83
|
-
number: unsafeBlockHeight
|
|
83
|
+
number: unsafeBlockHeight ?? head.number + 1,
|
|
84
84
|
stateRoot: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
85
85
|
extrinsicsRoot: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
86
86
|
digest: {
|
|
@@ -88,10 +88,9 @@ const newHeader = (head, unsafeBlockHeight) => __awaiter(void 0, void 0, void 0,
|
|
|
88
88
|
},
|
|
89
89
|
});
|
|
90
90
|
return header;
|
|
91
|
-
}
|
|
91
|
+
};
|
|
92
92
|
exports.newHeader = newHeader;
|
|
93
|
-
const initNewBlock = (head, header, inherents, storageLayer, callback) =>
|
|
94
|
-
var _c, _d;
|
|
93
|
+
const initNewBlock = async (head, header, inherents, storageLayer, callback) => {
|
|
95
94
|
const blockNumber = header.number.toNumber();
|
|
96
95
|
const hash = `0x${Math.round(Math.random() * 100000000)
|
|
97
96
|
.toString(16)
|
|
@@ -99,23 +98,23 @@ const initNewBlock = (head, header, inherents, storageLayer, callback) => __awai
|
|
|
99
98
|
const newBlock = new block_1.Block(head.chain, blockNumber, hash, head, {
|
|
100
99
|
header,
|
|
101
100
|
extrinsics: [],
|
|
102
|
-
storage: storageLayer
|
|
101
|
+
storage: storageLayer ?? head.storage,
|
|
103
102
|
});
|
|
104
103
|
{
|
|
105
104
|
// initialize block
|
|
106
|
-
const resp =
|
|
105
|
+
const resp = await newBlock.call('Core_initialize_block', [header.toHex()]);
|
|
107
106
|
newBlock.pushStorageLayer().setAll(resp.storageDiff);
|
|
108
|
-
|
|
107
|
+
callback?.onPhaseApplied?.('initialize', resp);
|
|
109
108
|
}
|
|
110
109
|
const layers = [];
|
|
111
110
|
// apply inherents
|
|
112
111
|
for (const extrinsic of inherents) {
|
|
113
112
|
try {
|
|
114
|
-
const resp =
|
|
113
|
+
const resp = await newBlock.call('BlockBuilder_apply_extrinsic', [extrinsic]);
|
|
115
114
|
const layer = newBlock.pushStorageLayer();
|
|
116
115
|
layer.setAll(resp.storageDiff);
|
|
117
116
|
layers.push(layer);
|
|
118
|
-
|
|
117
|
+
callback?.onPhaseApplied?.(layers.length - 1, resp);
|
|
119
118
|
}
|
|
120
119
|
catch (e) {
|
|
121
120
|
logger.warn('Failed to apply inherents %o %s', e, e);
|
|
@@ -126,11 +125,10 @@ const initNewBlock = (head, header, inherents, storageLayer, callback) => __awai
|
|
|
126
125
|
block: newBlock,
|
|
127
126
|
layers: layers,
|
|
128
127
|
};
|
|
129
|
-
}
|
|
130
|
-
const buildBlock = (head, inherents, extrinsics, ump, callbacks, unsafeBlockHeight) =>
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
const header = yield (0, exports.newHeader)(head, unsafeBlockHeight);
|
|
128
|
+
};
|
|
129
|
+
const buildBlock = async (head, inherents, extrinsics, ump, callbacks, unsafeBlockHeight) => {
|
|
130
|
+
const registry = await head.registry;
|
|
131
|
+
const header = await (0, exports.newHeader)(head, unsafeBlockHeight);
|
|
134
132
|
const newBlockNumber = header.number.toNumber();
|
|
135
133
|
logger.info({
|
|
136
134
|
number: newBlockNumber,
|
|
@@ -140,7 +138,7 @@ const buildBlock = (head, inherents, extrinsics, ump, callbacks, unsafeBlockHeig
|
|
|
140
138
|
let layer;
|
|
141
139
|
// apply ump via storage override hack
|
|
142
140
|
if (Object.keys(ump).length > 0) {
|
|
143
|
-
const meta =
|
|
141
|
+
const meta = await head.meta;
|
|
144
142
|
layer = new storage_layer_1.StorageLayer(head.storage);
|
|
145
143
|
for (const [paraId, upwardMessages] of Object.entries(ump)) {
|
|
146
144
|
const upwardMessagesU8a = upwardMessages.map((x) => (0, util_1.hexToU8a)(x));
|
|
@@ -209,21 +207,21 @@ const buildBlock = (head, inherents, extrinsics, ump, callbacks, unsafeBlockHeig
|
|
|
209
207
|
layer.set((0, utils_1.compactHex)(meta.query.ump.needsDispatch()), needsDispatch.toHex());
|
|
210
208
|
}
|
|
211
209
|
}
|
|
212
|
-
const { block: newBlock } =
|
|
210
|
+
const { block: newBlock } = await initNewBlock(head, header, inherents, layer);
|
|
213
211
|
const pendingExtrinsics = [];
|
|
214
212
|
const includedExtrinsic = [];
|
|
215
213
|
// apply extrinsics
|
|
216
214
|
for (const extrinsic of extrinsics) {
|
|
217
215
|
try {
|
|
218
|
-
const resp =
|
|
216
|
+
const resp = await newBlock.call('BlockBuilder_apply_extrinsic', [extrinsic]);
|
|
219
217
|
const outcome = registry.createType('ApplyExtrinsicResult', resp.result);
|
|
220
218
|
if (outcome.isErr) {
|
|
221
|
-
|
|
219
|
+
callbacks?.onApplyExtrinsicError?.(extrinsic, outcome.asErr);
|
|
222
220
|
continue;
|
|
223
221
|
}
|
|
224
222
|
newBlock.pushStorageLayer().setAll(resp.storageDiff);
|
|
225
223
|
includedExtrinsic.push(extrinsic);
|
|
226
|
-
|
|
224
|
+
callbacks?.onPhaseApplied?.(includedExtrinsic.length - 1, resp);
|
|
227
225
|
}
|
|
228
226
|
catch (e) {
|
|
229
227
|
logger.info('Failed to apply extrinsic %o %s', e, e);
|
|
@@ -232,15 +230,15 @@ const buildBlock = (head, inherents, extrinsics, ump, callbacks, unsafeBlockHeig
|
|
|
232
230
|
}
|
|
233
231
|
{
|
|
234
232
|
// finalize block
|
|
235
|
-
const resp =
|
|
233
|
+
const resp = await newBlock.call('BlockBuilder_finalize_block', []);
|
|
236
234
|
newBlock.pushStorageLayer().setAll(resp.storageDiff);
|
|
237
|
-
|
|
235
|
+
callbacks?.onPhaseApplied?.('finalize', resp);
|
|
238
236
|
}
|
|
239
237
|
const blockData = registry.createType('Block', {
|
|
240
238
|
header,
|
|
241
239
|
extrinsics: includedExtrinsic,
|
|
242
240
|
});
|
|
243
|
-
const storageDiff =
|
|
241
|
+
const storageDiff = await newBlock.storageDiff();
|
|
244
242
|
if (logger.level.toLowerCase() === 'trace') {
|
|
245
243
|
logger.trace(Object.entries(storageDiff).map(([key, value]) => [key, (0, logger_1.truncate)(value)]), 'Final block');
|
|
246
244
|
}
|
|
@@ -258,25 +256,25 @@ const buildBlock = (head, inherents, extrinsics, ump, callbacks, unsafeBlockHeig
|
|
|
258
256
|
ump: (0, logger_1.truncate)(ump),
|
|
259
257
|
}, 'Block built');
|
|
260
258
|
return [finalBlock, pendingExtrinsics];
|
|
261
|
-
}
|
|
259
|
+
};
|
|
262
260
|
exports.buildBlock = buildBlock;
|
|
263
|
-
const dryRunExtrinsic = (head, inherents, extrinsic) =>
|
|
264
|
-
const registry =
|
|
265
|
-
const header =
|
|
266
|
-
const { block: newBlock } =
|
|
261
|
+
const dryRunExtrinsic = async (head, inherents, extrinsic) => {
|
|
262
|
+
const registry = await head.registry;
|
|
263
|
+
const header = await (0, exports.newHeader)(head);
|
|
264
|
+
const { block: newBlock } = await initNewBlock(head, header, inherents);
|
|
267
265
|
if (typeof extrinsic !== 'string') {
|
|
268
266
|
if (!head.chain.mockSignatureHost) {
|
|
269
267
|
throw new Error('Cannot fake signature because mock signature host is not enabled. Start chain with `mockSignatureHost: true`');
|
|
270
268
|
}
|
|
271
|
-
const meta =
|
|
269
|
+
const meta = await head.meta;
|
|
272
270
|
const call = registry.createType('Call', (0, util_1.hexToU8a)(extrinsic.call));
|
|
273
271
|
const generic = registry.createType('GenericExtrinsic', call);
|
|
274
|
-
const accountRaw =
|
|
272
|
+
const accountRaw = await head.get((0, utils_1.compactHex)(meta.query.system.account(extrinsic.address)));
|
|
275
273
|
const account = registry.createType('AccountInfo', (0, util_1.hexToU8a)(accountRaw));
|
|
276
274
|
generic.signFake(extrinsic.address, {
|
|
277
275
|
blockHash: head.hash,
|
|
278
276
|
genesisHash: head.hash,
|
|
279
|
-
runtimeVersion:
|
|
277
|
+
runtimeVersion: await head.runtimeVersion,
|
|
280
278
|
nonce: account.nonce,
|
|
281
279
|
});
|
|
282
280
|
const mockSignature = new Uint8Array(64);
|
|
@@ -288,15 +286,15 @@ const dryRunExtrinsic = (head, inherents, extrinsic) => __awaiter(void 0, void 0
|
|
|
288
286
|
}
|
|
289
287
|
logger_1.defaultLogger.info({ call: registry.createType('GenericExtrinsic', (0, util_1.hexToU8a)(extrinsic)).toHuman() }, 'dry_run_extrinsic');
|
|
290
288
|
return newBlock.call('BlockBuilder_apply_extrinsic', [extrinsic]);
|
|
291
|
-
}
|
|
289
|
+
};
|
|
292
290
|
exports.dryRunExtrinsic = dryRunExtrinsic;
|
|
293
|
-
const dryRunInherents = (head, inherents) =>
|
|
294
|
-
const header =
|
|
295
|
-
const { layers } =
|
|
291
|
+
const dryRunInherents = async (head, inherents) => {
|
|
292
|
+
const header = await (0, exports.newHeader)(head);
|
|
293
|
+
const { layers } = await initNewBlock(head, header, inherents);
|
|
296
294
|
const storage = {};
|
|
297
295
|
for (const layer of layers) {
|
|
298
|
-
|
|
296
|
+
await layer.mergeInto(storage);
|
|
299
297
|
}
|
|
300
298
|
return Object.entries(storage);
|
|
301
|
-
}
|
|
299
|
+
};
|
|
302
300
|
exports.dryRunInherents = dryRunInherents;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Header } from '@polkadot/types/interfaces';
|
|
2
2
|
import { DecoratedMeta } from '@polkadot/types/metadata/decorate/types';
|
|
3
3
|
import { TypeRegistry } from '@polkadot/types';
|
|
4
|
+
import { StorageEntry } from '@polkadot/types/primitive/types';
|
|
4
5
|
import type { HexString } from '@polkadot/util/types';
|
|
5
6
|
import { Blockchain } from '.';
|
|
6
7
|
import { StorageLayer, StorageLayerProvider, StorageValue } from './storage-layer';
|
|
@@ -44,7 +45,7 @@ export declare class Block {
|
|
|
44
45
|
get chain(): Blockchain;
|
|
45
46
|
get header(): Header | Promise<Header>;
|
|
46
47
|
get extrinsics(): HexString[] | Promise<HexString[]>;
|
|
47
|
-
get parentBlock():
|
|
48
|
+
get parentBlock(): Promise<Block | undefined>;
|
|
48
49
|
/**
|
|
49
50
|
* Get the block storage.
|
|
50
51
|
*/
|
|
@@ -53,6 +54,7 @@ export declare class Block {
|
|
|
53
54
|
* Get the block storage by key.
|
|
54
55
|
*/
|
|
55
56
|
get(key: string): Promise<string | undefined>;
|
|
57
|
+
read<T extends string>(type: T, query: StorageEntry, ...args: any[]): Promise<import("@polkadot/types/types").DetectCodec<import("@polkadot/types-codec/types").Codec, T> | undefined>;
|
|
56
58
|
/**
|
|
57
59
|
* Get paged storage keys.
|
|
58
60
|
*/
|