@bithomp/xrpl-api 3.1.7 → 3.1.9
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 +1 -1
- package/lib/client.js +2 -2
- package/lib/connection.js +7 -1
- package/lib/ledger/account_objects.d.ts +8 -1
- package/lib/ledger/account_objects.js +20 -4
- package/lib/ledger/account_tx.js +22 -21
- package/lib/models/account_object.d.ts +1 -1
- package/lib/models/account_object.js +2 -2
- package/package.json +1 -1
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() {
|
package/lib/connection.js
CHANGED
|
@@ -279,6 +279,9 @@ class Connection extends events_1.EventEmitter {
|
|
|
279
279
|
this.client.connection.on("validationReceived", (validation) => {
|
|
280
280
|
this.emit("validationReceived", validation);
|
|
281
281
|
});
|
|
282
|
+
this.client.connection.on("manifestReceived", (manifest) => {
|
|
283
|
+
this.emit("manifestReceived", manifest);
|
|
284
|
+
});
|
|
282
285
|
this.client.connection.on("peerStatusChange", (status) => {
|
|
283
286
|
this.emit("peerStatusChange", status);
|
|
284
287
|
});
|
|
@@ -355,8 +358,11 @@ class Connection extends events_1.EventEmitter {
|
|
|
355
358
|
return { status: "success" };
|
|
356
359
|
}
|
|
357
360
|
async subscribe(streams, accounts) {
|
|
361
|
+
if (this.shutdown) {
|
|
362
|
+
return { error: "shutdownConnection", error_message: "Connection is shutdown.", status: "error" };
|
|
363
|
+
}
|
|
358
364
|
if (this.streamsSubscribed === true && streams === undefined && accounts === undefined) {
|
|
359
|
-
return
|
|
365
|
+
return { status: "success" };
|
|
360
366
|
}
|
|
361
367
|
streams = streams || Object.keys(this.streams);
|
|
362
368
|
accounts = accounts || Object.keys(this.accounts);
|
|
@@ -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?:
|
|
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 =
|
|
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
|
|
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:
|
|
208
|
+
uritokens: uritokens,
|
|
193
209
|
};
|
|
194
210
|
}
|
package/lib/ledger/account_tx.js
CHANGED
|
@@ -107,28 +107,29 @@ async function getTransactions(account, options = { limit: DEFAULT_LIMIT }) {
|
|
|
107
107
|
async function findTransactions(account, options = { limit: DEFAULT_LIMIT, timeout: 15000 }) {
|
|
108
108
|
let transactions = [];
|
|
109
109
|
let accountTransactionsError = null;
|
|
110
|
-
const formatted = options.legacy === true || options.formatted === true;
|
|
111
110
|
const timeStart = new Date();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
const loadOptions = { ...options };
|
|
112
|
+
const formatted = loadOptions.legacy === true || loadOptions.formatted === true;
|
|
113
|
+
loadOptions.binary = false;
|
|
114
|
+
applyLimitOptions(loadOptions);
|
|
115
|
+
await applyStartTxOptions(loadOptions);
|
|
116
|
+
while (transactions.length !== loadOptions.limit) {
|
|
116
117
|
const currentTime = new Date();
|
|
117
|
-
if (
|
|
118
|
+
if (loadOptions.timeout && currentTime.getTime() - timeStart.getTime() > loadOptions.timeout) {
|
|
118
119
|
break;
|
|
119
120
|
}
|
|
120
|
-
let limit =
|
|
121
|
-
if (transactions.length === 0 &&
|
|
121
|
+
let limit = loadOptions.limit;
|
|
122
|
+
if (transactions.length === 0 && loadOptions.startTxHash) {
|
|
122
123
|
limit += LIMIT_INCREASE_COUNT;
|
|
123
124
|
}
|
|
124
|
-
if (
|
|
125
|
+
if (loadOptions.sourceTag || loadOptions.destinationTag) {
|
|
125
126
|
limit += LIMIT_INCREASE_COUNT;
|
|
126
127
|
}
|
|
127
128
|
if (limit > MAX_LIMIT) {
|
|
128
129
|
limit = MAX_LIMIT;
|
|
129
130
|
}
|
|
130
131
|
const accountTransactions = await getTransactions(account, {
|
|
131
|
-
...
|
|
132
|
+
...loadOptions,
|
|
132
133
|
...{ balanceChanges: false, specification: false, limit },
|
|
133
134
|
});
|
|
134
135
|
if (!accountTransactions || accountTransactions.error) {
|
|
@@ -136,16 +137,16 @@ async function findTransactions(account, options = { limit: DEFAULT_LIMIT, timeo
|
|
|
136
137
|
break;
|
|
137
138
|
}
|
|
138
139
|
let newTransactions = accountTransactions.transactions;
|
|
139
|
-
|
|
140
|
+
loadOptions.marker = accountTransactions.marker;
|
|
140
141
|
newTransactions = newTransactions
|
|
141
|
-
.filter(lodash_1.default.partial(filterHelperTransactions, account,
|
|
142
|
-
.filter(lodash_1.default.partial(filterHelperStartTx,
|
|
143
|
-
if (formatted !== true && (
|
|
142
|
+
.filter(lodash_1.default.partial(filterHelperTransactions, account, loadOptions))
|
|
143
|
+
.filter(lodash_1.default.partial(filterHelperStartTx, loadOptions));
|
|
144
|
+
if (formatted !== true && (loadOptions.balanceChanges === true || loadOptions.specification === true)) {
|
|
144
145
|
for (const newTransaction of newTransactions) {
|
|
145
|
-
if (
|
|
146
|
+
if (loadOptions.balanceChanges === true) {
|
|
146
147
|
newTransaction.balanceChanges = (0, xrpl_1.getBalanceChanges)(newTransaction.meta);
|
|
147
148
|
}
|
|
148
|
-
if (
|
|
149
|
+
if (loadOptions.specification === true) {
|
|
149
150
|
const details = (0, transaction_1.getAccountTxDetails)(newTransaction, true);
|
|
150
151
|
newTransaction.specification = details.specification;
|
|
151
152
|
newTransaction.outcome = details.outcome;
|
|
@@ -154,23 +155,23 @@ async function findTransactions(account, options = { limit: DEFAULT_LIMIT, timeo
|
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
157
|
transactions = transactions.concat(newTransactions);
|
|
157
|
-
transactions = transactions.slice(0,
|
|
158
|
-
if (
|
|
158
|
+
transactions = transactions.slice(0, loadOptions.limit);
|
|
159
|
+
if (loadOptions.marker === undefined) {
|
|
159
160
|
break;
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
if (accountTransactionsError && transactions.length === 0) {
|
|
163
164
|
return accountTransactionsError;
|
|
164
165
|
}
|
|
165
|
-
if (
|
|
166
|
+
if (loadOptions.marker && transactions.length === 0) {
|
|
166
167
|
return {
|
|
167
168
|
status: "timeout",
|
|
168
169
|
error: "searchTimeout",
|
|
169
|
-
marker:
|
|
170
|
+
marker: loadOptions.marker,
|
|
170
171
|
};
|
|
171
172
|
}
|
|
172
173
|
if (formatted === true) {
|
|
173
|
-
transactions = transactions.map((transaction) => (0, transaction_1.getAccountTxDetails)(transaction,
|
|
174
|
+
transactions = transactions.map((transaction) => (0, transaction_1.getAccountTxDetails)(transaction, loadOptions.includeRawTransactions === true));
|
|
174
175
|
}
|
|
175
176
|
return transactions;
|
|
176
177
|
}
|
|
@@ -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 =
|
|
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
|
|
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
|
|
87
|
+
return uritokens;
|
|
88
88
|
}
|