@acala-network/chopsticks-core 0.8.0-0 → 0.8.0-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 +5 -1
- package/lib/blockchain/block-builder.js +52 -45
- package/lib/blockchain/block.js +31 -27
- package/lib/blockchain/head-state.js +14 -9
- package/lib/blockchain/index.js +36 -32
- package/lib/blockchain/inherent/index.js +20 -11
- package/lib/blockchain/inherent/para-enter.js +7 -3
- package/lib/blockchain/inherent/parachain/babe-randomness.js +7 -3
- package/lib/blockchain/inherent/parachain/nimbus-author-inherent.js +7 -3
- package/lib/blockchain/inherent/parachain/validation-data.js +33 -26
- package/lib/blockchain/storage-layer.js +22 -14
- package/lib/blockchain/txpool.js +26 -19
- package/lib/db/browser.d.ts +1 -1
- package/lib/db/browser.js +42 -11
- package/lib/db/entities.js +6 -3
- package/lib/db/index.d.ts +1 -1
- package/lib/db/index.js +31 -4
- package/lib/db/node.js +31 -4
- package/lib/executor.js +40 -32
- package/lib/genesis-provider.js +46 -16
- package/lib/index.js +29 -13
- package/lib/logger.js +10 -3
- package/lib/offchain.js +11 -7
- package/lib/schema/index.js +12 -9
- package/lib/setup.d.ts +1 -1
- package/lib/setup.js +30 -21
- package/lib/utils/index.js +35 -12
- package/lib/utils/key-cache.js +24 -17
- package/lib/utils/proof.js +17 -9
- package/lib/utils/set-storage.js +15 -11
- package/lib/utils/time-travel.js +28 -21
- package/lib/xcm/downward.js +15 -11
- package/lib/xcm/horizontal.js +11 -7
- package/lib/xcm/index.js +19 -14
- package/lib/xcm/upward.js +10 -6
- package/package.json +2 -2
package/lib/api.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,7 +20,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
19
20
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
21
|
};
|
|
21
22
|
var _Api_provider, _Api_ready, _Api_chain, _Api_chainProperties;
|
|
22
|
-
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.Api = void 0;
|
|
25
|
+
class Api {
|
|
23
26
|
constructor(provider, signedExtensions) {
|
|
24
27
|
_Api_provider.set(this, void 0);
|
|
25
28
|
_Api_ready.set(this, void 0);
|
|
@@ -113,4 +116,5 @@ export class Api {
|
|
|
113
116
|
});
|
|
114
117
|
}
|
|
115
118
|
}
|
|
119
|
+
exports.Api = Api;
|
|
116
120
|
_Api_provider = new WeakMap(), _Api_ready = new WeakMap(), _Api_chain = new WeakMap(), _Api_chainProperties = new WeakMap();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -7,13 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.dryRunInherents = exports.dryRunExtrinsic = exports.buildBlock = exports.newHeader = void 0;
|
|
13
|
+
const block_1 = require("./block");
|
|
14
|
+
const storage_layer_1 = require("./storage-layer");
|
|
15
|
+
const util_1 = require("@polkadot/util");
|
|
16
|
+
const utils_1 = require("../utils");
|
|
17
|
+
const logger_1 = require("../logger");
|
|
18
|
+
const time_travel_1 = require("../utils/time-travel");
|
|
19
|
+
const logger = logger_1.defaultLogger.child({ name: 'block-builder' });
|
|
17
20
|
const getConsensus = (header) => {
|
|
18
21
|
if (header.digest.logs.length === 0)
|
|
19
22
|
return;
|
|
@@ -39,25 +42,25 @@ const getNewSlot = (digest, slotNumber) => {
|
|
|
39
42
|
}
|
|
40
43
|
return digest.toJSON();
|
|
41
44
|
};
|
|
42
|
-
|
|
45
|
+
const newHeader = (head) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
46
|
var _a, _b;
|
|
44
47
|
const meta = yield head.meta;
|
|
45
48
|
const parentHeader = yield head.header;
|
|
46
49
|
let newLogs = parentHeader.digest.logs;
|
|
47
50
|
const consensus = getConsensus(parentHeader);
|
|
48
51
|
if (consensus === null || consensus === void 0 ? void 0 : consensus.consensusEngine.isAura) {
|
|
49
|
-
const slot = yield getCurrentSlot(head.chain);
|
|
50
|
-
const newSlot = compactAddLength(meta.registry.createType('Slot', slot + 1).toU8a());
|
|
52
|
+
const slot = yield (0, time_travel_1.getCurrentSlot)(head.chain);
|
|
53
|
+
const newSlot = (0, util_1.compactAddLength)(meta.registry.createType('Slot', slot + 1).toU8a());
|
|
51
54
|
newLogs = [{ PreRuntime: [consensus.consensusEngine, newSlot] }, ...consensus.rest];
|
|
52
55
|
}
|
|
53
56
|
else if (consensus === null || consensus === void 0 ? void 0 : consensus.consensusEngine.isBabe) {
|
|
54
|
-
const slot = yield getCurrentSlot(head.chain);
|
|
57
|
+
const slot = yield (0, time_travel_1.getCurrentSlot)(head.chain);
|
|
55
58
|
const digest = meta.registry.createType('RawBabePreDigest', consensus.slot);
|
|
56
|
-
const newSlot = compactAddLength(meta.registry.createType('RawBabePreDigest', getNewSlot(digest, slot + 1)).toU8a());
|
|
59
|
+
const newSlot = (0, util_1.compactAddLength)(meta.registry.createType('RawBabePreDigest', getNewSlot(digest, slot + 1)).toU8a());
|
|
57
60
|
newLogs = [{ PreRuntime: [consensus.consensusEngine, newSlot] }, ...consensus.rest];
|
|
58
61
|
}
|
|
59
62
|
else if (((_a = consensus === null || consensus === void 0 ? void 0 : consensus.consensusEngine) === null || _a === void 0 ? void 0 : _a.toString()) == 'nmbs') {
|
|
60
|
-
const nmbsKey = stringToHex('nmbs');
|
|
63
|
+
const nmbsKey = (0, util_1.stringToHex)('nmbs');
|
|
61
64
|
newLogs = [
|
|
62
65
|
{
|
|
63
66
|
// Using previous block author
|
|
@@ -72,7 +75,7 @@ export const newHeader = (head) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
72
75
|
if (meta.query.randomness) {
|
|
73
76
|
// TODO: shouldn't modify existing head
|
|
74
77
|
// reset notFirstBlock so randomness will skip validation
|
|
75
|
-
head.pushStorageLayer().set(compactHex(meta.query.randomness.notFirstBlock()), StorageValueKind.Deleted);
|
|
78
|
+
head.pushStorageLayer().set((0, utils_1.compactHex)(meta.query.randomness.notFirstBlock()), storage_layer_1.StorageValueKind.Deleted);
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
const header = meta.registry.createType('Header', {
|
|
@@ -86,12 +89,13 @@ export const newHeader = (head) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
86
89
|
});
|
|
87
90
|
return header;
|
|
88
91
|
});
|
|
92
|
+
exports.newHeader = newHeader;
|
|
89
93
|
const initNewBlock = (head, header, inherents, storageLayer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
94
|
const blockNumber = header.number.toNumber();
|
|
91
95
|
const hash = `0x${Math.round(Math.random() * 100000000)
|
|
92
96
|
.toString(16)
|
|
93
97
|
.padEnd(64, '0')}`;
|
|
94
|
-
const newBlock = new Block(head.chain, blockNumber, hash, head, {
|
|
98
|
+
const newBlock = new block_1.Block(head.chain, blockNumber, hash, head, {
|
|
95
99
|
header,
|
|
96
100
|
extrinsics: [],
|
|
97
101
|
storage: storageLayer !== null && storageLayer !== void 0 ? storageLayer : head.storage,
|
|
@@ -100,7 +104,7 @@ const initNewBlock = (head, header, inherents, storageLayer) => __awaiter(void 0
|
|
|
100
104
|
// initialize block
|
|
101
105
|
const { storageDiff } = yield newBlock.call('Core_initialize_block', [header.toHex()]);
|
|
102
106
|
newBlock.pushStorageLayer().setAll(storageDiff);
|
|
103
|
-
logger.trace(truncate(storageDiff), 'Initialize block');
|
|
107
|
+
logger.trace((0, logger_1.truncate)(storageDiff), 'Initialize block');
|
|
104
108
|
}
|
|
105
109
|
const layers = [];
|
|
106
110
|
// apply inherents
|
|
@@ -110,7 +114,7 @@ const initNewBlock = (head, header, inherents, storageLayer) => __awaiter(void 0
|
|
|
110
114
|
const layer = newBlock.pushStorageLayer();
|
|
111
115
|
layer.setAll(storageDiff);
|
|
112
116
|
layers.push(layer);
|
|
113
|
-
logger.trace(truncate(storageDiff), 'Applied inherent');
|
|
117
|
+
logger.trace((0, logger_1.truncate)(storageDiff), 'Applied inherent');
|
|
114
118
|
}
|
|
115
119
|
catch (e) {
|
|
116
120
|
logger.warn('Failed to apply inherents %o %s', e, e);
|
|
@@ -122,9 +126,9 @@ const initNewBlock = (head, header, inherents, storageLayer) => __awaiter(void 0
|
|
|
122
126
|
layers: layers,
|
|
123
127
|
};
|
|
124
128
|
});
|
|
125
|
-
|
|
129
|
+
const buildBlock = (head, inherents, extrinsics, ump, onApplyExtrinsicError) => __awaiter(void 0, void 0, void 0, function* () {
|
|
126
130
|
const registry = yield head.registry;
|
|
127
|
-
const header = yield newHeader(head);
|
|
131
|
+
const header = yield (0, exports.newHeader)(head);
|
|
128
132
|
logger.info({
|
|
129
133
|
number: head.number + 1,
|
|
130
134
|
extrinsicsCount: extrinsics.length,
|
|
@@ -134,9 +138,9 @@ export const buildBlock = (head, inherents, extrinsics, ump, onApplyExtrinsicErr
|
|
|
134
138
|
// apply ump via storage override hack
|
|
135
139
|
if (Object.keys(ump).length > 0) {
|
|
136
140
|
const meta = yield head.meta;
|
|
137
|
-
layer = new StorageLayer(head.storage);
|
|
141
|
+
layer = new storage_layer_1.StorageLayer(head.storage);
|
|
138
142
|
for (const [paraId, upwardMessages] of Object.entries(ump)) {
|
|
139
|
-
const upwardMessagesU8a = upwardMessages.map((x) => hexToU8a(x));
|
|
143
|
+
const upwardMessagesU8a = upwardMessages.map((x) => (0, util_1.hexToU8a)(x));
|
|
140
144
|
const messagesCount = upwardMessages.length;
|
|
141
145
|
const messagesSize = upwardMessagesU8a.map((x) => x.length).reduce((s, i) => s + i, 0);
|
|
142
146
|
if (meta.query.ump) {
|
|
@@ -144,8 +148,8 @@ export const buildBlock = (head, inherents, extrinsics, ump, onApplyExtrinsicErr
|
|
|
144
148
|
const messages = meta.registry.createType('Vec<Bytes>', upwardMessages);
|
|
145
149
|
// TODO: make sure we append instead of replace
|
|
146
150
|
layer.setAll([
|
|
147
|
-
[compactHex(meta.query.ump.relayDispatchQueues(paraId)), messages.toHex()],
|
|
148
|
-
[compactHex(meta.query.ump.relayDispatchQueueSize(paraId)), queueSize.toHex()],
|
|
151
|
+
[(0, utils_1.compactHex)(meta.query.ump.relayDispatchQueues(paraId)), messages.toHex()],
|
|
152
|
+
[(0, utils_1.compactHex)(meta.query.ump.relayDispatchQueueSize(paraId)), queueSize.toHex()],
|
|
149
153
|
]);
|
|
150
154
|
}
|
|
151
155
|
else if (meta.query.messageQueue) {
|
|
@@ -157,11 +161,11 @@ export const buildBlock = (head, inherents, extrinsics, ump, onApplyExtrinsicErr
|
|
|
157
161
|
const payloadLen = message.length;
|
|
158
162
|
const header = meta.registry.createType('(u32, bool)', [payloadLen, false]);
|
|
159
163
|
last = heap.length;
|
|
160
|
-
heap = u8aConcat(heap, header.toU8a(), message);
|
|
164
|
+
heap = (0, util_1.u8aConcat)(heap, header.toU8a(), message);
|
|
161
165
|
}
|
|
162
166
|
layer.setAll([
|
|
163
167
|
[
|
|
164
|
-
compactHex(meta.query.messageQueue.bookStateFor(origin)),
|
|
168
|
+
(0, utils_1.compactHex)(meta.query.messageQueue.bookStateFor(origin)),
|
|
165
169
|
meta.registry
|
|
166
170
|
.createType('PalletMessageQueueBookState', {
|
|
167
171
|
begin: 0,
|
|
@@ -174,11 +178,11 @@ export const buildBlock = (head, inherents, extrinsics, ump, onApplyExtrinsicErr
|
|
|
174
178
|
.toHex(),
|
|
175
179
|
],
|
|
176
180
|
[
|
|
177
|
-
compactHex(meta.query.messageQueue.serviceHead(origin)),
|
|
181
|
+
(0, utils_1.compactHex)(meta.query.messageQueue.serviceHead(origin)),
|
|
178
182
|
meta.registry.createType('PolkadotRuntimeParachainsInclusionAggregateMessageOrigin', origin).toHex(),
|
|
179
183
|
],
|
|
180
184
|
[
|
|
181
|
-
compactHex(meta.query.messageQueue.pages(origin, 0)),
|
|
185
|
+
(0, utils_1.compactHex)(meta.query.messageQueue.pages(origin, 0)),
|
|
182
186
|
meta.registry
|
|
183
187
|
.createType('PalletMessageQueuePage', {
|
|
184
188
|
remaining: messagesCount,
|
|
@@ -186,7 +190,7 @@ export const buildBlock = (head, inherents, extrinsics, ump, onApplyExtrinsicErr
|
|
|
186
190
|
first_index: 0,
|
|
187
191
|
first: 0,
|
|
188
192
|
last,
|
|
189
|
-
heap: compactAddLength(heap),
|
|
193
|
+
heap: (0, util_1.compactAddLength)(heap),
|
|
190
194
|
})
|
|
191
195
|
.toHex(),
|
|
192
196
|
],
|
|
@@ -195,11 +199,11 @@ export const buildBlock = (head, inherents, extrinsics, ump, onApplyExtrinsicErr
|
|
|
195
199
|
else {
|
|
196
200
|
throw new Error('Unknown ump storage');
|
|
197
201
|
}
|
|
198
|
-
logger.trace({ paraId, upwardMessages: truncate(upwardMessages) }, 'Pushed UMP');
|
|
202
|
+
logger.trace({ paraId, upwardMessages: (0, logger_1.truncate)(upwardMessages) }, 'Pushed UMP');
|
|
199
203
|
}
|
|
200
204
|
if (meta.query.ump) {
|
|
201
205
|
const needsDispatch = meta.registry.createType('Vec<u32>', Object.keys(ump));
|
|
202
|
-
layer.set(compactHex(meta.query.ump.needsDispatch()), needsDispatch.toHex());
|
|
206
|
+
layer.set((0, utils_1.compactHex)(meta.query.ump.needsDispatch()), needsDispatch.toHex());
|
|
203
207
|
}
|
|
204
208
|
}
|
|
205
209
|
const { block: newBlock } = yield initNewBlock(head, header, inherents, layer);
|
|
@@ -215,7 +219,7 @@ export const buildBlock = (head, inherents, extrinsics, ump, onApplyExtrinsicErr
|
|
|
215
219
|
continue;
|
|
216
220
|
}
|
|
217
221
|
newBlock.pushStorageLayer().setAll(storageDiff);
|
|
218
|
-
logger.trace(truncate(storageDiff), 'Applied extrinsic');
|
|
222
|
+
logger.trace((0, logger_1.truncate)(storageDiff), 'Applied extrinsic');
|
|
219
223
|
includedExtrinsic.push(extrinsic);
|
|
220
224
|
}
|
|
221
225
|
catch (e) {
|
|
@@ -227,15 +231,15 @@ export const buildBlock = (head, inherents, extrinsics, ump, onApplyExtrinsicErr
|
|
|
227
231
|
// finalize block
|
|
228
232
|
const { storageDiff } = yield newBlock.call('BlockBuilder_finalize_block', []);
|
|
229
233
|
newBlock.pushStorageLayer().setAll(storageDiff);
|
|
230
|
-
logger.trace(truncate(storageDiff), 'Finalize block');
|
|
234
|
+
logger.trace((0, logger_1.truncate)(storageDiff), 'Finalize block');
|
|
231
235
|
}
|
|
232
236
|
const blockData = registry.createType('Block', {
|
|
233
237
|
header,
|
|
234
238
|
extrinsics: includedExtrinsic,
|
|
235
239
|
});
|
|
236
240
|
const storageDiff = yield newBlock.storageDiff();
|
|
237
|
-
logger.trace(Object.entries(storageDiff).map(([key, value]) => [key, truncate(value)]), 'Final block');
|
|
238
|
-
const finalBlock = new Block(head.chain, newBlock.number, blockData.hash.toHex(), head, {
|
|
241
|
+
logger.trace(Object.entries(storageDiff).map(([key, value]) => [key, (0, logger_1.truncate)(value)]), 'Final block');
|
|
242
|
+
const finalBlock = new block_1.Block(head.chain, newBlock.number, blockData.hash.toHex(), head, {
|
|
239
243
|
header,
|
|
240
244
|
extrinsics: [...inherents, ...includedExtrinsic],
|
|
241
245
|
storage: head.storage,
|
|
@@ -244,25 +248,26 @@ export const buildBlock = (head, inherents, extrinsics, ump, onApplyExtrinsicErr
|
|
|
244
248
|
logger.info({
|
|
245
249
|
number: newBlock.number,
|
|
246
250
|
hash: finalBlock.hash,
|
|
247
|
-
extrinsics: truncate(includedExtrinsic),
|
|
251
|
+
extrinsics: (0, logger_1.truncate)(includedExtrinsic),
|
|
248
252
|
pendingExtrinsicsCount: pendingExtrinsics.length,
|
|
249
|
-
ump: truncate(ump),
|
|
253
|
+
ump: (0, logger_1.truncate)(ump),
|
|
250
254
|
}, 'Block built');
|
|
251
255
|
return [finalBlock, pendingExtrinsics];
|
|
252
256
|
});
|
|
253
|
-
|
|
257
|
+
exports.buildBlock = buildBlock;
|
|
258
|
+
const dryRunExtrinsic = (head, inherents, extrinsic) => __awaiter(void 0, void 0, void 0, function* () {
|
|
254
259
|
const registry = yield head.registry;
|
|
255
|
-
const header = yield newHeader(head);
|
|
260
|
+
const header = yield (0, exports.newHeader)(head);
|
|
256
261
|
const { block: newBlock } = yield initNewBlock(head, header, inherents);
|
|
257
262
|
if (typeof extrinsic !== 'string') {
|
|
258
263
|
if (!head.chain.mockSignatureHost) {
|
|
259
264
|
throw new Error('Cannot fake signature because mock signature host is not enabled. Start chain with `mockSignatureHost: true`');
|
|
260
265
|
}
|
|
261
266
|
const meta = yield head.meta;
|
|
262
|
-
const call = registry.createType('Call', hexToU8a(extrinsic.call));
|
|
267
|
+
const call = registry.createType('Call', (0, util_1.hexToU8a)(extrinsic.call));
|
|
263
268
|
const generic = registry.createType('GenericExtrinsic', call);
|
|
264
|
-
const accountRaw = yield head.get(compactHex(meta.query.system.account(extrinsic.address)));
|
|
265
|
-
const account = registry.createType('AccountInfo', hexToU8a(accountRaw));
|
|
269
|
+
const accountRaw = yield head.get((0, utils_1.compactHex)(meta.query.system.account(extrinsic.address)));
|
|
270
|
+
const account = registry.createType('AccountInfo', (0, util_1.hexToU8a)(accountRaw));
|
|
266
271
|
generic.signFake(extrinsic.address, {
|
|
267
272
|
blockHash: head.hash,
|
|
268
273
|
genesisHash: head.hash,
|
|
@@ -273,14 +278,15 @@ export const dryRunExtrinsic = (head, inherents, extrinsic) => __awaiter(void 0,
|
|
|
273
278
|
mockSignature.fill(0xcd);
|
|
274
279
|
mockSignature.set([0xde, 0xad, 0xbe, 0xef]);
|
|
275
280
|
generic.signature.set(mockSignature);
|
|
276
|
-
defaultLogger.info({ call: call.toHuman() }, 'dry_run_call');
|
|
281
|
+
logger_1.defaultLogger.info({ call: call.toHuman() }, 'dry_run_call');
|
|
277
282
|
return newBlock.call('BlockBuilder_apply_extrinsic', [generic.toHex()]);
|
|
278
283
|
}
|
|
279
|
-
defaultLogger.info({ call: registry.createType('GenericExtrinsic', hexToU8a(extrinsic)).toHuman() }, 'dry_run_extrinsic');
|
|
284
|
+
logger_1.defaultLogger.info({ call: registry.createType('GenericExtrinsic', (0, util_1.hexToU8a)(extrinsic)).toHuman() }, 'dry_run_extrinsic');
|
|
280
285
|
return newBlock.call('BlockBuilder_apply_extrinsic', [extrinsic]);
|
|
281
286
|
});
|
|
282
|
-
|
|
283
|
-
|
|
287
|
+
exports.dryRunExtrinsic = dryRunExtrinsic;
|
|
288
|
+
const dryRunInherents = (head, inherents) => __awaiter(void 0, void 0, void 0, function* () {
|
|
289
|
+
const header = yield (0, exports.newHeader)(head);
|
|
284
290
|
const { layers } = yield initNewBlock(head, header, inherents);
|
|
285
291
|
const storage = {};
|
|
286
292
|
for (const layer of layers) {
|
|
@@ -288,3 +294,4 @@ export const dryRunInherents = (head, inherents) => __awaiter(void 0, void 0, vo
|
|
|
288
294
|
}
|
|
289
295
|
return Object.entries(storage);
|
|
290
296
|
});
|
|
297
|
+
exports.dryRunInherents = dryRunInherents;
|
package/lib/blockchain/block.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,15 +20,17 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
19
20
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
21
|
};
|
|
21
22
|
var _Block_chain, _Block_header, _Block_parentBlock, _Block_extrinsics, _Block_wasm, _Block_runtimeVersion, _Block_metadata, _Block_registry, _Block_meta, _Block_baseStorage, _Block_storages;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.Block = void 0;
|
|
25
|
+
const types_1 = require("@polkadot/types");
|
|
26
|
+
const metadata_1 = require("@polkadot/types/metadata");
|
|
27
|
+
const util_1 = require("@polkadot/types-known/util");
|
|
28
|
+
const util_2 = require("@polkadot/util");
|
|
29
|
+
const storage_layer_1 = require("./storage-layer");
|
|
30
|
+
const utils_1 = require("../utils");
|
|
31
|
+
const logger_1 = require("../logger");
|
|
32
|
+
const executor_1 = require("../executor");
|
|
33
|
+
class Block {
|
|
31
34
|
constructor(chain, number, hash, parentBlock, block) {
|
|
32
35
|
var _a;
|
|
33
36
|
this.number = number;
|
|
@@ -47,12 +50,12 @@ export class Block {
|
|
|
47
50
|
__classPrivateFieldSet(this, _Block_parentBlock, parentBlock, "f");
|
|
48
51
|
__classPrivateFieldSet(this, _Block_header, block === null || block === void 0 ? void 0 : block.header, "f");
|
|
49
52
|
__classPrivateFieldSet(this, _Block_extrinsics, block === null || block === void 0 ? void 0 : block.extrinsics, "f");
|
|
50
|
-
__classPrivateFieldSet(this, _Block_baseStorage, (_a = block === null || block === void 0 ? void 0 : block.storage) !== null && _a !== void 0 ? _a : new RemoteStorageLayer(chain.api, hash, chain.db), "f");
|
|
53
|
+
__classPrivateFieldSet(this, _Block_baseStorage, (_a = block === null || block === void 0 ? void 0 : block.storage) !== null && _a !== void 0 ? _a : new storage_layer_1.RemoteStorageLayer(chain.api, hash, chain.db), "f");
|
|
51
54
|
__classPrivateFieldSet(this, _Block_storages, [], "f");
|
|
52
55
|
const storageDiff = block === null || block === void 0 ? void 0 : block.storageDiff;
|
|
53
56
|
if (storageDiff) {
|
|
54
57
|
// if code doesn't change then reuse parent block's meta
|
|
55
|
-
if (!(storageDiff === null || storageDiff === void 0 ? void 0 : storageDiff[stringToHex(':code')])) {
|
|
58
|
+
if (!(storageDiff === null || storageDiff === void 0 ? void 0 : storageDiff[(0, util_2.stringToHex)(':code')])) {
|
|
56
59
|
__classPrivateFieldSet(this, _Block_runtimeVersion, parentBlock === null || parentBlock === void 0 ? void 0 : parentBlock.runtimeVersion, "f");
|
|
57
60
|
__classPrivateFieldSet(this, _Block_metadata, parentBlock === null || parentBlock === void 0 ? void 0 : parentBlock.metadata, "f");
|
|
58
61
|
__classPrivateFieldSet(this, _Block_registry, parentBlock === null || parentBlock === void 0 ? void 0 : parentBlock.registry, "f");
|
|
@@ -93,7 +96,7 @@ export class Block {
|
|
|
93
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
97
|
const val = yield this.storage.get(key, true);
|
|
95
98
|
switch (val) {
|
|
96
|
-
case StorageValueKind.Deleted:
|
|
99
|
+
case storage_layer_1.StorageValueKind.Deleted:
|
|
97
100
|
return undefined;
|
|
98
101
|
default:
|
|
99
102
|
return val;
|
|
@@ -103,7 +106,7 @@ export class Block {
|
|
|
103
106
|
getKeysPaged(options) {
|
|
104
107
|
var _a, _b;
|
|
105
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
const layer = new StorageLayer(this.storage);
|
|
109
|
+
const layer = new storage_layer_1.StorageLayer(this.storage);
|
|
107
110
|
yield layer.fold();
|
|
108
111
|
const prefix = (_a = options.prefix) !== null && _a !== void 0 ? _a : '0x';
|
|
109
112
|
const startKey = (_b = options.startKey) !== null && _b !== void 0 ? _b : prefix;
|
|
@@ -112,7 +115,7 @@ export class Block {
|
|
|
112
115
|
});
|
|
113
116
|
}
|
|
114
117
|
pushStorageLayer() {
|
|
115
|
-
const layer = new StorageLayer(this.storage);
|
|
118
|
+
const layer = new storage_layer_1.StorageLayer(this.storage);
|
|
116
119
|
__classPrivateFieldGet(this, _Block_storages, "f").push(layer);
|
|
117
120
|
return layer;
|
|
118
121
|
}
|
|
@@ -131,7 +134,7 @@ export class Block {
|
|
|
131
134
|
get wasm() {
|
|
132
135
|
if (!__classPrivateFieldGet(this, _Block_wasm, "f")) {
|
|
133
136
|
__classPrivateFieldSet(this, _Block_wasm, (() => __awaiter(this, void 0, void 0, function* () {
|
|
134
|
-
const wasmKey = stringToHex(':code');
|
|
137
|
+
const wasmKey = (0, util_2.stringToHex)(':code');
|
|
135
138
|
const wasm = yield this.get(wasmKey);
|
|
136
139
|
if (!wasm) {
|
|
137
140
|
throw new Error('No wasm found');
|
|
@@ -142,7 +145,7 @@ export class Block {
|
|
|
142
145
|
return __classPrivateFieldGet(this, _Block_wasm, "f");
|
|
143
146
|
}
|
|
144
147
|
setWasm(wasm) {
|
|
145
|
-
const wasmKey = stringToHex(':code');
|
|
148
|
+
const wasmKey = (0, util_2.stringToHex)(':code');
|
|
146
149
|
this.pushStorageLayer().set(wasmKey, wasm);
|
|
147
150
|
__classPrivateFieldSet(this, _Block_wasm, Promise.resolve(wasm), "f");
|
|
148
151
|
__classPrivateFieldSet(this, _Block_runtimeVersion, undefined, "f");
|
|
@@ -158,12 +161,12 @@ export class Block {
|
|
|
158
161
|
__classPrivateFieldGet(this, _Block_chain, "f").api.chain,
|
|
159
162
|
this.runtimeVersion,
|
|
160
163
|
]).then(([data, properties, chain, version]) => {
|
|
161
|
-
const registry = new TypeRegistry(this.hash);
|
|
164
|
+
const registry = new types_1.TypeRegistry(this.hash);
|
|
162
165
|
registry.setKnownTypes(this.chain.registeredTypes);
|
|
163
166
|
registry.setChainProperties(registry.createType('ChainProperties', properties));
|
|
164
|
-
registry.register(getSpecTypes(registry, chain, version.specName, version.specVersion));
|
|
165
|
-
registry.setHasher(getSpecHasher(registry, chain, version.specName));
|
|
166
|
-
registry.setMetadata(new Metadata(registry, data), undefined, objectSpread({}, getSpecExtensions(registry, chain, version.specName), __classPrivateFieldGet(this, _Block_chain, "f").api.signedExtensions));
|
|
167
|
+
registry.register((0, util_1.getSpecTypes)(registry, chain, version.specName, version.specVersion));
|
|
168
|
+
registry.setHasher((0, util_1.getSpecHasher)(registry, chain, version.specName));
|
|
169
|
+
registry.setMetadata(new types_1.Metadata(registry, data), undefined, (0, util_2.objectSpread)({}, (0, util_1.getSpecExtensions)(registry, chain, version.specName), __classPrivateFieldGet(this, _Block_chain, "f").api.signedExtensions));
|
|
167
170
|
return registry;
|
|
168
171
|
}), "f");
|
|
169
172
|
}
|
|
@@ -171,21 +174,21 @@ export class Block {
|
|
|
171
174
|
}
|
|
172
175
|
get runtimeVersion() {
|
|
173
176
|
if (!__classPrivateFieldGet(this, _Block_runtimeVersion, "f")) {
|
|
174
|
-
__classPrivateFieldSet(this, _Block_runtimeVersion, this.wasm.then(getRuntimeVersion), "f");
|
|
177
|
+
__classPrivateFieldSet(this, _Block_runtimeVersion, this.wasm.then(executor_1.getRuntimeVersion), "f");
|
|
175
178
|
}
|
|
176
179
|
return __classPrivateFieldGet(this, _Block_runtimeVersion, "f");
|
|
177
180
|
}
|
|
178
181
|
get metadata() {
|
|
179
182
|
if (!__classPrivateFieldGet(this, _Block_metadata, "f")) {
|
|
180
|
-
__classPrivateFieldSet(this, _Block_metadata, this.call('Metadata_metadata', []).then((resp) => compactHex(hexToU8a(resp.result))), "f");
|
|
183
|
+
__classPrivateFieldSet(this, _Block_metadata, this.call('Metadata_metadata', []).then((resp) => (0, utils_1.compactHex)((0, util_2.hexToU8a)(resp.result))), "f");
|
|
181
184
|
}
|
|
182
185
|
return __classPrivateFieldGet(this, _Block_metadata, "f");
|
|
183
186
|
}
|
|
184
187
|
get meta() {
|
|
185
188
|
if (!__classPrivateFieldGet(this, _Block_meta, "f")) {
|
|
186
189
|
__classPrivateFieldSet(this, _Block_meta, Promise.all([this.registry, this.metadata]).then(([registry, metadataStr]) => {
|
|
187
|
-
const metadata = new Metadata(registry, metadataStr);
|
|
188
|
-
return expandMetadata(registry, metadata);
|
|
190
|
+
const metadata = new types_1.Metadata(registry, metadataStr);
|
|
191
|
+
return (0, metadata_1.expandMetadata)(registry, metadata);
|
|
189
192
|
}), "f");
|
|
190
193
|
}
|
|
191
194
|
return __classPrivateFieldGet(this, _Block_meta, "f");
|
|
@@ -193,16 +196,16 @@ export class Block {
|
|
|
193
196
|
call(method, args) {
|
|
194
197
|
return __awaiter(this, void 0, void 0, function* () {
|
|
195
198
|
const wasm = yield this.wasm;
|
|
196
|
-
const response = yield runTask({
|
|
199
|
+
const response = yield (0, executor_1.runTask)({
|
|
197
200
|
wasm,
|
|
198
201
|
calls: [[method, args]],
|
|
199
202
|
mockSignatureHost: __classPrivateFieldGet(this, _Block_chain, "f").mockSignatureHost,
|
|
200
203
|
allowUnresolvedImports: __classPrivateFieldGet(this, _Block_chain, "f").allowUnresolvedImports,
|
|
201
204
|
runtimeLogLevel: __classPrivateFieldGet(this, _Block_chain, "f").runtimeLogLevel,
|
|
202
|
-
}, taskHandler(this));
|
|
205
|
+
}, (0, executor_1.taskHandler)(this));
|
|
203
206
|
if (response.Call) {
|
|
204
207
|
for (const log of response.Call.runtimeLogs) {
|
|
205
|
-
defaultLogger.info(`RuntimeLogs:\n${log}`);
|
|
208
|
+
logger_1.defaultLogger.info(`RuntimeLogs:\n${log}`);
|
|
206
209
|
}
|
|
207
210
|
if (this.chain.offchainWorker) {
|
|
208
211
|
// apply offchain storage
|
|
@@ -218,4 +221,5 @@ export class Block {
|
|
|
218
221
|
});
|
|
219
222
|
}
|
|
220
223
|
}
|
|
224
|
+
exports.Block = Block;
|
|
221
225
|
_Block_chain = new WeakMap(), _Block_header = new WeakMap(), _Block_parentBlock = new WeakMap(), _Block_extrinsics = new WeakMap(), _Block_wasm = new WeakMap(), _Block_runtimeVersion = new WeakMap(), _Block_metadata = new WeakMap(), _Block_registry = new WeakMap(), _Block_meta = new WeakMap(), _Block_baseStorage = new WeakMap(), _Block_storages = new WeakMap();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,11 +20,14 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
19
20
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
21
|
};
|
|
21
22
|
var _HeadState_headListeners, _HeadState_storageListeners, _HeadState_oldValues, _HeadState_head;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.HeadState = exports.randomId = void 0;
|
|
25
|
+
const util_1 = require("@polkadot/util");
|
|
26
|
+
const logger_1 = require("../logger");
|
|
27
|
+
const randomId = () => Math.random().toString(36).substring(2);
|
|
28
|
+
exports.randomId = randomId;
|
|
29
|
+
const logger = logger_1.defaultLogger.child({ name: 'head-state' });
|
|
30
|
+
class HeadState {
|
|
27
31
|
constructor(head) {
|
|
28
32
|
_HeadState_headListeners.set(this, {});
|
|
29
33
|
_HeadState_storageListeners.set(this, {});
|
|
@@ -32,7 +36,7 @@ export class HeadState {
|
|
|
32
36
|
__classPrivateFieldSet(this, _HeadState_head, head, "f");
|
|
33
37
|
}
|
|
34
38
|
subscribeHead(cb) {
|
|
35
|
-
const id = randomId();
|
|
39
|
+
const id = (0, exports.randomId)();
|
|
36
40
|
__classPrivateFieldGet(this, _HeadState_headListeners, "f")[id] = cb;
|
|
37
41
|
return id;
|
|
38
42
|
}
|
|
@@ -41,7 +45,7 @@ export class HeadState {
|
|
|
41
45
|
}
|
|
42
46
|
subscribeStorage(keys, cb) {
|
|
43
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
const id = randomId();
|
|
48
|
+
const id = (0, exports.randomId)();
|
|
45
49
|
__classPrivateFieldGet(this, _HeadState_storageListeners, "f")[id] = [keys, cb];
|
|
46
50
|
for (const key of keys) {
|
|
47
51
|
__classPrivateFieldGet(this, _HeadState_oldValues, "f")[key] = yield __classPrivateFieldGet(this, _HeadState_head, "f").get(key);
|
|
@@ -54,8 +58,8 @@ export class HeadState {
|
|
|
54
58
|
}
|
|
55
59
|
subscrubeRuntimeVersion(cb) {
|
|
56
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
const id = randomId();
|
|
58
|
-
const codeKey = stringToHex(':code');
|
|
61
|
+
const id = (0, exports.randomId)();
|
|
62
|
+
const codeKey = (0, util_1.stringToHex)(':code');
|
|
59
63
|
__classPrivateFieldGet(this, _HeadState_storageListeners, "f")[id] = [[codeKey], cb];
|
|
60
64
|
__classPrivateFieldGet(this, _HeadState_oldValues, "f")[codeKey] = yield __classPrivateFieldGet(this, _HeadState_head, "f").get(codeKey);
|
|
61
65
|
return id;
|
|
@@ -91,4 +95,5 @@ export class HeadState {
|
|
|
91
95
|
});
|
|
92
96
|
}
|
|
93
97
|
}
|
|
98
|
+
exports.HeadState = HeadState;
|
|
94
99
|
_HeadState_headListeners = new WeakMap(), _HeadState_storageListeners = new WeakMap(), _HeadState_oldValues = new WeakMap(), _HeadState_head = new WeakMap();
|