@acala-network/chopsticks 0.8.5-6 → 0.9.0

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.
@@ -1,12 +1,8 @@
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 = exports.cli = void 0;
7
4
  const node_fs_1 = require("node:fs");
8
5
  const zod_1 = require("zod");
9
- const lodash_1 = __importDefault(require("lodash"));
10
6
  const chopsticks_core_1 = require("@acala-network/chopsticks-core");
11
7
  const cli_options_1 = require("../../cli-options");
12
8
  const generate_html_diff_1 = require("../../utils/generate-html-diff");
@@ -97,6 +93,7 @@ const rpc = async ({ chain }, [params]) => {
97
93
  const registry = await parentBlock.registry;
98
94
  const header = registry.createType('Header', block.header);
99
95
  const wasm = await parentBlock.wasm;
96
+ const meta = await parentBlock.meta;
100
97
  const blockNumber = parentBlock.number + 1;
101
98
  const hash = `0x${Math.round(Math.random() * 100000000)
102
99
  .toString(16)
@@ -109,6 +106,8 @@ const rpc = async ({ chain }, [params]) => {
109
106
  const resp = {
110
107
  phases: [],
111
108
  };
109
+ // exclude system events because it can be stupidly large and redudant
110
+ const systemEventsKey = (0, chopsticks_core_1.compactHex)(meta.query.system.events());
112
111
  const run = async (fn, args) => {
113
112
  const result = await (0, chopsticks_core_1.runTask)({
114
113
  wasm,
@@ -120,23 +119,21 @@ const rpc = async ({ chain }, [params]) => {
120
119
  if ('Error' in result) {
121
120
  throw new Error(result.Error);
122
121
  }
123
- const resp = {};
122
+ const resp = { storageDiff: [] };
124
123
  const raw = result.Call.storageDiff;
125
124
  newBlock.pushStorageLayer().setAll(raw);
126
- if (includeRawStorage) {
127
- resp.raw = raw;
128
- }
129
- if (includeParsed) {
130
- const meta = await newBlock.meta;
131
- const parsed = {};
132
- for (const [key, value] of raw) {
133
- lodash_1.default.merge(parsed, (0, chopsticks_core_1.decodeKeyValue)(meta, newBlock, key, value, false));
125
+ for (const [key, value] of raw) {
126
+ if (key === systemEventsKey) {
127
+ continue;
128
+ }
129
+ const obj = {};
130
+ if (includeRawStorage) {
131
+ obj.raw = { key, value };
134
132
  }
135
- // clear events because it can be stupidly large and redudant
136
- if (parsed['system']?.['events']) {
137
- delete parsed['system']['events'];
133
+ if (includeParsed) {
134
+ obj.parsed = (0, chopsticks_core_1.decodeKeyValue)(await newBlock.meta, newBlock, key, value, false);
138
135
  }
139
- resp.parsed = parsed;
136
+ resp.storageDiff.push(obj);
140
137
  }
141
138
  resp.logs = result.Call.runtimeLogs;
142
139
  return resp;
@@ -1,7 +1,6 @@
1
1
  import { writeFileSync } from 'node:fs';
2
2
  import { z } from 'zod';
3
- import _ from 'lodash';
4
- import { Block, decodeKeyValue, printRuntimeLogs, runTask, taskHandler } from '@acala-network/chopsticks-core';
3
+ import { Block, compactHex, decodeKeyValue, printRuntimeLogs, runTask, taskHandler, } from '@acala-network/chopsticks-core';
5
4
  import { defaultOptions, mockOptions } from '../../cli-options';
6
5
  import { generateHtmlDiffPreviewFile } from '../../utils/generate-html-diff';
7
6
  import { openHtml } from '../../utils/open-html';
@@ -90,6 +89,7 @@ export const rpc = async ({ chain }, [params]) => {
90
89
  const registry = await parentBlock.registry;
91
90
  const header = registry.createType('Header', block.header);
92
91
  const wasm = await parentBlock.wasm;
92
+ const meta = await parentBlock.meta;
93
93
  const blockNumber = parentBlock.number + 1;
94
94
  const hash = `0x${Math.round(Math.random() * 100000000)
95
95
  .toString(16)
@@ -102,6 +102,8 @@ export const rpc = async ({ chain }, [params]) => {
102
102
  const resp = {
103
103
  phases: [],
104
104
  };
105
+ // exclude system events because it can be stupidly large and redudant
106
+ const systemEventsKey = compactHex(meta.query.system.events());
105
107
  const run = async (fn, args) => {
106
108
  const result = await runTask({
107
109
  wasm,
@@ -113,23 +115,21 @@ export const rpc = async ({ chain }, [params]) => {
113
115
  if ('Error' in result) {
114
116
  throw new Error(result.Error);
115
117
  }
116
- const resp = {};
118
+ const resp = { storageDiff: [] };
117
119
  const raw = result.Call.storageDiff;
118
120
  newBlock.pushStorageLayer().setAll(raw);
119
- if (includeRawStorage) {
120
- resp.raw = raw;
121
- }
122
- if (includeParsed) {
123
- const meta = await newBlock.meta;
124
- const parsed = {};
125
- for (const [key, value] of raw) {
126
- _.merge(parsed, decodeKeyValue(meta, newBlock, key, value, false));
121
+ for (const [key, value] of raw) {
122
+ if (key === systemEventsKey) {
123
+ continue;
124
+ }
125
+ const obj = {};
126
+ if (includeRawStorage) {
127
+ obj.raw = { key, value };
127
128
  }
128
- // clear events because it can be stupidly large and redudant
129
- if (parsed['system']?.['events']) {
130
- delete parsed['system']['events'];
129
+ if (includeParsed) {
130
+ obj.parsed = decodeKeyValue(await newBlock.meta, newBlock, key, value, false);
131
131
  }
132
- resp.parsed = parsed;
132
+ resp.storageDiff.push(obj);
133
133
  }
134
134
  resp.logs = result.Call.runtimeLogs;
135
135
  return resp;
@@ -75,13 +75,21 @@ export interface RunBlockResponse {
75
75
  */
76
76
  phase: Phase;
77
77
  /**
78
- * Parsed storage diff. Only available when `includeParsed` is true.
78
+ * The modified storages of this phase.
79
79
  */
80
- parsed?: Record<string, Record<string, any>>;
81
- /**
82
- * Raw storage diff. Only available when `includeRaw` is true.
83
- */
84
- raw?: [HexString, HexString | null][];
80
+ storageDiff: {
81
+ /**
82
+ * Raw storage diff in bytes. Only available when `includeRaw` is true.
83
+ */
84
+ raw?: {
85
+ key: HexString;
86
+ value: HexString | null;
87
+ };
88
+ /**
89
+ * Decoded storage diff. Only available when `includeParsed` is true.
90
+ */
91
+ parsed?: any;
92
+ }[];
85
93
  /**
86
94
  * Runtime logs.
87
95
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acala-network/chopsticks",
3
- "version": "0.8.5-6",
3
+ "version": "0.9.0",
4
4
  "author": "Acala Developers <hello@acala.network>",
5
5
  "license": "Apache-2.0",
6
6
  "bin": "./chopsticks.js",
@@ -17,8 +17,8 @@
17
17
  "docs:prep": "typedoc"
18
18
  },
19
19
  "dependencies": {
20
- "@acala-network/chopsticks-core": "0.8.5-6",
21
- "@acala-network/chopsticks-db": "0.8.5-6",
20
+ "@acala-network/chopsticks-core": "0.9.0",
21
+ "@acala-network/chopsticks-db": "0.9.0",
22
22
  "@pnpm/npm-conf": "^2.2.2",
23
23
  "axios": "^1.5.1",
24
24
  "dotenv": "^16.3.1",