@acala-network/chopsticks 0.9.1-2 → 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 +78 -46
- package/dist/cjs/plugins/index.js +76 -40
- 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 +52 -28
- package/dist/esm/plugins/index.js +8 -6
- 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 +10 -6
- package/dist/esm/utils/open-html.js +1 -1
- package/dist/esm/utils/override.js +11 -13
- package/dist/esm/utils/tunnel.js +1 -8
- package/package.json +13 -17
- package/dist/esm/package.json +0 -1
- /package/{chopsticks.js → chopsticks.cjs} +0 -0
|
@@ -1,70 +1,103 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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");
|
|
14
|
+
const _clioptions = require("../../cli-options");
|
|
15
|
+
const _rpc = require("../../rpc");
|
|
16
|
+
const _context = require("../../context");
|
|
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)=>{
|
|
28
47
|
const port = argv.port ?? 8000;
|
|
29
48
|
const endpoint = argv.endpoint;
|
|
30
49
|
if (/^(https|http):\/\//.test(endpoint || '')) {
|
|
31
50
|
throw Error('http provider is not supported');
|
|
32
51
|
}
|
|
33
|
-
const context = await (0,
|
|
34
|
-
const { close, port: listenPort } = await (0,
|
|
52
|
+
const context = await (0, _context.setupContext)(argv, true);
|
|
53
|
+
const { close, port: listenPort } = await (0, _server.createServer)((0, _rpc.handler)(context), port);
|
|
35
54
|
logger.info(`${await context.chain.api.getSystemChain()} RPC listening on port ${listenPort}`);
|
|
36
55
|
const chain = context.chain;
|
|
37
|
-
chain.api[argv.headMode === 'latest' ? 'subscribeRemoteNewHeads' : 'subscribeRemoteFinalizedHeads'](async (error, data)
|
|
56
|
+
chain.api[argv.headMode === 'latest' ? 'subscribeRemoteNewHeads' : 'subscribeRemoteFinalizedHeads'](async (error, data)=>{
|
|
38
57
|
try {
|
|
39
|
-
if (error)
|
|
40
|
-
|
|
41
|
-
|
|
58
|
+
if (error) throw error;
|
|
59
|
+
logger.info({
|
|
60
|
+
header: data
|
|
61
|
+
}, `Follow ${argv.headMode} head from upstream`);
|
|
42
62
|
const parent = await chain.getBlock(data.parentHash);
|
|
43
|
-
if (!parent)
|
|
44
|
-
throw Error(`Cannot find parent', ${data.parentHash}`);
|
|
63
|
+
if (!parent) throw Error(`Cannot find parent', ${data.parentHash}`);
|
|
45
64
|
const registry = await parent.registry;
|
|
46
65
|
const header = registry.createType('Header', data);
|
|
47
66
|
const wasm = await parent.wasm;
|
|
48
|
-
const block = new
|
|
67
|
+
const block = new _chopstickscore.Block(chain, header.number.toNumber(), header.hash.toHex(), parent);
|
|
49
68
|
await chain.setHead(block);
|
|
50
|
-
const calls = [
|
|
51
|
-
|
|
52
|
-
|
|
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
|
+
]);
|
|
53
84
|
}
|
|
54
|
-
calls.push([
|
|
55
|
-
|
|
85
|
+
calls.push([
|
|
86
|
+
'BlockBuilder_finalize_block',
|
|
87
|
+
[]
|
|
88
|
+
]);
|
|
89
|
+
const result = await (0, _chopstickscore.runTask)({
|
|
56
90
|
wasm,
|
|
57
91
|
calls,
|
|
58
92
|
mockSignatureHost: false,
|
|
59
93
|
allowUnresolvedImports: false,
|
|
60
|
-
runtimeLogLevel: argv.runtimeLogLevel || 0
|
|
61
|
-
}, (0,
|
|
94
|
+
runtimeLogLevel: argv.runtimeLogLevel || 0
|
|
95
|
+
}, (0, _chopstickscore.taskHandler)(parent));
|
|
62
96
|
if ('Error' in result) {
|
|
63
97
|
throw new Error(result.Error);
|
|
64
98
|
}
|
|
65
|
-
(0,
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
99
|
+
(0, _chopstickscore.printRuntimeLogs)(result.Call.runtimeLogs);
|
|
100
|
+
} catch (e) {
|
|
68
101
|
logger.error(e, 'Error when processing new head');
|
|
69
102
|
await close();
|
|
70
103
|
process.exit(1);
|
|
@@ -72,4 +105,3 @@ const cli = (y) => {
|
|
|
72
105
|
});
|
|
73
106
|
});
|
|
74
107
|
};
|
|
75
|
-
exports.cli = cli;
|
|
@@ -1,36 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
+
pluginExtendCli: function() {
|
|
13
|
+
return pluginExtendCli;
|
|
14
|
+
},
|
|
15
|
+
pluginHandlers: function() {
|
|
16
|
+
return pluginHandlers;
|
|
7
17
|
}
|
|
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;
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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 = {};
|
|
34
71
|
const plugins = [
|
|
35
72
|
'decode-key',
|
|
36
73
|
'dry-run',
|
|
@@ -42,25 +79,24 @@ const plugins = [
|
|
|
42
79
|
'set-runtime-log-level',
|
|
43
80
|
'set-storage',
|
|
44
81
|
'time-travel',
|
|
45
|
-
'try-runtime'
|
|
82
|
+
'try-runtime'
|
|
46
83
|
];
|
|
47
|
-
(async ()
|
|
48
|
-
for (const plugin of plugins)
|
|
49
|
-
const { rpc, name } = await Promise.resolve(
|
|
84
|
+
(async ()=>{
|
|
85
|
+
for (const plugin of plugins){
|
|
86
|
+
const { rpc, name } = await Promise.resolve(`./${plugin}`).then((p)=>/*#__PURE__*/ _interop_require_wildcard(require(p)));
|
|
50
87
|
if (rpc) {
|
|
51
|
-
const methodName = name ||
|
|
52
|
-
|
|
88
|
+
const methodName = name || _lodash.default.camelCase(plugin);
|
|
89
|
+
pluginHandlers[`dev_${methodName}`] = rpc;
|
|
53
90
|
logger.debug(`Registered plugin ${plugin} RPC`);
|
|
54
91
|
}
|
|
55
92
|
}
|
|
56
93
|
})();
|
|
57
|
-
const pluginExtendCli = async (y)
|
|
58
|
-
for (const plugin of plugins)
|
|
59
|
-
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)));
|
|
60
97
|
if (cli) {
|
|
61
98
|
cli(y);
|
|
62
99
|
logger.debug(`Registered plugin ${plugin} CLI`);
|
|
63
100
|
}
|
|
64
101
|
}
|
|
65
102
|
};
|
|
66
|
-
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;
|