@acala-network/chopsticks 0.9.2-2 → 0.9.2-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/context.js +0 -4
- package/dist/cjs/plugins/decode-key/cli.js +30 -0
- package/dist/cjs/plugins/decode-key/index.js +12 -24
- package/dist/cjs/plugins/dry-run/rpc.js +11 -21
- package/dist/cjs/plugins/follow-chain/cli.js +106 -0
- package/dist/cjs/plugins/follow-chain/index.js +12 -100
- package/dist/cjs/plugins/index.js +21 -14
- package/dist/cjs/plugins/new-block/index.js +14 -35
- package/dist/cjs/plugins/new-block/rpc.js +55 -0
- package/dist/cjs/plugins/run-block/cli.js +84 -0
- package/dist/cjs/plugins/run-block/index.js +12 -229
- package/dist/cjs/plugins/run-block/rpc.js +159 -0
- package/dist/cjs/plugins/set-block-build-mode/index.js +14 -17
- package/dist/cjs/plugins/set-block-build-mode/rpc.js +21 -0
- package/dist/cjs/plugins/set-head/index.js +14 -21
- package/dist/cjs/plugins/set-head/rpc.js +29 -0
- package/dist/cjs/plugins/set-runtime-log-level/index.js +14 -17
- package/dist/cjs/plugins/set-runtime-log-level/rpc.js +21 -0
- package/dist/cjs/plugins/set-storage/index.js +13 -18
- package/dist/cjs/plugins/set-storage/rpc.js +23 -0
- package/dist/cjs/plugins/time-travel/index.js +14 -13
- package/dist/cjs/plugins/time-travel/rpc.js +17 -0
- package/dist/cjs/rpc/index.js +5 -5
- package/dist/cjs/schema/index.js +8 -0
- package/dist/esm/context.js +0 -4
- package/dist/esm/plugins/decode-key/cli.js +20 -0
- package/dist/esm/plugins/decode-key/index.js +1 -20
- package/dist/esm/plugins/dry-run/rpc.js +1 -4
- package/dist/esm/plugins/follow-chain/cli.js +91 -0
- package/dist/esm/plugins/follow-chain/index.js +1 -91
- package/dist/esm/plugins/index.js +15 -10
- package/dist/esm/plugins/new-block/index.js +1 -66
- package/dist/esm/plugins/new-block/rpc.js +82 -0
- package/dist/esm/plugins/run-block/cli.js +74 -0
- package/dist/esm/plugins/run-block/index.js +2 -222
- package/dist/esm/plugins/run-block/rpc.js +148 -0
- package/dist/esm/plugins/set-block-build-mode/index.js +1 -26
- package/dist/esm/plugins/set-block-build-mode/rpc.js +28 -0
- package/dist/esm/plugins/set-head/index.js +1 -29
- package/dist/esm/plugins/set-head/rpc.js +33 -0
- package/dist/esm/plugins/set-runtime-log-level/index.js +1 -25
- package/dist/esm/plugins/set-runtime-log-level/rpc.js +25 -0
- package/dist/esm/plugins/set-storage/index.js +1 -37
- package/dist/esm/plugins/set-storage/rpc.js +37 -0
- package/dist/esm/plugins/time-travel/index.js +1 -21
- package/dist/esm/plugins/time-travel/rpc.js +21 -0
- package/dist/esm/rpc/index.js +6 -6
- package/dist/esm/schema/index.js +2 -0
- package/dist/types/plugins/decode-key/cli.d.ts +2 -0
- package/dist/types/plugins/decode-key/index.d.ts +1 -2
- package/dist/types/plugins/dry-run/rpc.d.ts +0 -1
- package/dist/types/plugins/follow-chain/cli.d.ts +2 -0
- package/dist/types/plugins/follow-chain/index.d.ts +1 -2
- package/dist/types/plugins/index.d.ts +3 -2
- package/dist/types/plugins/new-block/index.d.ts +1 -71
- package/dist/types/plugins/new-block/rpc.d.ts +128 -0
- package/dist/types/plugins/run-block/cli.d.ts +2 -0
- package/dist/types/plugins/run-block/index.d.ts +2 -141
- package/dist/types/plugins/run-block/rpc.d.ts +139 -0
- package/dist/types/plugins/set-block-build-mode/index.d.ts +1 -18
- package/dist/types/plugins/set-block-build-mode/rpc.d.ts +20 -0
- package/dist/types/plugins/set-head/index.d.ts +1 -18
- package/dist/types/plugins/set-head/rpc.d.ts +21 -0
- package/dist/types/plugins/set-runtime-log-level/index.d.ts +1 -17
- package/dist/types/plugins/set-runtime-log-level/rpc.d.ts +17 -0
- package/dist/types/plugins/set-storage/index.d.ts +1 -28
- package/dist/types/plugins/set-storage/rpc.d.ts +28 -0
- package/dist/types/plugins/time-travel/index.d.ts +1 -17
- package/dist/types/plugins/time-travel/rpc.d.ts +17 -0
- package/dist/types/schema/index.d.ts +2 -0
- package/package.json +3 -3
package/dist/cjs/context.js
CHANGED
|
@@ -19,7 +19,6 @@ _export(exports, {
|
|
|
19
19
|
require("./utils/tunnel.js");
|
|
20
20
|
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
21
21
|
const _chopsticksdb = require("@acala-network/chopsticks-db");
|
|
22
|
-
const _index = require("./plugins/index.js");
|
|
23
22
|
const _override = require("./utils/override.js");
|
|
24
23
|
const _axios = /*#__PURE__*/ _interop_require_default(require("axios"));
|
|
25
24
|
function _interop_require_default(obj) {
|
|
@@ -141,9 +140,6 @@ const setupContext = async (argv, overrideParent = false)=>{
|
|
|
141
140
|
// added that have storage imports
|
|
142
141
|
await (0, _override.overrideWasm)(chain, argv['wasm-override'], at);
|
|
143
142
|
await (0, _override.overrideStorage)(chain, argv['import-storage'], at);
|
|
144
|
-
if (!process.env.DISABLE_PLUGINS) {
|
|
145
|
-
await (0, _index.loadRPCPlugins)();
|
|
146
|
-
}
|
|
147
143
|
return {
|
|
148
144
|
chain
|
|
149
145
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "cli", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return cli;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
12
|
+
const _clioptions = require("../../cli-options.js");
|
|
13
|
+
const _context = require("../../context.js");
|
|
14
|
+
const cli = (y)=>{
|
|
15
|
+
y.command('decode-key <key>', 'Deocde a key', (yargs)=>yargs.positional('key', {
|
|
16
|
+
desc: 'Key to decode',
|
|
17
|
+
type: 'string'
|
|
18
|
+
}).options({
|
|
19
|
+
..._clioptions.defaultOptions
|
|
20
|
+
}), async (argv)=>{
|
|
21
|
+
const context = await (0, _context.setupContext)(argv);
|
|
22
|
+
const { storage, decodedKey } = (0, _chopstickscore.decodeKey)(await context.chain.head.meta, context.chain.head, argv.key);
|
|
23
|
+
if (storage && decodedKey) {
|
|
24
|
+
console.log(`${storage.section}.${storage.method}`, decodedKey.args.map((x)=>JSON.stringify(x.toHuman())).join(', '));
|
|
25
|
+
} else {
|
|
26
|
+
console.log('Unknown');
|
|
27
|
+
}
|
|
28
|
+
process.exit(0);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
@@ -2,29 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
y.command('decode-key <key>', 'Deocde a key', (yargs)=>yargs.positional('key', {
|
|
16
|
-
desc: 'Key to decode',
|
|
17
|
-
type: 'string'
|
|
18
|
-
}).options({
|
|
19
|
-
..._clioptions.defaultOptions
|
|
20
|
-
}), async (argv)=>{
|
|
21
|
-
const context = await (0, _context.setupContext)(argv);
|
|
22
|
-
const { storage, decodedKey } = (0, _chopstickscore.decodeKey)(await context.chain.head.meta, context.chain.head, argv.key);
|
|
23
|
-
if (storage && decodedKey) {
|
|
24
|
-
console.log(`${storage.section}.${storage.method}`, decodedKey.args.map((x)=>JSON.stringify(x.toHuman())).join(', '));
|
|
25
|
-
} else {
|
|
26
|
-
console.log('Unknown');
|
|
5
|
+
_export_star(require("./cli.js"), exports);
|
|
6
|
+
function _export_star(from, to) {
|
|
7
|
+
Object.keys(from).forEach(function(k) {
|
|
8
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
+
Object.defineProperty(to, k, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return from[k];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
27
15
|
}
|
|
28
|
-
process.exit(0);
|
|
29
16
|
});
|
|
30
|
-
|
|
17
|
+
return from;
|
|
18
|
+
}
|
|
@@ -2,17 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
name: function() {
|
|
13
|
-
return name;
|
|
14
|
-
},
|
|
15
|
-
rpc: function() {
|
|
5
|
+
Object.defineProperty(exports, "rpc", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
16
8
|
return rpc;
|
|
17
9
|
}
|
|
18
10
|
});
|
|
@@ -20,28 +12,26 @@ const _zod = require("zod");
|
|
|
20
12
|
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
21
13
|
const _decoder = require("../../utils/decoder.js");
|
|
22
14
|
const _generatehtmldiff = require("../../utils/generate-html-diff.js");
|
|
23
|
-
const
|
|
24
|
-
const zHash = _zod.z.string().length(66).and(zHex);
|
|
15
|
+
const _index = require("../../schema/index.js");
|
|
25
16
|
const zParaId = _zod.z.string().regex(/^\d+$/).transform(Number);
|
|
26
17
|
const schema = _zod.z.object({
|
|
27
18
|
raw: _zod.z.boolean().optional(),
|
|
28
19
|
html: _zod.z.boolean().optional(),
|
|
29
|
-
extrinsic: zHex.or(_zod.z.object({
|
|
30
|
-
call: zHex,
|
|
31
|
-
address: zHex
|
|
20
|
+
extrinsic: _index.zHex.or(_zod.z.object({
|
|
21
|
+
call: _index.zHex,
|
|
22
|
+
address: _index.zHex
|
|
32
23
|
})).optional(),
|
|
33
24
|
hrmp: _zod.z.record(zParaId, _zod.z.array(_zod.z.object({
|
|
34
25
|
sentAt: _zod.z.number(),
|
|
35
|
-
data: zHex
|
|
26
|
+
data: _index.zHex
|
|
36
27
|
})).min(1)).optional(),
|
|
37
28
|
dmp: _zod.z.array(_zod.z.object({
|
|
38
29
|
sentAt: _zod.z.number(),
|
|
39
|
-
msg: zHex
|
|
30
|
+
msg: _index.zHex
|
|
40
31
|
})).min(1).optional(),
|
|
41
|
-
ump: _zod.z.record(zParaId, _zod.z.array(zHex).min(1)).optional(),
|
|
42
|
-
at: zHash.optional()
|
|
32
|
+
ump: _zod.z.record(zParaId, _zod.z.array(_index.zHex).min(1)).optional(),
|
|
33
|
+
at: _index.zHash.optional()
|
|
43
34
|
});
|
|
44
|
-
const name = 'dryRun';
|
|
45
35
|
const rpc = async (context, [params])=>{
|
|
46
36
|
const { html, extrinsic, hrmp, dmp, ump, raw, at } = schema.parse(params);
|
|
47
37
|
const dryRun = async ()=>{
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "cli", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return cli;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
12
|
+
const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
|
|
13
|
+
const _server = require("../../server.js");
|
|
14
|
+
const _clioptions = require("../../cli-options.js");
|
|
15
|
+
const _index = require("../../rpc/index.js");
|
|
16
|
+
const _context = require("../../context.js");
|
|
17
|
+
function _interop_require_default(obj) {
|
|
18
|
+
return obj && obj.__esModule ? obj : {
|
|
19
|
+
default: obj
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const logger = _chopstickscore.defaultLogger.child({
|
|
23
|
+
name: 'follow-chain'
|
|
24
|
+
});
|
|
25
|
+
const options = _lodash.default.pick(_clioptions.defaultOptions, [
|
|
26
|
+
'endpoint',
|
|
27
|
+
'wasm-override',
|
|
28
|
+
'runtime-log-level',
|
|
29
|
+
'offchain-worker'
|
|
30
|
+
]);
|
|
31
|
+
const cli = (y)=>{
|
|
32
|
+
y.command('follow-chain', 'Always follow the latest block on upstream', (yargs)=>yargs.options({
|
|
33
|
+
...options,
|
|
34
|
+
port: {
|
|
35
|
+
desc: 'Port to listen on',
|
|
36
|
+
number: true
|
|
37
|
+
},
|
|
38
|
+
'head-mode': {
|
|
39
|
+
desc: 'Head mode',
|
|
40
|
+
choices: [
|
|
41
|
+
'latest',
|
|
42
|
+
'finalized'
|
|
43
|
+
],
|
|
44
|
+
default: 'finalized'
|
|
45
|
+
}
|
|
46
|
+
}), async (argv)=>{
|
|
47
|
+
const port = argv.port ?? 8000;
|
|
48
|
+
const endpoint = argv.endpoint;
|
|
49
|
+
if (/^(https|http):\/\//.test(endpoint || '')) {
|
|
50
|
+
throw Error('http provider is not supported');
|
|
51
|
+
}
|
|
52
|
+
const context = await (0, _context.setupContext)(argv, true);
|
|
53
|
+
const { close, port: listenPort } = await (0, _server.createServer)((0, _index.handler)(context), port);
|
|
54
|
+
logger.info(`${await context.chain.api.getSystemChain()} RPC listening on port ${listenPort}`);
|
|
55
|
+
const chain = context.chain;
|
|
56
|
+
chain.api[argv.headMode === 'latest' ? 'subscribeRemoteNewHeads' : 'subscribeRemoteFinalizedHeads'](async (error, data)=>{
|
|
57
|
+
try {
|
|
58
|
+
if (error) throw error;
|
|
59
|
+
logger.info({
|
|
60
|
+
header: data
|
|
61
|
+
}, `Follow ${argv.headMode} head from upstream`);
|
|
62
|
+
const parent = await chain.getBlock(data.parentHash);
|
|
63
|
+
if (!parent) throw Error(`Cannot find parent', ${data.parentHash}`);
|
|
64
|
+
const registry = await parent.registry;
|
|
65
|
+
const header = registry.createType('Header', data);
|
|
66
|
+
const wasm = await parent.wasm;
|
|
67
|
+
const block = new _chopstickscore.Block(chain, header.number.toNumber(), header.hash.toHex(), parent);
|
|
68
|
+
await chain.setHead(block);
|
|
69
|
+
const calls = [
|
|
70
|
+
[
|
|
71
|
+
'Core_initialize_block',
|
|
72
|
+
[
|
|
73
|
+
header.toHex()
|
|
74
|
+
]
|
|
75
|
+
]
|
|
76
|
+
];
|
|
77
|
+
for (const extrinsic of (await block.extrinsics)){
|
|
78
|
+
calls.push([
|
|
79
|
+
'BlockBuilder_apply_extrinsic',
|
|
80
|
+
[
|
|
81
|
+
extrinsic
|
|
82
|
+
]
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
calls.push([
|
|
86
|
+
'BlockBuilder_finalize_block',
|
|
87
|
+
[]
|
|
88
|
+
]);
|
|
89
|
+
const result = await (0, _chopstickscore.runTask)({
|
|
90
|
+
wasm,
|
|
91
|
+
calls,
|
|
92
|
+
mockSignatureHost: false,
|
|
93
|
+
allowUnresolvedImports: false,
|
|
94
|
+
runtimeLogLevel: argv.runtimeLogLevel || 0
|
|
95
|
+
}, (0, _chopstickscore.taskHandler)(parent));
|
|
96
|
+
if ('Error' in result) {
|
|
97
|
+
throw new Error(result.Error);
|
|
98
|
+
}
|
|
99
|
+
} catch (e) {
|
|
100
|
+
logger.error(e, 'Error when processing new head');
|
|
101
|
+
await close();
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
@@ -2,105 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const _server = require("../../server.js");
|
|
14
|
-
const _clioptions = require("../../cli-options.js");
|
|
15
|
-
const _index = require("../../rpc/index.js");
|
|
16
|
-
const _context = require("../../context.js");
|
|
17
|
-
function _interop_require_default(obj) {
|
|
18
|
-
return obj && obj.__esModule ? obj : {
|
|
19
|
-
default: obj
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
const logger = _chopstickscore.defaultLogger.child({
|
|
23
|
-
name: 'follow-chain'
|
|
24
|
-
});
|
|
25
|
-
const options = _lodash.default.pick(_clioptions.defaultOptions, [
|
|
26
|
-
'endpoint',
|
|
27
|
-
'wasm-override',
|
|
28
|
-
'runtime-log-level',
|
|
29
|
-
'offchain-worker'
|
|
30
|
-
]);
|
|
31
|
-
const cli = (y)=>{
|
|
32
|
-
y.command('follow-chain', 'Always follow the latest block on upstream', (yargs)=>yargs.options({
|
|
33
|
-
...options,
|
|
34
|
-
port: {
|
|
35
|
-
desc: 'Port to listen on',
|
|
36
|
-
number: true
|
|
37
|
-
},
|
|
38
|
-
'head-mode': {
|
|
39
|
-
desc: 'Head mode',
|
|
40
|
-
choices: [
|
|
41
|
-
'latest',
|
|
42
|
-
'finalized'
|
|
43
|
-
],
|
|
44
|
-
default: 'finalized'
|
|
45
|
-
}
|
|
46
|
-
}), async (argv)=>{
|
|
47
|
-
const port = argv.port ?? 8000;
|
|
48
|
-
const endpoint = argv.endpoint;
|
|
49
|
-
if (/^(https|http):\/\//.test(endpoint || '')) {
|
|
50
|
-
throw Error('http provider is not supported');
|
|
51
|
-
}
|
|
52
|
-
const context = await (0, _context.setupContext)(argv, true);
|
|
53
|
-
const { close, port: listenPort } = await (0, _server.createServer)((0, _index.handler)(context), port);
|
|
54
|
-
logger.info(`${await context.chain.api.getSystemChain()} RPC listening on port ${listenPort}`);
|
|
55
|
-
const chain = context.chain;
|
|
56
|
-
chain.api[argv.headMode === 'latest' ? 'subscribeRemoteNewHeads' : 'subscribeRemoteFinalizedHeads'](async (error, data)=>{
|
|
57
|
-
try {
|
|
58
|
-
if (error) throw error;
|
|
59
|
-
logger.info({
|
|
60
|
-
header: data
|
|
61
|
-
}, `Follow ${argv.headMode} head from upstream`);
|
|
62
|
-
const parent = await chain.getBlock(data.parentHash);
|
|
63
|
-
if (!parent) throw Error(`Cannot find parent', ${data.parentHash}`);
|
|
64
|
-
const registry = await parent.registry;
|
|
65
|
-
const header = registry.createType('Header', data);
|
|
66
|
-
const wasm = await parent.wasm;
|
|
67
|
-
const block = new _chopstickscore.Block(chain, header.number.toNumber(), header.hash.toHex(), parent);
|
|
68
|
-
await chain.setHead(block);
|
|
69
|
-
const calls = [
|
|
70
|
-
[
|
|
71
|
-
'Core_initialize_block',
|
|
72
|
-
[
|
|
73
|
-
header.toHex()
|
|
74
|
-
]
|
|
75
|
-
]
|
|
76
|
-
];
|
|
77
|
-
for (const extrinsic of (await block.extrinsics)){
|
|
78
|
-
calls.push([
|
|
79
|
-
'BlockBuilder_apply_extrinsic',
|
|
80
|
-
[
|
|
81
|
-
extrinsic
|
|
82
|
-
]
|
|
83
|
-
]);
|
|
5
|
+
_export_star(require("./cli.js"), exports);
|
|
6
|
+
function _export_star(from, to) {
|
|
7
|
+
Object.keys(from).forEach(function(k) {
|
|
8
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
+
Object.defineProperty(to, k, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return from[k];
|
|
84
13
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
[]
|
|
88
|
-
]);
|
|
89
|
-
const result = await (0, _chopstickscore.runTask)({
|
|
90
|
-
wasm,
|
|
91
|
-
calls,
|
|
92
|
-
mockSignatureHost: false,
|
|
93
|
-
allowUnresolvedImports: false,
|
|
94
|
-
runtimeLogLevel: argv.runtimeLogLevel || 0
|
|
95
|
-
}, (0, _chopstickscore.taskHandler)(parent));
|
|
96
|
-
if ('Error' in result) {
|
|
97
|
-
throw new Error(result.Error);
|
|
98
|
-
}
|
|
99
|
-
} catch (e) {
|
|
100
|
-
logger.error(e, 'Error when processing new head');
|
|
101
|
-
await close();
|
|
102
|
-
process.exit(1);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
14
|
+
});
|
|
15
|
+
}
|
|
105
16
|
});
|
|
106
|
-
|
|
17
|
+
return from;
|
|
18
|
+
}
|
|
@@ -9,14 +9,17 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
|
|
13
|
-
return
|
|
12
|
+
loadRpcPlugin: function() {
|
|
13
|
+
return loadRpcPlugin;
|
|
14
14
|
},
|
|
15
15
|
pluginExtendCli: function() {
|
|
16
16
|
return pluginExtendCli;
|
|
17
17
|
},
|
|
18
|
-
|
|
19
|
-
return
|
|
18
|
+
rpcPluginHandlers: function() {
|
|
19
|
+
return rpcPluginHandlers;
|
|
20
|
+
},
|
|
21
|
+
rpcPluginMethods: function() {
|
|
22
|
+
return rpcPluginMethods;
|
|
20
23
|
}
|
|
21
24
|
});
|
|
22
25
|
const _fs = require("fs");
|
|
@@ -71,19 +74,23 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
71
74
|
const logger = _logger.defaultLogger.child({
|
|
72
75
|
name: 'plugin'
|
|
73
76
|
});
|
|
74
|
-
const
|
|
77
|
+
const rpcPluginHandlers = {};
|
|
75
78
|
// list of plugins directory
|
|
76
79
|
const plugins = (0, _fs.readdirSync)(new URL('.', require("url").pathToFileURL(__filename).toString())).filter((file)=>(0, _fs.lstatSync)(new URL(file, require("url").pathToFileURL(__filename).toString())).isDirectory());
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (rpc) {
|
|
82
|
-
const methodName = name || _lodash.default.camelCase(plugin);
|
|
83
|
-
pluginHandlers[`dev_${methodName}`] = rpc;
|
|
84
|
-
logger.debug(`Registered plugin RPC: ${`dev_${methodName}`}`);
|
|
85
|
-
}
|
|
80
|
+
const rpcPluginMethods = plugins.filter((name)=>(0, _fs.readdirSync)(new URL(name, require("url").pathToFileURL(__filename).toString())).some((file)=>file.startsWith('rpc'))).map((name)=>`dev_${_lodash.default.camelCase(name)}`);
|
|
81
|
+
const loadRpcPlugin = async (method)=>{
|
|
82
|
+
if (process.env.DISABLE_PLUGINS) {
|
|
83
|
+
return undefined;
|
|
86
84
|
}
|
|
85
|
+
if (rpcPluginHandlers[method]) return rpcPluginHandlers[method];
|
|
86
|
+
const plugin = _lodash.default.snakeCase(method.split('dev_')[1]).replaceAll('_', '-');
|
|
87
|
+
if (!plugin) return undefined;
|
|
88
|
+
const location = new URL(`${plugin}/index.js`, require("url").pathToFileURL(__filename).toString());
|
|
89
|
+
const { rpc } = await Promise.resolve(location.pathname).then((p)=>/*#__PURE__*/ _interop_require_wildcard(require(p)));
|
|
90
|
+
if (!rpc) return undefined;
|
|
91
|
+
rpcPluginHandlers[method] = rpc;
|
|
92
|
+
logger.debug(`Registered plugin ${plugin} RPC`);
|
|
93
|
+
return rpc;
|
|
87
94
|
};
|
|
88
95
|
const pluginExtendCli = async (y)=>{
|
|
89
96
|
for (const plugin of plugins){
|
|
@@ -2,38 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let finalHash;
|
|
20
|
-
if (unsafeBlockHeight < now) {
|
|
21
|
-
throw new _chopstickscore.ResponseError(1, 'unsafeBlockHeight must be greater than current block height');
|
|
22
|
-
}
|
|
23
|
-
for(let i = 0; i < finalCount; i++){
|
|
24
|
-
const block = await context.chain.newBlock({
|
|
25
|
-
transactions,
|
|
26
|
-
horizontalMessages: hrmp,
|
|
27
|
-
upwardMessages: ump,
|
|
28
|
-
downwardMessages: dmp,
|
|
29
|
-
unsafeBlockHeight: i === 0 ? unsafeBlockHeight : undefined
|
|
30
|
-
}).catch((error)=>{
|
|
31
|
-
throw new _chopstickscore.ResponseError(1, error.toString());
|
|
32
|
-
});
|
|
33
|
-
_logger.defaultLogger.debug({
|
|
34
|
-
hash: block.hash
|
|
35
|
-
}, 'dev_newBlock');
|
|
36
|
-
finalHash = block.hash;
|
|
37
|
-
}
|
|
38
|
-
return finalHash;
|
|
39
|
-
};
|
|
5
|
+
_export_star(require("./rpc.js"), exports);
|
|
6
|
+
function _export_star(from, to) {
|
|
7
|
+
Object.keys(from).forEach(function(k) {
|
|
8
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
+
Object.defineProperty(to, k, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return from[k];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return from;
|
|
18
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
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 _zod = require("zod");
|
|
13
|
+
const _logger = require("../../logger.js");
|
|
14
|
+
const _index = require("../../schema/index.js");
|
|
15
|
+
const schema = _zod.z.object({
|
|
16
|
+
count: _zod.z.number().optional(),
|
|
17
|
+
to: _zod.z.number().optional(),
|
|
18
|
+
dmp: _zod.z.array(_zod.z.object({
|
|
19
|
+
sentAt: _zod.z.number(),
|
|
20
|
+
msg: _index.zHex
|
|
21
|
+
})).min(1).optional(),
|
|
22
|
+
ump: _zod.z.record(_zod.z.number(), _zod.z.array(_index.zHex).min(1)).optional(),
|
|
23
|
+
hrmp: _zod.z.record(_zod.z.number(), _zod.z.array(_zod.z.object({
|
|
24
|
+
sentAt: _zod.z.number(),
|
|
25
|
+
data: _index.zHex
|
|
26
|
+
})).min(1)).optional(),
|
|
27
|
+
transactions: _zod.z.array(_index.zHex).min(1).optional(),
|
|
28
|
+
unsafeBlockHeight: _zod.z.number().optional()
|
|
29
|
+
});
|
|
30
|
+
const rpc = async (context, [params])=>{
|
|
31
|
+
const { count, to, hrmp, ump, dmp, transactions, unsafeBlockHeight } = schema.parse(params || {});
|
|
32
|
+
const now = context.chain.head.number;
|
|
33
|
+
const diff = to ? to - now : count;
|
|
34
|
+
const finalCount = diff !== undefined ? Math.max(diff, 1) : 1;
|
|
35
|
+
let finalHash;
|
|
36
|
+
if (unsafeBlockHeight !== undefined && unsafeBlockHeight <= now) {
|
|
37
|
+
throw new _chopstickscore.ResponseError(1, 'unsafeBlockHeight must be greater than current block height');
|
|
38
|
+
}
|
|
39
|
+
for(let i = 0; i < finalCount; i++){
|
|
40
|
+
const block = await context.chain.newBlock({
|
|
41
|
+
transactions,
|
|
42
|
+
horizontalMessages: hrmp,
|
|
43
|
+
upwardMessages: ump,
|
|
44
|
+
downwardMessages: dmp,
|
|
45
|
+
unsafeBlockHeight: i === 0 ? unsafeBlockHeight : undefined
|
|
46
|
+
}).catch((error)=>{
|
|
47
|
+
throw new _chopstickscore.ResponseError(1, error.toString());
|
|
48
|
+
});
|
|
49
|
+
_logger.defaultLogger.debug({
|
|
50
|
+
hash: block.hash
|
|
51
|
+
}, 'dev_newBlock');
|
|
52
|
+
finalHash = block.hash;
|
|
53
|
+
}
|
|
54
|
+
return finalHash;
|
|
55
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "cli", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return cli;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _nodefs = require("node:fs");
|
|
12
|
+
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
13
|
+
const _clioptions = require("../../cli-options.js");
|
|
14
|
+
const _generatehtmldiff = require("../../utils/generate-html-diff.js");
|
|
15
|
+
const _openhtml = require("../../utils/open-html.js");
|
|
16
|
+
const _context = require("../../context.js");
|
|
17
|
+
const cli = (y)=>{
|
|
18
|
+
y.command('run-block', 'Replay a block', (yargs)=>yargs.options({
|
|
19
|
+
..._clioptions.defaultOptions,
|
|
20
|
+
..._clioptions.mockOptions,
|
|
21
|
+
'output-path': {
|
|
22
|
+
desc: 'File path to print output',
|
|
23
|
+
string: true
|
|
24
|
+
},
|
|
25
|
+
html: {
|
|
26
|
+
desc: 'Generate html with storage diff'
|
|
27
|
+
},
|
|
28
|
+
open: {
|
|
29
|
+
desc: 'Open generated html'
|
|
30
|
+
}
|
|
31
|
+
}), async (argv)=>{
|
|
32
|
+
const context = await (0, _context.setupContext)(argv, true);
|
|
33
|
+
const header = await context.chain.head.header;
|
|
34
|
+
const block = context.chain.head;
|
|
35
|
+
const parent = await block.parentBlock;
|
|
36
|
+
if (!parent) throw Error('cant find parent block');
|
|
37
|
+
const wasm = await parent.wasm;
|
|
38
|
+
const calls = [
|
|
39
|
+
[
|
|
40
|
+
'Core_initialize_block',
|
|
41
|
+
[
|
|
42
|
+
header.toHex()
|
|
43
|
+
]
|
|
44
|
+
]
|
|
45
|
+
];
|
|
46
|
+
for (const extrinsic of (await block.extrinsics)){
|
|
47
|
+
calls.push([
|
|
48
|
+
'BlockBuilder_apply_extrinsic',
|
|
49
|
+
[
|
|
50
|
+
extrinsic
|
|
51
|
+
]
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
calls.push([
|
|
55
|
+
'BlockBuilder_finalize_block',
|
|
56
|
+
[]
|
|
57
|
+
]);
|
|
58
|
+
const result = await (0, _chopstickscore.runTask)({
|
|
59
|
+
wasm,
|
|
60
|
+
calls,
|
|
61
|
+
mockSignatureHost: false,
|
|
62
|
+
allowUnresolvedImports: false,
|
|
63
|
+
runtimeLogLevel: argv.runtimeLogLevel || 0
|
|
64
|
+
}, (0, _chopstickscore.taskHandler)(parent));
|
|
65
|
+
if ('Error' in result) {
|
|
66
|
+
throw new Error(result.Error);
|
|
67
|
+
}
|
|
68
|
+
if (argv.html) {
|
|
69
|
+
const filePath = await (0, _generatehtmldiff.generateHtmlDiffPreviewFile)(parent, result.Call.storageDiff, block.hash);
|
|
70
|
+
console.log(`Generated preview ${filePath}`);
|
|
71
|
+
if (argv.open) {
|
|
72
|
+
(0, _openhtml.openHtml)(filePath);
|
|
73
|
+
}
|
|
74
|
+
} else if (argv.outputPath) {
|
|
75
|
+
(0, _nodefs.writeFileSync)(argv.outputPath, JSON.stringify(result, null, 2));
|
|
76
|
+
} else {
|
|
77
|
+
console.dir(result, {
|
|
78
|
+
depth: null,
|
|
79
|
+
colors: false
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
process.exit(0);
|
|
83
|
+
});
|
|
84
|
+
};
|