@acala-network/chopsticks 0.3.6 → 0.3.8

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,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HeadState = exports.randomId = void 0;
4
+ const rxjs_1 = require("rxjs");
4
5
  const util_1 = require("@polkadot/util");
5
6
  const logger_1 = require("../logger");
6
7
  const randomId = () => Math.random().toString(36).substring(2);
@@ -46,23 +47,27 @@ class HeadState {
46
47
  async setHead(head) {
47
48
  this.#head = head;
48
49
  for (const cb of Object.values(this.#headListeners)) {
49
- try {
50
- cb(head);
51
- }
52
- catch (error) {
53
- logger.error(error, 'callback');
54
- }
55
- }
56
- const diff = await this.#head.storageDiff();
57
- for (const [keys, cb] of Object.values(this.#storageListeners)) {
58
- const changed = keys.filter((key) => diff[key]).map((key) => [key, diff[key]]);
59
- if (changed.length > 0) {
50
+ rxjs_1.asapScheduler.schedule(() => {
60
51
  try {
61
- cb(head, changed);
52
+ cb(head);
62
53
  }
63
54
  catch (error) {
64
55
  logger.error(error, 'callback');
65
56
  }
57
+ });
58
+ }
59
+ const diff = await this.#head.storageDiff();
60
+ for (const [keys, cb] of Object.values(this.#storageListeners)) {
61
+ const changed = keys.filter((key) => diff[key]).map((key) => [key, diff[key]]);
62
+ if (changed.length > 0) {
63
+ rxjs_1.asapScheduler.schedule(() => {
64
+ try {
65
+ cb(head, changed);
66
+ }
67
+ catch (error) {
68
+ logger.error(error, 'callback');
69
+ }
70
+ });
66
71
  }
67
72
  }
68
73
  Object.assign(this.#oldValues, diff);
@@ -54,12 +54,7 @@ class TxPool {
54
54
  async upcomingBlock(count = 1) {
55
55
  if (count < 1)
56
56
  throw new Error('count needs to be greater than 0');
57
- return new Promise((resolve) => {
58
- const sub = this.#upcoming.pipe((0, operators_1.skip)(count - 1)).subscribe((block) => {
59
- sub.unsubscribe();
60
- resolve(block);
61
- });
62
- });
57
+ return (0, rxjs_1.firstValueFrom)(this.#upcoming.pipe((0, operators_1.skip)(count - 1), (0, operators_1.first)()));
63
58
  }
64
59
  async #buildBlock(wait, params) {
65
60
  await this.#chain.api.isReady;
package/dist/cli.js CHANGED
@@ -5,21 +5,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const helpers_1 = require("yargs/helpers");
7
7
  const node_fs_1 = require("node:fs");
8
+ const axios_1 = __importDefault(require("axios"));
8
9
  const js_yaml_1 = __importDefault(require("js-yaml"));
9
10
  const yargs_1 = __importDefault(require("yargs"));
10
11
  const _1 = require(".");
11
12
  const schema_1 = require("./schema");
12
13
  const decoder_1 = require("./utils/decoder");
13
14
  const dry_run_1 = require("./dry-run");
15
+ const utils_1 = require("./utils");
14
16
  const run_block_1 = require("./run-block");
15
- const processConfig = (path) => {
16
- const configFile = (0, node_fs_1.readFileSync)(path, 'utf8');
17
- const config = js_yaml_1.default.load(configFile);
17
+ const processConfig = async (path) => {
18
+ let file;
19
+ if ((0, utils_1.isUrl)(path)) {
20
+ file = await axios_1.default.get(path).then((x) => x.data);
21
+ }
22
+ else {
23
+ file = (0, node_fs_1.readFileSync)(path, 'utf8');
24
+ }
25
+ const config = js_yaml_1.default.load(file);
18
26
  return schema_1.configSchema.parse(config);
19
27
  };
20
- const processArgv = (argv) => {
28
+ const processArgv = async (argv) => {
21
29
  if (argv.config) {
22
- return { ...processConfig(argv.config), ...argv };
30
+ return { ...(await processConfig(argv.config)), ...argv };
23
31
  }
24
32
  return argv;
25
33
  };
@@ -63,7 +71,7 @@ const defaultOptions = {
63
71
  desc: 'Open generated html',
64
72
  },
65
73
  }), async (argv) => {
66
- await (0, run_block_1.runBlock)(processArgv(argv));
74
+ await (0, run_block_1.runBlock)(await processArgv(argv));
67
75
  })
68
76
  .command('dry-run', 'Dry run an extrinsic', (yargs) => yargs.options({
69
77
  ...defaultOptions,
@@ -91,7 +99,7 @@ const defaultOptions = {
91
99
  desc: 'Open generated html',
92
100
  },
93
101
  }), async (argv) => {
94
- await (0, dry_run_1.dryRun)(processArgv(argv));
102
+ await (0, dry_run_1.dryRun)(await processArgv(argv));
95
103
  })
96
104
  .command('dev', 'Dev mode', (yargs) => yargs.options({
97
105
  ...defaultOptions,
@@ -116,7 +124,7 @@ const defaultOptions = {
116
124
  boolean: true,
117
125
  },
118
126
  }), async (argv) => {
119
- await (0, _1.setupWithServer)(processArgv(argv));
127
+ await (0, _1.setupWithServer)(await processArgv(argv));
120
128
  })
121
129
  .command('decode-key <key>', 'Deocde a key', (yargs) => yargs
122
130
  .positional('key', {
@@ -126,7 +134,7 @@ const defaultOptions = {
126
134
  .options({
127
135
  ...defaultOptions,
128
136
  }), async (argv) => {
129
- const context = await (0, _1.setup)(processArgv(argv));
137
+ const context = await (0, _1.setup)(await processArgv(argv));
130
138
  const { storage, decodedKey } = await (0, decoder_1.decodeKey)(context.chain.head, argv.key);
131
139
  if (storage && decodedKey) {
132
140
  console.log(`${storage.section}.${storage.method}`, decodedKey.args.map((x) => JSON.stringify(x.toHuman())).join(', '));
@@ -150,14 +158,14 @@ const defaultOptions = {
150
158
  }), async (argv) => {
151
159
  const parachains = [];
152
160
  for (const config of argv.parachain) {
153
- const { chain } = await (0, _1.setupWithServer)(processConfig(config));
161
+ const { chain } = await (0, _1.setupWithServer)(await processConfig(config));
154
162
  parachains.push(chain);
155
163
  }
156
164
  if (parachains.length > 1) {
157
165
  await (0, _1.connectParachains)(parachains);
158
166
  }
159
167
  if (argv.relaychain) {
160
- const { chain: relaychain } = await (0, _1.setupWithServer)(processConfig(argv.relaychain));
168
+ const { chain: relaychain } = await (0, _1.setupWithServer)(await processConfig(argv.relaychain));
161
169
  for (const parachain of parachains) {
162
170
  await (0, _1.connectVertical)(relaychain, parachain);
163
171
  }
@@ -10,6 +10,7 @@ const util_1 = require("@polkadot/util");
10
10
  const axios_1 = __importDefault(require("axios"));
11
11
  const schema_1 = require("./schema");
12
12
  const executor_1 = require("./executor");
13
+ const utils_1 = require("./utils");
13
14
  class GenesisProvider {
14
15
  #isConnected = false;
15
16
  stats;
@@ -32,16 +33,8 @@ class GenesisProvider {
32
33
  });
33
34
  }
34
35
  static fromUrl = async (url) => {
35
- let isUrl = false;
36
- try {
37
- new URL(url);
38
- isUrl = true;
39
- }
40
- catch (e) {
41
- void e;
42
- }
43
36
  let file;
44
- if (isUrl) {
37
+ if ((0, utils_1.isUrl)(url)) {
45
38
  file = await axios_1.default.get(url).then((x) => x.data);
46
39
  }
47
40
  else if ((0, node_fs_1.lstatSync)(url).isFile()) {
@@ -7,3 +7,4 @@ export declare function fetchKeys(getKeys: GetKeys, processKey: ProcessKey): Pro
7
7
  export declare function fetchKeysToArray(getKeys: GetKeys): Promise<StorageKey<any>[]>;
8
8
  export declare const compactHex: (value: Uint8Array) => HexString;
9
9
  export declare const getParaId: (chain: Blockchain) => Promise<import("@polkadot/types").u32>;
10
+ export declare const isUrl: (url: string) => boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getParaId = exports.compactHex = exports.fetchKeysToArray = exports.fetchKeys = void 0;
3
+ exports.isUrl = exports.getParaId = exports.compactHex = exports.fetchKeysToArray = exports.fetchKeys = void 0;
4
4
  const util_1 = require("@polkadot/util");
5
5
  async function fetchKeys(getKeys, processKey) {
6
6
  const processKeys = async (keys) => {
@@ -38,3 +38,13 @@ const getParaId = async (chain) => {
38
38
  return meta.registry.createType('u32', (0, util_1.hexToU8a)(raw));
39
39
  };
40
40
  exports.getParaId = getParaId;
41
+ const isUrl = (url) => {
42
+ try {
43
+ new URL(url);
44
+ return true;
45
+ }
46
+ catch (e) {
47
+ return false;
48
+ }
49
+ };
50
+ exports.isUrl = isUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acala-network/chopsticks",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Bryan Chen <xlchen1291@gmail.com>",
@@ -29,7 +29,7 @@
29
29
  "dev:moonbeam": "ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=configs/moonbeam.yml"
30
30
  },
31
31
  "dependencies": {
32
- "@acala-network/chopsticks-executor": "0.3.0",
32
+ "@acala-network/chopsticks-executor": "0.3.7",
33
33
  "@polkadot/api": "^9.11.3",
34
34
  "@polkadot/rpc-provider": "^9.11.3",
35
35
  "@polkadot/types": "^9.11.3",