@acala-network/chopsticks 0.2.2 → 0.3.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/LICENSE +201 -0
- package/README.md +6 -0
- package/dist/api.d.ts +3 -2
- package/dist/api.js +15 -20
- package/dist/blockchain/block-builder.d.ts +4 -0
- package/dist/blockchain/block-builder.js +71 -0
- package/dist/blockchain/block.d.ts +12 -8
- package/dist/blockchain/block.js +34 -75
- package/dist/blockchain/head-state.d.ts +4 -2
- package/dist/blockchain/head-state.js +13 -7
- package/dist/blockchain/index.d.ts +14 -13
- package/dist/blockchain/index.js +31 -27
- package/dist/blockchain/inherent/index.d.ts +17 -0
- package/dist/blockchain/inherent/index.js +32 -0
- package/dist/blockchain/inherent/para-enter.d.ts +7 -0
- package/dist/blockchain/inherent/para-enter.js +33 -0
- package/dist/blockchain/inherent/parachain/validation-data.d.ts +25 -0
- package/dist/blockchain/{inherents.js → inherent/parachain/validation-data.js} +87 -55
- package/dist/blockchain/txpool.d.ts +19 -3
- package/dist/blockchain/txpool.js +46 -81
- package/dist/decode-key.d.ts +2 -0
- package/dist/decode-key.js +24 -0
- package/dist/executor.d.ts +23 -4
- package/dist/executor.js +60 -12
- package/dist/executor.test.js +16 -21
- package/dist/genesis-provider.d.ts +5 -0
- package/dist/genesis-provider.js +21 -2
- package/dist/index.d.ts +1 -21
- package/dist/index.js +43 -159
- package/dist/logger.d.ts +3 -1
- package/dist/logger.js +5 -1
- package/dist/rpc/dev.js +11 -1
- package/dist/rpc/index.js +0 -2
- package/dist/rpc/shared.d.ts +0 -6
- package/dist/rpc/substrate/author.d.ts +1 -1
- package/dist/rpc/substrate/author.js +7 -2
- package/dist/rpc/substrate/chain.js +2 -2
- package/dist/rpc/substrate/state.js +1 -1
- package/dist/rpc/substrate/system.js +3 -3
- package/dist/run-block.d.ts +2 -0
- package/dist/run-block.js +36 -0
- package/dist/schema/index.d.ts +2 -5
- package/dist/schema/index.js +1 -2
- package/dist/server.d.ts +3 -3
- package/dist/server.js +26 -11
- package/dist/setup-with-server.d.ts +8 -0
- package/dist/setup-with-server.js +23 -0
- package/dist/setup.d.ts +10 -0
- package/dist/setup.js +62 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +9 -1
- package/dist/utils/proof.d.ts +10 -2
- package/dist/utils/proof.js +12 -8
- package/dist/utils/set-storage.d.ts +2 -1
- package/dist/utils/set-storage.js +1 -1
- package/dist/utils/time-travel.d.ts +5 -0
- package/dist/utils/time-travel.js +64 -0
- package/dist/xcm/index.d.ts +3 -0
- package/dist/xcm/index.js +67 -0
- package/package.json +9 -10
- package/dist/blockchain/inherents.d.ts +0 -26
- package/dist/rpc/exec.d.ts +0 -3
- package/dist/rpc/exec.js +0 -44
- package/dist/task.d.ts +0 -38
- package/dist/task.js +0 -67
|
@@ -6,11 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.TxPool = exports.BuildBlockMode = void 0;
|
|
7
7
|
const util_1 = require("@polkadot/util");
|
|
8
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const utils_1 = require("../utils");
|
|
12
|
-
const logger_1 = require("../logger");
|
|
13
|
-
const logger = logger_1.defaultLogger.child({ name: 'txpool' });
|
|
9
|
+
const block_builder_1 = require("./block-builder");
|
|
10
|
+
const time_travel_1 = require("../utils/time-travel");
|
|
14
11
|
var BuildBlockMode;
|
|
15
12
|
(function (BuildBlockMode) {
|
|
16
13
|
BuildBlockMode[BuildBlockMode["Batch"] = 0] = "Batch";
|
|
@@ -21,8 +18,35 @@ const getConsensus = (header) => {
|
|
|
21
18
|
if (header.digest.logs.length === 0)
|
|
22
19
|
return;
|
|
23
20
|
const preRuntime = header.digest.logs[0].asPreRuntime;
|
|
24
|
-
const [consensusEngine] = preRuntime;
|
|
25
|
-
return { consensusEngine, rest: header.digest.logs.slice(1) };
|
|
21
|
+
const [consensusEngine, slot] = preRuntime;
|
|
22
|
+
return { consensusEngine, slot, rest: header.digest.logs.slice(1) };
|
|
23
|
+
};
|
|
24
|
+
const getNewSlot = (digest, slotNumber) => {
|
|
25
|
+
if (digest.isPrimary) {
|
|
26
|
+
return {
|
|
27
|
+
primary: {
|
|
28
|
+
...digest.asPrimary.toJSON(),
|
|
29
|
+
slotNumber,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (digest.isSecondaryPlain) {
|
|
34
|
+
return {
|
|
35
|
+
secondaryPlain: {
|
|
36
|
+
...digest.asSecondaryPlain.toJSON(),
|
|
37
|
+
slotNumber,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (digest.isSecondaryVRF) {
|
|
42
|
+
return {
|
|
43
|
+
secondaryVRF: {
|
|
44
|
+
...digest.asSecondaryVRF.toJSON(),
|
|
45
|
+
slotNumber,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return digest.toJSON();
|
|
26
50
|
};
|
|
27
51
|
class TxPool {
|
|
28
52
|
#chain;
|
|
@@ -35,6 +59,9 @@ class TxPool {
|
|
|
35
59
|
this.#mode = mode;
|
|
36
60
|
this.#inherentProvider = inherentProvider;
|
|
37
61
|
}
|
|
62
|
+
get pendingExtrinsics() {
|
|
63
|
+
return this.#pool;
|
|
64
|
+
}
|
|
38
65
|
submitExtrinsic(extrinsic) {
|
|
39
66
|
this.#pool.push(extrinsic);
|
|
40
67
|
switch (this.#mode) {
|
|
@@ -50,29 +77,29 @@ class TxPool {
|
|
|
50
77
|
}
|
|
51
78
|
}
|
|
52
79
|
#batchBuildBlock = lodash_1.default.debounce(this.buildBlock, 100, { maxWait: 1000 });
|
|
53
|
-
async buildBlock() {
|
|
80
|
+
async buildBlock(params) {
|
|
54
81
|
const last = this.#lastBuildBlockPromise;
|
|
55
|
-
this.#lastBuildBlockPromise = this.#buildBlock(last);
|
|
82
|
+
this.#lastBuildBlockPromise = this.#buildBlock(last, params);
|
|
56
83
|
await this.#lastBuildBlockPromise;
|
|
57
84
|
}
|
|
58
|
-
async #buildBlock(wait) {
|
|
85
|
+
async #buildBlock(wait, params) {
|
|
59
86
|
await this.#chain.api.isReady;
|
|
60
87
|
await wait.catch(() => { }); // ignore error
|
|
61
88
|
const head = this.#chain.head;
|
|
62
89
|
const extrinsics = this.#pool.splice(0);
|
|
63
90
|
const meta = await head.meta;
|
|
64
91
|
const parentHeader = await head.header;
|
|
65
|
-
const time = this.#inherentProvider.getTimestamp(head.number + 1);
|
|
66
92
|
let newLogs = parentHeader.digest.logs;
|
|
67
|
-
const expectedSlot = Math.floor(time / (meta.consts.timestamp.minimumPeriod.toNumber() * 2));
|
|
68
93
|
const consensus = getConsensus(parentHeader);
|
|
69
94
|
if (consensus?.consensusEngine.isAura) {
|
|
70
|
-
const
|
|
95
|
+
const slot = await (0, time_travel_1.getCurrentSlot)(this.#chain);
|
|
96
|
+
const newSlot = (0, util_1.compactAddLength)(meta.registry.createType('Slot', slot + 1).toU8a());
|
|
71
97
|
newLogs = [{ PreRuntime: [consensus.consensusEngine, newSlot] }, ...consensus.rest];
|
|
72
98
|
}
|
|
73
99
|
else if (consensus?.consensusEngine.isBabe) {
|
|
74
|
-
|
|
75
|
-
const
|
|
100
|
+
const slot = await (0, time_travel_1.getCurrentSlot)(this.#chain);
|
|
101
|
+
const digest = meta.registry.createType('RawBabePreDigest', consensus.slot);
|
|
102
|
+
const newSlot = (0, util_1.compactAddLength)(meta.registry.createType('RawBabePreDigest', getNewSlot(digest, slot + 1)).toU8a());
|
|
76
103
|
newLogs = [{ PreRuntime: [consensus.consensusEngine, newSlot] }, ...consensus.rest];
|
|
77
104
|
}
|
|
78
105
|
const registry = await head.registry;
|
|
@@ -85,72 +112,10 @@ class TxPool {
|
|
|
85
112
|
logs: newLogs,
|
|
86
113
|
},
|
|
87
114
|
});
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
extrinsicsCount: extrinsics.length,
|
|
93
|
-
tempHash: newBlock.hash,
|
|
94
|
-
timeValue: time,
|
|
95
|
-
expectedSlot,
|
|
96
|
-
}, 'Building block');
|
|
97
|
-
const resp = await newBlock.call('Core_initialize_block', header.toHex());
|
|
98
|
-
logger.trace(resp.storageDiff, 'Initialize block');
|
|
99
|
-
newBlock.pushStorageLayer().setAll(resp.storageDiff);
|
|
100
|
-
if (meta.query.babe?.currentSlot) {
|
|
101
|
-
// TODO: figure out how to generate a valid babe slot digest instead of just modify the data
|
|
102
|
-
// but hey, we can get it working without a valid digest
|
|
103
|
-
const key = (0, utils_1.compactHex)(meta.query.babe.currentSlot());
|
|
104
|
-
newBlock.pushStorageLayer().set(key, (0, util_1.bnToHex)(expectedSlot, { isLe: true, bitLength: 64 }));
|
|
105
|
-
}
|
|
106
|
-
const inherents = await this.#inherentProvider.createInherents(meta, time, newBlock);
|
|
107
|
-
for (const extrinsic of inherents) {
|
|
108
|
-
try {
|
|
109
|
-
const resp = await newBlock.call('BlockBuilder_apply_extrinsic', extrinsic);
|
|
110
|
-
newBlock.pushStorageLayer().setAll(resp.storageDiff);
|
|
111
|
-
logger.trace(resp.storageDiff, 'Applied inherent');
|
|
112
|
-
}
|
|
113
|
-
catch (e) {
|
|
114
|
-
logger.warn('Failed to apply inherents %o %s', e, e);
|
|
115
|
-
throw new shared_1.ResponseError(1, 'Failed to apply inherents');
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
for (const extrinsic of extrinsics) {
|
|
119
|
-
try {
|
|
120
|
-
const resp = await newBlock.call('BlockBuilder_apply_extrinsic', extrinsic);
|
|
121
|
-
newBlock.pushStorageLayer().setAll(resp.storageDiff);
|
|
122
|
-
logger.trace(resp.storageDiff, 'Applied extrinsic');
|
|
123
|
-
}
|
|
124
|
-
catch (e) {
|
|
125
|
-
logger.info('Failed to apply extrinsic %o %s', e, e);
|
|
126
|
-
this.#pool.push(extrinsic);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (meta.query.paraInherent?.included) {
|
|
130
|
-
// TODO: remvoe this once paraInherent.enter is implemented
|
|
131
|
-
// we are relaychain, however as we have not yet implemented the paraInherent.enter
|
|
132
|
-
// so need to do some trick to make the on_finalize check happy
|
|
133
|
-
const paraInherentIncludedKey = (0, utils_1.compactHex)(meta.query.paraInherent.included());
|
|
134
|
-
newBlock.pushStorageLayer().set(paraInherentIncludedKey, '0x01');
|
|
135
|
-
}
|
|
136
|
-
const resp2 = await newBlock.call('BlockBuilder_finalize_block', '0x');
|
|
137
|
-
newBlock.pushStorageLayer().setAll(resp2.storageDiff);
|
|
138
|
-
logger.trace(resp2.storageDiff, 'Finalize block');
|
|
139
|
-
const blockData = registry.createType('Block', {
|
|
140
|
-
header,
|
|
141
|
-
extrinsics,
|
|
142
|
-
});
|
|
143
|
-
const finalBlock = new block_1.Block(this.#chain, newBlock.number, blockData.hash.toHex(), head, {
|
|
144
|
-
header,
|
|
145
|
-
extrinsics: [...inherents, ...extrinsics],
|
|
146
|
-
storage: head.storage,
|
|
147
|
-
});
|
|
148
|
-
const diff = await newBlock.storageDiff();
|
|
149
|
-
logger.trace(diff, 'Final block');
|
|
150
|
-
finalBlock.pushStorageLayer().setAll(diff);
|
|
151
|
-
this.#chain.unregisterBlock(newBlock);
|
|
152
|
-
this.#chain.setHead(finalBlock);
|
|
153
|
-
logger.info({ hash: finalBlock.hash, number: finalBlock.number, prevHash: newBlock.hash }, 'Block built');
|
|
115
|
+
const inherents = await this.#inherentProvider.createInherents(head, params?.inherent);
|
|
116
|
+
const [newBlock, pendingExtrinsics] = await (0, block_builder_1.buildBlock)(head, header, inherents, extrinsics);
|
|
117
|
+
this.#pool.push(...pendingExtrinsics);
|
|
118
|
+
await this.#chain.setHead(newBlock);
|
|
154
119
|
}
|
|
155
120
|
}
|
|
156
121
|
exports.TxPool = TxPool;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeKey = void 0;
|
|
4
|
+
require("@polkadot/types-codec");
|
|
5
|
+
const util_1 = require("@polkadot/util");
|
|
6
|
+
const setup_1 = require("./setup");
|
|
7
|
+
const decodeKey = async (argv) => {
|
|
8
|
+
const context = await (0, setup_1.setup)(argv);
|
|
9
|
+
const key = argv.key;
|
|
10
|
+
const meta = await context.chain.head.meta;
|
|
11
|
+
outer: for (const module of Object.values(meta.query)) {
|
|
12
|
+
for (const storage of Object.values(module)) {
|
|
13
|
+
const keyPrefix = (0, util_1.u8aToHex)(storage.keyPrefix());
|
|
14
|
+
if (key.startsWith(keyPrefix)) {
|
|
15
|
+
const decodedKey = meta.registry.createType('StorageKey', key);
|
|
16
|
+
decodedKey.setMeta(storage.meta);
|
|
17
|
+
console.log(`${storage.section}.${storage.method}`, decodedKey.args.map((x) => JSON.stringify(x.toHuman())).join(', '));
|
|
18
|
+
break outer;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
setTimeout(() => process.exit(0), 50);
|
|
23
|
+
};
|
|
24
|
+
exports.decodeKey = decodeKey;
|
package/dist/executor.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { HexString } from '@polkadot/util/types';
|
|
2
|
-
import {
|
|
2
|
+
import { Block } from './blockchain/block';
|
|
3
|
+
import { Registry } from '@polkadot/types-codec/types';
|
|
4
|
+
interface JsCallback {
|
|
5
|
+
getStorage: (key: HexString) => Promise<string | undefined>;
|
|
6
|
+
getPrefixKeys: (key: HexString) => Promise<string[]>;
|
|
7
|
+
getNextKey: (key: HexString) => Promise<string | undefined>;
|
|
8
|
+
}
|
|
3
9
|
export type RuntimeVersion = {
|
|
4
10
|
specName: string;
|
|
5
11
|
implName: string;
|
|
@@ -11,11 +17,24 @@ export type RuntimeVersion = {
|
|
|
11
17
|
stateVersion: number;
|
|
12
18
|
};
|
|
13
19
|
export declare const getRuntimeVersion: (code: HexString) => Promise<RuntimeVersion>;
|
|
14
|
-
export declare const getMetadata: (code: HexString) => Promise<HexString>;
|
|
15
20
|
export declare const calculateStateRoot: (entries: [HexString, HexString][]) => Promise<HexString>;
|
|
16
21
|
export declare const decodeProof: (trieRootHash: HexString, keys: HexString[], nodes: HexString[]) => Promise<Record<`0x${string}`, `0x${string}` | null>>;
|
|
17
|
-
export declare const createProof: (trieRootHash: HexString, nodes: HexString[], entries: [HexString, HexString][]) => Promise<{
|
|
22
|
+
export declare const createProof: (trieRootHash: HexString, nodes: HexString[], entries: [HexString, HexString | null][]) => Promise<{
|
|
18
23
|
trieRootHash: `0x${string}`;
|
|
19
24
|
nodes: `0x${string}`[];
|
|
20
25
|
}>;
|
|
21
|
-
export
|
|
26
|
+
export declare const runTask: (task: {
|
|
27
|
+
wasm: HexString;
|
|
28
|
+
calls: [string, HexString][];
|
|
29
|
+
storage: [HexString, HexString | null][];
|
|
30
|
+
mockSignatureHost: boolean;
|
|
31
|
+
allowUnresolvedImports: boolean;
|
|
32
|
+
}, callback?: JsCallback) => Promise<any>;
|
|
33
|
+
export declare const taskHandler: (block: Block) => JsCallback;
|
|
34
|
+
export declare const emptyTaskHandler: {
|
|
35
|
+
getStorage: (_key: HexString) => Promise<never>;
|
|
36
|
+
getPrefixKeys: (_key: HexString) => Promise<never>;
|
|
37
|
+
getNextKey: (_key: HexString) => Promise<never>;
|
|
38
|
+
};
|
|
39
|
+
export declare const getAuraSlotDuration: ((wasm: HexString, registry: Registry) => Promise<number>) & import("lodash").MemoizedFunction;
|
|
40
|
+
export {};
|
package/dist/executor.js
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getAuraSlotDuration = exports.emptyTaskHandler = exports.taskHandler = exports.runTask = exports.createProof = exports.decodeProof = exports.calculateStateRoot = exports.getRuntimeVersion = void 0;
|
|
4
4
|
const ws_1 = require("ws");
|
|
5
5
|
const util_1 = require("@polkadot/util");
|
|
6
6
|
global.WebSocket = ws_1.WebSocket;
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
7
|
+
const chopsticks_executor_1 = require("@acala-network/chopsticks-executor");
|
|
8
|
+
const logger_1 = require("./logger");
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
const logger = logger_1.defaultLogger.child({ name: 'executor' });
|
|
10
11
|
const getRuntimeVersion = async (code) => {
|
|
11
|
-
return (0,
|
|
12
|
+
return (0, chopsticks_executor_1.get_runtime_version)(code).then((version) => {
|
|
12
13
|
version.specName = (0, util_1.hexToString)(version.specName);
|
|
13
14
|
version.implName = (0, util_1.hexToString)(version.implName);
|
|
14
15
|
return version;
|
|
15
16
|
});
|
|
16
17
|
};
|
|
17
18
|
exports.getRuntimeVersion = getRuntimeVersion;
|
|
18
|
-
const getMetadata = async (code) => {
|
|
19
|
-
return (0, utils_1.compactHex)((0, util_1.hexToU8a)(await (0, pkg_1.get_metadata)(code)));
|
|
20
|
-
};
|
|
21
|
-
exports.getMetadata = getMetadata;
|
|
22
19
|
const calculateStateRoot = async (entries) => {
|
|
23
|
-
return (0,
|
|
20
|
+
return (0, chopsticks_executor_1.calculate_state_root)(entries);
|
|
24
21
|
};
|
|
25
22
|
exports.calculateStateRoot = calculateStateRoot;
|
|
26
23
|
const nodesAddLength = (nodes) => {
|
|
@@ -28,7 +25,7 @@ const nodesAddLength = (nodes) => {
|
|
|
28
25
|
return (0, util_1.u8aToHex)((0, util_1.u8aConcatStrict)([(0, util_1.compactToU8a)(nodesWithLength.length), (0, util_1.u8aConcat)(...nodesWithLength)]));
|
|
29
26
|
};
|
|
30
27
|
const decodeProof = async (trieRootHash, keys, nodes) => {
|
|
31
|
-
const decoded = await (0,
|
|
28
|
+
const decoded = await (0, chopsticks_executor_1.decode_proof)(trieRootHash, keys, nodesAddLength(nodes));
|
|
32
29
|
return decoded.reduce((accum, [key, value]) => {
|
|
33
30
|
accum[key] = value;
|
|
34
31
|
return accum;
|
|
@@ -36,7 +33,58 @@ const decodeProof = async (trieRootHash, keys, nodes) => {
|
|
|
36
33
|
};
|
|
37
34
|
exports.decodeProof = decodeProof;
|
|
38
35
|
const createProof = async (trieRootHash, nodes, entries) => {
|
|
39
|
-
const result = await (0,
|
|
36
|
+
const result = await (0, chopsticks_executor_1.create_proof)(trieRootHash, nodesAddLength(nodes), entries);
|
|
40
37
|
return { trieRootHash: result[0], nodes: result[1] };
|
|
41
38
|
};
|
|
42
39
|
exports.createProof = createProof;
|
|
40
|
+
const runTask = async (task, callback = exports.emptyTaskHandler) => {
|
|
41
|
+
logger.trace({ task: { ...task, wasm: (0, logger_1.truncate)(task.wasm) } }, 'taskRun');
|
|
42
|
+
const response = await (0, chopsticks_executor_1.run_task)(task, callback);
|
|
43
|
+
if (response.Call) {
|
|
44
|
+
logger.trace({ result: (0, logger_1.truncate)(response.Call.result), storageDiff: (0, logger_1.truncateStorageDiff)(response.Call.storageDiff) }, 'taskResponse');
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
logger.trace({ response }, 'taskResponse');
|
|
48
|
+
}
|
|
49
|
+
return response;
|
|
50
|
+
};
|
|
51
|
+
exports.runTask = runTask;
|
|
52
|
+
const taskHandler = (block) => {
|
|
53
|
+
return {
|
|
54
|
+
getStorage: async function (key) {
|
|
55
|
+
return block.get(key);
|
|
56
|
+
},
|
|
57
|
+
getPrefixKeys: async function (key) {
|
|
58
|
+
return block.getKeysPaged({ prefix: key, pageSize: 1000, startKey: key });
|
|
59
|
+
},
|
|
60
|
+
getNextKey: async function (key) {
|
|
61
|
+
const keys = await block.getKeysPaged({ prefix: key, pageSize: 1, startKey: key });
|
|
62
|
+
return keys[0];
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
exports.taskHandler = taskHandler;
|
|
67
|
+
exports.emptyTaskHandler = {
|
|
68
|
+
getStorage: async function (_key) {
|
|
69
|
+
throw new Error('Method not implemented');
|
|
70
|
+
},
|
|
71
|
+
getPrefixKeys: async function (_key) {
|
|
72
|
+
throw new Error('Method not implemented');
|
|
73
|
+
},
|
|
74
|
+
getNextKey: async function (_key) {
|
|
75
|
+
throw new Error('Method not implemented');
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
exports.getAuraSlotDuration = (0, lodash_1.memoize)(async (wasm, registry) => {
|
|
79
|
+
const result = await (0, exports.runTask)({
|
|
80
|
+
wasm,
|
|
81
|
+
calls: [['AuraApi_slot_duration', '0x']],
|
|
82
|
+
storage: [],
|
|
83
|
+
mockSignatureHost: false,
|
|
84
|
+
allowUnresolvedImports: false,
|
|
85
|
+
});
|
|
86
|
+
if (!result.Call)
|
|
87
|
+
throw new Error(result.Error);
|
|
88
|
+
const slotDuration = registry.createType('u64', (0, util_1.hexToU8a)(result.Call.result)).toNumber();
|
|
89
|
+
return slotDuration;
|
|
90
|
+
});
|
package/dist/executor.test.js
CHANGED
|
@@ -3,38 +3,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const metadata_1 = require("@polkadot/types/metadata");
|
|
7
6
|
const types_1 = require("@polkadot/types");
|
|
8
|
-
const decorate_1 = require("@polkadot/types/metadata/decorate");
|
|
9
7
|
const vitest_1 = require("vitest");
|
|
10
8
|
const node_fs_1 = require("node:fs");
|
|
11
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
12
10
|
const proof_1 = require("./utils/proof");
|
|
13
11
|
const executor_1 = require("./executor");
|
|
12
|
+
const getCode = () => {
|
|
13
|
+
const code = String((0, node_fs_1.readFileSync)(node_path_1.default.join(__dirname, '../e2e/blobs/acala-runtime-2101.txt'))).trim();
|
|
14
|
+
(0, vitest_1.expect)(code.length).toBeGreaterThan(2);
|
|
15
|
+
return code;
|
|
16
|
+
};
|
|
14
17
|
(0, vitest_1.describe)('wasm', () => {
|
|
15
|
-
(0, vitest_1.it)('get metadata from wasm runtime', async () => {
|
|
16
|
-
const code = String((0, node_fs_1.readFileSync)(node_path_1.default.join(__dirname, 'runtime.example'))).trim();
|
|
17
|
-
(0, vitest_1.expect)(code.length).toBeGreaterThan(2);
|
|
18
|
-
const registry = new types_1.TypeRegistry();
|
|
19
|
-
const metadata = new metadata_1.Metadata(registry, await (0, executor_1.getMetadata)(code));
|
|
20
|
-
registry.setMetadata(metadata);
|
|
21
|
-
(0, vitest_1.expect)(registry.metadata.pallets.length).toBeGreaterThan(0);
|
|
22
|
-
const storage = (0, decorate_1.decorateStorage)(registry, metadata.asLatest, metadata.version);
|
|
23
|
-
(0, vitest_1.expect)(storage.system).toBeTruthy;
|
|
24
|
-
});
|
|
25
18
|
(0, vitest_1.it)('get runtime version from wasm runtime', async () => {
|
|
26
|
-
const code = String((0, node_fs_1.readFileSync)(node_path_1.default.join(__dirname, 'runtime.example'))).trim();
|
|
27
|
-
(0, vitest_1.expect)(code.length).toBeGreaterThan(2);
|
|
28
19
|
const expectedRuntimeVersion = {
|
|
29
20
|
specName: 'acala',
|
|
30
21
|
implName: 'acala',
|
|
31
22
|
authoringVersion: 1,
|
|
32
|
-
specVersion:
|
|
23
|
+
specVersion: 2101,
|
|
33
24
|
implVersion: 0,
|
|
34
25
|
apis: [
|
|
35
|
-
['0xdf6acb689907609b',
|
|
26
|
+
['0xdf6acb689907609b', 4],
|
|
36
27
|
['0x37e397fc7c91f5e4', 1],
|
|
37
|
-
['0x40fe3ad401f8959a',
|
|
28
|
+
['0x40fe3ad401f8959a', 6],
|
|
38
29
|
['0xd2bc9897eed08f15', 3],
|
|
39
30
|
['0xf78b278be53f454c', 2],
|
|
40
31
|
['0xdd718d5cc53262d4', 1],
|
|
@@ -42,14 +33,14 @@ const executor_1 = require("./executor");
|
|
|
42
33
|
['0xbc9d89904f5b923f', 1],
|
|
43
34
|
['0x37c8bb1350a9a2a8', 1],
|
|
44
35
|
['0x6ef953004ba30e59', 1],
|
|
45
|
-
['
|
|
46
|
-
['0xe3df3f2aa8a5cc57',
|
|
47
|
-
['0xea93e3f16f3d6962',
|
|
36
|
+
['0x955e168e0cfb3409', 1],
|
|
37
|
+
['0xe3df3f2aa8a5cc57', 2],
|
|
38
|
+
['0xea93e3f16f3d6962', 2],
|
|
48
39
|
],
|
|
49
40
|
transactionVersion: 1,
|
|
50
41
|
stateVersion: 0,
|
|
51
42
|
};
|
|
52
|
-
(0, vitest_1.expect)(await (0, executor_1.getRuntimeVersion)(
|
|
43
|
+
(0, vitest_1.expect)(await (0, executor_1.getRuntimeVersion)(getCode())).toMatchObject(expectedRuntimeVersion);
|
|
53
44
|
});
|
|
54
45
|
(0, vitest_1.it)('calculate state root', async () => {
|
|
55
46
|
const a = await (0, executor_1.calculateStateRoot)([['0x5301bf5ff0298f5c7b93a446709f8e885f772afdd0d8ba3d4d559a06f0742f12', '0x01']]);
|
|
@@ -140,4 +131,8 @@ const executor_1 = require("./executor");
|
|
|
140
131
|
(0, vitest_1.expect)(decoded).toMatchSnapshot();
|
|
141
132
|
(0, vitest_1.expect)(decoded[upgradeKey]).toBe('0x01');
|
|
142
133
|
});
|
|
134
|
+
(0, vitest_1.it)('get aura slot duration', async () => {
|
|
135
|
+
const slotDuration = await (0, executor_1.getAuraSlotDuration)(getCode(), new types_1.TypeRegistry());
|
|
136
|
+
(0, vitest_1.expect)(slotDuration).eq(12000);
|
|
137
|
+
});
|
|
143
138
|
});
|
|
@@ -36,6 +36,11 @@ export declare class GenesisProvider implements ProviderInterface {
|
|
|
36
36
|
extrinsics: never[];
|
|
37
37
|
};
|
|
38
38
|
}>;
|
|
39
|
+
get _jsCallback(): {
|
|
40
|
+
getStorage: (key: HexString) => Promise<string>;
|
|
41
|
+
getNextKey: (_key: HexString) => Promise<string>;
|
|
42
|
+
getPrefixKeys: (_key: HexString) => Promise<never[]>;
|
|
43
|
+
};
|
|
39
44
|
send: (method: string, params: unknown[], _isCacheable?: boolean) => Promise<any>;
|
|
40
45
|
subscribe: (_type: string, _method: string, _params: unknown[], _cb: ProviderInterfaceCallback) => Promise<number | string>;
|
|
41
46
|
unsubscribe: (_type: string, _method: string, _id: number | string) => Promise<boolean>;
|
package/dist/genesis-provider.js
CHANGED
|
@@ -30,7 +30,6 @@ class GenesisProvider {
|
|
|
30
30
|
});
|
|
31
31
|
this.#eventemitter.once('error', reject);
|
|
32
32
|
});
|
|
33
|
-
this.connect();
|
|
34
33
|
}
|
|
35
34
|
static fromUrl = async (url) => {
|
|
36
35
|
let isUrl = false;
|
|
@@ -103,6 +102,20 @@ class GenesisProvider {
|
|
|
103
102
|
},
|
|
104
103
|
};
|
|
105
104
|
};
|
|
105
|
+
get _jsCallback() {
|
|
106
|
+
const storage = this.#genesis.genesis.raw.top;
|
|
107
|
+
return {
|
|
108
|
+
getStorage: async function (key) {
|
|
109
|
+
return storage[key];
|
|
110
|
+
},
|
|
111
|
+
getNextKey: async function (_key) {
|
|
112
|
+
return '0x';
|
|
113
|
+
},
|
|
114
|
+
getPrefixKeys: async function (_key) {
|
|
115
|
+
return [];
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
106
119
|
send = async (method, params, _isCacheable) => {
|
|
107
120
|
await this.isReady;
|
|
108
121
|
switch (method) {
|
|
@@ -114,7 +127,13 @@ class GenesisProvider {
|
|
|
114
127
|
return this.#genesis.name;
|
|
115
128
|
case 'state_getMetadata': {
|
|
116
129
|
const code = this.#genesis.genesis.raw.top[(0, util_1.stringToHex)(':code')];
|
|
117
|
-
return (0, executor_1.
|
|
130
|
+
return (0, executor_1.runTask)({
|
|
131
|
+
wasm: code,
|
|
132
|
+
calls: [['Metadata_metadata', '0x']],
|
|
133
|
+
storage: [],
|
|
134
|
+
mockSignatureHost: false,
|
|
135
|
+
allowUnresolvedImports: true,
|
|
136
|
+
}, this._jsCallback);
|
|
118
137
|
}
|
|
119
138
|
case 'chain_getHeader':
|
|
120
139
|
return this.getHeader();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { ProviderInterface } from '@polkadot/rpc-provider/types';
|
|
3
|
-
import { Api } from './api';
|
|
4
|
-
import { Blockchain } from './blockchain';
|
|
5
|
-
import { Config } from './schema';
|
|
6
|
-
import { TaskManager } from './task';
|
|
7
|
-
export declare const setup: (argv: Config) => Promise<{
|
|
8
|
-
chain: Blockchain;
|
|
9
|
-
api: Api;
|
|
10
|
-
ws: ProviderInterface;
|
|
11
|
-
tasks: TaskManager;
|
|
12
|
-
}>;
|
|
13
|
-
export declare const setupWithServer: (argv: Config) => Promise<{
|
|
14
|
-
close: () => Promise<void>;
|
|
15
|
-
chain: Blockchain;
|
|
16
|
-
api: Api;
|
|
17
|
-
ws: ProviderInterface;
|
|
18
|
-
tasks: TaskManager;
|
|
19
|
-
}>;
|
|
20
|
-
export declare const runBlock: (argv: Config) => Promise<void>;
|
|
21
|
-
export declare const decodeKey: (argv: any) => Promise<void>;
|
|
1
|
+
export {};
|