@bithomp/xrpl-api 3.1.5 → 3.1.7
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/common/utils.d.ts +1 -0
- package/lib/common/utils.js +4 -0
- package/lib/connection.js +15 -9
- package/lib/ledger/account_tx.js +8 -1
- package/lib/ledger/transaction.js +1 -1
- package/package.json +5 -5
package/lib/common/utils.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type SortDirection = -1 | 0 | 1;
|
|
|
3
3
|
export declare function signum(num: number): SortDirection;
|
|
4
4
|
export declare function compareTransactions(first: any, second: any): SortDirection;
|
|
5
5
|
export declare function sleep(ms: number): Promise<void>;
|
|
6
|
+
export declare function getTimestamp(): number;
|
|
6
7
|
export declare function createMarker(hash: string, marker?: any): any;
|
|
7
8
|
export declare function parseMarker(marker?: any): any;
|
|
8
9
|
export declare function dropsToXrp(drops: BigNumber.Value): string;
|
package/lib/common/utils.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.signum = signum;
|
|
7
7
|
exports.compareTransactions = compareTransactions;
|
|
8
8
|
exports.sleep = sleep;
|
|
9
|
+
exports.getTimestamp = getTimestamp;
|
|
9
10
|
exports.createMarker = createMarker;
|
|
10
11
|
exports.parseMarker = parseMarker;
|
|
11
12
|
exports.dropsToXrp = dropsToXrp;
|
|
@@ -32,6 +33,9 @@ async function sleep(ms) {
|
|
|
32
33
|
setTimeout(resolve, ms);
|
|
33
34
|
});
|
|
34
35
|
}
|
|
36
|
+
function getTimestamp() {
|
|
37
|
+
return new Date().getTime();
|
|
38
|
+
}
|
|
35
39
|
function createMarker(hash, marker) {
|
|
36
40
|
if (marker === undefined) {
|
|
37
41
|
return undefined;
|
package/lib/connection.js
CHANGED
|
@@ -88,20 +88,26 @@ class Connection extends events_1.EventEmitter {
|
|
|
88
88
|
(request.command === "subscribe" || request.command === "unsubscribe")) {
|
|
89
89
|
return this.updateSubscriptions(request);
|
|
90
90
|
}
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
const waitTime = (0, utils_1.getTimestamp)() + RECONNECT_TIMEOUT;
|
|
92
|
+
while ((!this.client || !this.isConnected())) {
|
|
93
|
+
await (0, utils_1.sleep)(100);
|
|
94
|
+
if (this.shutdown) {
|
|
95
|
+
return { error: "shutdownConnection", error_message: "Connection is shutdown.", status: "error" };
|
|
96
|
+
}
|
|
97
|
+
if ((0, utils_1.getTimestamp)() > waitTime) {
|
|
98
|
+
return { error: "notConnected", error_message: "Not connected.", status: "error" };
|
|
99
|
+
}
|
|
93
100
|
}
|
|
94
|
-
const
|
|
101
|
+
const startTimestamp = (0, utils_1.getTimestamp)();
|
|
95
102
|
if (this.apiVersion && !request.hasOwnProperty("api_version") && exports.DEFAULT_API_VERSION !== this.apiVersion) {
|
|
96
103
|
request.api_version = this.apiVersion;
|
|
97
104
|
}
|
|
98
105
|
const response = await this.client.connection.request(request);
|
|
99
|
-
|
|
100
|
-
this.updateLatency(endDate.getTime() - startDate.getTime());
|
|
106
|
+
this.updateLatency((0, utils_1.getTimestamp)() - startTimestamp);
|
|
101
107
|
return response;
|
|
102
108
|
}
|
|
103
109
|
catch (err) {
|
|
104
|
-
this.updateLatency(
|
|
110
|
+
this.updateLatency(RECONNECT_TIMEOUT);
|
|
105
111
|
this.logger?.debug({
|
|
106
112
|
service: "Bithomp::XRPL::Connection",
|
|
107
113
|
function: "request",
|
|
@@ -144,7 +150,7 @@ class Connection extends events_1.EventEmitter {
|
|
|
144
150
|
}
|
|
145
151
|
getOnlinePeriodMs() {
|
|
146
152
|
if (this.isConnected()) {
|
|
147
|
-
return this.onlineSince ?
|
|
153
|
+
return this.onlineSince ? (0, utils_1.getTimestamp)() - this.onlineSince : 0;
|
|
148
154
|
}
|
|
149
155
|
return null;
|
|
150
156
|
}
|
|
@@ -229,7 +235,7 @@ class Connection extends events_1.EventEmitter {
|
|
|
229
235
|
url: this.url,
|
|
230
236
|
});
|
|
231
237
|
this.emit("connected");
|
|
232
|
-
this.onlineSince =
|
|
238
|
+
this.onlineSince = (0, utils_1.getTimestamp)();
|
|
233
239
|
});
|
|
234
240
|
this.client.connection.on("disconnected", (code) => {
|
|
235
241
|
this.logger?.debug({
|
|
@@ -383,7 +389,7 @@ class Connection extends events_1.EventEmitter {
|
|
|
383
389
|
return await this.request(request, { skip_subscription_update: true });
|
|
384
390
|
}
|
|
385
391
|
onLedgerClosed(ledgerStream) {
|
|
386
|
-
const time =
|
|
392
|
+
const time = (0, utils_1.getTimestamp)();
|
|
387
393
|
const ledgerTime = (0, ledger_1.ledgerTimeToTimestamp)(ledgerStream.ledger_time);
|
|
388
394
|
if (ledgerTime < time) {
|
|
389
395
|
this.updateLatency(time - ledgerTime);
|
package/lib/ledger/account_tx.js
CHANGED
|
@@ -76,6 +76,13 @@ async function getTransactions(account, options = { limit: DEFAULT_LIMIT }) {
|
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
const result = response?.result;
|
|
79
|
+
if (!result) {
|
|
80
|
+
return {
|
|
81
|
+
account,
|
|
82
|
+
status: "error",
|
|
83
|
+
error: "invalidResponse",
|
|
84
|
+
};
|
|
85
|
+
}
|
|
79
86
|
if (Array.isArray(result.transactions)) {
|
|
80
87
|
if (options.balanceChanges === true || options.specification === true) {
|
|
81
88
|
for (const transaction of result.transactions) {
|
|
@@ -152,7 +159,7 @@ async function findTransactions(account, options = { limit: DEFAULT_LIMIT, timeo
|
|
|
152
159
|
break;
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
|
-
if (accountTransactionsError) {
|
|
162
|
+
if (accountTransactionsError && transactions.length === 0) {
|
|
156
163
|
return accountTransactionsError;
|
|
157
164
|
}
|
|
158
165
|
if (options.marker && transactions.length === 0) {
|
|
@@ -387,7 +387,7 @@ async function waitForFinalTransactionOutcome(txHash, lastLedger) {
|
|
|
387
387
|
await (0, utils_1.sleep)(LEDGER_CLOSE_TIME_AWAIT);
|
|
388
388
|
const tx = await getTransaction(txHash);
|
|
389
389
|
const error = tx?.error;
|
|
390
|
-
if (error === "
|
|
390
|
+
if (error === "notConnected") {
|
|
391
391
|
return tx;
|
|
392
392
|
}
|
|
393
393
|
if (!tx || error === "txnNotFound" || tx.validated !== true) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bithomp/xrpl-api",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.7",
|
|
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",
|
|
@@ -65,18 +65,18 @@
|
|
|
65
65
|
"@types/chai": "^4.3.19",
|
|
66
66
|
"@types/chai-as-promised": "^7.1.8",
|
|
67
67
|
"@types/lodash": "^4.17.7",
|
|
68
|
-
"@types/mocha": "^10.0.
|
|
68
|
+
"@types/mocha": "^10.0.8",
|
|
69
69
|
"@types/nconf": "^0.10.7",
|
|
70
70
|
"@types/node": "^20.14.15",
|
|
71
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
72
|
-
"@typescript-eslint/parser": "^8.
|
|
71
|
+
"@typescript-eslint/eslint-plugin": "^8.6.0",
|
|
72
|
+
"@typescript-eslint/parser": "^8.6.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
78
|
"eslint-plugin-import": "^2.30.0",
|
|
79
|
-
"eslint-plugin-n": "^17.10.
|
|
79
|
+
"eslint-plugin-n": "^17.10.3",
|
|
80
80
|
"eslint-plugin-promise": "^7.1.0",
|
|
81
81
|
"mocha": "^10.7.3",
|
|
82
82
|
"nconf": "^0.12.1",
|