@chainflip/rpc 2.0.6-wbtc-dev.4 → 2.0.7-wbtc-dev.2
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/Client.cjs +88 -91
- package/dist/Client.d.ts +30 -33
- package/dist/Client.mjs +87 -90
- package/dist/HttpClient.cjs +33 -32
- package/dist/HttpClient.d.ts +6 -10
- package/dist/HttpClient.mjs +32 -31
- package/dist/WsClient.cjs +119 -124
- package/dist/WsClient.d.ts +23 -24
- package/dist/WsClient.mjs +117 -122
- package/dist/_virtual/rolldown_runtime.cjs +19 -0
- package/dist/_virtual/rolldown_runtime.mjs +18 -0
- package/dist/common.cjs +55 -98
- package/dist/common.d.ts +30444 -31238
- package/dist/common.mjs +54 -98
- package/dist/constants.cjs +16 -7
- package/dist/constants.d.ts +11 -1
- package/dist/constants.mjs +12 -9
- package/dist/index.cjs +12 -10
- package/dist/index.d.ts +7 -11
- package/dist/index.mjs +5 -10
- package/dist/parsers.cjs +794 -751
- package/dist/parsers.d.ts +36226 -37034
- package/dist/parsers.mjs +738 -747
- package/dist/types.cjs +0 -1
- package/dist/types.d.ts +6 -9
- package/dist/types.mjs +1 -0
- package/package.json +18 -18
- package/dist/Client.d.cts +0 -43
- package/dist/HttpClient.d.cts +0 -13
- package/dist/WsClient.d.cts +0 -27
- package/dist/common.d.cts +0 -31922
- package/dist/constants-jLrn-AnI.d.cts +0 -13
- package/dist/constants-jLrn-AnI.d.ts +0 -13
- package/dist/constants.d.cts +0 -1
- package/dist/index.d.cts +0 -11
- package/dist/parsers.d.cts +0 -37861
- package/dist/types.d.cts +0 -87
package/dist/Client.cjs
CHANGED
|
@@ -1,93 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const require_common = require('./common.cjs');
|
|
2
|
+
let _chainflip_utils_async = require("@chainflip/utils/async");
|
|
3
3
|
|
|
4
|
+
//#region src/Client.ts
|
|
5
|
+
var Client = class {
|
|
6
|
+
lastRequestId = 0;
|
|
7
|
+
timer = null;
|
|
8
|
+
requestMap = /* @__PURE__ */ new Map();
|
|
9
|
+
archiveNodeUrl;
|
|
10
|
+
eventTarget = new EventTarget();
|
|
11
|
+
constructor(url, opts = {}) {
|
|
12
|
+
this.url = url;
|
|
13
|
+
this.archiveNodeUrl = opts.archiveNodeUrl;
|
|
14
|
+
}
|
|
15
|
+
getRequestId() {
|
|
16
|
+
try {
|
|
17
|
+
return crypto.randomUUID();
|
|
18
|
+
} catch {
|
|
19
|
+
return String(++this.lastRequestId);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
formatRequest(method, params) {
|
|
23
|
+
return {
|
|
24
|
+
jsonrpc: "2.0",
|
|
25
|
+
id: this.getRequestId(),
|
|
26
|
+
method,
|
|
27
|
+
params
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
handleResponse(response, clonedMap) {
|
|
31
|
+
const clonedItem = clonedMap.get(response.id);
|
|
32
|
+
if (!clonedItem) return;
|
|
33
|
+
clonedMap.delete(response.id);
|
|
34
|
+
if (!response.success) return clonedItem.deferred.reject(response.error);
|
|
35
|
+
const rpcResponse = response.result;
|
|
36
|
+
if ("error" in rpcResponse) return clonedItem.deferred.reject(/* @__PURE__ */ new Error(`RPC error [${rpcResponse.error.code}]: ${rpcResponse.error.message}`));
|
|
37
|
+
const parseResult = require_common.rpcResult[clonedItem.method].safeParse(rpcResponse.result);
|
|
38
|
+
if (parseResult.error) return clonedItem.deferred.reject(parseResult.error);
|
|
39
|
+
clonedItem.deferred.resolve(parseResult.data);
|
|
40
|
+
}
|
|
41
|
+
handleErrorResponse(error, clonedMap) {
|
|
42
|
+
for (const [id] of clonedMap) this.handleResponse({
|
|
43
|
+
id,
|
|
44
|
+
success: false,
|
|
45
|
+
error
|
|
46
|
+
}, clonedMap);
|
|
47
|
+
}
|
|
48
|
+
async handleBatch() {
|
|
49
|
+
const clonedMap = new Map(this.requestMap);
|
|
50
|
+
this.requestMap.clear();
|
|
51
|
+
const requests = [...clonedMap.values()].map((item) => item.body);
|
|
52
|
+
await this.send(requests, clonedMap);
|
|
53
|
+
clonedMap.forEach((item) => {
|
|
54
|
+
item.deferred.reject(/* @__PURE__ */ new Error("Could not find the result for the request"));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
sendRequest(method, ...params) {
|
|
58
|
+
if (!require_common.rpcResult[method]) return Promise.reject(/* @__PURE__ */ new Error(`Unknown method: ${method}`));
|
|
59
|
+
const deferred = (0, _chainflip_utils_async.deferredPromise)();
|
|
60
|
+
const body = this.formatRequest(method, params);
|
|
61
|
+
this.requestMap.set(body.id, {
|
|
62
|
+
deferred,
|
|
63
|
+
body,
|
|
64
|
+
method
|
|
65
|
+
});
|
|
66
|
+
if (!this.timer) this.timer = setTimeout(() => {
|
|
67
|
+
this.timer = null;
|
|
68
|
+
this.handleBatch();
|
|
69
|
+
}, 0);
|
|
70
|
+
return deferred.promise.catch((error) => {
|
|
71
|
+
if (error instanceof Error) {
|
|
72
|
+
if (this.archiveNodeUrl && error.message.includes("Unknown block: State already discarded")) {
|
|
73
|
+
this.eventTarget.dispatchEvent(new CustomEvent("archiveNodeFallback", { detail: {
|
|
74
|
+
method,
|
|
75
|
+
params
|
|
76
|
+
} }));
|
|
77
|
+
return new this.constructor(this.archiveNodeUrl).sendRequest(method, ...params);
|
|
78
|
+
}
|
|
79
|
+
Error.captureStackTrace(error);
|
|
80
|
+
}
|
|
81
|
+
throw error;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
methods() {
|
|
85
|
+
return Object.keys(require_common.rpcResult).sort();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
4
88
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
constructor(url, opts = {}) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);
|
|
8
|
-
this.url = url;
|
|
9
|
-
this.archiveNodeUrl = opts.archiveNodeUrl;
|
|
10
|
-
}
|
|
11
|
-
__init() {this.lastRequestId = 0}
|
|
12
|
-
__init2() {this.timer = null}
|
|
13
|
-
__init3() {this.requestMap = /* @__PURE__ */ new Map()}
|
|
14
|
-
|
|
15
|
-
__init4() {this.eventTarget = new EventTarget()}
|
|
16
|
-
getRequestId() {
|
|
17
|
-
try {
|
|
18
|
-
return crypto.randomUUID();
|
|
19
|
-
} catch (e) {
|
|
20
|
-
return String(++this.lastRequestId);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
formatRequest(method, params) {
|
|
24
|
-
return { jsonrpc: "2.0", id: this.getRequestId(), method, params };
|
|
25
|
-
}
|
|
26
|
-
handleResponse(response, clonedMap) {
|
|
27
|
-
const clonedItem = clonedMap.get(response.id);
|
|
28
|
-
if (!clonedItem) return;
|
|
29
|
-
clonedMap.delete(response.id);
|
|
30
|
-
if (!response.success) {
|
|
31
|
-
return clonedItem.deferred.reject(response.error);
|
|
32
|
-
}
|
|
33
|
-
const rpcResponse = response.result;
|
|
34
|
-
if ("error" in rpcResponse) {
|
|
35
|
-
return clonedItem.deferred.reject(
|
|
36
|
-
new Error(`RPC error [${rpcResponse.error.code}]: ${rpcResponse.error.message}`)
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
const parseResult = _commoncjs.rpcResult[clonedItem.method].safeParse(rpcResponse.result);
|
|
40
|
-
if (parseResult.error) {
|
|
41
|
-
return clonedItem.deferred.reject(parseResult.error);
|
|
42
|
-
}
|
|
43
|
-
clonedItem.deferred.resolve(parseResult.data);
|
|
44
|
-
}
|
|
45
|
-
handleErrorResponse(error, clonedMap) {
|
|
46
|
-
for (const [id] of clonedMap) {
|
|
47
|
-
this.handleResponse({ id, success: false, error }, clonedMap);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async handleBatch() {
|
|
51
|
-
const clonedMap = new Map(this.requestMap);
|
|
52
|
-
this.requestMap.clear();
|
|
53
|
-
const requests = [...clonedMap.values()].map((item) => item.body);
|
|
54
|
-
await this.send(requests, clonedMap);
|
|
55
|
-
clonedMap.forEach((item) => {
|
|
56
|
-
item.deferred.reject(new Error("Could not find the result for the request"));
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
sendRequest(method, ...params) {
|
|
60
|
-
if (!_commoncjs.rpcResult[method]) {
|
|
61
|
-
return Promise.reject(new Error(`Unknown method: ${method}`));
|
|
62
|
-
}
|
|
63
|
-
const deferred = _async.deferredPromise.call(void 0, );
|
|
64
|
-
const body = this.formatRequest(method, params);
|
|
65
|
-
this.requestMap.set(body.id, { deferred, body, method });
|
|
66
|
-
if (!this.timer) {
|
|
67
|
-
this.timer = setTimeout(() => {
|
|
68
|
-
this.timer = null;
|
|
69
|
-
void this.handleBatch();
|
|
70
|
-
}, 0);
|
|
71
|
-
}
|
|
72
|
-
return deferred.promise.catch((error) => {
|
|
73
|
-
if (error instanceof Error) {
|
|
74
|
-
if (this.archiveNodeUrl && error.message.includes("Unknown block: State already discarded")) {
|
|
75
|
-
this.eventTarget.dispatchEvent(
|
|
76
|
-
new CustomEvent("archiveNodeFallback", { detail: { method, params } })
|
|
77
|
-
);
|
|
78
|
-
return new this.constructor(
|
|
79
|
-
this.archiveNodeUrl
|
|
80
|
-
).sendRequest(method, ...params);
|
|
81
|
-
}
|
|
82
|
-
Error.captureStackTrace(error);
|
|
83
|
-
}
|
|
84
|
-
throw error;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
methods() {
|
|
88
|
-
return Object.keys(_commoncjs.rpcResult).sort();
|
|
89
|
-
}
|
|
90
|
-
}, _class);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
exports.default = Client;
|
|
89
|
+
//#endregion
|
|
90
|
+
module.exports = Client;
|
package/dist/Client.d.ts
CHANGED
|
@@ -1,43 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import '@chainflip/utils/chainflip';
|
|
4
|
-
import '@chainflip/utils/types';
|
|
5
|
-
import 'zod';
|
|
6
|
-
import './parsers.js';
|
|
1
|
+
import { JsonRpcRequest, JsonRpcResponse, RpcMethod, RpcRequest, RpcResult } from "./common.js";
|
|
2
|
+
import { DeferredPromise } from "@chainflip/utils/async";
|
|
7
3
|
|
|
4
|
+
//#region src/Client.d.ts
|
|
8
5
|
type Response = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
success: true;
|
|
7
|
+
id: string;
|
|
8
|
+
result: JsonRpcResponse;
|
|
12
9
|
} | {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
success: false;
|
|
11
|
+
id: string;
|
|
12
|
+
error: Error;
|
|
16
13
|
};
|
|
17
14
|
type RequestMap = Map<string, {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
deferred: DeferredPromise<RpcResult<RpcMethod>>;
|
|
16
|
+
body: JsonRpcRequest<RpcMethod>;
|
|
17
|
+
method: RpcMethod;
|
|
21
18
|
}>;
|
|
22
19
|
type ClientOpts = {
|
|
23
|
-
|
|
20
|
+
archiveNodeUrl?: string;
|
|
24
21
|
};
|
|
25
22
|
declare abstract class Client {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
protected readonly url: string;
|
|
24
|
+
private lastRequestId;
|
|
25
|
+
private timer;
|
|
26
|
+
private requestMap;
|
|
27
|
+
private readonly archiveNodeUrl?;
|
|
28
|
+
readonly eventTarget: EventTarget;
|
|
29
|
+
constructor(url: string, opts?: ClientOpts);
|
|
30
|
+
protected abstract send<const T extends RpcMethod>(data: JsonRpcRequest<T>[], clonedMap: RequestMap): Promise<void>;
|
|
31
|
+
private getRequestId;
|
|
32
|
+
private formatRequest;
|
|
33
|
+
protected handleResponse(response: Response, clonedMap: RequestMap): void;
|
|
34
|
+
protected handleErrorResponse(error: Error, clonedMap: RequestMap): void;
|
|
35
|
+
private handleBatch;
|
|
36
|
+
sendRequest<const T extends RpcMethod>(method: T, ...params: RpcRequest[T]): Promise<RpcResult<T>>;
|
|
37
|
+
methods(): RpcMethod[];
|
|
41
38
|
}
|
|
42
|
-
|
|
43
|
-
export {
|
|
39
|
+
//#endregion
|
|
40
|
+
export { ClientOpts, RequestMap, Response, Client as default };
|
package/dist/Client.mjs
CHANGED
|
@@ -1,93 +1,90 @@
|
|
|
1
|
-
|
|
1
|
+
import { rpcResult } from "./common.mjs";
|
|
2
2
|
import { deferredPromise } from "@chainflip/utils/async";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "./common.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/Client.ts
|
|
6
5
|
var Client = class {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return Object.keys(rpcResult).sort();
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
export {
|
|
92
|
-
Client as default
|
|
6
|
+
lastRequestId = 0;
|
|
7
|
+
timer = null;
|
|
8
|
+
requestMap = /* @__PURE__ */ new Map();
|
|
9
|
+
archiveNodeUrl;
|
|
10
|
+
eventTarget = new EventTarget();
|
|
11
|
+
constructor(url, opts = {}) {
|
|
12
|
+
this.url = url;
|
|
13
|
+
this.archiveNodeUrl = opts.archiveNodeUrl;
|
|
14
|
+
}
|
|
15
|
+
getRequestId() {
|
|
16
|
+
try {
|
|
17
|
+
return crypto.randomUUID();
|
|
18
|
+
} catch {
|
|
19
|
+
return String(++this.lastRequestId);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
formatRequest(method, params) {
|
|
23
|
+
return {
|
|
24
|
+
jsonrpc: "2.0",
|
|
25
|
+
id: this.getRequestId(),
|
|
26
|
+
method,
|
|
27
|
+
params
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
handleResponse(response, clonedMap) {
|
|
31
|
+
const clonedItem = clonedMap.get(response.id);
|
|
32
|
+
if (!clonedItem) return;
|
|
33
|
+
clonedMap.delete(response.id);
|
|
34
|
+
if (!response.success) return clonedItem.deferred.reject(response.error);
|
|
35
|
+
const rpcResponse = response.result;
|
|
36
|
+
if ("error" in rpcResponse) return clonedItem.deferred.reject(/* @__PURE__ */ new Error(`RPC error [${rpcResponse.error.code}]: ${rpcResponse.error.message}`));
|
|
37
|
+
const parseResult = rpcResult[clonedItem.method].safeParse(rpcResponse.result);
|
|
38
|
+
if (parseResult.error) return clonedItem.deferred.reject(parseResult.error);
|
|
39
|
+
clonedItem.deferred.resolve(parseResult.data);
|
|
40
|
+
}
|
|
41
|
+
handleErrorResponse(error, clonedMap) {
|
|
42
|
+
for (const [id] of clonedMap) this.handleResponse({
|
|
43
|
+
id,
|
|
44
|
+
success: false,
|
|
45
|
+
error
|
|
46
|
+
}, clonedMap);
|
|
47
|
+
}
|
|
48
|
+
async handleBatch() {
|
|
49
|
+
const clonedMap = new Map(this.requestMap);
|
|
50
|
+
this.requestMap.clear();
|
|
51
|
+
const requests = [...clonedMap.values()].map((item) => item.body);
|
|
52
|
+
await this.send(requests, clonedMap);
|
|
53
|
+
clonedMap.forEach((item) => {
|
|
54
|
+
item.deferred.reject(/* @__PURE__ */ new Error("Could not find the result for the request"));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
sendRequest(method, ...params) {
|
|
58
|
+
if (!rpcResult[method]) return Promise.reject(/* @__PURE__ */ new Error(`Unknown method: ${method}`));
|
|
59
|
+
const deferred = deferredPromise();
|
|
60
|
+
const body = this.formatRequest(method, params);
|
|
61
|
+
this.requestMap.set(body.id, {
|
|
62
|
+
deferred,
|
|
63
|
+
body,
|
|
64
|
+
method
|
|
65
|
+
});
|
|
66
|
+
if (!this.timer) this.timer = setTimeout(() => {
|
|
67
|
+
this.timer = null;
|
|
68
|
+
this.handleBatch();
|
|
69
|
+
}, 0);
|
|
70
|
+
return deferred.promise.catch((error) => {
|
|
71
|
+
if (error instanceof Error) {
|
|
72
|
+
if (this.archiveNodeUrl && error.message.includes("Unknown block: State already discarded")) {
|
|
73
|
+
this.eventTarget.dispatchEvent(new CustomEvent("archiveNodeFallback", { detail: {
|
|
74
|
+
method,
|
|
75
|
+
params
|
|
76
|
+
} }));
|
|
77
|
+
return new this.constructor(this.archiveNodeUrl).sendRequest(method, ...params);
|
|
78
|
+
}
|
|
79
|
+
Error.captureStackTrace(error);
|
|
80
|
+
}
|
|
81
|
+
throw error;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
methods() {
|
|
85
|
+
return Object.keys(rpcResult).sort();
|
|
86
|
+
}
|
|
93
87
|
};
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { Client as default };
|
package/dist/HttpClient.cjs
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
var _Clientcjs = require('./Client.cjs'); var _Clientcjs2 = _interopRequireDefault(_Clientcjs);
|
|
3
|
-
var HttpClient = class extends _Clientcjs2.default {
|
|
4
|
-
async send(request, requestMap) {
|
|
5
|
-
let res;
|
|
6
|
-
try {
|
|
7
|
-
res = await fetch(this.url, {
|
|
8
|
-
body: JSON.stringify(request),
|
|
9
|
-
method: "POST",
|
|
10
|
-
headers: {
|
|
11
|
-
"Content-Type": "application/json"
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
} catch (error) {
|
|
15
|
-
this.handleErrorResponse(new Error("Network error", { cause: error }), requestMap);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (!res.ok) {
|
|
19
|
-
this.handleErrorResponse(new Error(`HTTP error: ${res.status}`), requestMap);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
try {
|
|
23
|
-
const jsonRpcResponse = await res.json();
|
|
24
|
-
for (const r of jsonRpcResponse) {
|
|
25
|
-
this.handleResponse({ id: r.id, success: true, result: r }, requestMap);
|
|
26
|
-
}
|
|
27
|
-
} catch (cause) {
|
|
28
|
-
this.handleErrorResponse(new Error("Invalid JSON response", { cause }), requestMap);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
1
|
+
const require_Client = require('./Client.cjs');
|
|
32
2
|
|
|
3
|
+
//#region src/HttpClient.ts
|
|
4
|
+
var HttpClient = class extends require_Client {
|
|
5
|
+
async send(request, requestMap) {
|
|
6
|
+
let res;
|
|
7
|
+
try {
|
|
8
|
+
res = await fetch(this.url, {
|
|
9
|
+
body: JSON.stringify(request),
|
|
10
|
+
method: "POST",
|
|
11
|
+
headers: { "Content-Type": "application/json" }
|
|
12
|
+
});
|
|
13
|
+
} catch (error) {
|
|
14
|
+
this.handleErrorResponse(new Error("Network error", { cause: error }), requestMap);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (!res.ok) {
|
|
18
|
+
this.handleErrorResponse(/* @__PURE__ */ new Error(`HTTP error: ${res.status}`), requestMap);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const jsonRpcResponse = await res.json();
|
|
23
|
+
for (const r of jsonRpcResponse) this.handleResponse({
|
|
24
|
+
id: r.id,
|
|
25
|
+
success: true,
|
|
26
|
+
result: r
|
|
27
|
+
}, requestMap);
|
|
28
|
+
} catch (cause) {
|
|
29
|
+
this.handleErrorResponse(new Error("Invalid JSON response", { cause }), requestMap);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
//#endregion
|
|
35
|
+
module.exports = HttpClient;
|
package/dist/HttpClient.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import '@chainflip/utils/async';
|
|
4
|
-
import '@chainflip/utils/chainflip';
|
|
5
|
-
import '@chainflip/utils/types';
|
|
6
|
-
import 'zod';
|
|
7
|
-
import './parsers.js';
|
|
1
|
+
import { JsonRpcRequest, RpcMethod } from "./common.js";
|
|
2
|
+
import Client, { RequestMap } from "./Client.js";
|
|
8
3
|
|
|
4
|
+
//#region src/HttpClient.d.ts
|
|
9
5
|
declare class HttpClient extends Client {
|
|
10
|
-
|
|
6
|
+
protected send<const T extends RpcMethod>(request: JsonRpcRequest<T>[], requestMap: RequestMap): Promise<void>;
|
|
11
7
|
}
|
|
12
|
-
|
|
13
|
-
export { HttpClient as default };
|
|
8
|
+
//#endregion
|
|
9
|
+
export { HttpClient as default };
|
package/dist/HttpClient.mjs
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
// src/HttpClient.ts
|
|
2
1
|
import Client from "./Client.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/HttpClient.ts
|
|
3
4
|
var HttpClient = class extends Client {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
export {
|
|
33
|
-
HttpClient as default
|
|
5
|
+
async send(request, requestMap) {
|
|
6
|
+
let res;
|
|
7
|
+
try {
|
|
8
|
+
res = await fetch(this.url, {
|
|
9
|
+
body: JSON.stringify(request),
|
|
10
|
+
method: "POST",
|
|
11
|
+
headers: { "Content-Type": "application/json" }
|
|
12
|
+
});
|
|
13
|
+
} catch (error) {
|
|
14
|
+
this.handleErrorResponse(new Error("Network error", { cause: error }), requestMap);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (!res.ok) {
|
|
18
|
+
this.handleErrorResponse(/* @__PURE__ */ new Error(`HTTP error: ${res.status}`), requestMap);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const jsonRpcResponse = await res.json();
|
|
23
|
+
for (const r of jsonRpcResponse) this.handleResponse({
|
|
24
|
+
id: r.id,
|
|
25
|
+
success: true,
|
|
26
|
+
result: r
|
|
27
|
+
}, requestMap);
|
|
28
|
+
} catch (cause) {
|
|
29
|
+
this.handleErrorResponse(new Error("Invalid JSON response", { cause }), requestMap);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
34
32
|
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { HttpClient as default };
|