@ckb-ccc/core 1.0.1 → 1.1.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.
- package/CHANGELOG.md +6 -0
- package/dist/client/clientPublicMainnet.d.ts +4 -4
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.d.ts +4 -4
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.js +3 -0
- package/dist/client/jsonRpc/index.d.ts +4 -0
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +11 -0
- package/dist.commonjs/client/clientPublicMainnet.d.ts +4 -4
- package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.d.ts +4 -4
- package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.js +3 -0
- package/dist.commonjs/client/jsonRpc/index.d.ts +4 -0
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.js +11 -0
- package/package.json +1 -1
- package/src/client/clientPublicMainnet.ts +4 -3
- package/src/client/clientPublicTestnet.ts +9 -3
- package/src/client/jsonRpc/index.ts +24 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @ckb-ccc/core
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#112](https://github.com/ckb-devrel/ccc/pull/112) [`ddc0a28`](https://github.com/ckb-devrel/ccc/commit/ddc0a281c3d1dfa6ebc990dae92994f026dfddcc) Thanks [@Hanssen0](https://github.com/Hanssen0)! - feat: set maxConcurrent for ClientJsonRpc
|
|
8
|
+
|
|
3
9
|
## 1.0.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ClientCache } from "./cache/index.js";
|
|
2
|
-
import {
|
|
3
|
-
import { KnownScript, ScriptInfo } from "./clientTypes.js";
|
|
2
|
+
import { KnownScript, ScriptInfo, ScriptInfoLike } from "./clientTypes.js";
|
|
4
3
|
import { ClientJsonRpc } from "./jsonRpc/index.js";
|
|
5
4
|
/**
|
|
6
5
|
* @public
|
|
@@ -10,10 +9,11 @@ export declare class ClientPublicMainnet extends ClientJsonRpc {
|
|
|
10
9
|
constructor(config?: {
|
|
11
10
|
url?: string;
|
|
12
11
|
timeout?: number;
|
|
13
|
-
|
|
12
|
+
maxConcurrent?: number;
|
|
13
|
+
scripts?: Record<KnownScript, ScriptInfoLike | undefined>;
|
|
14
14
|
cache?: ClientCache;
|
|
15
15
|
} | undefined);
|
|
16
|
-
get scripts():
|
|
16
|
+
get scripts(): Record<KnownScript, ScriptInfoLike | undefined>;
|
|
17
17
|
get addressPrefix(): string;
|
|
18
18
|
getKnownScript(script: KnownScript): Promise<ScriptInfo>;
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientPublicMainnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"clientPublicMainnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,aAAa;IAElD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAAP,MAAM,CAAC,EAAE;QACxB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,OAAO,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC,CAAC;QAC1D,KAAK,CAAC,EAAE,WAAW,CAAC;KACrB,YAAA;IAWH,IAAI,OAAO,IAAI,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC,CAE7D;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAEK,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;CAS/D"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ClientCache } from "./cache/index.js";
|
|
2
|
-
import {
|
|
3
|
-
import { KnownScript, ScriptInfo } from "./clientTypes.js";
|
|
2
|
+
import { KnownScript, ScriptInfo, ScriptInfoLike } from "./clientTypes.js";
|
|
4
3
|
import { ClientJsonRpc } from "./jsonRpc/index.js";
|
|
5
4
|
/**
|
|
6
5
|
* @public
|
|
@@ -10,10 +9,11 @@ export declare class ClientPublicTestnet extends ClientJsonRpc {
|
|
|
10
9
|
constructor(config?: {
|
|
11
10
|
url?: string;
|
|
12
11
|
timeout?: number;
|
|
13
|
-
|
|
12
|
+
maxConcurrent?: number;
|
|
13
|
+
scripts?: Record<KnownScript, ScriptInfoLike | undefined>;
|
|
14
14
|
cache?: ClientCache;
|
|
15
15
|
} | undefined);
|
|
16
|
-
get scripts():
|
|
16
|
+
get scripts(): Record<KnownScript, ScriptInfoLike | undefined>;
|
|
17
17
|
get addressPrefix(): string;
|
|
18
18
|
getKnownScript(script: KnownScript): Promise<ScriptInfo>;
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientPublicTestnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicTestnet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"clientPublicTestnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicTestnet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,aAAa;IAElD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAAP,MAAM,CAAC,EAAE;QACxB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,OAAO,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC,CAAC;QAC1D,KAAK,CAAC,EAAE,WAAW,CAAC;KACrB,YAAA;IAWH,IAAI,OAAO,IAAI,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC,CAE7D;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAEK,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;CAS/D"}
|
|
@@ -21,6 +21,9 @@ export class ClientPublicTestnet extends ClientJsonRpc {
|
|
|
21
21
|
}
|
|
22
22
|
async getKnownScript(script) {
|
|
23
23
|
const found = this.scripts[script];
|
|
24
|
+
if (!found) {
|
|
25
|
+
throw new Error(`No script information was found for ${script} on ${this.addressPrefix}`);
|
|
26
|
+
}
|
|
24
27
|
return ScriptInfo.from(found);
|
|
25
28
|
}
|
|
26
29
|
}
|
|
@@ -11,6 +11,9 @@ import { JsonRpcPayload } from "../transports/advanced.js";
|
|
|
11
11
|
*/
|
|
12
12
|
export declare abstract class ClientJsonRpc extends Client {
|
|
13
13
|
private readonly url_;
|
|
14
|
+
private readonly maxConcurrent?;
|
|
15
|
+
private concurrent;
|
|
16
|
+
private readonly pending;
|
|
14
17
|
private id;
|
|
15
18
|
private readonly transport;
|
|
16
19
|
/**
|
|
@@ -22,6 +25,7 @@ export declare abstract class ClientJsonRpc extends Client {
|
|
|
22
25
|
constructor(url_: string, config?: {
|
|
23
26
|
timeout?: number;
|
|
24
27
|
cache?: ClientCache;
|
|
28
|
+
maxConcurrent?: number;
|
|
25
29
|
});
|
|
26
30
|
/**
|
|
27
31
|
* Returns the URL of the JSON-RPC server.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAEJ,YAAY,EACZ,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,OAAO,EAAqB,MAAM,oBAAoB,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,yBAAyB,EAOzB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,cAAc,EAGf,MAAM,2BAA2B,CAAC;AAgEnC;;;GAGG;AAEH,8BAAsB,aAAc,SAAQ,MAAM;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAEJ,YAAY,EACZ,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,OAAO,EAAqB,MAAM,oBAAoB,CAAC;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E,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC;IAsC1C;;;;;;;OAOG;IACG,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IA6BrD;;;;;;OAMG;IAEH,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,cAAc;CAQ7D"}
|
|
@@ -61,6 +61,8 @@ export class ClientJsonRpc extends Client {
|
|
|
61
61
|
constructor(url_, config) {
|
|
62
62
|
super(config);
|
|
63
63
|
this.url_ = url_;
|
|
64
|
+
this.concurrent = 0;
|
|
65
|
+
this.pending = [];
|
|
64
66
|
this.id = 0;
|
|
65
67
|
/**
|
|
66
68
|
* Get fee rate statistics
|
|
@@ -183,6 +185,7 @@ export class ClientJsonRpc extends Client {
|
|
|
183
185
|
* @returns The sum of cells capacity.
|
|
184
186
|
*/
|
|
185
187
|
this.getCellsCapacity = this.buildSender("get_cells_capacity", [JsonRpcTransformers.indexerSearchKeyFrom], ({ capacity }) => numFrom(capacity));
|
|
188
|
+
this.maxConcurrent = config?.maxConcurrent;
|
|
186
189
|
this.transport = transportFromUri(url_, config);
|
|
187
190
|
}
|
|
188
191
|
/**
|
|
@@ -255,7 +258,15 @@ export class ClientJsonRpc extends Client {
|
|
|
255
258
|
* @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
|
|
256
259
|
*/
|
|
257
260
|
async send(payload) {
|
|
261
|
+
if (this.maxConcurrent !== undefined &&
|
|
262
|
+
this.concurrent >= this.maxConcurrent) {
|
|
263
|
+
const pending = new Promise((resolve) => this.pending.push(resolve));
|
|
264
|
+
await pending;
|
|
265
|
+
}
|
|
266
|
+
this.concurrent += 1;
|
|
258
267
|
const res = (await this.transport.request(payload));
|
|
268
|
+
this.concurrent -= 1;
|
|
269
|
+
this.pending.pop()?.();
|
|
259
270
|
if (res.id !== payload.id) {
|
|
260
271
|
throw new Error(`Id mismatched, got ${res.id}, expected ${payload.id}`);
|
|
261
272
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ClientCache } from "./cache/index.js";
|
|
2
|
-
import {
|
|
3
|
-
import { KnownScript, ScriptInfo } from "./clientTypes.js";
|
|
2
|
+
import { KnownScript, ScriptInfo, ScriptInfoLike } from "./clientTypes.js";
|
|
4
3
|
import { ClientJsonRpc } from "./jsonRpc/index.js";
|
|
5
4
|
/**
|
|
6
5
|
* @public
|
|
@@ -10,10 +9,11 @@ export declare class ClientPublicMainnet extends ClientJsonRpc {
|
|
|
10
9
|
constructor(config?: {
|
|
11
10
|
url?: string;
|
|
12
11
|
timeout?: number;
|
|
13
|
-
|
|
12
|
+
maxConcurrent?: number;
|
|
13
|
+
scripts?: Record<KnownScript, ScriptInfoLike | undefined>;
|
|
14
14
|
cache?: ClientCache;
|
|
15
15
|
} | undefined);
|
|
16
|
-
get scripts():
|
|
16
|
+
get scripts(): Record<KnownScript, ScriptInfoLike | undefined>;
|
|
17
17
|
get addressPrefix(): string;
|
|
18
18
|
getKnownScript(script: KnownScript): Promise<ScriptInfo>;
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientPublicMainnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"clientPublicMainnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,aAAa;IAElD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAAP,MAAM,CAAC,EAAE;QACxB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,OAAO,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC,CAAC;QAC1D,KAAK,CAAC,EAAE,WAAW,CAAC;KACrB,YAAA;IAWH,IAAI,OAAO,IAAI,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC,CAE7D;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAEK,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;CAS/D"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ClientCache } from "./cache/index.js";
|
|
2
|
-
import {
|
|
3
|
-
import { KnownScript, ScriptInfo } from "./clientTypes.js";
|
|
2
|
+
import { KnownScript, ScriptInfo, ScriptInfoLike } from "./clientTypes.js";
|
|
4
3
|
import { ClientJsonRpc } from "./jsonRpc/index.js";
|
|
5
4
|
/**
|
|
6
5
|
* @public
|
|
@@ -10,10 +9,11 @@ export declare class ClientPublicTestnet extends ClientJsonRpc {
|
|
|
10
9
|
constructor(config?: {
|
|
11
10
|
url?: string;
|
|
12
11
|
timeout?: number;
|
|
13
|
-
|
|
12
|
+
maxConcurrent?: number;
|
|
13
|
+
scripts?: Record<KnownScript, ScriptInfoLike | undefined>;
|
|
14
14
|
cache?: ClientCache;
|
|
15
15
|
} | undefined);
|
|
16
|
-
get scripts():
|
|
16
|
+
get scripts(): Record<KnownScript, ScriptInfoLike | undefined>;
|
|
17
17
|
get addressPrefix(): string;
|
|
18
18
|
getKnownScript(script: KnownScript): Promise<ScriptInfo>;
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientPublicTestnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicTestnet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"clientPublicTestnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicTestnet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,aAAa;IAElD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAAP,MAAM,CAAC,EAAE;QACxB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,OAAO,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC,CAAC;QAC1D,KAAK,CAAC,EAAE,WAAW,CAAC;KACrB,YAAA;IAWH,IAAI,OAAO,IAAI,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC,CAE7D;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAEK,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;CAS/D"}
|
|
@@ -27,6 +27,9 @@ class ClientPublicTestnet extends index_js_1.ClientJsonRpc {
|
|
|
27
27
|
}
|
|
28
28
|
async getKnownScript(script) {
|
|
29
29
|
const found = this.scripts[script];
|
|
30
|
+
if (!found) {
|
|
31
|
+
throw new Error(`No script information was found for ${script} on ${this.addressPrefix}`);
|
|
32
|
+
}
|
|
30
33
|
return clientTypes_js_1.ScriptInfo.from(found);
|
|
31
34
|
}
|
|
32
35
|
}
|
|
@@ -11,6 +11,9 @@ import { JsonRpcPayload } from "../transports/advanced.js";
|
|
|
11
11
|
*/
|
|
12
12
|
export declare abstract class ClientJsonRpc extends Client {
|
|
13
13
|
private readonly url_;
|
|
14
|
+
private readonly maxConcurrent?;
|
|
15
|
+
private concurrent;
|
|
16
|
+
private readonly pending;
|
|
14
17
|
private id;
|
|
15
18
|
private readonly transport;
|
|
16
19
|
/**
|
|
@@ -22,6 +25,7 @@ export declare abstract class ClientJsonRpc extends Client {
|
|
|
22
25
|
constructor(url_: string, config?: {
|
|
23
26
|
timeout?: number;
|
|
24
27
|
cache?: ClientCache;
|
|
28
|
+
maxConcurrent?: number;
|
|
25
29
|
});
|
|
26
30
|
/**
|
|
27
31
|
* Returns the URL of the JSON-RPC server.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAEJ,YAAY,EACZ,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,OAAO,EAAqB,MAAM,oBAAoB,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,yBAAyB,EAOzB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,cAAc,EAGf,MAAM,2BAA2B,CAAC;AAgEnC;;;GAGG;AAEH,8BAAsB,aAAc,SAAQ,MAAM;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAEJ,YAAY,EACZ,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE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,GAAG,KAAK,OAAO,GACnC,CAAC,GAAG,GAAG,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC;IAsC1C;;;;;;;OAOG;IACG,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IA6BrD;;;;;;OAMG;IAEH,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,cAAc;CAQ7D"}
|
|
@@ -64,6 +64,8 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
64
64
|
constructor(url_, config) {
|
|
65
65
|
super(config);
|
|
66
66
|
this.url_ = url_;
|
|
67
|
+
this.concurrent = 0;
|
|
68
|
+
this.pending = [];
|
|
67
69
|
this.id = 0;
|
|
68
70
|
/**
|
|
69
71
|
* Get fee rate statistics
|
|
@@ -186,6 +188,7 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
186
188
|
* @returns The sum of cells capacity.
|
|
187
189
|
*/
|
|
188
190
|
this.getCellsCapacity = this.buildSender("get_cells_capacity", [advanced_js_2.JsonRpcTransformers.indexerSearchKeyFrom], ({ capacity }) => (0, index_js_3.numFrom)(capacity));
|
|
191
|
+
this.maxConcurrent = config?.maxConcurrent;
|
|
189
192
|
this.transport = (0, advanced_js_1.transportFromUri)(url_, config);
|
|
190
193
|
}
|
|
191
194
|
/**
|
|
@@ -258,7 +261,15 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
258
261
|
* @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
|
|
259
262
|
*/
|
|
260
263
|
async send(payload) {
|
|
264
|
+
if (this.maxConcurrent !== undefined &&
|
|
265
|
+
this.concurrent >= this.maxConcurrent) {
|
|
266
|
+
const pending = new Promise((resolve) => this.pending.push(resolve));
|
|
267
|
+
await pending;
|
|
268
|
+
}
|
|
269
|
+
this.concurrent += 1;
|
|
261
270
|
const res = (await this.transport.request(payload));
|
|
271
|
+
this.concurrent -= 1;
|
|
272
|
+
this.pending.pop()?.();
|
|
262
273
|
if (res.id !== payload.id) {
|
|
263
274
|
throw new Error(`Id mismatched, got ${res.id}, expected ${payload.id}`);
|
|
264
275
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import WebSocket from "isomorphic-ws";
|
|
2
2
|
import { ClientCache } from "./cache/index.js";
|
|
3
3
|
import { MAINNET_SCRIPTS } from "./clientPublicMainnet.advanced.js";
|
|
4
|
-
import { KnownScript, ScriptInfo } from "./clientTypes.js";
|
|
4
|
+
import { KnownScript, ScriptInfo, ScriptInfoLike } from "./clientTypes.js";
|
|
5
5
|
import { ClientJsonRpc } from "./jsonRpc/index.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -12,7 +12,8 @@ export class ClientPublicMainnet extends ClientJsonRpc {
|
|
|
12
12
|
private readonly config?: {
|
|
13
13
|
url?: string;
|
|
14
14
|
timeout?: number;
|
|
15
|
-
|
|
15
|
+
maxConcurrent?: number;
|
|
16
|
+
scripts?: Record<KnownScript, ScriptInfoLike | undefined>;
|
|
16
17
|
cache?: ClientCache;
|
|
17
18
|
},
|
|
18
19
|
) {
|
|
@@ -25,7 +26,7 @@ export class ClientPublicMainnet extends ClientJsonRpc {
|
|
|
25
26
|
);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
get scripts():
|
|
29
|
+
get scripts(): Record<KnownScript, ScriptInfoLike | undefined> {
|
|
29
30
|
return this.config?.scripts ?? MAINNET_SCRIPTS;
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import WebSocket from "isomorphic-ws";
|
|
2
2
|
import { ClientCache } from "./cache/index.js";
|
|
3
3
|
import { TESTNET_SCRIPTS } from "./clientPublicTestnet.advanced.js";
|
|
4
|
-
import { KnownScript, ScriptInfo } from "./clientTypes.js";
|
|
4
|
+
import { KnownScript, ScriptInfo, ScriptInfoLike } from "./clientTypes.js";
|
|
5
5
|
import { ClientJsonRpc } from "./jsonRpc/index.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -12,7 +12,8 @@ export class ClientPublicTestnet extends ClientJsonRpc {
|
|
|
12
12
|
private readonly config?: {
|
|
13
13
|
url?: string;
|
|
14
14
|
timeout?: number;
|
|
15
|
-
|
|
15
|
+
maxConcurrent?: number;
|
|
16
|
+
scripts?: Record<KnownScript, ScriptInfoLike | undefined>,
|
|
16
17
|
cache?: ClientCache;
|
|
17
18
|
},
|
|
18
19
|
) {
|
|
@@ -25,7 +26,7 @@ export class ClientPublicTestnet extends ClientJsonRpc {
|
|
|
25
26
|
);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
get scripts():
|
|
29
|
+
get scripts(): Record<KnownScript, ScriptInfoLike | undefined> {
|
|
29
30
|
return this.config?.scripts ?? TESTNET_SCRIPTS;
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -35,6 +36,11 @@ export class ClientPublicTestnet extends ClientJsonRpc {
|
|
|
35
36
|
|
|
36
37
|
async getKnownScript(script: KnownScript): Promise<ScriptInfo> {
|
|
37
38
|
const found = this.scripts[script];
|
|
39
|
+
if (!found) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`No script information was found for ${script} on ${this.addressPrefix}`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
38
44
|
return ScriptInfo.from(found);
|
|
39
45
|
}
|
|
40
46
|
}
|
|
@@ -95,6 +95,10 @@ const ERROR_PARSERS: [
|
|
|
95
95
|
*/
|
|
96
96
|
|
|
97
97
|
export abstract class ClientJsonRpc extends Client {
|
|
98
|
+
private readonly maxConcurrent?: number;
|
|
99
|
+
private concurrent = 0;
|
|
100
|
+
private readonly pending: (() => void)[] = [];
|
|
101
|
+
|
|
98
102
|
private id = 0;
|
|
99
103
|
private readonly transport: Transport;
|
|
100
104
|
|
|
@@ -107,10 +111,15 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
107
111
|
|
|
108
112
|
constructor(
|
|
109
113
|
private readonly url_: string,
|
|
110
|
-
config?: {
|
|
114
|
+
config?: {
|
|
115
|
+
timeout?: number;
|
|
116
|
+
cache?: ClientCache;
|
|
117
|
+
maxConcurrent?: number;
|
|
118
|
+
},
|
|
111
119
|
) {
|
|
112
120
|
super(config);
|
|
113
121
|
|
|
122
|
+
this.maxConcurrent = config?.maxConcurrent;
|
|
114
123
|
this.transport = transportFromUri(url_, config);
|
|
115
124
|
}
|
|
116
125
|
|
|
@@ -433,11 +442,25 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
433
442
|
* @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
|
|
434
443
|
*/
|
|
435
444
|
async send(payload: JsonRpcPayload): Promise<unknown> {
|
|
445
|
+
if (
|
|
446
|
+
this.maxConcurrent !== undefined &&
|
|
447
|
+
this.concurrent >= this.maxConcurrent
|
|
448
|
+
) {
|
|
449
|
+
const pending = new Promise<void>((resolve) =>
|
|
450
|
+
this.pending.push(resolve),
|
|
451
|
+
);
|
|
452
|
+
await pending;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
this.concurrent += 1;
|
|
436
456
|
const res = (await this.transport.request(payload)) as {
|
|
437
457
|
id: number;
|
|
438
458
|
error: unknown;
|
|
439
459
|
result: unknown;
|
|
440
460
|
};
|
|
461
|
+
this.concurrent -= 1;
|
|
462
|
+
this.pending.pop()?.();
|
|
463
|
+
|
|
441
464
|
if (res.id !== payload.id) {
|
|
442
465
|
throw new Error(`Id mismatched, got ${res.id}, expected ${payload.id}`);
|
|
443
466
|
}
|