@acala-network/chopsticks 0.8.0 → 0.8.1
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/lib/cli.js +6 -0
- package/lib/context.js +22 -0
- package/lib/rpc/substrate/author.js +7 -7
- package/lib/rpc/substrate/state.js +17 -0
- package/lib/schema/index.d.ts +7 -4
- package/lib/schema/index.js +1 -0
- package/package.json +2 -2
package/lib/cli.js
CHANGED
|
@@ -41,6 +41,12 @@ const commands = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
|
41
41
|
desc: 'Max memory block count',
|
|
42
42
|
number: true,
|
|
43
43
|
},
|
|
44
|
+
resume: {
|
|
45
|
+
desc: `Resume from the specified block hash or block number in db.
|
|
46
|
+
If true, it will resume from the latest block in db.
|
|
47
|
+
Note this will override the block option`,
|
|
48
|
+
string: true,
|
|
49
|
+
},
|
|
44
50
|
}), async (argv) => {
|
|
45
51
|
await (0, _1.setupWithServer)(argv);
|
|
46
52
|
})
|
package/lib/context.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setupContext = void 0;
|
|
4
4
|
require("./utils/tunnel");
|
|
5
|
+
const entities_1 = require("@acala-network/chopsticks-core/db/entities");
|
|
5
6
|
const override_1 = require("./utils/override");
|
|
6
7
|
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
7
8
|
const setupContext = async (argv, overrideParent = false) => {
|
|
@@ -18,6 +19,27 @@ const setupContext = async (argv, overrideParent = false) => {
|
|
|
18
19
|
offchainWorker: argv['offchain-worker'],
|
|
19
20
|
maxMemoryBlockCount: argv['max-memory-block-count'],
|
|
20
21
|
});
|
|
22
|
+
// load block from db
|
|
23
|
+
if (chain.db) {
|
|
24
|
+
if (argv.resume) {
|
|
25
|
+
const where = {};
|
|
26
|
+
switch (typeof argv.resume) {
|
|
27
|
+
case 'string':
|
|
28
|
+
where.hash = argv.resume;
|
|
29
|
+
break;
|
|
30
|
+
case 'number':
|
|
31
|
+
where.number = argv.resume;
|
|
32
|
+
break;
|
|
33
|
+
default:
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
const blockData = await chain.db.getRepository(entities_1.BlockEntity).findOne({ where, order: { number: 'desc' } });
|
|
37
|
+
if (blockData) {
|
|
38
|
+
const block = await chain.loadBlockFromDB(blockData?.number);
|
|
39
|
+
block && (await chain.setHead(block));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
21
43
|
if (argv.timestamp)
|
|
22
44
|
await (0, chopsticks_core_1.timeTravel)(chain, argv.timestamp);
|
|
23
45
|
let at;
|
|
@@ -39,18 +39,18 @@ const handlers = {
|
|
|
39
39
|
});
|
|
40
40
|
done(id);
|
|
41
41
|
};
|
|
42
|
-
|
|
43
|
-
.submitExtrinsic(extrinsic)
|
|
44
|
-
.then(() => {
|
|
42
|
+
try {
|
|
43
|
+
await context.chain.submitExtrinsic(extrinsic);
|
|
45
44
|
callback({
|
|
46
45
|
Ready: null,
|
|
47
46
|
});
|
|
48
|
-
}
|
|
49
|
-
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
50
49
|
logger.error({ error }, 'ExtrinsicFailed');
|
|
51
|
-
|
|
50
|
+
const code = error.isInvalid ? 1010 : 1011;
|
|
52
51
|
done(id);
|
|
53
|
-
|
|
52
|
+
throw new shared_1.ResponseError(code, error.toString());
|
|
53
|
+
}
|
|
54
54
|
return id;
|
|
55
55
|
},
|
|
56
56
|
author_unwatchExtrinsic: async (_context, [subid], { unsubscribe }) => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chopsticks_core_1 = require("@acala-network/chopsticks-core");
|
|
3
4
|
const shared_1 = require("../shared");
|
|
4
5
|
const logger_1 = require("../../logger");
|
|
5
6
|
const logger = logger_1.defaultLogger.child({ name: 'rpc-state' });
|
|
@@ -78,5 +79,21 @@ const handlers = {
|
|
|
78
79
|
state_unsubscribeStorage: async (_context, [subid], { unsubscribe }) => {
|
|
79
80
|
unsubscribe(subid);
|
|
80
81
|
},
|
|
82
|
+
childstate_getStorage: async (context, [child, key, hash]) => {
|
|
83
|
+
if (!(0, chopsticks_core_1.isPrefixedChildKey)(child)) {
|
|
84
|
+
throw new shared_1.ResponseError(-32000, 'Client error: Invalid child storage key');
|
|
85
|
+
}
|
|
86
|
+
const block = await context.chain.getBlock(hash);
|
|
87
|
+
return block?.get((0, chopsticks_core_1.prefixedChildKey)(child, key));
|
|
88
|
+
},
|
|
89
|
+
childstate_getKeysPaged: async (context, [child, prefix, pageSize, startKey, hash]) => {
|
|
90
|
+
if (!(0, chopsticks_core_1.isPrefixedChildKey)(child)) {
|
|
91
|
+
throw new shared_1.ResponseError(-32000, 'Client error: Invalid child storage key');
|
|
92
|
+
}
|
|
93
|
+
const block = await context.chain.getBlock(hash);
|
|
94
|
+
return block
|
|
95
|
+
?.getKeysPaged({ prefix: (0, chopsticks_core_1.prefixedChildKey)(child, prefix), pageSize, startKey: (0, chopsticks_core_1.prefixedChildKey)(child, startKey) })
|
|
96
|
+
.then((keys) => keys.map(chopsticks_core_1.stripChildPrefix));
|
|
97
|
+
},
|
|
81
98
|
};
|
|
82
99
|
exports.default = handlers;
|
package/lib/schema/index.d.ts
CHANGED
|
@@ -45,12 +45,12 @@ export declare const configSchema: z.ZodObject<{
|
|
|
45
45
|
}>;
|
|
46
46
|
}, "strip", z.ZodTypeAny, {
|
|
47
47
|
name: string;
|
|
48
|
-
id: string;
|
|
49
48
|
properties: {
|
|
50
49
|
ss58Format?: number | undefined;
|
|
51
50
|
tokenDecimals?: number | number[] | undefined;
|
|
52
51
|
tokenSymbol?: string | string[] | undefined;
|
|
53
52
|
};
|
|
53
|
+
id: string;
|
|
54
54
|
genesis: {
|
|
55
55
|
raw: {
|
|
56
56
|
top: Record<string, string>;
|
|
@@ -58,12 +58,12 @@ export declare const configSchema: z.ZodObject<{
|
|
|
58
58
|
};
|
|
59
59
|
}, {
|
|
60
60
|
name: string;
|
|
61
|
-
id: string;
|
|
62
61
|
properties: {
|
|
63
62
|
ss58Format?: number | undefined;
|
|
64
63
|
tokenDecimals?: number | number[] | undefined;
|
|
65
64
|
tokenSymbol?: string | string[] | undefined;
|
|
66
65
|
};
|
|
66
|
+
id: string;
|
|
67
67
|
genesis: {
|
|
68
68
|
raw: {
|
|
69
69
|
top: Record<string, string>;
|
|
@@ -74,6 +74,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
74
74
|
'registered-types': z.ZodOptional<z.ZodAny>;
|
|
75
75
|
'runtime-log-level': z.ZodOptional<z.ZodNumber>;
|
|
76
76
|
'offchain-worker': z.ZodOptional<z.ZodBoolean>;
|
|
77
|
+
resume: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
77
78
|
}, "strict", z.ZodTypeAny, {
|
|
78
79
|
port?: number | undefined;
|
|
79
80
|
endpoint?: string | undefined;
|
|
@@ -86,12 +87,12 @@ export declare const configSchema: z.ZodObject<{
|
|
|
86
87
|
'wasm-override'?: string | undefined;
|
|
87
88
|
genesis?: string | {
|
|
88
89
|
name: string;
|
|
89
|
-
id: string;
|
|
90
90
|
properties: {
|
|
91
91
|
ss58Format?: number | undefined;
|
|
92
92
|
tokenDecimals?: number | number[] | undefined;
|
|
93
93
|
tokenSymbol?: string | string[] | undefined;
|
|
94
94
|
};
|
|
95
|
+
id: string;
|
|
95
96
|
genesis: {
|
|
96
97
|
raw: {
|
|
97
98
|
top: Record<string, string>;
|
|
@@ -102,6 +103,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
102
103
|
'registered-types'?: any;
|
|
103
104
|
'runtime-log-level'?: number | undefined;
|
|
104
105
|
'offchain-worker'?: boolean | undefined;
|
|
106
|
+
resume?: string | number | boolean | undefined;
|
|
105
107
|
}, {
|
|
106
108
|
port?: number | undefined;
|
|
107
109
|
endpoint?: string | undefined;
|
|
@@ -114,12 +116,12 @@ export declare const configSchema: z.ZodObject<{
|
|
|
114
116
|
'wasm-override'?: string | undefined;
|
|
115
117
|
genesis?: string | {
|
|
116
118
|
name: string;
|
|
117
|
-
id: string;
|
|
118
119
|
properties: {
|
|
119
120
|
ss58Format?: number | undefined;
|
|
120
121
|
tokenDecimals?: number | number[] | undefined;
|
|
121
122
|
tokenSymbol?: string | string[] | undefined;
|
|
122
123
|
};
|
|
124
|
+
id: string;
|
|
123
125
|
genesis: {
|
|
124
126
|
raw: {
|
|
125
127
|
top: Record<string, string>;
|
|
@@ -130,6 +132,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
130
132
|
'registered-types'?: any;
|
|
131
133
|
'runtime-log-level'?: number | undefined;
|
|
132
134
|
'offchain-worker'?: boolean | undefined;
|
|
135
|
+
resume?: string | number | boolean | undefined;
|
|
133
136
|
}>;
|
|
134
137
|
export type Config = z.infer<typeof configSchema>;
|
|
135
138
|
export declare const fetchConfig: (path: string) => Promise<Config>;
|
package/lib/schema/index.js
CHANGED
|
@@ -27,6 +27,7 @@ exports.configSchema = zod_1.z
|
|
|
27
27
|
'registered-types': zod_1.z.any().optional(),
|
|
28
28
|
'runtime-log-level': zod_1.z.number().min(0).max(5).optional(),
|
|
29
29
|
'offchain-worker': zod_1.z.boolean().optional(),
|
|
30
|
+
resume: zod_1.z.union([zod_1.z.string().length(66).startsWith('0x'), zod_1.z.number(), zod_1.z.boolean()]).optional(),
|
|
30
31
|
})
|
|
31
32
|
.strict();
|
|
32
33
|
const CONFIGS_BASE_URL = 'https://raw.githubusercontent.com/AcalaNetwork/chopsticks/master/configs/';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"author": "Bryan Chen <xlchen1291@gmail.com>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"bin": "./chopsticks.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dev:moonbeam": "cd ../..; ts-node-dev --transpile-only --inspect -r tsconfig-paths/register --notify=false packages/chopsticks/src/cli.ts -- --config=configs/moonbeam.yml"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@acala-network/chopsticks-core": "0.8.
|
|
19
|
+
"@acala-network/chopsticks-core": "0.8.1",
|
|
20
20
|
"@pnpm/npm-conf": "^2.2.2",
|
|
21
21
|
"@polkadot/api": "^10.9.1",
|
|
22
22
|
"axios": "^1.5.0",
|