@acala-network/chopsticks 0.9.1-1 → 0.9.1-3
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/dist/cjs/cli-options.js +30 -15
- package/dist/cjs/cli.js +69 -80
- package/dist/cjs/context.js +93 -64
- package/dist/cjs/index.js +32 -20
- package/dist/cjs/logger.js +18 -5
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/plugins/decode-key/index.js +23 -20
- package/dist/cjs/plugins/dry-run/cli.js +46 -41
- package/dist/cjs/plugins/dry-run/dry-run-extrinsic.js +37 -21
- package/dist/cjs/plugins/dry-run/dry-run-preimage.js +101 -47
- package/dist/cjs/plugins/dry-run/index.js +18 -17
- package/dist/cjs/plugins/dry-run/rpc.js +48 -74
- package/dist/cjs/plugins/follow-chain/index.js +107 -0
- package/dist/cjs/plugins/index.js +89 -39
- package/dist/cjs/plugins/new-block/index.js +21 -53
- package/dist/cjs/plugins/run-block/index.js +145 -104
- package/dist/cjs/plugins/set-block-build-mode/index.js +17 -25
- package/dist/cjs/plugins/set-head/index.js +13 -23
- package/dist/cjs/plugins/set-runtime-log-level/index.js +16 -23
- package/dist/cjs/plugins/set-storage/index.js +16 -35
- package/dist/cjs/plugins/time-travel/index.js +13 -23
- package/dist/cjs/plugins/try-runtime/index.js +51 -42
- package/dist/cjs/plugins/types.js +43 -18
- package/dist/cjs/rpc/index.js +30 -21
- package/dist/cjs/schema/index.js +77 -48
- package/dist/cjs/server.js +89 -65
- package/dist/cjs/setup-with-server.js +19 -13
- package/dist/cjs/types.js +30 -18
- package/dist/cjs/utils/decoder.js +32 -16
- package/dist/cjs/utils/generate-html-diff.js +38 -19
- package/dist/cjs/utils/index.js +20 -19
- package/dist/cjs/utils/open-html.js +12 -6
- package/dist/cjs/utils/override.js +40 -27
- package/dist/cjs/utils/tunnel.js +11 -14
- package/dist/esm/cli-options.js +11 -11
- package/dist/esm/cli.js +45 -60
- package/dist/esm/context.js +20 -24
- package/dist/esm/plugins/decode-key/index.js +9 -12
- package/dist/esm/plugins/dry-run/cli.js +32 -33
- package/dist/esm/plugins/dry-run/dry-run-extrinsic.js +18 -8
- package/dist/esm/plugins/dry-run/dry-run-preimage.js +72 -24
- package/dist/esm/plugins/dry-run/rpc.js +14 -24
- package/dist/esm/plugins/follow-chain/index.js +92 -0
- package/dist/esm/plugins/index.js +22 -9
- package/dist/esm/plugins/new-block/index.js +8 -9
- package/dist/esm/plugins/run-block/index.js +97 -65
- package/dist/esm/plugins/set-block-build-mode/index.js +4 -3
- package/dist/esm/plugins/set-head/index.js +2 -4
- package/dist/esm/plugins/set-runtime-log-level/index.js +4 -3
- package/dist/esm/plugins/set-storage/index.js +3 -4
- package/dist/esm/plugins/time-travel/index.js +2 -4
- package/dist/esm/plugins/try-runtime/index.js +33 -30
- package/dist/esm/rpc/index.js +18 -15
- package/dist/esm/schema/index.js +31 -18
- package/dist/esm/server.js +70 -52
- package/dist/esm/setup-with-server.js +3 -3
- package/dist/esm/types.js +12 -1
- package/dist/esm/utils/decoder.js +12 -4
- package/dist/esm/utils/generate-html-diff.js +11 -7
- package/dist/esm/utils/open-html.js +1 -1
- package/dist/esm/utils/override.js +11 -13
- package/dist/esm/utils/template/diff.html +304 -0
- package/dist/esm/utils/tunnel.js +1 -8
- package/dist/types/plugins/decode-key/index.d.ts +2 -2
- package/dist/types/plugins/dry-run/cli.d.ts +2 -2
- package/dist/types/plugins/follow-chain/index.d.ts +2 -0
- package/dist/types/plugins/index.d.ts +2 -2
- package/dist/types/plugins/run-block/index.d.ts +2 -2
- package/dist/types/plugins/try-runtime/index.d.ts +2 -2
- package/package.json +14 -17
- /package/{chopsticks.js → chopsticks.cjs} +0 -0
- /package/{template → dist/cjs/utils/template}/diff.html +0 -0
|
@@ -1,52 +1,102 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
17
4
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
pluginExtendCli: function() {
|
|
13
|
+
return pluginExtendCli;
|
|
14
|
+
},
|
|
15
|
+
pluginHandlers: function() {
|
|
16
|
+
return pluginHandlers;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
|
|
20
|
+
const _logger = require("../logger");
|
|
21
|
+
function _interop_require_default(obj) {
|
|
22
|
+
return obj && obj.__esModule ? obj : {
|
|
23
|
+
default: obj
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
27
|
+
if (typeof WeakMap !== "function") return null;
|
|
28
|
+
var cacheBabelInterop = new WeakMap();
|
|
29
|
+
var cacheNodeInterop = new WeakMap();
|
|
30
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
31
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
32
|
+
})(nodeInterop);
|
|
33
|
+
}
|
|
34
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
35
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
36
|
+
return obj;
|
|
37
|
+
}
|
|
38
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
39
|
+
return {
|
|
40
|
+
default: obj
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
44
|
+
if (cache && cache.has(obj)) {
|
|
45
|
+
return cache.get(obj);
|
|
46
|
+
}
|
|
47
|
+
var newObj = {
|
|
48
|
+
__proto__: null
|
|
49
|
+
};
|
|
50
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
51
|
+
for(var key in obj){
|
|
52
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
53
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
54
|
+
if (desc && (desc.get || desc.set)) {
|
|
55
|
+
Object.defineProperty(newObj, key, desc);
|
|
56
|
+
} else {
|
|
57
|
+
newObj[key] = obj[key];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
newObj.default = obj;
|
|
62
|
+
if (cache) {
|
|
63
|
+
cache.set(obj, newObj);
|
|
64
|
+
}
|
|
65
|
+
return newObj;
|
|
66
|
+
}
|
|
67
|
+
const logger = _logger.defaultLogger.child({
|
|
68
|
+
name: 'plugin'
|
|
69
|
+
});
|
|
70
|
+
const pluginHandlers = {};
|
|
71
|
+
const plugins = [
|
|
72
|
+
'decode-key',
|
|
73
|
+
'dry-run',
|
|
74
|
+
'follow-chain',
|
|
75
|
+
'new-block',
|
|
76
|
+
'run-block',
|
|
77
|
+
'set-block-build-mode',
|
|
78
|
+
'set-head',
|
|
79
|
+
'set-runtime-log-level',
|
|
80
|
+
'set-storage',
|
|
81
|
+
'time-travel',
|
|
82
|
+
'try-runtime'
|
|
83
|
+
];
|
|
84
|
+
(async ()=>{
|
|
85
|
+
for (const plugin of plugins){
|
|
86
|
+
const { rpc, name } = await Promise.resolve(`./${plugin}`).then((p)=>/*#__PURE__*/ _interop_require_wildcard(require(p)));
|
|
36
87
|
if (rpc) {
|
|
37
|
-
const methodName = name ||
|
|
38
|
-
|
|
88
|
+
const methodName = name || _lodash.default.camelCase(plugin);
|
|
89
|
+
pluginHandlers[`dev_${methodName}`] = rpc;
|
|
39
90
|
logger.debug(`Registered plugin ${plugin} RPC`);
|
|
40
91
|
}
|
|
41
92
|
}
|
|
42
93
|
})();
|
|
43
|
-
const pluginExtendCli = async (y)
|
|
44
|
-
for (const plugin of plugins)
|
|
45
|
-
const { cli } = await Promise.resolve(
|
|
94
|
+
const pluginExtendCli = async (y)=>{
|
|
95
|
+
for (const plugin of plugins){
|
|
96
|
+
const { cli } = await Promise.resolve(`./${plugin}`).then((p)=>/*#__PURE__*/ _interop_require_wildcard(require(p)));
|
|
46
97
|
if (cli) {
|
|
47
98
|
cli(y);
|
|
48
99
|
logger.debug(`Registered plugin ${plugin} CLI`);
|
|
49
100
|
}
|
|
50
101
|
}
|
|
51
102
|
};
|
|
52
|
-
exports.pluginExtendCli = pluginExtendCli;
|
|
@@ -1,47 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @example Build 2 blocks
|
|
15
|
-
* ```ts
|
|
16
|
-
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
17
|
-
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
18
|
-
* await ws.send('dev_newBlock', [{ count: 2 }])
|
|
19
|
-
* ```
|
|
20
|
-
* @example Build a block with upward messages
|
|
21
|
-
* ```ts
|
|
22
|
-
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
23
|
-
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
24
|
-
* await ws.send('dev_newBlock', [
|
|
25
|
-
* {
|
|
26
|
-
* ump: {
|
|
27
|
-
* // https://acala.subscan.io/xcm_message/polkadot-ff66f28818d0b74573e62db8317e354b253fbc80
|
|
28
|
-
* 2000: [
|
|
29
|
-
* '0x021000040000000007903fc4db080a130000000007903fc4db08000d010004000101009c4b11a0974cba4a395c94832fba812868a6cb0ba09e8519b3521093ea359905',
|
|
30
|
-
* ],
|
|
31
|
-
* }
|
|
32
|
-
* }
|
|
33
|
-
* ])
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @example Build two blocks with unsafeBlockHeight
|
|
37
|
-
* ```ts
|
|
38
|
-
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
39
|
-
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
40
|
-
* // this will create two blocks with block height 100000001 and 100000002
|
|
41
|
-
* await ws.send('dev_newBlock', [{ count: 2, unsafeBlockHeight: 100000001 }])
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
const rpc = async (context, params) => {
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "rpc", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return rpc;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
12
|
+
const _logger = require("../../logger");
|
|
13
|
+
const rpc = async (context, params)=>{
|
|
45
14
|
const [param] = params;
|
|
46
15
|
const { count, to, hrmp, ump, dmp, transactions, unsafeBlockHeight } = param || {};
|
|
47
16
|
const now = context.chain.head.number;
|
|
@@ -49,23 +18,22 @@ const rpc = async (context, params) => {
|
|
|
49
18
|
const finalCount = diff > 0 ? diff : 1;
|
|
50
19
|
let finalHash;
|
|
51
20
|
if (unsafeBlockHeight < now) {
|
|
52
|
-
throw new
|
|
21
|
+
throw new _chopstickscore.ResponseError(1, 'unsafeBlockHeight must be greater than current block height');
|
|
53
22
|
}
|
|
54
|
-
for
|
|
55
|
-
const block = await context.chain
|
|
56
|
-
.newBlock({
|
|
23
|
+
for(let i = 0; i < finalCount; i++){
|
|
24
|
+
const block = await context.chain.newBlock({
|
|
57
25
|
transactions,
|
|
58
26
|
horizontalMessages: hrmp,
|
|
59
27
|
upwardMessages: ump,
|
|
60
28
|
downwardMessages: dmp,
|
|
61
|
-
unsafeBlockHeight: i === 0 ? unsafeBlockHeight : undefined
|
|
62
|
-
})
|
|
63
|
-
.
|
|
64
|
-
throw new chopsticks_core_1.ResponseError(1, error.toString());
|
|
29
|
+
unsafeBlockHeight: i === 0 ? unsafeBlockHeight : undefined
|
|
30
|
+
}).catch((error)=>{
|
|
31
|
+
throw new _chopstickscore.ResponseError(1, error.toString());
|
|
65
32
|
});
|
|
66
|
-
|
|
33
|
+
_logger.defaultLogger.debug({
|
|
34
|
+
hash: block.hash
|
|
35
|
+
}, 'dev_newBlock');
|
|
67
36
|
finalHash = block.hash;
|
|
68
37
|
}
|
|
69
38
|
return finalHash;
|
|
70
39
|
};
|
|
71
|
-
exports.rpc = rpc;
|
|
@@ -1,91 +1,115 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
cli: function() {
|
|
13
|
+
return cli;
|
|
14
|
+
},
|
|
15
|
+
name: function() {
|
|
16
|
+
return name;
|
|
17
|
+
},
|
|
18
|
+
rpc: function() {
|
|
19
|
+
return rpc;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _util = require("@polkadot/util");
|
|
23
|
+
const _nodefs = require("node:fs");
|
|
24
|
+
const _zod = require("zod");
|
|
25
|
+
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
26
|
+
const _clioptions = require("../../cli-options");
|
|
27
|
+
const _generatehtmldiff = require("../../utils/generate-html-diff");
|
|
28
|
+
const _openhtml = require("../../utils/open-html");
|
|
29
|
+
const _context = require("../../context");
|
|
30
|
+
const cli = (y)=>{
|
|
31
|
+
y.command('run-block', 'Replay a block', (yargs)=>yargs.options({
|
|
32
|
+
..._clioptions.defaultOptions,
|
|
33
|
+
..._clioptions.mockOptions,
|
|
34
|
+
'output-path': {
|
|
35
|
+
desc: 'File path to print output',
|
|
36
|
+
string: true
|
|
37
|
+
},
|
|
38
|
+
html: {
|
|
39
|
+
desc: 'Generate html with storage diff'
|
|
40
|
+
},
|
|
41
|
+
open: {
|
|
42
|
+
desc: 'Open generated html'
|
|
43
|
+
}
|
|
44
|
+
}), async (argv)=>{
|
|
45
|
+
const context = await (0, _context.setupContext)(argv, true);
|
|
28
46
|
const header = await context.chain.head.header;
|
|
29
47
|
const block = context.chain.head;
|
|
30
48
|
const parent = await block.parentBlock;
|
|
31
|
-
if (!parent)
|
|
32
|
-
throw Error('cant find parent block');
|
|
49
|
+
if (!parent) throw Error('cant find parent block');
|
|
33
50
|
const wasm = await parent.wasm;
|
|
34
|
-
const calls = [
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
const calls = [
|
|
52
|
+
[
|
|
53
|
+
'Core_initialize_block',
|
|
54
|
+
[
|
|
55
|
+
header.toHex()
|
|
56
|
+
]
|
|
57
|
+
]
|
|
58
|
+
];
|
|
59
|
+
for (const extrinsic of (await block.extrinsics)){
|
|
60
|
+
calls.push([
|
|
61
|
+
'BlockBuilder_apply_extrinsic',
|
|
62
|
+
[
|
|
63
|
+
extrinsic
|
|
64
|
+
]
|
|
65
|
+
]);
|
|
37
66
|
}
|
|
38
|
-
calls.push([
|
|
39
|
-
|
|
67
|
+
calls.push([
|
|
68
|
+
'BlockBuilder_finalize_block',
|
|
69
|
+
[]
|
|
70
|
+
]);
|
|
71
|
+
const result = await (0, _chopstickscore.runTask)({
|
|
40
72
|
wasm,
|
|
41
73
|
calls,
|
|
42
74
|
mockSignatureHost: false,
|
|
43
75
|
allowUnresolvedImports: false,
|
|
44
|
-
runtimeLogLevel: argv.runtimeLogLevel || 0
|
|
45
|
-
}, (0,
|
|
76
|
+
runtimeLogLevel: argv.runtimeLogLevel || 0
|
|
77
|
+
}, (0, _chopstickscore.taskHandler)(parent));
|
|
46
78
|
if ('Error' in result) {
|
|
47
79
|
throw new Error(result.Error);
|
|
48
80
|
}
|
|
49
|
-
(0,
|
|
81
|
+
(0, _chopstickscore.printRuntimeLogs)(result.Call.runtimeLogs);
|
|
50
82
|
if (argv.html) {
|
|
51
|
-
const filePath = await (0,
|
|
83
|
+
const filePath = await (0, _generatehtmldiff.generateHtmlDiffPreviewFile)(parent, result.Call.storageDiff, block.hash);
|
|
52
84
|
console.log(`Generated preview ${filePath}`);
|
|
53
85
|
if (argv.open) {
|
|
54
|
-
(0,
|
|
86
|
+
(0, _openhtml.openHtml)(filePath);
|
|
55
87
|
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
88
|
+
} else if (argv.outputPath) {
|
|
89
|
+
(0, _nodefs.writeFileSync)(argv.outputPath, JSON.stringify(result, null, 2));
|
|
90
|
+
} else {
|
|
91
|
+
console.dir(result, {
|
|
92
|
+
depth: null,
|
|
93
|
+
colors: false
|
|
94
|
+
});
|
|
62
95
|
}
|
|
63
96
|
process.exit(0);
|
|
64
97
|
});
|
|
65
98
|
};
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
includeBlockDetails: zod_1.z.boolean().optional(),
|
|
99
|
+
const zHex = _zod.z.custom((val)=>/^0x\w+$/.test(val));
|
|
100
|
+
const zHash = _zod.z.string().length(66).and(zHex);
|
|
101
|
+
const schema = _zod.z.object({
|
|
102
|
+
includeRaw: _zod.z.boolean().optional(),
|
|
103
|
+
includeParsed: _zod.z.boolean().optional(),
|
|
104
|
+
includeBlockDetails: _zod.z.boolean().optional(),
|
|
73
105
|
parent: zHash.optional(),
|
|
74
|
-
block:
|
|
75
|
-
header:
|
|
76
|
-
extrinsics:
|
|
77
|
-
})
|
|
106
|
+
block: _zod.z.object({
|
|
107
|
+
header: _zod.z.any(),
|
|
108
|
+
extrinsics: _zod.z.array(zHex)
|
|
109
|
+
})
|
|
78
110
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
* Run a set of extrinsics on top of a block and get the storage diff
|
|
82
|
-
* and optionally the parsed storage diff and block details.
|
|
83
|
-
* NOTE: The extrinsics should include inherents or tranasctions may have unexpected results.
|
|
84
|
-
* NOTE: system.events and system.extrinsicData are excluded from storage diff to reduce size.
|
|
85
|
-
*
|
|
86
|
-
* This function is a dev rpc handler. Use `dev_runBlock` as the method name when calling it.
|
|
87
|
-
*/
|
|
88
|
-
const rpc = async ({ chain }, [params]) => {
|
|
111
|
+
const name = 'runBlock';
|
|
112
|
+
const rpc = async ({ chain }, [params])=>{
|
|
89
113
|
const { includeRaw, includeParsed, includeBlockDetails, parent, block } = schema.parse(params);
|
|
90
114
|
const includeRawStorage = includeRaw ?? true;
|
|
91
115
|
const parentBlock = await chain.getBlock(parent);
|
|
@@ -97,36 +121,41 @@ const rpc = async ({ chain }, [params]) => {
|
|
|
97
121
|
const wasm = await parentBlock.wasm;
|
|
98
122
|
const meta = await parentBlock.meta;
|
|
99
123
|
const blockNumber = parentBlock.number + 1;
|
|
100
|
-
const hash = `0x${Math.round(Math.random() * 100000000)
|
|
101
|
-
|
|
102
|
-
.padEnd(64, '0')}`;
|
|
103
|
-
const newBlock = new chopsticks_core_1.Block(chain, blockNumber, hash, parentBlock, {
|
|
124
|
+
const hash = `0x${Math.round(Math.random() * 100000000).toString(16).padEnd(64, '0')}`;
|
|
125
|
+
const newBlock = new _chopstickscore.Block(chain, blockNumber, hash, parentBlock, {
|
|
104
126
|
header,
|
|
105
127
|
extrinsics: [],
|
|
106
|
-
storage: parentBlock.storage
|
|
128
|
+
storage: parentBlock.storage
|
|
107
129
|
});
|
|
108
130
|
const resp = {
|
|
109
|
-
phases: []
|
|
131
|
+
phases: []
|
|
110
132
|
};
|
|
111
133
|
// exclude system events because it can be stupidly large and redudant
|
|
112
|
-
const systemEventsKey = (0,
|
|
134
|
+
const systemEventsKey = (0, _chopstickscore.compactHex)(meta.query.system.events());
|
|
113
135
|
// large and not really useful
|
|
114
|
-
const systemExtrinsicDataKey = (0,
|
|
115
|
-
const run = async (fn, args)
|
|
116
|
-
const result = await (0,
|
|
136
|
+
const systemExtrinsicDataKey = (0, _util.u8aToHex)(meta.query.system.extrinsicData.keyPrefix());
|
|
137
|
+
const run = async (fn, args)=>{
|
|
138
|
+
const result = await (0, _chopstickscore.runTask)({
|
|
117
139
|
wasm,
|
|
118
|
-
calls: [
|
|
140
|
+
calls: [
|
|
141
|
+
[
|
|
142
|
+
fn,
|
|
143
|
+
args
|
|
144
|
+
]
|
|
145
|
+
],
|
|
119
146
|
mockSignatureHost: false,
|
|
120
147
|
allowUnresolvedImports: false,
|
|
121
|
-
runtimeLogLevel: 5
|
|
122
|
-
}, (0,
|
|
148
|
+
runtimeLogLevel: 5
|
|
149
|
+
}, (0, _chopstickscore.taskHandler)(newBlock));
|
|
123
150
|
if ('Error' in result) {
|
|
124
151
|
throw new Error(result.Error);
|
|
125
152
|
}
|
|
126
|
-
const resp = {
|
|
153
|
+
const resp = {
|
|
154
|
+
storageDiff: []
|
|
155
|
+
};
|
|
127
156
|
const raw = result.Call.storageDiff;
|
|
128
157
|
newBlock.pushStorageLayer().setAll(raw);
|
|
129
|
-
for (const [key, value] of raw)
|
|
158
|
+
for (const [key, value] of raw){
|
|
130
159
|
if (key === systemEventsKey) {
|
|
131
160
|
continue;
|
|
132
161
|
}
|
|
@@ -135,16 +164,19 @@ const rpc = async ({ chain }, [params]) => {
|
|
|
135
164
|
}
|
|
136
165
|
const obj = {};
|
|
137
166
|
if (includeRawStorage) {
|
|
138
|
-
obj.raw = {
|
|
167
|
+
obj.raw = {
|
|
168
|
+
key,
|
|
169
|
+
value
|
|
170
|
+
};
|
|
139
171
|
}
|
|
140
172
|
if (includeParsed) {
|
|
141
|
-
const decoded = (0,
|
|
173
|
+
const decoded = (0, _chopstickscore.decodeKeyValue)(await newBlock.meta, newBlock, key, value, false);
|
|
142
174
|
if (decoded) {
|
|
143
175
|
obj.parsed = {
|
|
144
176
|
section: decoded.section,
|
|
145
177
|
method: decoded.method,
|
|
146
178
|
key: decoded.key,
|
|
147
|
-
value: decoded.value
|
|
179
|
+
value: decoded.value
|
|
148
180
|
};
|
|
149
181
|
}
|
|
150
182
|
}
|
|
@@ -153,44 +185,53 @@ const rpc = async ({ chain }, [params]) => {
|
|
|
153
185
|
resp.logs = result.Call.runtimeLogs;
|
|
154
186
|
return resp;
|
|
155
187
|
};
|
|
156
|
-
const resInit = await run('Core_initialize_block', [
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
188
|
+
const resInit = await run('Core_initialize_block', [
|
|
189
|
+
header.toHex()
|
|
190
|
+
]);
|
|
191
|
+
resp.phases.push({
|
|
192
|
+
phase: 'Initialization',
|
|
193
|
+
...resInit
|
|
194
|
+
});
|
|
195
|
+
for (const extrinsic of block.extrinsics){
|
|
196
|
+
const res = await run('BlockBuilder_apply_extrinsic', [
|
|
197
|
+
extrinsic
|
|
198
|
+
]);
|
|
199
|
+
resp.phases.push({
|
|
200
|
+
phase: resp.phases.length - 1,
|
|
201
|
+
...res
|
|
202
|
+
});
|
|
161
203
|
}
|
|
162
204
|
const resFinalize = await run('BlockBuilder_finalize_block', []);
|
|
163
|
-
resp.phases.push({
|
|
205
|
+
resp.phases.push({
|
|
206
|
+
phase: 'Finalization',
|
|
207
|
+
...resFinalize
|
|
208
|
+
});
|
|
164
209
|
if (includeBlockDetails) {
|
|
165
210
|
const meta = await newBlock.meta;
|
|
166
211
|
const registry = await newBlock.registry;
|
|
167
212
|
const timestamp = await newBlock.read('u64', meta.query.timestamp.now);
|
|
168
213
|
const events = await newBlock.read('Vec<EventRecord>', meta.query.system.events);
|
|
169
|
-
const parsedEvents = events?.map((event)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const extrinsics = block.extrinsics.map((extrinsic, idx)
|
|
214
|
+
const parsedEvents = events?.map((event)=>({
|
|
215
|
+
phase: event.phase.isApplyExtrinsic ? event.phase.asApplyExtrinsic.toNumber() : event.phase.toString(),
|
|
216
|
+
section: event.event.section,
|
|
217
|
+
method: event.event.method,
|
|
218
|
+
args: event.event.data.map((arg)=>arg.toJSON())
|
|
219
|
+
}));
|
|
220
|
+
const extrinsics = block.extrinsics.map((extrinsic, idx)=>{
|
|
176
221
|
const parsed = registry.createType('GenericExtrinsic', extrinsic);
|
|
177
|
-
const resultEvent = events?.find(({ event, phase })
|
|
178
|
-
(event.method === 'ExtrinsicSuccess' || event.method === 'ExtrinsicFailed') &&
|
|
179
|
-
phase.isApplyExtrinsic &&
|
|
180
|
-
phase.asApplyExtrinsic.eq(idx));
|
|
222
|
+
const resultEvent = events?.find(({ event, phase })=>event.section === 'system' && (event.method === 'ExtrinsicSuccess' || event.method === 'ExtrinsicFailed') && phase.isApplyExtrinsic && phase.asApplyExtrinsic.eq(idx));
|
|
181
223
|
return {
|
|
182
224
|
section: parsed.method.section,
|
|
183
225
|
method: parsed.method.method,
|
|
184
|
-
args: parsed.method.args.map((arg)
|
|
185
|
-
success: resultEvent?.event.method === 'ExtrinsicSuccess'
|
|
226
|
+
args: parsed.method.args.map((arg)=>arg.toJSON()),
|
|
227
|
+
success: resultEvent?.event.method === 'ExtrinsicSuccess'
|
|
186
228
|
};
|
|
187
229
|
});
|
|
188
230
|
resp.blockDetails = {
|
|
189
231
|
timestamp: timestamp?.toString(),
|
|
190
232
|
events: parsedEvents,
|
|
191
|
-
extrinsics
|
|
233
|
+
extrinsics
|
|
192
234
|
};
|
|
193
235
|
}
|
|
194
236
|
return resp;
|
|
195
237
|
};
|
|
196
|
-
exports.rpc = rpc;
|
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* await ws.send('dev_setBlockBuildMode', [BuildBlockMode.Instant])
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
const rpc = async (context, [mode]) => {
|
|
23
|
-
logger_1.defaultLogger.debug({ mode }, 'dev_setBlockBuildMode');
|
|
24
|
-
if (chopsticks_core_1.BuildBlockMode[mode] === undefined) {
|
|
25
|
-
throw new chopsticks_core_1.ResponseError(1, `Invalid mode ${mode}`);
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "rpc", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return rpc;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
12
|
+
const _logger = require("../../logger");
|
|
13
|
+
const rpc = async (context, [mode])=>{
|
|
14
|
+
_logger.defaultLogger.debug({
|
|
15
|
+
mode
|
|
16
|
+
}, 'dev_setBlockBuildMode');
|
|
17
|
+
if (_chopstickscore.BuildBlockMode[mode] === undefined) {
|
|
18
|
+
throw new _chopstickscore.ResponseError(1, `Invalid mode ${mode}`);
|
|
26
19
|
}
|
|
27
20
|
context.chain.txPool.mode = mode;
|
|
28
21
|
};
|
|
29
|
-
exports.rpc = rpc;
|