@acala-network/chopsticks 0.8.0-6 → 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 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;
@@ -1,41 +1,38 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.rpc = exports.name = void 0;
7
- const zod_1 = __importDefault(require("zod"));
4
+ const zod_1 = require("zod");
8
5
  const shared_1 = require("../../rpc/shared");
9
6
  const decoder_1 = require("../../utils/decoder");
10
7
  const generate_html_diff_1 = require("../../utils/generate-html-diff");
11
- const zHex = zod_1.default.custom((val) => /^0x\w+$/.test(val));
12
- const zHash = zod_1.default.string().length(66).and(zHex);
13
- const zParaId = zod_1.default.string().regex(/^\d+$/).transform(Number);
14
- const schema = zod_1.default.object({
15
- raw: zod_1.default.boolean().optional(),
16
- html: zod_1.default.boolean().optional(),
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(),
17
14
  extrinsic: zHex
18
- .or(zod_1.default.object({
15
+ .or(zod_1.z.object({
19
16
  call: zHex,
20
17
  address: zHex,
21
18
  }))
22
19
  .optional(),
23
- hrmp: zod_1.default
24
- .record(zParaId, zod_1.default
25
- .array(zod_1.default.object({
26
- sentAt: zod_1.default.number(),
20
+ hrmp: zod_1.z
21
+ .record(zParaId, zod_1.z
22
+ .array(zod_1.z.object({
23
+ sentAt: zod_1.z.number(),
27
24
  data: zHex,
28
25
  }))
29
26
  .min(1))
30
27
  .optional(),
31
- dmp: zod_1.default
32
- .array(zod_1.default.object({
33
- sentAt: zod_1.default.number(),
28
+ dmp: zod_1.z
29
+ .array(zod_1.z.object({
30
+ sentAt: zod_1.z.number(),
34
31
  msg: zHex,
35
32
  }))
36
33
  .min(1)
37
34
  .optional(),
38
- ump: zod_1.default.record(zParaId, zod_1.default.array(zHex).min(1)).optional(),
35
+ ump: zod_1.z.record(zParaId, zod_1.z.array(zHex).min(1)).optional(),
39
36
  at: zHash.optional(),
40
37
  });
41
38
  // custom rpc name (optional). e.g. dryRun will be called as dev_dryRun
@@ -0,0 +1,2 @@
1
+ import { Handler } from '../../rpc/shared';
2
+ export declare const rpc: Handler;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rpc = void 0;
4
+ const shared_1 = require("../../rpc/shared");
5
+ const logger_1 = require("../../logger");
6
+ const rpc = async (context, [runtimeLogLevel]) => {
7
+ logger_1.defaultLogger.debug({ runtimeLogLevel }, 'dev_setRuntimeLogLevel');
8
+ if (typeof runtimeLogLevel !== 'number') {
9
+ throw new shared_1.ResponseError(1, `Invalid runtimeLogLevel ${runtimeLogLevel}`);
10
+ }
11
+ context.chain.runtimeLogLevel = runtimeLogLevel;
12
+ };
13
+ exports.rpc = rpc;
@@ -39,18 +39,18 @@ const handlers = {
39
39
  });
40
40
  done(id);
41
41
  };
42
- context.chain
43
- .submitExtrinsic(extrinsic)
44
- .then(() => {
42
+ try {
43
+ await context.chain.submitExtrinsic(extrinsic);
45
44
  callback({
46
45
  Ready: null,
47
46
  });
48
- })
49
- .catch((error) => {
47
+ }
48
+ catch (error) {
50
49
  logger.error({ error }, 'ExtrinsicFailed');
51
- callback(error?.toJSON() ?? error);
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;
@@ -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>;
@@ -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.0-6",
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.0-6",
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",
@@ -57,6 +57,5 @@
57
57
  "default": "./lib/*.js"
58
58
  },
59
59
  "./package.json": "./package.json"
60
- },
61
- "stableVersion": "0.7.3"
60
+ }
62
61
  }