@acala-network/chopsticks 0.3.8 → 0.3.10

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.
@@ -92,14 +92,14 @@ const initNewBlock = async (head, header, inherents) => {
92
92
  const newBlock = new block_1.Block(head.chain, blockNumber, hash, head, { header, extrinsics: [], storage: head.storage });
93
93
  {
94
94
  // initialize block
95
- const { storageDiff } = await newBlock.call('Core_initialize_block', header.toHex());
95
+ const { storageDiff } = await newBlock.call('Core_initialize_block', [header.toHex()]);
96
96
  newBlock.pushStorageLayer().setAll(storageDiff);
97
97
  logger.trace((0, logger_1.truncate)(storageDiff), 'Initialize block');
98
98
  }
99
99
  // apply inherents
100
100
  for (const extrinsic of inherents) {
101
101
  try {
102
- const { storageDiff } = await newBlock.call('BlockBuilder_apply_extrinsic', extrinsic);
102
+ const { storageDiff } = await newBlock.call('BlockBuilder_apply_extrinsic', [extrinsic]);
103
103
  newBlock.pushStorageLayer().setAll(storageDiff);
104
104
  logger.trace((0, logger_1.truncate)(storageDiff), 'Applied inherent');
105
105
  }
@@ -123,7 +123,7 @@ const buildBlock = async (head, inherents, extrinsics) => {
123
123
  // apply extrinsics
124
124
  for (const extrinsic of extrinsics) {
125
125
  try {
126
- const { storageDiff } = await newBlock.call('BlockBuilder_apply_extrinsic', extrinsic);
126
+ const { storageDiff } = await newBlock.call('BlockBuilder_apply_extrinsic', [extrinsic]);
127
127
  newBlock.pushStorageLayer().setAll(storageDiff);
128
128
  logger.trace((0, logger_1.truncate)(storageDiff), 'Applied extrinsic');
129
129
  }
@@ -134,7 +134,7 @@ const buildBlock = async (head, inherents, extrinsics) => {
134
134
  }
135
135
  {
136
136
  // finalize block
137
- const { storageDiff } = await newBlock.call('BlockBuilder_finalize_block', '0x');
137
+ const { storageDiff } = await newBlock.call('BlockBuilder_finalize_block', []);
138
138
  newBlock.pushStorageLayer().setAll(storageDiff);
139
139
  logger.trace((0, logger_1.truncate)(storageDiff), 'Finalize block');
140
140
  }
@@ -178,10 +178,10 @@ const dryRunExtrinsic = async (head, inherents, extrinsic) => {
178
178
  mockSignature.set([0xde, 0xad, 0xbe, 0xef]);
179
179
  generic.signature.set(mockSignature);
180
180
  logger_1.defaultLogger.info({ call: call.toHuman() }, 'dry_run_call');
181
- return newBlock.call('BlockBuilder_apply_extrinsic', generic.toHex());
181
+ return newBlock.call('BlockBuilder_apply_extrinsic', [generic.toHex()]);
182
182
  }
183
183
  logger_1.defaultLogger.info({ call: registry.createType('GenericExtrinsic', (0, util_1.hexToU8a)(extrinsic)).toHuman() }, 'dry_run_extrinsic');
184
- return newBlock.call('BlockBuilder_apply_extrinsic', extrinsic);
184
+ return newBlock.call('BlockBuilder_apply_extrinsic', [extrinsic]);
185
185
  };
186
186
  exports.dryRunExtrinsic = dryRunExtrinsic;
187
187
  const dryRunInherents = async (head, inherents) => {
@@ -39,5 +39,5 @@ export declare class Block {
39
39
  get runtimeVersion(): Promise<RuntimeVersion>;
40
40
  get metadata(): Promise<HexString>;
41
41
  get meta(): Promise<DecoratedMeta>;
42
- call(method: string, args: HexString, storage?: [HexString, HexString | null][]): Promise<TaskCallResponse>;
42
+ call(method: string, args: HexString[], storage?: [HexString, HexString | null][]): Promise<TaskCallResponse>;
43
43
  }
@@ -131,6 +131,7 @@ class Block {
131
131
  this.runtimeVersion,
132
132
  ]).then(([data, properties, chain, version]) => {
133
133
  const registry = new types_1.TypeRegistry(this.hash);
134
+ registry.setKnownTypes(this.chain.registeredTypes);
134
135
  registry.setChainProperties(registry.createType('ChainProperties', properties));
135
136
  registry.register((0, util_1.getSpecTypes)(registry, chain, version.specName, version.specVersion));
136
137
  registry.setHasher((0, util_1.getSpecHasher)(registry, chain, version.specName));
@@ -148,7 +149,7 @@ class Block {
148
149
  }
149
150
  get metadata() {
150
151
  if (!this.#metadata) {
151
- this.#metadata = this.call('Metadata_metadata', '0x').then((resp) => (0, utils_1.compactHex)((0, util_2.hexToU8a)(resp.result)));
152
+ this.#metadata = this.call('Metadata_metadata', []).then((resp) => (0, utils_1.compactHex)((0, util_2.hexToU8a)(resp.result)));
152
153
  }
153
154
  return this.#metadata;
154
155
  }
@@ -1,6 +1,7 @@
1
1
  import { ApplyExtrinsicResult } from '@polkadot/types/interfaces';
2
2
  import { DataSource } from 'typeorm';
3
3
  import { HexString } from '@polkadot/util/types';
4
+ import { RegisteredTypes } from '@polkadot/types/types';
4
5
  import { Api } from '../api';
5
6
  import { Block } from './block';
6
7
  import { BuildBlockMode, BuildBlockParams, HorizontalMessage } from './txpool';
@@ -17,6 +18,7 @@ export interface Options {
17
18
  };
18
19
  mockSignatureHost?: boolean;
19
20
  allowUnresolvedImports?: boolean;
21
+ registeredTypes: RegisteredTypes;
20
22
  }
21
23
  export declare class Blockchain {
22
24
  #private;
@@ -25,8 +27,9 @@ export declare class Blockchain {
25
27
  readonly db: DataSource | undefined;
26
28
  readonly mockSignatureHost: boolean;
27
29
  readonly allowUnresolvedImports: boolean;
30
+ readonly registeredTypes: RegisteredTypes;
28
31
  readonly headState: HeadState;
29
- constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost, allowUnresolvedImports, }: Options);
32
+ constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost, allowUnresolvedImports, registeredTypes, }: Options);
30
33
  get head(): Block;
31
34
  get pendingExtrinsics(): HexString[];
32
35
  getBlockAt(number?: number): Promise<Block | undefined>;
@@ -35,7 +38,7 @@ export declare class Blockchain {
35
38
  setHead(block: Block): Promise<void>;
36
39
  submitExtrinsic(extrinsic: HexString): Promise<HexString>;
37
40
  newBlock(params?: BuildBlockParams): Promise<Block>;
38
- upcomingBlock(count?: number): Promise<Block>;
41
+ upcomingBlock(skipCount?: number): Promise<Block>;
39
42
  dryRunExtrinsic(extrinsic: HexString | {
40
43
  call: HexString;
41
44
  address: string;
@@ -15,6 +15,7 @@ class Blockchain {
15
15
  db;
16
16
  mockSignatureHost;
17
17
  allowUnresolvedImports;
18
+ registeredTypes;
18
19
  #txpool;
19
20
  #inherentProvider;
20
21
  #head;
@@ -22,11 +23,12 @@ class Blockchain {
22
23
  #blocksByHash = {};
23
24
  #loadingBlocks = {};
24
25
  headState;
25
- constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost = false, allowUnresolvedImports = false, }) {
26
+ constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost = false, allowUnresolvedImports = false, registeredTypes = {}, }) {
26
27
  this.api = api;
27
28
  this.db = db;
28
29
  this.mockSignatureHost = mockSignatureHost;
29
30
  this.allowUnresolvedImports = allowUnresolvedImports;
31
+ this.registeredTypes = registeredTypes;
30
32
  this.#head = new block_1.Block(this, header.number, header.hash);
31
33
  this.#registerBlock(this.#head);
32
34
  this.#txpool = new txpool_1.TxPool(this, inherentProvider, buildBlockMode);
@@ -106,7 +108,7 @@ class Blockchain {
106
108
  async submitExtrinsic(extrinsic) {
107
109
  const source = '0x02'; // External
108
110
  const args = (0, util_1.u8aToHex)((0, util_1.u8aConcat)(source, extrinsic, this.head.hash));
109
- const res = await this.head.call('TaggedTransactionQueue_validate_transaction', args);
111
+ const res = await this.head.call('TaggedTransactionQueue_validate_transaction', [args]);
110
112
  const registry = await this.head.registry;
111
113
  const validity = registry.createType('TransactionValidity', res.result);
112
114
  if (validity.isOk) {
@@ -119,8 +121,8 @@ class Blockchain {
119
121
  await this.#txpool.buildBlock(params);
120
122
  return this.#head;
121
123
  }
122
- async upcomingBlock(count = 1) {
123
- return this.#txpool.upcomingBlock(count);
124
+ async upcomingBlock(skipCount = 0) {
125
+ return this.#txpool.upcomingBlock(skipCount);
124
126
  }
125
127
  async dryRunExtrinsic(extrinsic, at) {
126
128
  await this.api.isReady;
@@ -27,5 +27,5 @@ export declare class TxPool {
27
27
  get pendingExtrinsics(): HexString[];
28
28
  submitExtrinsic(extrinsic: HexString): void;
29
29
  buildBlock(params?: BuildBlockParams): Promise<void>;
30
- upcomingBlock(count?: number): Promise<Block>;
30
+ upcomingBlock(skipCount?: number): Promise<Block>;
31
31
  }
@@ -19,11 +19,11 @@ class TxPool {
19
19
  #pool = [];
20
20
  #mode;
21
21
  #inherentProvider;
22
+ #last;
22
23
  #lastBuildBlockPromise = Promise.resolve();
23
- #last = new rxjs_1.ReplaySubject(1);
24
- #upcoming = this.#last.pipe((0, rxjs_1.share)());
25
24
  constructor(chain, inherentProvider, mode = BuildBlockMode.Batch) {
26
25
  this.#chain = chain;
26
+ this.#last = new rxjs_1.BehaviorSubject(chain.head);
27
27
  this.#mode = mode;
28
28
  this.#inherentProvider = inherentProvider;
29
29
  }
@@ -51,10 +51,10 @@ class TxPool {
51
51
  await this.#lastBuildBlockPromise;
52
52
  this.#last.next(this.#chain.head);
53
53
  }
54
- async upcomingBlock(count = 1) {
55
- if (count < 1)
56
- throw new Error('count needs to be greater than 0');
57
- return (0, rxjs_1.firstValueFrom)(this.#upcoming.pipe((0, operators_1.skip)(count - 1), (0, operators_1.first)()));
54
+ async upcomingBlock(skipCount = 0) {
55
+ if (skipCount < 0)
56
+ throw new Error('skipCount needs to be greater or equal to 0');
57
+ return (0, rxjs_1.firstValueFrom)(this.#last.pipe((0, operators_1.skip)(1 + skipCount), (0, operators_1.take)(1)));
58
58
  }
59
59
  async #buildBlock(wait, params) {
60
60
  await this.#chain.api.isReady;
@@ -26,7 +26,7 @@ export declare const createProof: (trieRootHash: HexString, nodes: HexString[],
26
26
  }>;
27
27
  export declare const runTask: (task: {
28
28
  wasm: HexString;
29
- calls: [string, HexString][];
29
+ calls: [string, HexString[]][];
30
30
  storage: [HexString, HexString | null][];
31
31
  mockSignatureHost: boolean;
32
32
  allowUnresolvedImports: boolean;
package/dist/executor.js CHANGED
@@ -79,7 +79,7 @@ exports.emptyTaskHandler = {
79
79
  exports.getAuraSlotDuration = lodash_1.default.memoize(async (wasm, registry) => {
80
80
  const result = await (0, exports.runTask)({
81
81
  wasm,
82
- calls: [['AuraApi_slot_duration', '0x']],
82
+ calls: [['AuraApi_slot_duration', []]],
83
83
  storage: [],
84
84
  mockSignatureHost: false,
85
85
  allowUnresolvedImports: false,
@@ -123,7 +123,7 @@ class GenesisProvider {
123
123
  const code = this.#genesis.genesis.raw.top[(0, util_1.stringToHex)(':code')];
124
124
  return (0, executor_1.runTask)({
125
125
  wasm: code,
126
- calls: [['Metadata_metadata', '0x']],
126
+ calls: [['Metadata_metadata', []]],
127
127
  storage: [],
128
128
  mockSignatureHost: false,
129
129
  allowUnresolvedImports: true,
package/dist/rpc/dev.js CHANGED
@@ -15,7 +15,7 @@ const handlers = {
15
15
  const finalCount = diff > 0 ? diff : 1;
16
16
  let finalHash;
17
17
  for (let i = 0; i < finalCount; i++) {
18
- const block = await context.chain.newBlock({ inherent: { horizontalMessages: hrmp } }).catch((error) => {
18
+ const block = await context.chain.newBlock({ inherent: { horizontalMessages: hrmp || [] } }).catch((error) => {
19
19
  throw new shared_1.ResponseError(1, error.toString());
20
20
  });
21
21
  logger.debug({ hash: block.hash }, 'dev_newBlock');
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const author_1 = __importDefault(require("./author"));
7
7
  const chain_1 = __importDefault(require("./chain"));
8
+ const payment_1 = __importDefault(require("./payment"));
8
9
  const state_1 = __importDefault(require("./state"));
9
10
  const system_1 = __importDefault(require("./system"));
10
11
  const handlers = {
@@ -12,5 +13,6 @@ const handlers = {
12
13
  ...chain_1.default,
13
14
  ...state_1.default,
14
15
  ...system_1.default,
16
+ ...payment_1.default,
15
17
  };
16
18
  exports.default = handlers;
@@ -0,0 +1,3 @@
1
+ import { Handlers } from '../shared';
2
+ declare const handlers: Handlers;
3
+ export default handlers;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const shared_1 = require("../shared");
4
+ const util_1 = require("@polkadot/util");
5
+ const handlers = {
6
+ payment_queryFeeDetails: async (context, [extrinsic, hash]) => {
7
+ const block = await context.chain.getBlock(hash);
8
+ if (!block) {
9
+ throw new shared_1.ResponseError(1, `Block ${hash} not found`);
10
+ }
11
+ const registry = await block.registry;
12
+ const tx = (0, util_1.hexToU8a)(extrinsic);
13
+ const resp = await block.call('TransactionPaymentApi_query_fee_details', [
14
+ registry.createType('Extrinsic', tx).toHex(),
15
+ registry.createType('u32', tx.byteLength).toHex(),
16
+ ]);
17
+ return resp.result;
18
+ },
19
+ payment_queryInfo: async (context, [extrinsic, hash]) => {
20
+ const block = await context.chain.getBlock(hash);
21
+ if (!block) {
22
+ throw new shared_1.ResponseError(1, `Block ${hash} not found`);
23
+ }
24
+ const registry = await block.registry;
25
+ const tx = (0, util_1.hexToU8a)(extrinsic);
26
+ const resp = await block.call('TransactionPaymentApi_query_info', [
27
+ registry.createType('Extrinsic', tx).toHex(),
28
+ registry.createType('u32', tx.byteLength).toHex(),
29
+ ]);
30
+ return resp.result;
31
+ },
32
+ };
33
+ exports.default = handlers;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const shared_1 = require("../shared");
3
4
  const logger_1 = require("../../logger");
4
5
  const logger = logger_1.defaultLogger.child({ name: 'rpc-state' });
5
6
  const handlers = {
@@ -35,9 +36,10 @@ const handlers = {
35
36
  state_call: async (context, [method, data, hash]) => {
36
37
  const block = await context.chain.getBlock(hash);
37
38
  if (!block) {
38
- return [];
39
+ throw new shared_1.ResponseError(1, `Block ${hash} not found`);
39
40
  }
40
- return (await block.call(method, data)).result;
41
+ const resp = await block.call(method, [data]);
42
+ return resp.result;
41
43
  },
42
44
  state_subscribeRuntimeVersion: async (context, _params, { subscribe }) => {
43
45
  let update = (_block) => { };
@@ -7,6 +7,9 @@ const util_1 = require("@polkadot/util");
7
7
  const node_fs_1 = require("node:fs");
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const handlers = {
10
+ system_localPeerId: async () => '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
11
+ system_nodeRoles: async () => ['Full'],
12
+ system_localListenAddresses: async () => [],
10
13
  system_chain: async (context) => {
11
14
  return context.chain.api.getSystemChain();
12
15
  },
@@ -38,7 +41,7 @@ const handlers = {
38
41
  const head = context.chain.head;
39
42
  const registry = await head.registry;
40
43
  const account = registry.createType('AccountId', address);
41
- const result = await head.call('AccountNonceApi_account_nonce', account.toHex());
44
+ const result = await head.call('AccountNonceApi_account_nonce', [account.toHex()]);
42
45
  return registry.createType('Index', (0, util_1.hexToU8a)(result.result)).toNumber();
43
46
  },
44
47
  };
package/dist/run-block.js CHANGED
@@ -14,11 +14,11 @@ const runBlock = async (argv) => {
14
14
  const parent = await block.parentBlock;
15
15
  if (!parent)
16
16
  throw Error('cant find parent block');
17
- const calls = [['Core_initialize_block', header.toHex()]];
17
+ const calls = [['Core_initialize_block', [header.toHex()]]];
18
18
  for (const extrinsic of await block.extrinsics) {
19
- calls.push(['BlockBuilder_apply_extrinsic', extrinsic]);
19
+ calls.push(['BlockBuilder_apply_extrinsic', [extrinsic]]);
20
20
  }
21
- calls.push(['BlockBuilder_finalize_block', '0x']);
21
+ calls.push(['BlockBuilder_finalize_block', []]);
22
22
  const result = await (0, executor_1.runTask)({
23
23
  wasm,
24
24
  calls,
@@ -131,6 +131,7 @@ export declare const configSchema: z.ZodObject<{
131
131
  };
132
132
  }>]>>;
133
133
  timestamp: z.ZodOptional<z.ZodNumber>;
134
+ 'registered-types': z.ZodOptional<z.ZodAny>;
134
135
  }, "strict", z.ZodTypeAny, {
135
136
  timestamp?: number | undefined;
136
137
  db?: string | undefined;
@@ -155,6 +156,7 @@ export declare const configSchema: z.ZodObject<{
155
156
  'import-storage'?: any;
156
157
  'mock-signature-host'?: boolean | undefined;
157
158
  'wasm-override'?: string | undefined;
159
+ 'registered-types'?: any;
158
160
  }, {
159
161
  timestamp?: number | undefined;
160
162
  db?: string | undefined;
@@ -179,5 +181,6 @@ export declare const configSchema: z.ZodObject<{
179
181
  'import-storage'?: any;
180
182
  'mock-signature-host'?: boolean | undefined;
181
183
  'wasm-override'?: string | undefined;
184
+ 'registered-types'?: any;
182
185
  }>;
183
186
  export type Config = z.infer<typeof configSchema>;
@@ -25,5 +25,6 @@ exports.configSchema = zod_1.z
25
25
  'wasm-override': zod_1.z.string().optional(),
26
26
  genesis: zod_1.z.union([zod_1.z.string(), exports.genesisSchema]).optional(),
27
27
  timestamp: zod_1.z.number().optional(),
28
+ 'registered-types': zod_1.z.any().optional(),
28
29
  })
29
30
  .strict();
package/dist/setup.js CHANGED
@@ -59,6 +59,7 @@ const setup = async (argv) => {
59
59
  },
60
60
  mockSignatureHost: argv['mock-signature-host'],
61
61
  allowUnresolvedImports: argv['allow-unresolved-imports'],
62
+ registeredTypes: argv['registered-types'],
62
63
  });
63
64
  if (argv.timestamp)
64
65
  await (0, time_travel_1.timeTravel)(chain, argv.timestamp);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acala-network/chopsticks",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Bryan Chen <xlchen1291@gmail.com>",
@@ -30,14 +30,14 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@acala-network/chopsticks-executor": "0.3.7",
33
- "@polkadot/api": "^9.11.3",
34
- "@polkadot/rpc-provider": "^9.11.3",
35
- "@polkadot/types": "^9.11.3",
36
- "@polkadot/types-codec": "^9.11.3",
37
- "@polkadot/types-known": "^9.11.3",
33
+ "@polkadot/api": "^9.12.1",
34
+ "@polkadot/rpc-provider": "^9.12.1",
35
+ "@polkadot/types": "^9.12.1",
36
+ "@polkadot/types-codec": "^9.12.1",
37
+ "@polkadot/types-known": "^9.12.1",
38
38
  "@polkadot/util": "^10.2.6",
39
39
  "@polkadot/util-crypto": "^10.2.6",
40
- "axios": "^1.2.3",
40
+ "axios": "^1.2.5",
41
41
  "js-yaml": "^4.1.0",
42
42
  "jsondiffpatch": "^0.4.1",
43
43
  "lodash": "^4.17.21",
@@ -56,9 +56,9 @@
56
56
  "@types/lodash": "^4.14.191",
57
57
  "@types/node": "^18.11.18",
58
58
  "@types/ws": "^8.5.4",
59
- "@types/yargs": "^17.0.19",
60
- "@typescript-eslint/eslint-plugin": "^5.48.2",
61
- "@typescript-eslint/parser": "^5.48.2",
59
+ "@types/yargs": "^17.0.20",
60
+ "@typescript-eslint/eslint-plugin": "^5.49.0",
61
+ "@typescript-eslint/parser": "^5.49.0",
62
62
  "eslint": "^8.32.0",
63
63
  "eslint-config-prettier": "^8.6.0",
64
64
  "eslint-plugin-import": "^2.27.5",
@@ -68,7 +68,7 @@
68
68
  "prettier": "^2.8.3",
69
69
  "ts-node": "^10.9.1",
70
70
  "ts-node-dev": "^2.0.0",
71
- "vitest": "^0.27.2",
71
+ "vitest": "^0.28.3",
72
72
  "wasm-pack": "^0.10.3"
73
73
  },
74
74
  "files": [