@bithomp/xrpl-api 3.1.2 → 3.1.4
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/lib/connection.d.ts +2 -0
- package/lib/connection.js +11 -2
- package/package.json +13 -13
package/lib/connection.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ declare class Connection extends EventEmitter {
|
|
|
35
35
|
readonly timeout?: number;
|
|
36
36
|
readonly connectionTimeout: number;
|
|
37
37
|
readonly hash?: string;
|
|
38
|
+
private onlineSince;
|
|
38
39
|
private networkID?;
|
|
39
40
|
private apiVersion;
|
|
40
41
|
private serverInfoUpdating;
|
|
@@ -50,6 +51,7 @@ declare class Connection extends EventEmitter {
|
|
|
50
51
|
request(request: Request, options?: any): Promise<Response | any>;
|
|
51
52
|
submit(transaction: string): Promise<Response | any>;
|
|
52
53
|
isConnected(): boolean;
|
|
54
|
+
getOnlinePeriodMs(): number | null;
|
|
53
55
|
getLatencyMs(): number;
|
|
54
56
|
getNetworkID(): number | undefined;
|
|
55
57
|
isLedgerIndexAvailable(ledgerIndex: any): boolean;
|
package/lib/connection.js
CHANGED
|
@@ -18,6 +18,8 @@ exports.DEFAULT_API_VERSION = xrpl_1.RIPPLED_API_V1;
|
|
|
18
18
|
class Connection extends events_1.EventEmitter {
|
|
19
19
|
constructor(url, type, options = {}) {
|
|
20
20
|
super();
|
|
21
|
+
this.latency = [];
|
|
22
|
+
this.onlineSince = null;
|
|
21
23
|
this.serverInfo = {};
|
|
22
24
|
this.shutdown = false;
|
|
23
25
|
this.connectionTimer = null;
|
|
@@ -30,7 +32,6 @@ class Connection extends events_1.EventEmitter {
|
|
|
30
32
|
else {
|
|
31
33
|
this.types = [];
|
|
32
34
|
}
|
|
33
|
-
this.latency = [];
|
|
34
35
|
this.client = null;
|
|
35
36
|
this.logger = options.logger;
|
|
36
37
|
this.timeout = options.timeout;
|
|
@@ -91,7 +92,7 @@ class Connection extends events_1.EventEmitter {
|
|
|
91
92
|
return { error: "Not connected" };
|
|
92
93
|
}
|
|
93
94
|
const startDate = new Date();
|
|
94
|
-
const response = await this.client.request(request);
|
|
95
|
+
const response = await this.client.connection.request(request);
|
|
95
96
|
const endDate = new Date();
|
|
96
97
|
this.updateLatency(endDate.getTime() - startDate.getTime());
|
|
97
98
|
return response;
|
|
@@ -138,6 +139,12 @@ class Connection extends events_1.EventEmitter {
|
|
|
138
139
|
}
|
|
139
140
|
return this.client.isConnected();
|
|
140
141
|
}
|
|
142
|
+
getOnlinePeriodMs() {
|
|
143
|
+
if (this.isConnected()) {
|
|
144
|
+
return this.onlineSince ? new Date().getTime() - this.onlineSince : 0;
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
141
148
|
getLatencyMs() {
|
|
142
149
|
return this.latency.map((info) => info.delta).reduce((a, b) => a + b, 0) / this.latency.length || 0;
|
|
143
150
|
}
|
|
@@ -219,6 +226,7 @@ class Connection extends events_1.EventEmitter {
|
|
|
219
226
|
url: this.url,
|
|
220
227
|
});
|
|
221
228
|
this.emit("connected");
|
|
229
|
+
this.onlineSince = new Date().getTime();
|
|
222
230
|
});
|
|
223
231
|
this.client.on("disconnected", (code) => {
|
|
224
232
|
this.logger?.debug({
|
|
@@ -227,6 +235,7 @@ class Connection extends events_1.EventEmitter {
|
|
|
227
235
|
code,
|
|
228
236
|
url: this.url,
|
|
229
237
|
});
|
|
238
|
+
this.onlineSince = 0;
|
|
230
239
|
this.serverInfo = null;
|
|
231
240
|
this.streamsSubscribed = false;
|
|
232
241
|
this.emit("disconnected", code);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bithomp/xrpl-api",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.4",
|
|
4
4
|
"description": "A Bithomp JavaScript/TypeScript library for interacting with the XRP Ledger",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
44
44
|
"lint": "eslint -c .eslintrc.json --ext .ts src/",
|
|
45
45
|
"prepare": "npm run build",
|
|
46
|
-
"prepublishOnly": "npm test && npm run lint",
|
|
46
|
+
"-prepublishOnly": "npm test && npm run lint",
|
|
47
47
|
"preversion": "npm run lint",
|
|
48
48
|
"version": "npm run format && git add -A src",
|
|
49
49
|
"postversion": "git push && git push --tags"
|
|
@@ -52,35 +52,35 @@
|
|
|
52
52
|
"lib/**/*"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"axios": "^1.7.
|
|
55
|
+
"axios": "^1.7.7",
|
|
56
56
|
"base-x": "^5.0.0",
|
|
57
57
|
"bignumber.js": "^9.1.2",
|
|
58
|
-
"elliptic": "^6.5.
|
|
58
|
+
"elliptic": "^6.5.7",
|
|
59
59
|
"lodash": "^4.17.21",
|
|
60
60
|
"ripple-address-codec": "^5.0.0",
|
|
61
61
|
"ripple-binary-codec": "^2.1.0",
|
|
62
62
|
"xrpl": "^4.0.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@types/chai": "^4.3.
|
|
65
|
+
"@types/chai": "^4.3.19",
|
|
66
66
|
"@types/chai-as-promised": "^7.1.8",
|
|
67
67
|
"@types/lodash": "^4.17.7",
|
|
68
68
|
"@types/mocha": "^10.0.7",
|
|
69
69
|
"@types/nconf": "^0.10.7",
|
|
70
|
-
"@types/node": "^20.14.
|
|
71
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
72
|
-
"@typescript-eslint/parser": "^
|
|
70
|
+
"@types/node": "^20.14.15",
|
|
71
|
+
"@typescript-eslint/eslint-plugin": "^8.4.0",
|
|
72
|
+
"@typescript-eslint/parser": "^8.4.0",
|
|
73
73
|
"chai": "^4.5.0",
|
|
74
74
|
"chai-as-promised": "^7.1.2",
|
|
75
75
|
"eslint": "^8.57.0",
|
|
76
76
|
"eslint-config-prettier": "^9.1.0",
|
|
77
77
|
"eslint-plugin-chai-friendly": "^1.0.1",
|
|
78
|
-
"eslint-plugin-import": "^2.
|
|
79
|
-
"eslint-plugin-n": "^17.10.
|
|
80
|
-
"eslint-plugin-promise": "^7.
|
|
81
|
-
"mocha": "^10.7.
|
|
78
|
+
"eslint-plugin-import": "^2.30.0",
|
|
79
|
+
"eslint-plugin-n": "^17.10.2",
|
|
80
|
+
"eslint-plugin-promise": "^7.1.0",
|
|
81
|
+
"mocha": "^10.7.3",
|
|
82
82
|
"nconf": "^0.12.1",
|
|
83
|
-
"ts-jest": "^29.2.
|
|
83
|
+
"ts-jest": "^29.2.5",
|
|
84
84
|
"ts-node": "^10.9.2",
|
|
85
85
|
"typescript": "^5.4.5"
|
|
86
86
|
}
|