Skip to content

Commit 93ff1b4

Browse files
authoredNov 9, 2023
refactor: migrate axios to fetch (#564)
1 parent a243f11 commit 93ff1b4

12 files changed

+251
-179
lines changed
 

‎.changeset/red-rings-approve.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ckb-lumos/rpc": minor
3+
---
4+
5+
Replace the HTTP client `axios` with the native supported `fetch` to avoid the modifying the default adapter of axios

‎packages/rpc/__tests__/ckb-rpc.test.js

+50-40
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
/* eslint-disable max-len */
2+
/** mock template start **/
3+
jest.mock("cross-fetch");
4+
const axiosMock = require("cross-fetch").default;
5+
6+
beforeAll(() => {
7+
const originalResolve = axiosMock.mockResolvedValue;
8+
axiosMock.mockResolvedValue = (value) =>
9+
originalResolve({
10+
json: () => Promise.resolve(value.data),
11+
});
12+
});
213

3-
jest.mock("axios");
14+
/** mock template end **/
415

5-
const axiosMock = require("axios");
616
const { CKBRPC, ResultFormatter } = require("../lib");
717

818
describe("Test with mock", () => {
@@ -94,7 +104,7 @@ describe("Test with mock", () => {
94104
},
95105
});
96106
const res = await rpc.getBlockByNumber(BLOCK_NUMBER);
97-
expect(axiosMock.mock.calls[0][0].data).toEqual({
107+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
98108
id,
99109
jsonrpc: "2.0",
100110
method: "get_block_by_number",
@@ -175,7 +185,7 @@ describe("Test with mock", () => {
175185
},
176186
});
177187
const res = await rpc.txPoolInfo();
178-
expect(axiosMock.mock.calls[0][0].data).toEqual({
188+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
179189
id,
180190
jsonrpc: "2.0",
181191
method: "tx_pool_info",
@@ -202,7 +212,7 @@ describe("Test with mock", () => {
202212
});
203213

204214
const res = await rpc.clearTxPool();
205-
expect(axiosMock.mock.calls[0][0].data).toEqual({
215+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
206216
id,
207217
jsonrpc: "2.0",
208218
method: "clear_tx_pool",
@@ -245,7 +255,7 @@ describe("Test with mock", () => {
245255
});
246256

247257
const res = await rpc.getRawTxPool(true);
248-
expect(axiosMock.mock.calls[0][0].data).toEqual({
258+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
249259
id,
250260
jsonrpc: "2.0",
251261
method: "get_raw_tx_pool",
@@ -292,7 +302,7 @@ describe("Test with mock", () => {
292302
});
293303

294304
const res = await rpc.getRawTxPool(false);
295-
expect(axiosMock.mock.calls[0][0].data).toEqual({
305+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
296306
id,
297307
jsonrpc: "2.0",
298308
method: "get_raw_tx_pool",
@@ -321,7 +331,7 @@ describe("Test with mock", () => {
321331
});
322332

323333
const res = await rpc.getRawTxPool(null);
324-
expect(axiosMock.mock.calls[0][0].data).toEqual({
334+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
325335
id,
326336
jsonrpc: "2.0",
327337
method: "get_raw_tx_pool",
@@ -350,7 +360,7 @@ describe("Test with mock", () => {
350360
});
351361

352362
const res = await rpc.getRawTxPool();
353-
expect(axiosMock.mock.calls[0][0].data).toEqual({
363+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
354364
id,
355365
jsonrpc: "2.0",
356366
method: "get_raw_tx_pool",
@@ -379,7 +389,7 @@ describe("Test with mock", () => {
379389
},
380390
});
381391
const res = await rpc.getCurrentEpoch();
382-
expect(axiosMock.mock.calls[0][0].data).toEqual({
392+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
383393
id,
384394
jsonrpc: "2.0",
385395
method: "get_current_epoch",
@@ -407,7 +417,7 @@ describe("Test with mock", () => {
407417
},
408418
});
409419
const res = await rpc.getEpochByNumber(BLOCK_NUMBER);
410-
expect(axiosMock.mock.calls[0][0].data).toEqual({
420+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
411421
id,
412422
jsonrpc: "2.0",
413423
method: "get_epoch_by_number",
@@ -438,7 +448,7 @@ describe("Test with mock", () => {
438448
},
439449
});
440450
const res = await rpc.getCellbaseOutputCapacityDetails(BLOCK_HASH);
441-
expect(axiosMock.mock.calls[0][0].data).toEqual({
451+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
442452
id,
443453
jsonrpc: "2.0",
444454
method: "get_cellbase_output_capacity_details",
@@ -469,7 +479,7 @@ describe("Test with mock", () => {
469479
},
470480
});
471481
const res = await rpc.calculateDaoMaximumWithdraw(...PARAMS);
472-
expect(axiosMock.mock.calls[0][0].data).toEqual({
482+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
473483
id,
474484
jsonrpc: "2.0",
475485
method: "calculate_dao_maximum_withdraw",
@@ -510,7 +520,7 @@ describe("Test with mock", () => {
510520
},
511521
});
512522
const res = await rpc.getBlockEconomicState(BLOCK_HASH);
513-
expect(axiosMock.mock.calls[0][0].data).toEqual({
523+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
514524
id,
515525
jsonrpc: "2.0",
516526
method: "get_block_economic_state",
@@ -564,7 +574,7 @@ describe("Test with mock", () => {
564574
TRANSACTION_HASHES,
565575
BLOCK_HASH
566576
);
567-
expect(axiosMock.mock.calls[0][0].data).toEqual({
577+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
568578
id,
569579
jsonrpc: "2.0",
570580
method: "get_transaction_proof",
@@ -609,7 +619,7 @@ describe("Test with mock", () => {
609619
},
610620
});
611621
const res = await rpc.getTransactionProof(TRANSACTION_HASHES);
612-
expect(axiosMock.mock.calls[0][0].data).toEqual({
622+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
613623
id,
614624
jsonrpc: "2.0",
615625
method: "get_transaction_proof",
@@ -652,7 +662,7 @@ describe("Test with mock", () => {
652662
},
653663
});
654664
const res = await rpc.verifyTransactionProof(TRANSACTION_PROOF);
655-
expect(axiosMock.mock.calls[0][0].data).toEqual({
665+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
656666
id,
657667
jsonrpc: "2.0",
658668
method: "verify_transaction_proof",
@@ -716,7 +726,7 @@ describe("Test with mock", () => {
716726
});
717727

718728
const res = await rpc.getConsensus();
719-
expect(axiosMock.mock.calls[0][0].data).toEqual({
729+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
720730
id,
721731
jsonrpc: "2.0",
722732
method: "get_consensus",
@@ -778,7 +788,7 @@ describe("Test with mock", () => {
778788
},
779789
});
780790
const res = await rpc.getBlockchainInfo();
781-
expect(axiosMock.mock.calls[0][0].data).toEqual({
791+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
782792
id,
783793
jsonrpc: "2.0",
784794
method: "get_blockchain_info",
@@ -822,7 +832,7 @@ describe("Test with mock", () => {
822832
},
823833
});
824834
const res = await rpc.localNodeInfo();
825-
expect(axiosMock.mock.calls[0][0].data).toEqual({
835+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
826836
id,
827837
jsonrpc: "2.0",
828838
method: "local_node_info",
@@ -859,7 +869,7 @@ describe("Test with mock", () => {
859869
},
860870
});
861871
const res = await rpc.getPeers();
862-
expect(axiosMock.mock.calls[0][0].data).toEqual({
872+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
863873
id,
864874
jsonrpc: "2.0",
865875
method: "get_peers",
@@ -877,7 +887,7 @@ describe("Test with mock", () => {
877887
},
878888
});
879889
const res = await rpc.getTipBlockNumber();
880-
expect(axiosMock.mock.calls[0][0].data).toEqual({
890+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
881891
id,
882892
jsonrpc: "2.0",
883893
method: "get_tip_block_number",
@@ -896,7 +906,7 @@ describe("Test with mock", () => {
896906
},
897907
});
898908
const res = await rpc.getBlockHash("0x0");
899-
expect(axiosMock.mock.calls[0][0].data).toEqual({
909+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
900910
id,
901911
jsonrpc: "2.0",
902912
method: "get_block_hash",
@@ -974,7 +984,7 @@ describe("Test with mock", () => {
974984
});
975985

976986
const res = await rpc.getBlock(BLOCK_HASH);
977-
expect(axiosMock.mock.calls[0][0].data).toEqual({
987+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
978988
id,
979989
jsonrpc: "2.0",
980990
method: "get_block",
@@ -1064,7 +1074,7 @@ describe("Test with mock", () => {
10641074
},
10651075
});
10661076
const res = await rpc.getTipHeader();
1067-
expect(axiosMock.mock.calls[0][0].data).toEqual({
1077+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
10681078
id,
10691079
jsonrpc: "2.0",
10701080
method: "get_tip_header",
@@ -1139,7 +1149,7 @@ describe("Test with mock", () => {
11391149
},
11401150
});
11411151
const res = await rpc.getTransaction(TX_HASH);
1142-
expect(axiosMock.mock.calls[0][0].data).toEqual({
1152+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
11431153
id,
11441154
jsonrpc: "2.0",
11451155
method: "get_transaction",
@@ -1218,7 +1228,7 @@ describe("Test with mock", () => {
12181228
},
12191229
});
12201230
const res = await rpc.getLiveCell(OUT_POINT, true);
1221-
expect(axiosMock.mock.calls[0][0].data).toEqual({
1231+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
12221232
id,
12231233
jsonrpc: "2.0",
12241234
method: "get_live_cell",
@@ -1261,7 +1271,7 @@ describe("Test with mock", () => {
12611271
},
12621272
});
12631273
const res = await rpc.getBannedAddresses();
1264-
expect(axiosMock.mock.calls[0][0].data).toEqual({
1274+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
12651275
id,
12661276
jsonrpc: "2.0",
12671277
method: "get_banned_addresses",
@@ -1279,7 +1289,7 @@ describe("Test with mock", () => {
12791289
},
12801290
});
12811291
const res = await rpc.clearBannedAddresses();
1282-
expect(axiosMock.mock.calls[0][0].data).toEqual({
1292+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
12831293
id,
12841294
jsonrpc: "2.0",
12851295
method: "clear_banned_addresses",
@@ -1298,7 +1308,7 @@ describe("Test with mock", () => {
12981308
},
12991309
});
13001310
const res = await rpc.setBan(...PARAMS);
1301-
expect(axiosMock.mock.calls[0][0].data).toEqual({
1311+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
13021312
id,
13031313
jsonrpc: "2.0",
13041314
method: "set_ban",
@@ -1325,7 +1335,7 @@ describe("Test with mock", () => {
13251335
},
13261336
});
13271337
const res = await rpc.syncState();
1328-
expect(axiosMock.mock.calls[0][0].data).toEqual({
1338+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
13291339
id,
13301340
jsonrpc: "2.0",
13311341
method: "sync_state",
@@ -1352,7 +1362,7 @@ describe("Test with mock", () => {
13521362
},
13531363
});
13541364
const res = await rpc.setNetworkActive(false);
1355-
expect(axiosMock.mock.calls[0][0].data).toEqual({
1365+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
13561366
id,
13571367
jsonrpc: "2.0",
13581368
method: "set_network_active",
@@ -1372,7 +1382,7 @@ describe("Test with mock", () => {
13721382
const PEER_ID = "peer id";
13731383
const ADDRESS = "address";
13741384
const res = await rpc.addNode(PEER_ID, ADDRESS);
1375-
expect(axiosMock.mock.calls[0][0].data).toEqual({
1385+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
13761386
id,
13771387
jsonrpc: "2.0",
13781388
method: "add_node",
@@ -1391,7 +1401,7 @@ describe("Test with mock", () => {
13911401
});
13921402
const PEER_ID = "peer id";
13931403
const res = await rpc.removeNode(PEER_ID);
1394-
expect(axiosMock.mock.calls[0][0].data).toEqual({
1404+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
13951405
id,
13961406
jsonrpc: "2.0",
13971407
method: "remove_node",
@@ -1409,7 +1419,7 @@ describe("Test with mock", () => {
14091419
},
14101420
});
14111421
const res = await rpc.pingPeers();
1412-
expect(axiosMock.mock.calls[0][0].data).toEqual({
1422+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
14131423
id,
14141424
jsonrpc: "2.0",
14151425
method: "ping_peers",
@@ -1446,7 +1456,7 @@ describe("Test with mock", () => {
14461456
},
14471457
});
14481458
const res = await rpc.getHeader(BLOCK_HASH);
1449-
expect(axiosMock.mock.calls[0][0].data).toEqual({
1459+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
14501460
id,
14511461
jsonrpc: "2.0",
14521462
method: "get_header",
@@ -1499,7 +1509,7 @@ describe("Test with mock", () => {
14991509
},
15001510
});
15011511
const res = await rpc.getHeaderByNumber(BLOCK_NUMBER);
1502-
expect(axiosMock.mock.calls[0][0].data).toEqual({
1512+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
15031513
id,
15041514
jsonrpc: "2.0",
15051515
method: "get_header_by_number",
@@ -1573,7 +1583,7 @@ describe("Test with mock", () => {
15731583
},
15741584
});
15751585
const res = await rpc.sendTransaction(tx, "passthrough");
1576-
expect(axiosMock.mock.calls[0][0].data).toEqual({
1586+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
15771587
id,
15781588
jsonrpc: "2.0",
15791589
method: "send_transaction",
@@ -2035,7 +2045,7 @@ describe("Test with mock", () => {
20352045
"\n",
20362046
JSON.stringify({ id, jsonrpc: "2.0", ...expectedParams })
20372047
);
2038-
expect(axiosMock.mock.calls[0][0].data).toEqual({
2048+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
20392049
id,
20402050
jsonrpc: "2.0",
20412051
...expectedParams,
@@ -2192,7 +2202,7 @@ describe("Test with mock", () => {
21922202
],
21932203
});
21942204
const res = await batch.exec();
2195-
expect(axiosMock.mock.calls[0][0].data).toEqual([
2205+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual([
21962206
{
21972207
id,
21982208
jsonrpc: "2.0",

‎packages/rpc/__tests__/initAxiosWebworkerAdapter.test.js

-25
This file was deleted.

‎packages/rpc/__tests__/method.test.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
jest.mock('axios')
2-
const axiosMock = require('axios')
31
const {Method} = require('../lib/method')
42

3+
jest.mock("cross-fetch");
4+
const axiosMock = require("cross-fetch").default;
5+
6+
beforeAll(() => {
7+
const originalResolve = axiosMock.mockResolvedValue;
8+
axiosMock.mockResolvedValue = (value) =>
9+
originalResolve({
10+
json: () => Promise.resolve(value.data),
11+
});
12+
});
13+
14+
afterAll(() => {
15+
jest.restoreAllMocks();
16+
});
17+
518
describe('Test Method', () => {
619
const ranNum = 1
720
const id = Math.round(ranNum * 10000)

‎packages/rpc/__tests__/mock.test.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/** mock template start **/
2+
jest.mock("cross-fetch");
3+
const axiosMock = require("cross-fetch").default;
4+
5+
const { RPC } = require("../");
6+
7+
beforeAll(() => {
8+
const originalResolve = axiosMock.mockResolvedValue;
9+
axiosMock.mockResolvedValue = (value) =>
10+
originalResolve({
11+
json: () => Promise.resolve(value),
12+
});
13+
});
14+
15+
/** mock template end **/
16+
17+
describe("mock cross-fetch", () => {
18+
afterEach(() => {
19+
jest.clearAllMocks();
20+
});
21+
22+
it("json() should work as expected", async () => {
23+
axiosMock.mockResolvedValue({ key: "value" });
24+
25+
const res = await axiosMock("test-url", {});
26+
await expect(res.json()).resolves.toEqual({ key: "value" });
27+
});
28+
29+
it("rpc should work as expected", async () => {
30+
const rpc = new RPC("mock-url");
31+
32+
jest.spyOn(globalThis.Math, "random").mockReturnValue(0.1);
33+
axiosMock.mockResolvedValue({ id: 1000, result: "0x1" });
34+
35+
const blockNumber = await rpc.getTipBlockNumber();
36+
expect(JSON.parse(axiosMock.mock.calls[0][1].body)).toEqual({
37+
jsonrpc: "2.0",
38+
id: 1000,
39+
method: "get_tip_block_number",
40+
params: [],
41+
});
42+
expect(blockNumber).toBe("0x1");
43+
});
44+
});

‎packages/rpc/__tests__/nock-test/rpc.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("rpc", () => {
2020
try {
2121
await rpc.getBlockHash("0x01");
2222
} catch (err) {
23-
expect(err.message).toEqual("timeout of 100ms exceeded");
23+
expect(err.message).toMatch(/aborted/);
2424
}
2525
});
2626
it("should call rpc successful", async () => {

‎packages/rpc/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@
3838
"dependencies": {
3939
"@ckb-lumos/base": "0.21.0-next.1",
4040
"@ckb-lumos/bi": "0.21.0-next.1",
41-
"@vespaiach/axios-fetch-adapter": "^0.3.1",
42-
"axios": "0.27.2",
43-
"tslib": "2.3.1"
41+
"abort-controller": "^3.0.0",
42+
"cross-fetch": "^3.1.5"
4443
},
4544
"devDependencies": {
4645
"@types/jest": "^29.4.0",

‎packages/rpc/src/index.ts

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
// import axios from 'axios'
21
import { Base } from "./Base";
32
import { Method } from "./method";
43
import { CKBComponents } from "./types/api";
5-
64
import { formatter as paramsFormatter } from "./paramsFormatter";
75
import * as resultFormatter from "./resultFormatter";
8-
96
import {
107
IdNotMatchedInBatchException,
118
MethodInBatchNotFoundException,
129
PayloadInBatchException,
1310
} from "./exceptions";
14-
import axios from "axios";
1511
import { RPCConfig } from "./types/common";
16-
import { initAxiosWebworkerAdapter } from "./initAxiosWebworkerAdapter";
12+
import fetch from "cross-fetch";
13+
import { AbortController as CrossAbortController } from "abort-controller";
1714

1815
export const ParamsFormatter = paramsFormatter;
1916
export const ResultFormatter = resultFormatter;
20-
initAxiosWebworkerAdapter();
17+
2118
export class CKBRPC extends Base {
2219
#config: RPCConfig;
2320
#node: CKBComponents.Node = {
@@ -136,17 +133,24 @@ export class CKBRPC extends Base {
136133
}
137134
});
138135

139-
const batchRes = await axios({
136+
const controller = new CrossAbortController() as AbortController;
137+
const signal = controller.signal;
138+
139+
const timeout = setTimeout(
140+
() => controller.abort(),
141+
ctx.#config.timeout
142+
);
143+
144+
const batchRes = await fetch(ctx.#node.url, {
140145
method: "POST",
141146
headers: { "content-type": "application/json" },
142-
data: payload,
143-
url: ctx.#node.url,
144-
httpAgent: ctx.#node.httpAgent,
145-
httpsAgent: ctx.#node.httpsAgent,
146-
timeout: ctx.#config.timeout,
147-
});
147+
body: JSON.stringify(payload),
148+
signal: signal,
149+
}).then((res) => res.json());
150+
151+
clearTimeout(timeout);
148152

149-
return batchRes.data.map((res: any, i: number) => {
153+
return batchRes.map((res: any, i: number) => {
150154
if (res.id !== payload[i].id) {
151155
return new IdNotMatchedInBatchException(i, payload[i].id, res.id);
152156
}

‎packages/rpc/src/initAxiosWebworkerAdapter.ts

-18
This file was deleted.

‎packages/rpc/src/method.ts

+27-21
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import axios from "axios";
21
import { IdNotMatchException, ResponseException } from "./exceptions";
3-
import { initAxiosWebworkerAdapter } from "./initAxiosWebworkerAdapter";
42
import { CKBComponents } from "./types/api";
53
import { RPCConfig } from "./types/common";
4+
import fetch from "cross-fetch";
5+
import { AbortController as CrossAbortController } from "abort-controller";
66

7-
initAxiosWebworkerAdapter();
87
export class Method {
98
#name: string;
109
#config: RPCConfig;
@@ -40,29 +39,36 @@ export class Method {
4039
}
4140

4241
/* eslint-disable @typescript-eslint/ban-types, @typescript-eslint/explicit-module-boundary-types */
43-
public call = (...params: (string | number | object)[]) => {
42+
public call = async (...params: (string | number | object)[]) => {
4443
const payload = this.getPayload(...params);
45-
return axios({
44+
const controller = new CrossAbortController() as AbortController;
45+
const signal = controller.signal;
46+
47+
const timeout = setTimeout(() => controller.abort(), this.#config.timeout);
48+
49+
const res = await fetch(this.#node.url, {
4650
method: "POST",
4751
headers: {
4852
"content-type": "application/json",
4953
},
50-
data: payload,
51-
url: this.#node.url,
52-
httpAgent: this.#node.httpAgent,
53-
httpsAgent: this.#node.httpsAgent,
54-
timeout: this.#config.timeout,
55-
}).then((res) => {
56-
if (res.data.id !== payload.id) {
57-
throw new IdNotMatchException(payload.id, res.data.id);
58-
}
59-
if (res.data.error) {
60-
throw new ResponseException(JSON.stringify(res.data.error));
61-
}
62-
return (
63-
this.#options.resultFormatters?.(res.data.result) ?? res.data.result
64-
);
65-
});
54+
body: JSON.stringify(payload),
55+
signal,
56+
})
57+
.then((res) => res.json())
58+
.then((res) => {
59+
if (res.id !== payload.id) {
60+
throw new IdNotMatchException(payload.id, res.id);
61+
}
62+
if (res.error) {
63+
throw new ResponseException(JSON.stringify(res.error));
64+
}
65+
return (
66+
this.#options.resultFormatters?.(res.result) ?? res.result
67+
);
68+
});
69+
70+
clearTimeout(timeout);
71+
return res;
6672
};
6773

6874
public getPayload = (...params: (string | number | object)[]) => {

‎packages/rpc/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "lib",
5-
"lib": ["WebWorker"]
5+
"lib": ["DOM"]
66
},
77
"include": ["src"]
88
}

‎pnpm-lock.yaml

+88-54
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

2 commit comments

Comments
 (2)

vercel[bot] commented on Nov 9, 2023

@vercel[bot]

github-actions[bot] commented on Nov 9, 2023

@github-actions[bot]
Contributor

🚀 New canary release: 0.0.0-canary-93ff1b4-20231109020124

npm install @ckb-lumos/lumos@0.0.0-canary-93ff1b4-20231109020124
Please sign in to comment.