@acala-network/chopsticks 0.9.1-2 → 0.9.1-4
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 +94 -65
- 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 +102 -48
- 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/__snapshots__/index.test.ts.snap +16745 -0
- 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 +49 -64
- package/dist/esm/context.js +22 -26
- package/dist/esm/index.js +2 -2
- package/dist/esm/plugins/decode-key/index.js +11 -14
- package/dist/esm/plugins/dry-run/cli.js +35 -36
- package/dist/esm/plugins/dry-run/dry-run-extrinsic.js +22 -12
- package/dist/esm/plugins/dry-run/dry-run-preimage.js +77 -29
- package/dist/esm/plugins/dry-run/index.js +2 -2
- package/dist/esm/plugins/dry-run/rpc.js +16 -26
- package/dist/esm/plugins/follow-chain/index.js +56 -32
- package/dist/esm/plugins/index.js +9 -7
- package/dist/esm/plugins/new-block/index.js +9 -10
- package/dist/esm/plugins/run-block/__snapshots__/index.test.ts.snap +16745 -0
- package/dist/esm/plugins/run-block/index.js +101 -69
- package/dist/esm/plugins/set-block-build-mode/index.js +5 -4
- package/dist/esm/plugins/set-head/index.js +2 -4
- package/dist/esm/plugins/set-runtime-log-level/index.js +5 -4
- package/dist/esm/plugins/set-storage/index.js +4 -5
- package/dist/esm/plugins/time-travel/index.js +2 -4
- package/dist/esm/plugins/try-runtime/index.js +37 -34
- package/dist/esm/plugins/types.js +8 -8
- package/dist/esm/rpc/index.js +19 -16
- package/dist/esm/schema/index.js +31 -18
- package/dist/esm/server.js +71 -53
- package/dist/esm/setup-with-server.js +6 -6
- package/dist/esm/types.js +13 -2
- package/dist/esm/utils/decoder.js +12 -4
- package/dist/esm/utils/generate-html-diff.js +11 -7
- package/dist/esm/utils/index.js +4 -4
- package/dist/esm/utils/open-html.js +1 -1
- package/dist/esm/utils/override.js +12 -14
- package/dist/esm/utils/tunnel.js +1 -8
- package/dist/types/context.d.ts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/plugins/dry-run/dry-run-extrinsic.d.ts +1 -1
- package/dist/types/plugins/dry-run/dry-run-preimage.d.ts +1 -1
- package/dist/types/plugins/dry-run/index.d.ts +2 -2
- package/dist/types/plugins/run-block/index.d.ts +1 -1
- package/dist/types/plugins/types.d.ts +11 -11
- package/dist/types/setup-with-server.d.ts +1 -1
- package/dist/types/types.d.ts +2 -2
- package/dist/types/utils/index.d.ts +4 -4
- package/package.json +17 -21
- package/dist/esm/package.json +0 -1
- /package/{chopsticks.js → chopsticks.cjs} +0 -0
|
@@ -1,46 +1,51 @@
|
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 _clioptions = require("../../cli-options.js");
|
|
12
|
+
const _dryrunextrinsic = require("./dry-run-extrinsic.js");
|
|
13
|
+
const _dryrunpreimage = require("./dry-run-preimage.js");
|
|
14
|
+
const cli = (y)=>{
|
|
15
|
+
y.command('dry-run', 'Dry run an extrinsic', (yargs)=>yargs.options({
|
|
16
|
+
..._clioptions.defaultOptions,
|
|
17
|
+
..._clioptions.mockOptions,
|
|
18
|
+
extrinsic: {
|
|
19
|
+
desc: 'Extrinsic or call to dry run. If you pass call here then address is required to fake signature',
|
|
20
|
+
string: true
|
|
21
|
+
},
|
|
22
|
+
address: {
|
|
23
|
+
desc: 'Address to fake sign extrinsic',
|
|
24
|
+
string: true
|
|
25
|
+
},
|
|
26
|
+
preimage: {
|
|
27
|
+
desc: 'Preimage to dry run',
|
|
28
|
+
string: true
|
|
29
|
+
},
|
|
30
|
+
at: {
|
|
31
|
+
desc: 'Block hash to dry run',
|
|
32
|
+
string: true
|
|
33
|
+
},
|
|
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)=>{
|
|
38
45
|
if (argv.preimage) {
|
|
39
|
-
await (0,
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
await (0, dry_run_extrinsic_1.dryRunExtrinsic)(argv);
|
|
46
|
+
await (0, _dryrunpreimage.dryRunPreimage)(argv);
|
|
47
|
+
} else {
|
|
48
|
+
await (0, _dryrunextrinsic.dryRunExtrinsic)(argv);
|
|
43
49
|
}
|
|
44
50
|
});
|
|
45
51
|
};
|
|
46
|
-
exports.cli = cli;
|
|
@@ -1,33 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "dryRunExtrinsic", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return dryRunExtrinsic;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _utilcrypto = require("@polkadot/util-crypto");
|
|
12
|
+
const _nodefs = require("node:fs");
|
|
13
|
+
const _logger = require("../../logger.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 dryRunExtrinsic = async (argv)=>{
|
|
18
|
+
const context = await (0, _context.setupContext)(argv);
|
|
19
|
+
const input = argv['address'] ? {
|
|
20
|
+
call: argv['extrinsic'],
|
|
21
|
+
address: argv['address']
|
|
22
|
+
} : argv['extrinsic'];
|
|
13
23
|
const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(input, argv['at']);
|
|
14
24
|
if (outcome.isErr) {
|
|
15
25
|
throw new Error(outcome.asErr.toString());
|
|
16
26
|
}
|
|
17
|
-
|
|
27
|
+
_logger.defaultLogger.info(outcome.toHuman(), 'dry_run_outcome');
|
|
18
28
|
if (argv['html']) {
|
|
19
|
-
const filePath = await (0,
|
|
29
|
+
const filePath = await (0, _generatehtmldiff.generateHtmlDiffPreviewFile)(context.chain.head, storageDiff, (0, _utilcrypto.blake2AsHex)(argv['extrinsic'], 256));
|
|
20
30
|
console.log(`Generated preview ${filePath}`);
|
|
21
31
|
if (argv['open']) {
|
|
22
|
-
(0,
|
|
32
|
+
(0, _openhtml.openHtml)(filePath);
|
|
23
33
|
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
} else if (argv['output-path']) {
|
|
35
|
+
(0, _nodefs.writeFileSync)(argv['output-path'], JSON.stringify({
|
|
36
|
+
outcome: outcome.toHuman(),
|
|
37
|
+
storageDiff
|
|
38
|
+
}, null, 2));
|
|
39
|
+
} else {
|
|
40
|
+
console.dir({
|
|
41
|
+
outcome: outcome.toHuman(),
|
|
42
|
+
storageDiff
|
|
43
|
+
}, {
|
|
44
|
+
depth: null,
|
|
45
|
+
colors: false
|
|
46
|
+
});
|
|
30
47
|
}
|
|
31
48
|
process.exit(0);
|
|
32
49
|
};
|
|
33
|
-
exports.dryRunExtrinsic = dryRunExtrinsic;
|
|
@@ -1,40 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "dryRunPreimage", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return dryRunPreimage;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _utilcrypto = require("@polkadot/util-crypto");
|
|
12
|
+
const _util = require("@polkadot/util");
|
|
13
|
+
const _logger = require("../../logger.js");
|
|
14
|
+
const _generatehtmldiff = require("../../utils/generate-html-diff.js");
|
|
15
|
+
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
16
|
+
const _openhtml = require("../../utils/open-html.js");
|
|
17
|
+
const _context = require("../../context.js");
|
|
18
|
+
const dryRunPreimage = async (argv)=>{
|
|
19
|
+
const context = await (0, _context.setupContext)(argv);
|
|
13
20
|
const extrinsic = argv['preimage'];
|
|
14
21
|
const block = context.chain.head;
|
|
15
22
|
const registry = await block.registry;
|
|
16
|
-
const header = await (0,
|
|
17
|
-
const data = (0,
|
|
18
|
-
const hash = (0,
|
|
19
|
-
await (0,
|
|
23
|
+
const header = await (0, _chopstickscore.newHeader)(block);
|
|
24
|
+
const data = (0, _util.hexToU8a)(extrinsic);
|
|
25
|
+
const hash = (0, _utilcrypto.blake2AsHex)(data, 256);
|
|
26
|
+
await (0, _chopstickscore.setStorage)(context.chain, {
|
|
20
27
|
Preimage: {
|
|
21
|
-
PreimageFor: [
|
|
28
|
+
PreimageFor: [
|
|
29
|
+
[
|
|
30
|
+
[
|
|
31
|
+
[
|
|
32
|
+
hash,
|
|
33
|
+
data.byteLength
|
|
34
|
+
]
|
|
35
|
+
],
|
|
36
|
+
extrinsic
|
|
37
|
+
]
|
|
38
|
+
],
|
|
22
39
|
StatusFor: [
|
|
23
40
|
[
|
|
24
|
-
[
|
|
41
|
+
[
|
|
42
|
+
hash
|
|
43
|
+
],
|
|
25
44
|
{
|
|
26
45
|
Requested: {
|
|
27
46
|
count: 1,
|
|
28
|
-
len: data.byteLength
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
]
|
|
32
|
-
]
|
|
47
|
+
len: data.byteLength
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
]
|
|
33
52
|
},
|
|
34
53
|
Scheduler: {
|
|
35
54
|
Agenda: [
|
|
36
55
|
[
|
|
37
|
-
[
|
|
56
|
+
[
|
|
57
|
+
block.number + 1
|
|
58
|
+
],
|
|
38
59
|
[
|
|
39
60
|
{
|
|
40
61
|
maybeId: '0x64656d6f637261633a0000000000000000000000000000000000000000000000',
|
|
@@ -42,55 +63,88 @@ const dryRunPreimage = async (argv) => {
|
|
|
42
63
|
call: {
|
|
43
64
|
Lookup: {
|
|
44
65
|
hash: hash,
|
|
45
|
-
len: data.byteLength
|
|
46
|
-
}
|
|
66
|
+
len: data.byteLength
|
|
67
|
+
}
|
|
47
68
|
},
|
|
48
|
-
origin: {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
69
|
+
origin: {
|
|
70
|
+
system: {
|
|
71
|
+
Root: null
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
]
|
|
52
77
|
],
|
|
53
|
-
Lookup: [
|
|
54
|
-
|
|
78
|
+
Lookup: [
|
|
79
|
+
[
|
|
80
|
+
[
|
|
81
|
+
'0x64656d6f637261633a0000000000000000000000000000000000000000000000'
|
|
82
|
+
],
|
|
83
|
+
[
|
|
84
|
+
block.number + 1,
|
|
85
|
+
0
|
|
86
|
+
]
|
|
87
|
+
]
|
|
88
|
+
]
|
|
89
|
+
}
|
|
55
90
|
});
|
|
56
|
-
const calls = [
|
|
57
|
-
|
|
58
|
-
|
|
91
|
+
const calls = [
|
|
92
|
+
[
|
|
93
|
+
'Core_initialize_block',
|
|
94
|
+
[
|
|
95
|
+
header.toHex()
|
|
96
|
+
]
|
|
97
|
+
]
|
|
98
|
+
];
|
|
99
|
+
for (const inherent of (await block.chain.getInherents())){
|
|
100
|
+
calls.push([
|
|
101
|
+
'BlockBuilder_apply_extrinsic',
|
|
102
|
+
[
|
|
103
|
+
inherent
|
|
104
|
+
]
|
|
105
|
+
]);
|
|
59
106
|
}
|
|
60
|
-
calls.push([
|
|
61
|
-
|
|
62
|
-
|
|
107
|
+
calls.push([
|
|
108
|
+
'BlockBuilder_finalize_block',
|
|
109
|
+
[]
|
|
110
|
+
]);
|
|
111
|
+
_logger.defaultLogger.info({
|
|
112
|
+
preimage: registry.createType('Call', data).toHuman()
|
|
113
|
+
}, 'Dry run preimage');
|
|
114
|
+
const result = await (0, _chopstickscore.runTask)({
|
|
63
115
|
wasm: await block.wasm,
|
|
64
116
|
calls,
|
|
65
117
|
mockSignatureHost: false,
|
|
66
118
|
allowUnresolvedImports: false,
|
|
67
|
-
runtimeLogLevel: argv['runtime-log-level'] || 0
|
|
68
|
-
}, (0,
|
|
119
|
+
runtimeLogLevel: argv['runtime-log-level'] || 0
|
|
120
|
+
}, (0, _chopstickscore.taskHandler)(block));
|
|
69
121
|
if ('Error' in result) {
|
|
70
122
|
throw new Error(result.Error);
|
|
71
123
|
}
|
|
72
|
-
(0,
|
|
73
|
-
const filePath = await (0,
|
|
124
|
+
(0, _chopstickscore.printRuntimeLogs)(result.Call.runtimeLogs);
|
|
125
|
+
const filePath = await (0, _generatehtmldiff.generateHtmlDiffPreviewFile)(block, result.Call.storageDiff, hash);
|
|
74
126
|
console.log(`Generated preview ${filePath}`);
|
|
75
127
|
if (argv['open']) {
|
|
76
|
-
(0,
|
|
128
|
+
(0, _openhtml.openHtml)(filePath);
|
|
77
129
|
}
|
|
78
130
|
// if dry-run preimage has extrinsic arguments then dry-run extrinsic
|
|
79
|
-
// this is
|
|
131
|
+
// this is useful to test something after preimage is applied
|
|
80
132
|
if (argv['extrinsic']) {
|
|
81
133
|
await context.chain.newBlock();
|
|
82
|
-
const input = argv['address'] ? {
|
|
134
|
+
const input = argv['address'] ? {
|
|
135
|
+
call: argv['extrinsic'],
|
|
136
|
+
address: argv['address']
|
|
137
|
+
} : argv['extrinsic'];
|
|
83
138
|
const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(input);
|
|
84
139
|
if (outcome.isErr) {
|
|
85
140
|
throw new Error(outcome.asErr.toString());
|
|
86
141
|
}
|
|
87
|
-
|
|
88
|
-
const filePath = await (0,
|
|
142
|
+
_logger.defaultLogger.info(outcome.toHuman(), 'dry_run_outcome');
|
|
143
|
+
const filePath = await (0, _generatehtmldiff.generateHtmlDiffPreviewFile)(context.chain.head, storageDiff, (0, _utilcrypto.blake2AsHex)(argv['extrinsic'], 256));
|
|
89
144
|
console.log(`Generated preview ${filePath}`);
|
|
90
145
|
if (argv['open']) {
|
|
91
|
-
(0,
|
|
146
|
+
(0, _openhtml.openHtml)(filePath);
|
|
92
147
|
}
|
|
93
148
|
}
|
|
94
149
|
process.exit(0);
|
|
95
150
|
};
|
|
96
|
-
exports.dryRunPreimage = dryRunPreimage;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./cli.js"), exports);
|
|
6
|
+
_export_star(require("./rpc.js"), exports);
|
|
7
|
+
function _export_star(from, to) {
|
|
8
|
+
Object.keys(from).forEach(function(k) {
|
|
9
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
10
|
+
Object.defineProperty(to, k, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function() {
|
|
13
|
+
return from[k];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return from;
|
|
19
|
+
}
|
|
@@ -1,79 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
6
|
-
const decoder_1 = require("../../utils/decoder");
|
|
7
|
-
const generate_html_diff_1 = require("../../utils/generate-html-diff");
|
|
8
|
-
const zHex = zod_1.z.custom((val) => /^0x\w+$/.test(val));
|
|
9
|
-
const zHash = zod_1.z.string().length(66).and(zHex);
|
|
10
|
-
const zParaId = zod_1.z.string().regex(/^\d+$/).transform(Number);
|
|
11
|
-
const schema = zod_1.z.object({
|
|
12
|
-
raw: zod_1.z.boolean().optional(),
|
|
13
|
-
html: zod_1.z.boolean().optional(),
|
|
14
|
-
extrinsic: zHex
|
|
15
|
-
.or(zod_1.z.object({
|
|
16
|
-
call: zHex,
|
|
17
|
-
address: zHex,
|
|
18
|
-
}))
|
|
19
|
-
.optional(),
|
|
20
|
-
hrmp: zod_1.z
|
|
21
|
-
.record(zParaId, zod_1.z
|
|
22
|
-
.array(zod_1.z.object({
|
|
23
|
-
sentAt: zod_1.z.number(),
|
|
24
|
-
data: zHex,
|
|
25
|
-
}))
|
|
26
|
-
.min(1))
|
|
27
|
-
.optional(),
|
|
28
|
-
dmp: zod_1.z
|
|
29
|
-
.array(zod_1.z.object({
|
|
30
|
-
sentAt: zod_1.z.number(),
|
|
31
|
-
msg: zHex,
|
|
32
|
-
}))
|
|
33
|
-
.min(1)
|
|
34
|
-
.optional(),
|
|
35
|
-
ump: zod_1.z.record(zParaId, zod_1.z.array(zHex).min(1)).optional(),
|
|
36
|
-
at: zHash.optional(),
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
37
4
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
* @param context - The context object of the rpc handler
|
|
49
|
-
* @param params - The parameters of the rpc handler
|
|
50
|
-
*
|
|
51
|
-
* @example Dry run an dmp
|
|
52
|
-
* ```ts
|
|
53
|
-
* import { WsProvider } from '@polkadot/rpc-provider'
|
|
54
|
-
* const ws = new WsProvider(`ws://localhost:8000`)
|
|
55
|
-
* const params = [
|
|
56
|
-
{
|
|
57
|
-
raw: false,
|
|
58
|
-
dmp: [
|
|
59
|
-
// https://acala.subscan.io/xcm_message/polkadot-2ab22918c567455af3563989d852f307f4cc1250
|
|
60
|
-
{
|
|
61
|
-
sentAt: 14471353,
|
|
62
|
-
msg: '0x02100104000100000b00280b9bba030a13000100000b00280b9bba03010300286bee0d0100040001010070c53d8e216f9c0f2e3b11c53f5f4bf3e078b995d5f0ed590f889f41e20e6531',
|
|
63
|
-
},
|
|
64
|
-
],
|
|
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
|
+
name: function() {
|
|
13
|
+
return name;
|
|
65
14
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
15
|
+
rpc: function() {
|
|
16
|
+
return rpc;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _zod = require("zod");
|
|
20
|
+
const _chopstickscore = require("@acala-network/chopsticks-core");
|
|
21
|
+
const _decoder = require("../../utils/decoder.js");
|
|
22
|
+
const _generatehtmldiff = require("../../utils/generate-html-diff.js");
|
|
23
|
+
const zHex = _zod.z.custom((val)=>/^0x\w+$/.test(val));
|
|
24
|
+
const zHash = _zod.z.string().length(66).and(zHex);
|
|
25
|
+
const zParaId = _zod.z.string().regex(/^\d+$/).transform(Number);
|
|
26
|
+
const schema = _zod.z.object({
|
|
27
|
+
raw: _zod.z.boolean().optional(),
|
|
28
|
+
html: _zod.z.boolean().optional(),
|
|
29
|
+
extrinsic: zHex.or(_zod.z.object({
|
|
30
|
+
call: zHex,
|
|
31
|
+
address: zHex
|
|
32
|
+
})).optional(),
|
|
33
|
+
hrmp: _zod.z.record(zParaId, _zod.z.array(_zod.z.object({
|
|
34
|
+
sentAt: _zod.z.number(),
|
|
35
|
+
data: zHex
|
|
36
|
+
})).min(1)).optional(),
|
|
37
|
+
dmp: _zod.z.array(_zod.z.object({
|
|
38
|
+
sentAt: _zod.z.number(),
|
|
39
|
+
msg: zHex
|
|
40
|
+
})).min(1).optional(),
|
|
41
|
+
ump: _zod.z.record(zParaId, _zod.z.array(zHex).min(1)).optional(),
|
|
42
|
+
at: zHash.optional()
|
|
43
|
+
});
|
|
44
|
+
const name = 'dryRun';
|
|
45
|
+
const rpc = async (context, [params])=>{
|
|
71
46
|
const { html, extrinsic, hrmp, dmp, ump, raw, at } = schema.parse(params);
|
|
72
|
-
const dryRun = async ()
|
|
47
|
+
const dryRun = async ()=>{
|
|
73
48
|
if (extrinsic) {
|
|
74
49
|
const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(extrinsic, at);
|
|
75
50
|
if (outcome.isErr) {
|
|
76
|
-
throw new
|
|
51
|
+
throw new _chopstickscore.ResponseError(1, outcome.asErr.toString());
|
|
77
52
|
}
|
|
78
53
|
return storageDiff;
|
|
79
54
|
}
|
|
@@ -86,20 +61,19 @@ const rpc = async (context, [params]) => {
|
|
|
86
61
|
if (ump) {
|
|
87
62
|
return context.chain.dryRunUmp(ump, at);
|
|
88
63
|
}
|
|
89
|
-
throw new
|
|
64
|
+
throw new _chopstickscore.ResponseError(1, 'No extrinsic to run');
|
|
90
65
|
};
|
|
91
66
|
const storageDiff = await dryRun();
|
|
92
67
|
if (html) {
|
|
93
|
-
return (0,
|
|
68
|
+
return (0, _generatehtmldiff.generateHtmlDiff)(context.chain.head, storageDiff);
|
|
94
69
|
}
|
|
95
70
|
if (raw) {
|
|
96
71
|
return storageDiff;
|
|
97
72
|
}
|
|
98
|
-
const { oldState, newState, delta } = await (0,
|
|
73
|
+
const { oldState, newState, delta } = await (0, _decoder.decodeStorageDiff)(context.chain.head, storageDiff);
|
|
99
74
|
return {
|
|
100
75
|
old: oldState,
|
|
101
76
|
new: newState,
|
|
102
|
-
delta
|
|
77
|
+
delta
|
|
103
78
|
};
|
|
104
79
|
};
|
|
105
|
-
exports.rpc = rpc;
|