@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,35 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* @example Set head to block 1000000
|
|
14
|
-
* ```ts
|
|
15
|
-
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
16
|
-
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
17
|
-
* await ws.send('dev_setHead', [1000000])
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
const rpc = async (context, [hashOrNumber]) => {
|
|
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 rpc = async (context, [hashOrNumber])=>{
|
|
21
13
|
let block;
|
|
22
14
|
if (typeof hashOrNumber === 'number') {
|
|
23
15
|
const blockNumber = hashOrNumber > 0 ? hashOrNumber : context.chain.head.number + hashOrNumber;
|
|
24
16
|
block = await context.chain.getBlockAt(blockNumber);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
17
|
+
} else {
|
|
27
18
|
block = await context.chain.getBlock(hashOrNumber);
|
|
28
19
|
}
|
|
29
20
|
if (!block) {
|
|
30
|
-
throw new
|
|
21
|
+
throw new _chopstickscore.ResponseError(1, `Block not found ${hashOrNumber}`);
|
|
31
22
|
}
|
|
32
23
|
await context.chain.setHead(block);
|
|
33
24
|
return block.hash;
|
|
34
25
|
};
|
|
35
|
-
exports.rpc = rpc;
|
|
@@ -1,28 +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
|
-
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
18
|
-
* await ws.send('dev_setRuntimeLogLevel', [1])
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
const rpc = async (context, [runtimeLogLevel]) => {
|
|
22
|
-
logger_1.defaultLogger.debug({ runtimeLogLevel }, 'dev_setRuntimeLogLevel');
|
|
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, [runtimeLogLevel])=>{
|
|
14
|
+
_logger.defaultLogger.debug({
|
|
15
|
+
runtimeLogLevel
|
|
16
|
+
}, 'dev_setRuntimeLogLevel');
|
|
23
17
|
if (typeof runtimeLogLevel !== 'number') {
|
|
24
|
-
throw new
|
|
18
|
+
throw new _chopstickscore.ResponseError(1, `Invalid runtimeLogLevel ${runtimeLogLevel}`);
|
|
25
19
|
}
|
|
26
20
|
context.chain.runtimeLogLevel = runtimeLogLevel;
|
|
27
21
|
};
|
|
28
|
-
exports.rpc = rpc;
|
|
@@ -1,42 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
17
|
-
* import { Keyring } from '@polkadot/keyring'
|
|
18
|
-
*
|
|
19
|
-
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
20
|
-
* const keyring = new Keyring({ type: 'ed25519' })
|
|
21
|
-
* const bob = keyring.addFromUri('//Bob')
|
|
22
|
-
*
|
|
23
|
-
* const storage = {
|
|
24
|
-
* System: {
|
|
25
|
-
* Account: [[[bob.address], { data: { free: 100000 }, nonce: 1 }]],
|
|
26
|
-
* },
|
|
27
|
-
* }
|
|
28
|
-
* await ws.send('dev_setStorage', [storage])
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
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)=>{
|
|
32
14
|
const [values, blockHash] = params;
|
|
33
|
-
const hash = await (0,
|
|
34
|
-
throw new
|
|
15
|
+
const hash = await (0, _chopstickscore.setStorage)(context.chain, values, blockHash).catch((error)=>{
|
|
16
|
+
throw new _chopstickscore.ResponseError(1, error.toString());
|
|
35
17
|
});
|
|
36
|
-
|
|
18
|
+
_logger.defaultLogger.debug({
|
|
37
19
|
hash,
|
|
38
|
-
values
|
|
20
|
+
values
|
|
39
21
|
}, 'dev_setStorage');
|
|
40
22
|
return hash;
|
|
41
23
|
};
|
|
42
|
-
exports.rpc = rpc;
|
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
16
|
-
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
17
|
-
* await ws.send('dev_timeTravel', ['Jan 1, 2023'])
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
const rpc = async (context, [date]) => {
|
|
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 rpc = async (context, [date])=>{
|
|
21
13
|
const timestamp = typeof date === 'string' ? Date.parse(date) : date;
|
|
22
|
-
if (Number.isNaN(timestamp))
|
|
23
|
-
|
|
24
|
-
await (0, chopsticks_core_1.timeTravel)(context.chain, timestamp);
|
|
14
|
+
if (Number.isNaN(timestamp)) throw new _chopstickscore.ResponseError(1, 'Invalid date');
|
|
15
|
+
await (0, _chopstickscore.timeTravel)(context.chain, timestamp);
|
|
25
16
|
return timestamp;
|
|
26
17
|
};
|
|
27
|
-
exports.rpc = rpc;
|
|
@@ -1,58 +1,67 @@
|
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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 _clioptions = require("../../cli-options");
|
|
13
|
+
const _generatehtmldiff = require("../../utils/generate-html-diff");
|
|
14
|
+
const _openhtml = require("../../utils/open-html");
|
|
15
|
+
const _context = require("../../context");
|
|
16
|
+
const cli = (y)=>{
|
|
17
|
+
y.command('try-runtime', 'Runs runtime upgrade', (yargs)=>yargs.options({
|
|
18
|
+
..._clioptions.defaultOptions,
|
|
19
|
+
'wasm-override': {
|
|
20
|
+
desc: 'Path to WASM built with feature `try-runtime` enabled',
|
|
21
|
+
string: true,
|
|
22
|
+
required: true
|
|
23
|
+
},
|
|
24
|
+
'output-path': {
|
|
25
|
+
desc: 'File path to print output',
|
|
26
|
+
string: true
|
|
27
|
+
},
|
|
28
|
+
html: {
|
|
29
|
+
desc: 'Generate html with storage diff',
|
|
30
|
+
boolean: true
|
|
31
|
+
},
|
|
32
|
+
open: {
|
|
33
|
+
desc: 'Open generated html',
|
|
34
|
+
boolean: true
|
|
35
|
+
}
|
|
36
|
+
}), async (argv)=>{
|
|
37
|
+
const context = await (0, _context.setupContext)(argv);
|
|
31
38
|
const block = context.chain.head;
|
|
32
39
|
const registry = await block.registry;
|
|
33
40
|
registry.register({
|
|
34
41
|
UpgradeCheckSelect: {
|
|
35
42
|
_enum: {
|
|
36
|
-
None: null
|
|
37
|
-
}
|
|
38
|
-
}
|
|
43
|
+
None: null
|
|
44
|
+
}
|
|
45
|
+
}
|
|
39
46
|
});
|
|
40
47
|
const select_none = registry.createType('UpgradeCheckSelect', 'None');
|
|
41
|
-
const result = await block.call('TryRuntime_on_runtime_upgrade', [
|
|
48
|
+
const result = await block.call('TryRuntime_on_runtime_upgrade', [
|
|
49
|
+
select_none.toHex()
|
|
50
|
+
]);
|
|
42
51
|
if (argv.html) {
|
|
43
|
-
const filePath = await (0,
|
|
52
|
+
const filePath = await (0, _generatehtmldiff.generateHtmlDiffPreviewFile)(block, result.storageDiff, block.hash);
|
|
44
53
|
console.log(`Generated preview ${filePath}`);
|
|
45
54
|
if (argv.open) {
|
|
46
|
-
(0,
|
|
55
|
+
(0, _openhtml.openHtml)(filePath);
|
|
47
56
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
} else if (argv.outputPath) {
|
|
58
|
+
(0, _nodefs.writeFileSync)(argv.outputPath, JSON.stringify(result, null, 2));
|
|
59
|
+
} else {
|
|
60
|
+
console.dir(result, {
|
|
61
|
+
depth: null,
|
|
62
|
+
colors: false
|
|
63
|
+
});
|
|
54
64
|
}
|
|
55
65
|
process.exit(0);
|
|
56
66
|
});
|
|
57
67
|
};
|
|
58
|
-
exports.cli = cli;
|
|
@@ -1,19 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
dryRun: function() {
|
|
13
|
+
return _dryrun.rpc;
|
|
14
|
+
},
|
|
15
|
+
newBlock: function() {
|
|
16
|
+
return _newblock.rpc;
|
|
17
|
+
},
|
|
18
|
+
runBlock: function() {
|
|
19
|
+
return _runblock.rpc;
|
|
20
|
+
},
|
|
21
|
+
setBlockBuildMode: function() {
|
|
22
|
+
return _setblockbuildmode.rpc;
|
|
23
|
+
},
|
|
24
|
+
setHead: function() {
|
|
25
|
+
return _sethead.rpc;
|
|
26
|
+
},
|
|
27
|
+
setRuntimeLogLevel: function() {
|
|
28
|
+
return _setruntimeloglevel.rpc;
|
|
29
|
+
},
|
|
30
|
+
setStorage: function() {
|
|
31
|
+
return _setstorage.rpc;
|
|
32
|
+
},
|
|
33
|
+
timeTravel: function() {
|
|
34
|
+
return _timetravel.rpc;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const _newblock = require("./new-block");
|
|
38
|
+
const _dryrun = require("./dry-run");
|
|
39
|
+
const _setblockbuildmode = require("./set-block-build-mode");
|
|
40
|
+
const _sethead = require("./set-head");
|
|
41
|
+
const _setruntimeloglevel = require("./set-runtime-log-level");
|
|
42
|
+
const _setstorage = require("./set-storage");
|
|
43
|
+
const _timetravel = require("./time-travel");
|
|
44
|
+
const _runblock = require("./run-block");
|
package/dist/cjs/rpc/index.js
CHANGED
|
@@ -1,30 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "handler", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return handler;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
12
|
+
const _plugins = require("../plugins");
|
|
6
13
|
const allHandlers = {
|
|
7
|
-
...
|
|
8
|
-
rpc_methods: async ()
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
..._chopstickscore.substrate,
|
|
15
|
+
rpc_methods: async ()=>Promise.resolve({
|
|
16
|
+
version: 1,
|
|
17
|
+
methods: [
|
|
18
|
+
...Object.keys(allHandlers),
|
|
19
|
+
...Object.keys(_plugins.pluginHandlers)
|
|
20
|
+
]
|
|
21
|
+
})
|
|
12
22
|
};
|
|
13
|
-
const getHandler = (method)
|
|
23
|
+
const getHandler = (method)=>{
|
|
14
24
|
const handler = allHandlers[method];
|
|
15
25
|
if (!handler) {
|
|
16
26
|
// no handler for this method, check if it's a plugin
|
|
17
|
-
return
|
|
27
|
+
return _plugins.pluginHandlers[method];
|
|
18
28
|
}
|
|
19
29
|
return handler;
|
|
20
30
|
};
|
|
21
|
-
const handler = (context)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
exports.handler = handler;
|
|
31
|
+
const handler = (context)=>({ method, params }, subscriptionManager)=>{
|
|
32
|
+
_chopstickscore.logger.trace('Handling %s', method);
|
|
33
|
+
const handler = getHandler(method);
|
|
34
|
+
if (!handler) {
|
|
35
|
+
_chopstickscore.logger.warn('Method not found %s', method);
|
|
36
|
+
throw new _chopstickscore.ResponseError(-32601, `Method not found: ${method}`);
|
|
37
|
+
}
|
|
38
|
+
return handler(context, params, subscriptionManager);
|
|
39
|
+
};
|
package/dist/cjs/schema/index.js
CHANGED
|
@@ -1,60 +1,89 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
.
|
|
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
|
+
configSchema: function() {
|
|
13
|
+
return configSchema;
|
|
14
|
+
},
|
|
15
|
+
fetchConfig: function() {
|
|
16
|
+
return fetchConfig;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
20
|
+
const _nodepath = require("node:path");
|
|
21
|
+
const _nodefs = require("node:fs");
|
|
22
|
+
const _zod = require("zod");
|
|
23
|
+
const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
|
|
24
|
+
const _axios = /*#__PURE__*/ _interop_require_default(require("axios"));
|
|
25
|
+
const _jsyaml = /*#__PURE__*/ _interop_require_default(require("js-yaml"));
|
|
26
|
+
function _interop_require_default(obj) {
|
|
27
|
+
return obj && obj.__esModule ? obj : {
|
|
28
|
+
default: obj
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const configSchema = _zod.z.object({
|
|
32
|
+
port: _zod.z.number().optional(),
|
|
33
|
+
endpoint: _zod.z.string().optional(),
|
|
34
|
+
block: _zod.z.union([
|
|
35
|
+
_zod.z.string().length(66).startsWith('0x'),
|
|
36
|
+
_zod.z.number(),
|
|
37
|
+
_zod.z.null()
|
|
38
|
+
]).optional(),
|
|
39
|
+
'build-block-mode': _zod.z.nativeEnum(_chopstickscore.BuildBlockMode).optional(),
|
|
40
|
+
'import-storage': _zod.z.any().optional(),
|
|
41
|
+
'mock-signature-host': _zod.z.boolean().optional(),
|
|
42
|
+
'max-memory-block-count': _zod.z.number().optional(),
|
|
43
|
+
db: _zod.z.string().optional(),
|
|
44
|
+
'wasm-override': _zod.z.string().optional(),
|
|
45
|
+
genesis: _zod.z.union([
|
|
46
|
+
_zod.z.string(),
|
|
47
|
+
_chopstickscore.genesisSchema
|
|
48
|
+
]).optional(),
|
|
49
|
+
timestamp: _zod.z.number().optional(),
|
|
50
|
+
'registered-types': _zod.z.any().optional(),
|
|
51
|
+
'runtime-log-level': _zod.z.number().min(0).max(5).optional(),
|
|
52
|
+
'offchain-worker': _zod.z.boolean().optional(),
|
|
53
|
+
resume: _zod.z.union([
|
|
54
|
+
_zod.z.string().length(66).startsWith('0x'),
|
|
55
|
+
_zod.z.number(),
|
|
56
|
+
_zod.z.boolean()
|
|
57
|
+
]).optional()
|
|
58
|
+
}).strict();
|
|
33
59
|
const CONFIGS_BASE_URL = 'https://raw.githubusercontent.com/AcalaNetwork/chopsticks/master/configs/';
|
|
34
|
-
const fetchConfig = async (path)
|
|
60
|
+
const fetchConfig = async (path)=>{
|
|
35
61
|
let file;
|
|
36
|
-
if ((0,
|
|
37
|
-
file = await
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
62
|
+
if ((0, _chopstickscore.isUrl)(path)) {
|
|
63
|
+
file = await _axios.default.get(path).then((x)=>x.data);
|
|
64
|
+
} else {
|
|
40
65
|
try {
|
|
41
|
-
file = (0,
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
66
|
+
file = (0, _nodefs.readFileSync)(path, 'utf8');
|
|
67
|
+
} catch (err) {
|
|
68
|
+
if ((0, _nodepath.basename)(path) === path && [
|
|
69
|
+
'',
|
|
70
|
+
'.yml',
|
|
71
|
+
'.yaml',
|
|
72
|
+
'.json'
|
|
73
|
+
].includes((0, _nodepath.extname)(path))) {
|
|
74
|
+
if ((0, _nodepath.extname)(path) === '') {
|
|
46
75
|
path += '.yml';
|
|
47
76
|
}
|
|
48
77
|
const url = CONFIGS_BASE_URL + path;
|
|
49
|
-
|
|
50
|
-
file = await
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
78
|
+
_chopstickscore.defaultLogger.info(`Loading config file ${url}`);
|
|
79
|
+
file = await _axios.default.get(url).then((x)=>x.data);
|
|
80
|
+
} else {
|
|
53
81
|
throw err;
|
|
54
82
|
}
|
|
55
83
|
}
|
|
56
84
|
}
|
|
57
|
-
const config =
|
|
58
|
-
|
|
85
|
+
const config = _jsyaml.default.load(_lodash.default.template(file, {
|
|
86
|
+
variable: 'env'
|
|
87
|
+
})(process.env));
|
|
88
|
+
return configSchema.parse(config);
|
|
59
89
|
};
|
|
60
|
-
exports.fetchConfig = fetchConfig;
|