@bithomp/xrpl-api 3.1.6 → 3.1.8

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 CHANGED
@@ -18,6 +18,6 @@ export interface ClientConnection {
18
18
  }
19
19
  export declare function setup(servers: ClientConnection[], options?: ClientOptions): void;
20
20
  export declare function connect(): Promise<void>;
21
- export declare function disconnect(): void;
21
+ export declare function disconnect(): Promise<void>;
22
22
  export declare function getNativeCurrency(): string;
23
23
  export declare function findConnection(type?: string, url?: string, strongFilter?: boolean, hash?: string, networkID?: number): Connection | null;
package/lib/client.js CHANGED
@@ -61,13 +61,13 @@ async function connect() {
61
61
  await connection.connect();
62
62
  }
63
63
  }
64
- function disconnect() {
64
+ async function disconnect() {
65
65
  exports.logger?.debug({
66
66
  service: "Bithomp::XRPL::Client",
67
67
  function: "disconnect",
68
68
  });
69
69
  for (const connection of clientConnections) {
70
- connection.disconnect();
70
+ await connection.disconnect();
71
71
  }
72
72
  }
73
73
  function getNativeCurrency() {
@@ -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;
@@ -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
- if (!this.client || !this.isConnected()) {
92
- return { error: "Not connected" };
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 startDate = new Date();
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
- const endDate = new Date();
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(1000);
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 ? new Date().getTime() - this.onlineSince : 0;
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 = new Date().getTime();
238
+ this.onlineSince = (0, utils_1.getTimestamp)();
233
239
  });
234
240
  this.client.connection.on("disconnected", (code) => {
235
241
  this.logger?.debug({
@@ -273,6 +279,9 @@ class Connection extends events_1.EventEmitter {
273
279
  this.client.connection.on("validationReceived", (validation) => {
274
280
  this.emit("validationReceived", validation);
275
281
  });
282
+ this.client.connection.on("manifestReceived", (manifest) => {
283
+ this.emit("manifestReceived", manifest);
284
+ });
276
285
  this.client.connection.on("peerStatusChange", (status) => {
277
286
  this.emit("peerStatusChange", status);
278
287
  });
@@ -349,8 +358,11 @@ class Connection extends events_1.EventEmitter {
349
358
  return { status: "success" };
350
359
  }
351
360
  async subscribe(streams, accounts) {
361
+ if (this.shutdown) {
362
+ return { error: "shutdownConnection", error_message: "Connection is shutdown.", status: "error" };
363
+ }
352
364
  if (this.streamsSubscribed === true && streams === undefined && accounts === undefined) {
353
- return null;
365
+ return { status: "success" };
354
366
  }
355
367
  streams = streams || Object.keys(this.streams);
356
368
  accounts = accounts || Object.keys(this.accounts);
@@ -383,7 +395,7 @@ class Connection extends events_1.EventEmitter {
383
395
  return await this.request(request, { skip_subscription_update: true });
384
396
  }
385
397
  onLedgerClosed(ledgerStream) {
386
- const time = new Date().getTime();
398
+ const time = (0, utils_1.getTimestamp)();
387
399
  const ledgerTime = (0, ledger_1.ledgerTimeToTimestamp)(ledgerStream.ledger_time);
388
400
  if (ledgerTime < time) {
389
401
  this.updateLatency(time - ledgerTime);
@@ -28,10 +28,17 @@ export interface GetAccountNFTOffersObjectsOptions {
28
28
  marker?: string;
29
29
  }
30
30
  export declare function getAccountNFTOffersObjects(account: string, options?: GetAccountNFTOffersObjectsOptions): Promise<AccountNFTObjectsResponse | ErrorResponse>;
31
+ export interface GetAccountDepositPreauthObjectsOptions {
32
+ ledgerHash?: string;
33
+ ledgerIndex?: LedgerIndex;
34
+ limit?: number;
35
+ marker?: string;
36
+ }
37
+ export declare function getAccountDepositPreauthObjects(account: string, options?: GetAccountDepositPreauthObjectsOptions): Promise<any | ErrorResponse>;
31
38
  export interface GetAccountURITokensObjectsOptions {
32
39
  ledgerHash?: string;
33
40
  ledgerIndex?: LedgerIndex;
34
41
  limit?: number;
35
42
  marker?: string;
36
43
  }
37
- export declare function getAccountURITokensObjects(account: string, options?: GetAccountNFTOffersObjectsOptions): Promise<AccountURITokensObjectsResponse | ErrorResponse>;
44
+ export declare function getAccountURITokensObjects(account: string, options?: GetAccountURITokensObjectsOptions): Promise<AccountURITokensObjectsResponse | ErrorResponse>;
@@ -27,6 +27,7 @@ exports.getAccountObjects = getAccountObjects;
27
27
  exports.getAccountAllObjects = getAccountAllObjects;
28
28
  exports.getAccountLinesObjects = getAccountLinesObjects;
29
29
  exports.getAccountNFTOffersObjects = getAccountNFTOffersObjects;
30
+ exports.getAccountDepositPreauthObjects = getAccountDepositPreauthObjects;
30
31
  exports.getAccountURITokensObjects = getAccountURITokensObjects;
31
32
  const Client = __importStar(require("../client"));
32
33
  const account_object_1 = require("../models/account_object");
@@ -78,7 +79,8 @@ async function getAccountObjects(account, options = {}) {
78
79
  }
79
80
  async function getAccountAllObjects(account, options = {}) {
80
81
  const loadOptions = { ...options };
81
- loadOptions.connection = loadOptions.connection || Client.findConnection("account_objects", undefined, undefined);
82
+ loadOptions.connection =
83
+ loadOptions.connection || Client.findConnection("account_objects", undefined, undefined);
82
84
  const timeStart = new Date();
83
85
  const limit = loadOptions.limit;
84
86
  let response;
@@ -127,7 +129,7 @@ async function getAccountAllObjects(account, options = {}) {
127
129
  };
128
130
  }
129
131
  response.account_objects = accountObjects;
130
- if (!options.hasOwnProperty("limit")) {
132
+ if (!options.hasOwnProperty("limit") || options.limit === undefined) {
131
133
  delete response.limit;
132
134
  }
133
135
  return response;
@@ -172,8 +174,22 @@ async function getAccountNFTOffersObjects(account, options = {}) {
172
174
  nft_offers: nftOffers,
173
175
  };
174
176
  }
177
+ async function getAccountDepositPreauthObjects(account, options = {}) {
178
+ const response = await getAccountAllObjects(account, {
179
+ type: "deposit_preauth",
180
+ ledgerHash: options.ledgerHash,
181
+ ledgerIndex: options.ledgerIndex,
182
+ limit: options.limit,
183
+ marker: options.marker,
184
+ });
185
+ if ("error" in response) {
186
+ return response;
187
+ }
188
+ return response;
189
+ }
175
190
  async function getAccountURITokensObjects(account, options = {}) {
176
191
  const response = await getAccountAllObjects(account, {
192
+ type: "uri_token",
177
193
  ledgerHash: options.ledgerHash,
178
194
  ledgerIndex: options.ledgerIndex,
179
195
  limit: options.limit,
@@ -183,12 +199,12 @@ async function getAccountURITokensObjects(account, options = {}) {
183
199
  return response;
184
200
  }
185
201
  const accountObjects = response.account_objects;
186
- const uriTokens = (0, account_object_1.accountObjectsToURITokens)(accountObjects);
202
+ const uritokens = (0, account_object_1.accountObjectsToURITokens)(accountObjects);
187
203
  return {
188
204
  account: response.account,
189
205
  ledger_hash: response.ledger_hash,
190
206
  ledger_index: response.ledger_index,
191
207
  validated: response.validated,
192
- uritokens: uriTokens,
208
+ uritokens: uritokens,
193
209
  };
194
210
  }
@@ -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 === "Not connected") {
390
+ if (error === "notConnected") {
391
391
  return tx;
392
392
  }
393
393
  if (!tx || error === "txnNotFound" || tx.validated !== true) {
@@ -2,7 +2,7 @@ import { LedgerEntry } from "xrpl";
2
2
  import { Trustline } from "./account_lines";
3
3
  import { Amount } from "../types";
4
4
  export type AccountObject = LedgerEntry.Check | LedgerEntry.DepositPreauth | LedgerEntry.Escrow | LedgerEntry.Offer | LedgerEntry.PayChannel | LedgerEntry.SignerList | LedgerEntry.Ticket | LedgerEntry.RippleState;
5
- export type AccountObjectType = "check" | "escrow" | "offer" | "payment_channel" | "signer_list" | "state" | "ticket" | "nft_offer";
5
+ export type AccountObjectType = Exclude<LedgerEntry.LedgerEntryFilter, "amendments" | "fee" | "hashes"> | "uri_token";
6
6
  export interface AccountObjects {
7
7
  account: string;
8
8
  account_objects: AccountObject[];
@@ -70,7 +70,7 @@ function accountObjectsToURITokens(accountObjects) {
70
70
  const uriTokenObjects = accountObjects.filter((obj) => {
71
71
  return obj.LedgerEntryType === "URIToken";
72
72
  });
73
- const uriTokens = uriTokenObjects.map((obj) => {
73
+ const uritokens = uriTokenObjects.map((obj) => {
74
74
  return (0, common_1.removeUndefined)({
75
75
  flags: obj.Flags,
76
76
  index: obj.index,
@@ -84,5 +84,5 @@ function accountObjectsToURITokens(accountObjects) {
84
84
  transaction_hash: obj.PreviousTxnID,
85
85
  });
86
86
  });
87
- return uriTokens;
87
+ return uritokens;
88
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bithomp/xrpl-api",
3
- "version": "3.1.6",
3
+ "version": "3.1.8",
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",
@@ -76,7 +76,7 @@
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.2",
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",