@acala-network/chopsticks-core 1.0.2 → 1.0.3

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/dist/cjs/api.d.ts CHANGED
@@ -29,6 +29,7 @@ export declare class Api {
29
29
  getSystemChain(): Promise<string>;
30
30
  getBlockHash(blockNumber?: number): Promise<`0x${string}` | null>;
31
31
  getHeader(hash?: string): Promise<Header | null>;
32
+ getFinalizedHead(): Promise<string>;
32
33
  getBlock(hash?: string): Promise<SignedBlock | null>;
33
34
  getStorage(key: string, hash?: string): Promise<`0x${string}` | null>;
34
35
  getKeysPaged(prefix: string, pageSize: number, startKey: string, hash?: string): Promise<string[]>;
package/dist/cjs/api.js CHANGED
@@ -129,6 +129,9 @@ class Api {
129
129
  hash
130
130
  ] : [], !!hash);
131
131
  }
132
+ async getFinalizedHead() {
133
+ return this.send('chain_getFinalizedHead', []);
134
+ }
132
135
  async getBlock(hash) {
133
136
  return this.send('chain_getBlock', hash ? [
134
137
  hash
@@ -326,6 +326,14 @@ async function buildBlockIfNeeded() {
326
326
  _class_private_field_set(this, _isBuilding, true);
327
327
  try {
328
328
  await _class_private_method_get(this, _buildBlock, buildBlock).call(this);
329
+ } catch (error) {
330
+ logger.error({
331
+ error
332
+ }, 'build block failed');
333
+ for (const { deferred } of _class_private_field_get(this, _pendingBlocks)){
334
+ deferred.reject(error);
335
+ }
336
+ _class_private_field_get(this, _pendingBlocks).length = 0;
329
337
  } finally{
330
338
  _class_private_field_set(this, _isBuilding, false);
331
339
  }
@@ -191,6 +191,7 @@ class GenesisProvider {
191
191
  case 'chain_getBlock':
192
192
  return this.getBlock();
193
193
  case 'chain_getBlockHash':
194
+ case 'chain_getFinalizedHead':
194
195
  return this.blockHash;
195
196
  case 'state_getKeysPaged':
196
197
  case 'state_getKeysPagedAt':
@@ -45,10 +45,13 @@ const innerTruncate = (level = 0)=>(val)=>{
45
45
  }
46
46
  switch(typeof val){
47
47
  case 'string':
48
- if (val.length > 66 && !verboseLog) {
49
- return `${val.slice(0, 34)}…${val.slice(-32)}`;
48
+ {
49
+ const maxLength = verboseLog ? 10 * 1024 : 66;
50
+ if (val.length > maxLength) {
51
+ return `${val.slice(0, 34)}…${val.slice(-32)}`;
52
+ }
53
+ return val;
50
54
  }
51
- return val;
52
55
  case 'object':
53
56
  if (Array.isArray(val)) {
54
57
  return val.map(innerTruncate(level + 1));
package/dist/cjs/setup.js CHANGED
@@ -38,7 +38,7 @@ const processOptions = async (options)=>{
38
38
  await api.isReady;
39
39
  let blockHash;
40
40
  if (options.block == null) {
41
- blockHash = await api.getBlockHash().then((hash)=>{
41
+ blockHash = await api.getFinalizedHead().then((hash)=>{
42
42
  if (!hash) {
43
43
  // should not happen, but just in case
44
44
  throw new Error('Cannot find block hash');
package/dist/esm/api.d.ts CHANGED
@@ -29,6 +29,7 @@ export declare class Api {
29
29
  getSystemChain(): Promise<string>;
30
30
  getBlockHash(blockNumber?: number): Promise<`0x${string}` | null>;
31
31
  getHeader(hash?: string): Promise<Header | null>;
32
+ getFinalizedHead(): Promise<string>;
32
33
  getBlock(hash?: string): Promise<SignedBlock | null>;
33
34
  getStorage(key: string, hash?: string): Promise<`0x${string}` | null>;
34
35
  getKeysPaged(prefix: string, pageSize: number, startKey: string, hash?: string): Promise<string[]>;
package/dist/esm/api.js CHANGED
@@ -81,6 +81,9 @@ import { prefixedChildKey, splitChildKey, stripChildPrefix } from './utils/index
81
81
  hash
82
82
  ] : [], !!hash);
83
83
  }
84
+ async getFinalizedHead() {
85
+ return this.send('chain_getFinalizedHead', []);
86
+ }
84
87
  async getBlock(hash) {
85
88
  return this.send('chain_getBlock', hash ? [
86
89
  hash
@@ -201,6 +201,14 @@ export class TxPool {
201
201
  this.#isBuilding = true;
202
202
  try {
203
203
  await this.#buildBlock();
204
+ } catch (error) {
205
+ logger.error({
206
+ error
207
+ }, 'build block failed');
208
+ for (const { deferred } of this.#pendingBlocks){
209
+ deferred.reject(error);
210
+ }
211
+ this.#pendingBlocks.length = 0;
204
212
  } finally{
205
213
  this.#isBuilding = false;
206
214
  }
@@ -127,6 +127,7 @@ import { calculateStateRoot, emptyTaskHandler } from './wasm-executor/index.js';
127
127
  case 'chain_getBlock':
128
128
  return this.getBlock();
129
129
  case 'chain_getBlockHash':
130
+ case 'chain_getFinalizedHead':
130
131
  return this.blockHash;
131
132
  case 'state_getKeysPaged':
132
133
  case 'state_getKeysPagedAt':
@@ -24,10 +24,13 @@ const innerTruncate = (level = 0)=>(val)=>{
24
24
  }
25
25
  switch(typeof val){
26
26
  case 'string':
27
- if (val.length > 66 && !verboseLog) {
28
- return `${val.slice(0, 34)}…${val.slice(-32)}`;
27
+ {
28
+ const maxLength = verboseLog ? 10 * 1024 : 66;
29
+ if (val.length > maxLength) {
30
+ return `${val.slice(0, 34)}…${val.slice(-32)}`;
31
+ }
32
+ return val;
29
33
  }
30
- return val;
31
34
  case 'object':
32
35
  if (Array.isArray(val)) {
33
36
  return val.map(innerTruncate(level + 1));
package/dist/esm/setup.js CHANGED
@@ -20,7 +20,7 @@ export const processOptions = async (options)=>{
20
20
  await api.isReady;
21
21
  let blockHash;
22
22
  if (options.block == null) {
23
- blockHash = await api.getBlockHash().then((hash)=>{
23
+ blockHash = await api.getFinalizedHead().then((hash)=>{
24
24
  if (!hash) {
25
25
  // should not happen, but just in case
26
26
  throw new Error('Cannot find block hash');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acala-network/chopsticks-core",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "author": "Acala Developers <hello@acala.network>",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -14,28 +14,28 @@
14
14
  "depcheck": "npx depcheck"
15
15
  },
16
16
  "dependencies": {
17
- "@acala-network/chopsticks-executor": "1.0.2",
18
- "@polkadot/rpc-provider": "^15.0",
19
- "@polkadot/types": "^15.0",
20
- "@polkadot/types-codec": "^15.0",
21
- "@polkadot/types-known": "^15.0",
22
- "@polkadot/util": "^13.2",
23
- "@polkadot/util-crypto": "^13.2",
17
+ "@acala-network/chopsticks-executor": "1.0.3",
18
+ "@polkadot/rpc-provider": "^15.7.1",
19
+ "@polkadot/types": "^15.7.1",
20
+ "@polkadot/types-codec": "^15.7.1",
21
+ "@polkadot/types-known": "^15.7.1",
22
+ "@polkadot/util": "^13.4.3",
23
+ "@polkadot/util-crypto": "^13.4.3",
24
24
  "comlink": "^4.4.2",
25
25
  "eventemitter3": "^5.0.1",
26
26
  "lodash": "^4.17.21",
27
27
  "lru-cache": "^11.0.2",
28
- "pino": "^9.5.0",
28
+ "pino": "^9.6.0",
29
29
  "pino-pretty": "^13.0.0",
30
- "rxjs": "^7.8.1",
31
- "zod": "^3.24.1"
30
+ "rxjs": "^7.8.2",
31
+ "zod": "^3.24.2"
32
32
  },
33
33
  "devDependencies": {
34
- "@swc/cli": "0.5.2",
35
- "@swc/core": "^1.10.1",
36
- "@types/lodash": "^4.17.13",
37
- "typescript": "^5.7.2",
38
- "vitest": "^2.1.8"
34
+ "@swc/cli": "0.6.0",
35
+ "@swc/core": "^1.11.1",
36
+ "@types/lodash": "^4.17.15",
37
+ "typescript": "^5.7.3",
38
+ "vitest": "^3.0.7"
39
39
  },
40
40
  "files": [
41
41
  "dist/esm/**",