@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,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.js");
|
|
27
|
+
const _generatehtmldiff = require("../../utils/generate-html-diff.js");
|
|
28
|
+
const _openhtml = require("../../utils/open-html.js");
|
|
29
|
+
const _context = require("../../context.js");
|
|
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.js");
|
|
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;
|
|
@@ -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.js");
|
|
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.js");
|
|
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;
|