@bithomp/xrpl-api 3.7.2 → 3.7.3
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/client.d.ts +2 -0
- package/lib/client.js +32 -0
- package/lib/connection.d.ts +1 -0
- package/lib/connection.js +18 -0
- package/lib/ledger/ledger.js +1 -1
- package/package.json +4 -4
package/lib/client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Connection, ConnectionOptions } from "./connection";
|
|
2
|
+
import { LedgerIndex } from "./models/ledger";
|
|
2
3
|
export * from "./ledger";
|
|
3
4
|
export declare let feeCushion: number;
|
|
4
5
|
export declare let logger: any;
|
|
@@ -21,3 +22,4 @@ export declare function connect(): Promise<void>;
|
|
|
21
22
|
export declare function disconnect(): Promise<void>;
|
|
22
23
|
export declare function getNativeCurrency(): string;
|
|
23
24
|
export declare function findConnection(type?: string, url?: string, strongFilter?: boolean, hash?: string, networkID?: number): Connection | null;
|
|
25
|
+
export declare function findConnectionByLedger(ledgerIndex?: LedgerIndex, ledgerHash?: string, networkID?: number): Connection | null;
|
package/lib/client.js
CHANGED
|
@@ -20,6 +20,7 @@ exports.connect = connect;
|
|
|
20
20
|
exports.disconnect = disconnect;
|
|
21
21
|
exports.getNativeCurrency = getNativeCurrency;
|
|
22
22
|
exports.findConnection = findConnection;
|
|
23
|
+
exports.findConnectionByLedger = findConnectionByLedger;
|
|
23
24
|
const connection_1 = require("./connection");
|
|
24
25
|
const common_1 = require("./common");
|
|
25
26
|
__exportStar(require("./ledger"), exports);
|
|
@@ -149,6 +150,37 @@ function findConnection(type, url, strongFilter, hash, networkID) {
|
|
|
149
150
|
connections = connections.sort(sortHelperConnections);
|
|
150
151
|
return connections[0];
|
|
151
152
|
}
|
|
153
|
+
function findConnectionByLedger(ledgerIndex, ledgerHash, networkID) {
|
|
154
|
+
if (ledgerHash) {
|
|
155
|
+
return findConnection("history", undefined, false, undefined, networkID);
|
|
156
|
+
}
|
|
157
|
+
if (typeof ledgerIndex === "string" || ledgerIndex === undefined) {
|
|
158
|
+
return findConnection(undefined, undefined, false, undefined, networkID);
|
|
159
|
+
}
|
|
160
|
+
const availableConnections = clientConnections.filter((con) => {
|
|
161
|
+
if (!con.isConnected()) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
if (typeof networkID === "number" && typeof con.getNetworkID() === "number") {
|
|
165
|
+
if (con.getNetworkID() !== networkID) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return con.isLedgerIndexPresent(ledgerIndex);
|
|
170
|
+
});
|
|
171
|
+
if (availableConnections.length === 0) {
|
|
172
|
+
return findConnection(undefined, undefined, false, undefined, networkID);
|
|
173
|
+
}
|
|
174
|
+
else if (availableConnections.length === 1) {
|
|
175
|
+
return availableConnections[0];
|
|
176
|
+
}
|
|
177
|
+
if (loadBalancing) {
|
|
178
|
+
const index = Math.floor(Math.random() * availableConnections.length);
|
|
179
|
+
return availableConnections[index];
|
|
180
|
+
}
|
|
181
|
+
const sortedConnections = availableConnections.sort(sortHelperConnections);
|
|
182
|
+
return sortedConnections[0];
|
|
183
|
+
}
|
|
152
184
|
function sortHelperConnections(a, b) {
|
|
153
185
|
if (a.getLatencyMs() < b.getLatencyMs()) {
|
|
154
186
|
return -1;
|
package/lib/connection.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ declare class Connection extends EventEmitter {
|
|
|
57
57
|
getLatencyMs(): number;
|
|
58
58
|
getNetworkID(): number | undefined;
|
|
59
59
|
isLedgerIndexAvailable(ledgerIndex: any): boolean;
|
|
60
|
+
isLedgerIndexPresent(ledgerIndex: any): boolean;
|
|
60
61
|
private updateLatency;
|
|
61
62
|
private reconnect;
|
|
62
63
|
private removeClient;
|
package/lib/connection.js
CHANGED
|
@@ -259,6 +259,24 @@ class Connection extends events_1.EventEmitter {
|
|
|
259
259
|
}
|
|
260
260
|
return true;
|
|
261
261
|
}
|
|
262
|
+
isLedgerIndexPresent(ledgerIndex) {
|
|
263
|
+
if (typeof ledgerIndex !== "number") {
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
if (!this.serverInfo?.complete_ledgers) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
const completeLedgers = this.serverInfo.complete_ledgers.split("-");
|
|
270
|
+
if (completeLedgers.length !== 2) {
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
completeLedgers[0] = parseInt(completeLedgers[0], 10);
|
|
274
|
+
completeLedgers[1] = parseInt(completeLedgers[1], 10);
|
|
275
|
+
if (ledgerIndex < completeLedgers[0] || ledgerIndex > completeLedgers[1]) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
262
280
|
updateLatency(delta) {
|
|
263
281
|
this.latency.push({
|
|
264
282
|
timestamp: new Date(),
|
package/lib/ledger/ledger.js
CHANGED
|
@@ -40,7 +40,7 @@ const ledger_1 = require("../parse/ledger/ledger");
|
|
|
40
40
|
const utils_1 = require("../common/utils");
|
|
41
41
|
async function getLedger(options = {}) {
|
|
42
42
|
const formatted = options.legacy === true || options.formatted === true;
|
|
43
|
-
const connection = options.connection || Client.
|
|
43
|
+
const connection = options.connection || Client.findConnectionByLedger(options.ledgerIndex, options.ledgerHash);
|
|
44
44
|
if (!connection) {
|
|
45
45
|
throw new Error("There is no connection");
|
|
46
46
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bithomp/xrpl-api",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.3",
|
|
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",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"lib/**/*"
|
|
52
52
|
],
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"axios": "^1.13.
|
|
54
|
+
"axios": "^1.13.2",
|
|
55
55
|
"base-x": "^5.0.1",
|
|
56
56
|
"bignumber.js": "^9.3.1",
|
|
57
57
|
"elliptic": "^6.6.1",
|
|
@@ -73,13 +73,13 @@
|
|
|
73
73
|
"@typescript-eslint/parser": "^8.46.2",
|
|
74
74
|
"chai": "^6.2.0",
|
|
75
75
|
"chai-as-promised": "^8.0.2",
|
|
76
|
-
"eslint": "^9.39.
|
|
76
|
+
"eslint": "^9.39.1",
|
|
77
77
|
"eslint-config-prettier": "^10.1.8",
|
|
78
78
|
"eslint-plugin-chai-friendly": "^1.1.0",
|
|
79
79
|
"eslint-plugin-import": "^2.32.0",
|
|
80
80
|
"eslint-plugin-n": "^17.23.1",
|
|
81
81
|
"eslint-plugin-promise": "^7.2.1",
|
|
82
|
-
"mocha": "^11.7.
|
|
82
|
+
"mocha": "^11.7.5",
|
|
83
83
|
"nconf": "^0.13.0",
|
|
84
84
|
"ts-jest": "^29.4.5",
|
|
85
85
|
"ts-node": "^10.9.2",
|