@chainflip/rpc 1.6.9 → 1.6.11
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 +13 -12
- package/dist/Client.d.cts +2 -1
- package/dist/Client.d.ts +2 -1
- package/dist/Client.mjs +10 -9
- package/dist/HttpClient.cjs +1 -2
- package/dist/HttpClient.mjs +1 -2
- package/dist/WsClient.cjs +3 -5
- package/dist/WsClient.mjs +3 -5
- package/dist/common.cjs +2 -0
- package/dist/common.d.cts +1220 -546
- package/dist/common.d.ts +1220 -546
- package/dist/common.mjs +5 -3
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/parsers.cjs +5 -1
- package/dist/parsers.d.cts +1254 -591
- package/dist/parsers.d.ts +1254 -591
- package/dist/parsers.mjs +4 -0
- package/dist/types.d.cts +3 -1
- package/dist/types.d.ts +3 -1
- package/package.json +11 -6
package/dist/Client.cjs
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/Client.ts
|
|
2
|
-
var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;// src/Client.ts
|
|
2
|
+
var _assertion = require('@chainflip/utils/assertion');
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
3
6
|
var _commoncjs = require('./common.cjs');
|
|
4
|
-
var Client = class {
|
|
5
|
-
constructor(url) {
|
|
7
|
+
var Client = (_class = class {
|
|
8
|
+
constructor(url) {;_class.prototype.__init.call(this);
|
|
6
9
|
this.url = url;
|
|
7
10
|
}
|
|
11
|
+
__init() {this.lastRequestId = 0}
|
|
8
12
|
getRequestId() {
|
|
9
|
-
return
|
|
13
|
+
return String(++this.lastRequestId);
|
|
10
14
|
}
|
|
11
15
|
formatRequest(method, params) {
|
|
12
16
|
return { jsonrpc: "2.0", id: this.getRequestId(), method, params };
|
|
@@ -24,22 +28,19 @@ var Client = class {
|
|
|
24
28
|
`RPC error [${parseResult.data.error.code}]: ${parseResult.data.error.message}`
|
|
25
29
|
);
|
|
26
30
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
throw new Error("Malformed RPC response received");
|
|
31
|
+
_assertion.assert.call(void 0, "result" in parseResult.data);
|
|
32
|
+
return parseResult.data;
|
|
31
33
|
}
|
|
32
34
|
async sendRequest(method, ...params) {
|
|
33
35
|
const [response] = await this.send([this.formatRequest(method, params)]);
|
|
34
|
-
if (!response.success)
|
|
35
|
-
throw response.error;
|
|
36
|
+
if (!response.success) throw response.error;
|
|
36
37
|
const parseResult = this.parseSingleResponse(response);
|
|
37
38
|
return _commoncjs.rpcResult[method].parse(parseResult.result);
|
|
38
39
|
}
|
|
39
40
|
methods() {
|
|
40
41
|
return Object.keys(_commoncjs.rpcResult).sort();
|
|
41
42
|
}
|
|
42
|
-
};
|
|
43
|
+
}, _class);
|
|
43
44
|
|
|
44
45
|
|
|
45
46
|
exports.default = Client;
|
package/dist/Client.d.cts
CHANGED
|
@@ -14,9 +14,10 @@ type Response = {
|
|
|
14
14
|
};
|
|
15
15
|
declare abstract class Client {
|
|
16
16
|
protected readonly url: string;
|
|
17
|
+
private lastRequestId;
|
|
17
18
|
constructor(url: string);
|
|
18
19
|
protected abstract send<const T extends RpcMethod>(data: JsonRpcRequest<T>[]): Promise<Response[]>;
|
|
19
|
-
protected getRequestId():
|
|
20
|
+
protected getRequestId(): string;
|
|
20
21
|
protected formatRequest<T extends RpcMethod>(method: T, params: RpcRequest[T]): JsonRpcRequest<T>;
|
|
21
22
|
protected parseSingleResponse(response: Response): {
|
|
22
23
|
id: string | number;
|
package/dist/Client.d.ts
CHANGED
|
@@ -14,9 +14,10 @@ type Response = {
|
|
|
14
14
|
};
|
|
15
15
|
declare abstract class Client {
|
|
16
16
|
protected readonly url: string;
|
|
17
|
+
private lastRequestId;
|
|
17
18
|
constructor(url: string);
|
|
18
19
|
protected abstract send<const T extends RpcMethod>(data: JsonRpcRequest<T>[]): Promise<Response[]>;
|
|
19
|
-
protected getRequestId():
|
|
20
|
+
protected getRequestId(): string;
|
|
20
21
|
protected formatRequest<T extends RpcMethod>(method: T, params: RpcRequest[T]): JsonRpcRequest<T>;
|
|
21
22
|
protected parseSingleResponse(response: Response): {
|
|
22
23
|
id: string | number;
|
package/dist/Client.mjs
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
// src/Client.ts
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { assert } from "@chainflip/utils/assertion";
|
|
3
|
+
import {
|
|
4
|
+
rpcResult,
|
|
5
|
+
rpcResponse
|
|
6
|
+
} from "./common.mjs";
|
|
4
7
|
var Client = class {
|
|
5
8
|
constructor(url) {
|
|
6
9
|
this.url = url;
|
|
7
10
|
}
|
|
11
|
+
lastRequestId = 0;
|
|
8
12
|
getRequestId() {
|
|
9
|
-
return
|
|
13
|
+
return String(++this.lastRequestId);
|
|
10
14
|
}
|
|
11
15
|
formatRequest(method, params) {
|
|
12
16
|
return { jsonrpc: "2.0", id: this.getRequestId(), method, params };
|
|
@@ -24,15 +28,12 @@ var Client = class {
|
|
|
24
28
|
`RPC error [${parseResult.data.error.code}]: ${parseResult.data.error.message}`
|
|
25
29
|
);
|
|
26
30
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
throw new Error("Malformed RPC response received");
|
|
31
|
+
assert("result" in parseResult.data);
|
|
32
|
+
return parseResult.data;
|
|
31
33
|
}
|
|
32
34
|
async sendRequest(method, ...params) {
|
|
33
35
|
const [response] = await this.send([this.formatRequest(method, params)]);
|
|
34
|
-
if (!response.success)
|
|
35
|
-
throw response.error;
|
|
36
|
+
if (!response.success) throw response.error;
|
|
36
37
|
const parseResult = this.parseSingleResponse(response);
|
|
37
38
|
return rpcResult[method].parse(parseResult.result);
|
|
38
39
|
}
|
package/dist/HttpClient.cjs
CHANGED
|
@@ -38,8 +38,7 @@ var HttpClient = (_class = class extends _Clientcjs2.default {constructor(...arg
|
|
|
38
38
|
const deferred = _async.deferredPromise.call(void 0, );
|
|
39
39
|
const body = this.formatRequest(method, params);
|
|
40
40
|
this.requestMap.set(body.id, { deferred, body, method });
|
|
41
|
-
if (this.timer)
|
|
42
|
-
clearTimeout(this.timer);
|
|
41
|
+
if (this.timer) clearTimeout(this.timer);
|
|
43
42
|
this.timer = setTimeout(() => this.sendBatch(), this.batchDuration);
|
|
44
43
|
return deferred.promise;
|
|
45
44
|
}
|
package/dist/HttpClient.mjs
CHANGED
|
@@ -38,8 +38,7 @@ var HttpClient = class extends Client {
|
|
|
38
38
|
const deferred = deferredPromise();
|
|
39
39
|
const body = this.formatRequest(method, params);
|
|
40
40
|
this.requestMap.set(body.id, { deferred, body, method });
|
|
41
|
-
if (this.timer)
|
|
42
|
-
clearTimeout(this.timer);
|
|
41
|
+
if (this.timer) clearTimeout(this.timer);
|
|
43
42
|
this.timer = setTimeout(() => this.sendBatch(), this.batchDuration);
|
|
44
43
|
return deferred.promise;
|
|
45
44
|
}
|
package/dist/WsClient.cjs
CHANGED
|
@@ -17,8 +17,7 @@ var WsClient = (_class = class extends _Clientcjs2.default {
|
|
|
17
17
|
await this.handleClose();
|
|
18
18
|
}
|
|
19
19
|
async handleClose() {
|
|
20
|
-
if (!this.ws)
|
|
21
|
-
return;
|
|
20
|
+
if (!this.ws) return;
|
|
22
21
|
this.ws.removeEventListener("close", this.handleDisconnect);
|
|
23
22
|
this.ws.close();
|
|
24
23
|
if (this.ws.readyState !== this.WebSocket.CLOSED) {
|
|
@@ -49,8 +48,7 @@ var WsClient = (_class = class extends _Clientcjs2.default {
|
|
|
49
48
|
__init5() {this.handleMessage = (data) => {
|
|
50
49
|
const parsedData = JSON.parse(data.data);
|
|
51
50
|
const response = _commoncjs.rpcResponse.safeParse(parsedData);
|
|
52
|
-
if (!response.success)
|
|
53
|
-
return;
|
|
51
|
+
if (!response.success) return;
|
|
54
52
|
const { id } = response.data;
|
|
55
53
|
_optionalChain([this, 'access', _6 => _6.requestMap, 'access', _7 => _7.get, 'call', _8 => _8(id), 'optionalAccess', _9 => _9.resolve, 'call', _10 => _10(response.data)]);
|
|
56
54
|
}}
|
|
@@ -87,7 +85,7 @@ var WsClient = (_class = class extends _Clientcjs2.default {
|
|
|
87
85
|
() => ({ success: false, retry: false, error: new Error("timeout") })
|
|
88
86
|
),
|
|
89
87
|
request.promise.then(
|
|
90
|
-
(
|
|
88
|
+
(r) => ({ success: true, result: r }),
|
|
91
89
|
(error) => ({ success: false, error, retry: true })
|
|
92
90
|
)
|
|
93
91
|
]).finally(() => {
|
package/dist/WsClient.mjs
CHANGED
|
@@ -17,8 +17,7 @@ var WsClient = class extends Client {
|
|
|
17
17
|
await this.handleClose();
|
|
18
18
|
}
|
|
19
19
|
async handleClose() {
|
|
20
|
-
if (!this.ws)
|
|
21
|
-
return;
|
|
20
|
+
if (!this.ws) return;
|
|
22
21
|
this.ws.removeEventListener("close", this.handleDisconnect);
|
|
23
22
|
this.ws.close();
|
|
24
23
|
if (this.ws.readyState !== this.WebSocket.CLOSED) {
|
|
@@ -49,8 +48,7 @@ var WsClient = class extends Client {
|
|
|
49
48
|
handleMessage = (data) => {
|
|
50
49
|
const parsedData = JSON.parse(data.data);
|
|
51
50
|
const response = rpcResponse.safeParse(parsedData);
|
|
52
|
-
if (!response.success)
|
|
53
|
-
return;
|
|
51
|
+
if (!response.success) return;
|
|
54
52
|
const { id } = response.data;
|
|
55
53
|
this.requestMap.get(id)?.resolve(response.data);
|
|
56
54
|
};
|
|
@@ -87,7 +85,7 @@ var WsClient = class extends Client {
|
|
|
87
85
|
() => ({ success: false, retry: false, error: new Error("timeout") })
|
|
88
86
|
),
|
|
89
87
|
request.promise.then(
|
|
90
|
-
(
|
|
88
|
+
(r) => ({ success: true, result: r }),
|
|
91
89
|
(error) => ({ success: false, error, retry: true })
|
|
92
90
|
)
|
|
93
91
|
]).finally(() => {
|
package/dist/common.cjs
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
+
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
var _parserscjs = require('./parsers.cjs');
|
|
@@ -37,6 +38,7 @@ var rpcResult = {
|
|
|
37
38
|
cf_supported_assets: _parserscjs.cfSupportedAssets,
|
|
38
39
|
cf_swap_rate: _parserscjs.cfSwapRate,
|
|
39
40
|
cf_swap_rate_v2: _parserscjs.cfSwapRateV2,
|
|
41
|
+
cf_swap_rate_v3: _parserscjs.cfSwapRateV3,
|
|
40
42
|
cf_swapping_environment: _parserscjs.cfSwappingEnvironment,
|
|
41
43
|
chain_getBlockHash: _parserscjs.chainGetBlockHash,
|
|
42
44
|
cf_boost_pool_details: _parserscjs.cfBoostPoolDetails,
|