@bithomp/xrpl-api 3.0.6 → 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.
@@ -29,10 +29,16 @@ interface SubmitPaymentTransactionV1Interface {
29
29
  memos?: FormattedMemo[];
30
30
  secret: string;
31
31
  fee?: string;
32
+ sequence?: number;
33
+ lastLedgerSequence?: number;
32
34
  }
33
35
  export declare function submitPaymentTransactionV1(data: SubmitPaymentTransactionV1Interface, definitions?: XrplDefinitionsBase, validateTx?: boolean): Promise<TransactionResponse | FormattedTransaction | ErrorResponse>;
34
36
  export declare function getAccountPaymentParams(account: string, connection?: Connection): Promise<AccountPaymentParamsInterface | ErrorResponse>;
35
- export declare function getTxSubmitParams(account: string, tx?: string | any, definitions?: XrplDefinitionsBase, connection?: Connection): Promise<AccountPaymentParamsInterface | ErrorResponse>;
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>;
36
42
  export interface SubmitOptionsInterface {
37
43
  connection?: Connection;
38
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 submitParams = await getTxSubmitParams(data.sourceAddress, transaction, definitions, connection);
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
  }
@@ -195,8 +200,18 @@ async function submitPaymentTransactionV1(data, definitions, validateTx) {
195
200
  else {
196
201
  transaction.Fee = submitParams.fee;
197
202
  }
198
- transaction.Sequence = submitParams.sequence;
199
- transaction.LastLedgerSequence = submitParams.lastLedgerSequence;
203
+ if (data.sequence) {
204
+ transaction.Sequence = data.sequence;
205
+ }
206
+ else {
207
+ transaction.Sequence = submitParams.sequence;
208
+ }
209
+ if (data.lastLedgerSequence) {
210
+ transaction.LastLedgerSequence = data.lastLedgerSequence;
211
+ }
212
+ else if (submitParams.lastLedgerSequence) {
213
+ transaction.LastLedgerSequence = submitParams.lastLedgerSequence;
214
+ }
200
215
  const wallet = (0, wallet_1.walletFromSeed)(data.secret, { seedAddress: transaction.Account });
201
216
  const signedTransaction = (0, wallet_1.signTransaction)(wallet, transaction, false, definitions, validateTx).tx_blob;
202
217
  return await submit(signedTransaction, { connection, definitions });
@@ -260,55 +275,64 @@ async function getAccountPaymentParams(account, connection) {
260
275
  }
261
276
  }
262
277
  exports.getAccountPaymentParams = getAccountPaymentParams;
263
- async function getTxSubmitParams(account, tx, definitions, connection) {
278
+ async function getTxSubmitParams(account, tx, definitions, connection, skip) {
264
279
  try {
265
280
  connection = connection || Client.findConnection("submit") || undefined;
266
281
  if (!connection) {
267
282
  throw new Error("There is no connection");
268
283
  }
269
- const feePromise = new Promise(async (resolve, rejects) => {
270
- try {
271
- if (tx && typeof tx === "object") {
272
- tx = { ...tx, Sequence: 0, Fee: "0", SigningPubKey: "" };
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()));
273
299
  }
274
- const baseFee = await Client.getFee({ connection, tx, definitions });
275
- let fee = parseFloat(baseFee);
276
- if (fee > FEE_LIMIT) {
277
- fee = FEE_LIMIT;
300
+ catch (e) {
301
+ rejects(e);
278
302
  }
279
- resolve((0, common_1.xrpToDrops)(fee.toString()));
280
- }
281
- catch (e) {
282
- rejects(e);
283
- }
284
- });
285
- const sequencePromise = new Promise(async (resolve, rejects) => {
286
- try {
287
- const accountData = await Client.getAccountInfoData(account, { connection });
288
- if (!accountData) {
289
- return rejects(new Error("Account not found"));
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);
290
316
  }
291
- if ("error" in accountData) {
292
- return rejects(new Error(accountData.error));
317
+ catch (e) {
318
+ rejects(e);
293
319
  }
294
- resolve(accountData.Sequence);
295
- }
296
- catch (e) {
297
- rejects(e);
298
- }
299
- });
300
- const lastLedgerSequencePromise = new Promise(async (resolve) => {
301
- try {
302
- const ledgerIndex = await Client.getLedgerIndex();
303
- if (ledgerIndex !== undefined) {
304
- 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);
305
330
  }
306
- resolve(undefined);
307
- }
308
- catch (e) {
309
- resolve(undefined);
310
- }
311
- });
331
+ catch (e) {
332
+ resolve(undefined);
333
+ }
334
+ });
335
+ }
312
336
  const result = await Promise.all([feePromise, sequencePromise, lastLedgerSequencePromise]);
313
337
  return {
314
338
  fee: result[0],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bithomp/xrpl-api",
3
- "version": "3.0.6",
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",
@@ -39,7 +39,7 @@
39
39
  "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
40
40
  "lint": "eslint -c .eslintrc.json --ext .ts src/",
41
41
  "prepare": "npm run build",
42
- "-prepublishOnly": "npm test && npm run lint",
42
+ "prepublishOnly": "npm test && npm run lint",
43
43
  "preversion": "npm run lint",
44
44
  "version": "npm run format && git add -A src",
45
45
  "postversion": "git push && git push --tags"
@@ -49,7 +49,7 @@
49
49
  ],
50
50
  "dependencies": {
51
51
  "axios": "^1.7.2",
52
- "base-x": "^4.0.0",
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",
@@ -60,23 +60,23 @@
60
60
  "devDependencies": {
61
61
  "@types/chai": "^4.3.16",
62
62
  "@types/chai-as-promised": "^7.1.8",
63
- "@types/lodash": "^4.17.4",
64
- "@types/mocha": "^10.0.6",
63
+ "@types/lodash": "^4.17.5",
64
+ "@types/mocha": "^10.0.7",
65
65
  "@types/nconf": "^0.10.6",
66
- "@types/node": "^20.14.0",
67
- "@typescript-eslint/eslint-plugin": "^7.12.0",
68
- "@typescript-eslint/parser": "^7.12.0",
66
+ "@types/node": "^20.14.8",
67
+ "@typescript-eslint/eslint-plugin": "^7.13.1",
68
+ "@typescript-eslint/parser": "^7.13.1",
69
69
  "chai": "^4.4.1",
70
70
  "chai-as-promised": "^7.1.2",
71
71
  "eslint": "^8.57.0",
72
72
  "eslint-config-prettier": "^9.1.0",
73
- "eslint-plugin-chai-friendly": "^0.8.0",
73
+ "eslint-plugin-chai-friendly": "^1.0.0",
74
74
  "eslint-plugin-import": "^2.29.1",
75
- "eslint-plugin-n": "^17.7.0",
75
+ "eslint-plugin-n": "^17.9.0",
76
76
  "eslint-plugin-promise": "^6.2.0",
77
77
  "mocha": "^10.4.0",
78
78
  "nconf": "^0.12.1",
79
- "ts-jest": "^29.1.4",
79
+ "ts-jest": "^29.1.5",
80
80
  "ts-node": "^10.9.2",
81
81
  "typescript": "^5.4.5"
82
82
  }