@bithomp/xrpl-api 3.0.7 → 3.0.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/ledger/transaction.d.ts +6 -1
- package/lib/ledger/transaction.js +60 -41
- package/package.json +4 -4
|
@@ -30,10 +30,15 @@ interface SubmitPaymentTransactionV1Interface {
|
|
|
30
30
|
secret: string;
|
|
31
31
|
fee?: string;
|
|
32
32
|
sequence?: number;
|
|
33
|
+
lastLedgerSequence?: number;
|
|
33
34
|
}
|
|
34
35
|
export declare function submitPaymentTransactionV1(data: SubmitPaymentTransactionV1Interface, definitions?: XrplDefinitionsBase, validateTx?: boolean): Promise<TransactionResponse | FormattedTransaction | ErrorResponse>;
|
|
35
36
|
export declare function getAccountPaymentParams(account: string, connection?: Connection): Promise<AccountPaymentParamsInterface | ErrorResponse>;
|
|
36
|
-
export declare function getTxSubmitParams(account: string, tx?: string | any, definitions?: XrplDefinitionsBase, connection?: Connection
|
|
37
|
+
export declare function getTxSubmitParams(account: string, tx?: string | any, definitions?: XrplDefinitionsBase, connection?: Connection, skip?: {
|
|
38
|
+
fee?: boolean;
|
|
39
|
+
sequence?: boolean;
|
|
40
|
+
lastLedgerSequence?: boolean;
|
|
41
|
+
}): Promise<AccountPaymentParamsInterface | ErrorResponse>;
|
|
37
42
|
export interface SubmitOptionsInterface {
|
|
38
43
|
connection?: Connection;
|
|
39
44
|
definitions?: XrplDefinitionsBase;
|
|
@@ -185,7 +185,12 @@ async function submitPaymentTransactionV1(data, definitions, validateTx) {
|
|
|
185
185
|
memos: data.memos,
|
|
186
186
|
};
|
|
187
187
|
const transaction = (0, payment_1.createPaymentTransaction)(data.sourceAddress, txPayment);
|
|
188
|
-
const
|
|
188
|
+
const skip = {
|
|
189
|
+
fee: data.fee ? true : false,
|
|
190
|
+
sequence: data.sequence ? true : false,
|
|
191
|
+
lastLedgerSequence: data.lastLedgerSequence ? true : false,
|
|
192
|
+
};
|
|
193
|
+
const submitParams = await getTxSubmitParams(data.sourceAddress, transaction, definitions, connection, skip);
|
|
189
194
|
if ("error" in submitParams) {
|
|
190
195
|
return submitParams;
|
|
191
196
|
}
|
|
@@ -201,7 +206,12 @@ async function submitPaymentTransactionV1(data, definitions, validateTx) {
|
|
|
201
206
|
else {
|
|
202
207
|
transaction.Sequence = submitParams.sequence;
|
|
203
208
|
}
|
|
204
|
-
|
|
209
|
+
if (data.lastLedgerSequence) {
|
|
210
|
+
transaction.LastLedgerSequence = data.lastLedgerSequence;
|
|
211
|
+
}
|
|
212
|
+
else if (submitParams.lastLedgerSequence) {
|
|
213
|
+
transaction.LastLedgerSequence = submitParams.lastLedgerSequence;
|
|
214
|
+
}
|
|
205
215
|
const wallet = (0, wallet_1.walletFromSeed)(data.secret, { seedAddress: transaction.Account });
|
|
206
216
|
const signedTransaction = (0, wallet_1.signTransaction)(wallet, transaction, false, definitions, validateTx).tx_blob;
|
|
207
217
|
return await submit(signedTransaction, { connection, definitions });
|
|
@@ -265,55 +275,64 @@ async function getAccountPaymentParams(account, connection) {
|
|
|
265
275
|
}
|
|
266
276
|
}
|
|
267
277
|
exports.getAccountPaymentParams = getAccountPaymentParams;
|
|
268
|
-
async function getTxSubmitParams(account, tx, definitions, connection) {
|
|
278
|
+
async function getTxSubmitParams(account, tx, definitions, connection, skip) {
|
|
269
279
|
try {
|
|
270
280
|
connection = connection || Client.findConnection("submit") || undefined;
|
|
271
281
|
if (!connection) {
|
|
272
282
|
throw new Error("There is no connection");
|
|
273
283
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
284
|
+
let feePromise;
|
|
285
|
+
let sequencePromise;
|
|
286
|
+
let lastLedgerSequencePromise;
|
|
287
|
+
if (skip?.fee !== true) {
|
|
288
|
+
feePromise = new Promise(async (resolve, rejects) => {
|
|
289
|
+
try {
|
|
290
|
+
if (tx && typeof tx === "object") {
|
|
291
|
+
tx = { ...tx, Sequence: 0, Fee: "0", SigningPubKey: "" };
|
|
292
|
+
}
|
|
293
|
+
const baseFee = await Client.getFee({ connection, tx, definitions });
|
|
294
|
+
let fee = parseFloat(baseFee);
|
|
295
|
+
if (fee > FEE_LIMIT) {
|
|
296
|
+
fee = FEE_LIMIT;
|
|
297
|
+
}
|
|
298
|
+
resolve((0, common_1.xrpToDrops)(fee.toString()));
|
|
278
299
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if (fee > FEE_LIMIT) {
|
|
282
|
-
fee = FEE_LIMIT;
|
|
300
|
+
catch (e) {
|
|
301
|
+
rejects(e);
|
|
283
302
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
if (skip?.sequence !== true) {
|
|
306
|
+
sequencePromise = new Promise(async (resolve, rejects) => {
|
|
307
|
+
try {
|
|
308
|
+
const accountData = await Client.getAccountInfoData(account, { connection });
|
|
309
|
+
if (!accountData) {
|
|
310
|
+
return rejects(new Error("Account not found"));
|
|
311
|
+
}
|
|
312
|
+
if ("error" in accountData) {
|
|
313
|
+
return rejects(new Error(accountData.error));
|
|
314
|
+
}
|
|
315
|
+
resolve(accountData.Sequence);
|
|
295
316
|
}
|
|
296
|
-
|
|
297
|
-
|
|
317
|
+
catch (e) {
|
|
318
|
+
rejects(e);
|
|
298
319
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
resolve(ledgerIndex + MAX_LEDGERS_AWAIT);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
if (skip?.lastLedgerSequence !== true) {
|
|
323
|
+
lastLedgerSequencePromise = new Promise(async (resolve) => {
|
|
324
|
+
try {
|
|
325
|
+
const ledgerIndex = await Client.getLedgerIndex();
|
|
326
|
+
if (ledgerIndex !== undefined) {
|
|
327
|
+
resolve(ledgerIndex + MAX_LEDGERS_AWAIT);
|
|
328
|
+
}
|
|
329
|
+
resolve(undefined);
|
|
310
330
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
});
|
|
331
|
+
catch (e) {
|
|
332
|
+
resolve(undefined);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
317
336
|
const result = await Promise.all([feePromise, sequencePromise, lastLedgerSequencePromise]);
|
|
318
337
|
return {
|
|
319
338
|
fee: result[0],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bithomp/xrpl-api",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.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",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"axios": "^1.7.2",
|
|
52
|
-
"base-x": "^
|
|
52
|
+
"base-x": "^5.0.0",
|
|
53
53
|
"bignumber.js": "^9.1.2",
|
|
54
54
|
"elliptic": "^6.5.5",
|
|
55
55
|
"lodash": "^4.17.21",
|
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
"@types/chai": "^4.3.16",
|
|
62
62
|
"@types/chai-as-promised": "^7.1.8",
|
|
63
63
|
"@types/lodash": "^4.17.5",
|
|
64
|
-
"@types/mocha": "^10.0.
|
|
64
|
+
"@types/mocha": "^10.0.7",
|
|
65
65
|
"@types/nconf": "^0.10.6",
|
|
66
|
-
"@types/node": "^20.14.
|
|
66
|
+
"@types/node": "^20.14.8",
|
|
67
67
|
"@typescript-eslint/eslint-plugin": "^7.13.1",
|
|
68
68
|
"@typescript-eslint/parser": "^7.13.1",
|
|
69
69
|
"chai": "^4.4.1",
|