@xchainjs/xchain-utxo 2.1.0 → 2.2.1

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
@@ -68,6 +68,15 @@ export declare abstract class Client extends BaseXChainClient {
68
68
  * @returns {UTXO[]} The UTXOs found.
69
69
  */
70
70
  protected scanUTXOs(address: string, confirmedOnly?: boolean): Promise<UTXO[]>;
71
+ /**
72
+ * Get UTXOs for a given address.
73
+ * Public wrapper around the protected scanUTXOs method for coin control.
74
+ *
75
+ * @param {string} address The address to get UTXOs for.
76
+ * @param {boolean} confirmedOnly Whether to only return confirmed UTXOs. Default: true.
77
+ * @returns {Promise<UTXO[]>} The UTXOs for the address.
78
+ */
79
+ getUTXOs(address: string, confirmedOnly?: boolean): Promise<UTXO[]>;
71
80
  /**
72
81
  * Get estimated fees with fee rates.
73
82
  *
@@ -194,11 +203,12 @@ export declare abstract class Client extends BaseXChainClient {
194
203
  * @param params Transaction parameters
195
204
  * @returns Prepared transaction with UTXO details
196
205
  */
197
- prepareTxEnhanced({ sender, memo, amount, recipient, spendPendingUTXO, feeRate, utxoSelectionPreferences, }: TxParams & {
206
+ prepareTxEnhanced({ sender, memo, amount, recipient, spendPendingUTXO, feeRate, utxoSelectionPreferences, selectedUtxos, }: TxParams & {
198
207
  sender: Address;
199
208
  feeRate: FeeRate;
200
209
  spendPendingUTXO?: boolean;
201
210
  utxoSelectionPreferences?: UtxoSelectionPreferences;
211
+ selectedUtxos?: UTXO[];
202
212
  }): Promise<PreparedTx>;
203
213
  /**
204
214
  * Prepare maximum amount transfer (sweep transaction).
@@ -206,13 +216,14 @@ export declare abstract class Client extends BaseXChainClient {
206
216
  * @param params Send max parameters
207
217
  * @returns Prepared transaction with maximum sendable amount
208
218
  */
209
- prepareMaxTx({ sender, recipient, memo, feeRate, spendPendingUTXO, utxoSelectionPreferences, }: {
219
+ prepareMaxTx({ sender, recipient, memo, feeRate, spendPendingUTXO, utxoSelectionPreferences, selectedUtxos, }: {
210
220
  sender: Address;
211
221
  recipient: Address;
212
222
  memo?: string;
213
223
  feeRate: FeeRate;
214
224
  spendPendingUTXO?: boolean;
215
225
  utxoSelectionPreferences?: UtxoSelectionPreferences;
226
+ selectedUtxos?: UTXO[];
216
227
  }): Promise<PreparedTx & {
217
228
  maxAmount: number;
218
229
  fee: number;
package/lib/index.esm.js CHANGED
@@ -1126,6 +1126,19 @@ class Client extends BaseXChainClient {
1126
1126
  return this.roundRobinGetUnspentTxs(address, confirmedOnly);
1127
1127
  });
1128
1128
  }
1129
+ /**
1130
+ * Get UTXOs for a given address.
1131
+ * Public wrapper around the protected scanUTXOs method for coin control.
1132
+ *
1133
+ * @param {string} address The address to get UTXOs for.
1134
+ * @param {boolean} confirmedOnly Whether to only return confirmed UTXOs. Default: true.
1135
+ * @returns {Promise<UTXO[]>} The UTXOs for the address.
1136
+ */
1137
+ getUTXOs(address_1) {
1138
+ return __awaiter(this, arguments, void 0, function* (address, confirmedOnly = true) {
1139
+ return this.scanUTXOs(address, confirmedOnly);
1140
+ });
1141
+ }
1129
1142
  /**
1130
1143
  * Get estimated fees with fee rates.
1131
1144
  *
@@ -1437,7 +1450,7 @@ class Client extends BaseXChainClient {
1437
1450
  * @returns Prepared transaction with UTXO details
1438
1451
  */
1439
1452
  prepareTxEnhanced(_a) {
1440
- return __awaiter(this, arguments, void 0, function* ({ sender, memo, amount, recipient, spendPendingUTXO = true, feeRate, utxoSelectionPreferences, }) {
1453
+ return __awaiter(this, arguments, void 0, function* ({ sender, memo, amount, recipient, spendPendingUTXO = true, feeRate, utxoSelectionPreferences, selectedUtxos, }) {
1441
1454
  try {
1442
1455
  // Comprehensive input validation
1443
1456
  this.validateTransactionInputs({
@@ -1447,9 +1460,16 @@ class Client extends BaseXChainClient {
1447
1460
  sender,
1448
1461
  feeRate,
1449
1462
  });
1450
- // Get validated UTXOs
1451
- const confirmedOnly = !spendPendingUTXO;
1452
- const utxos = yield this.getValidatedUtxos(sender, confirmedOnly);
1463
+ // Use provided UTXOs (coin control) or fetch from chain
1464
+ let utxos;
1465
+ if (selectedUtxos && selectedUtxos.length > 0) {
1466
+ UtxoTransactionValidator.validateUtxoSet(selectedUtxos);
1467
+ utxos = selectedUtxos;
1468
+ }
1469
+ else {
1470
+ const confirmedOnly = !spendPendingUTXO;
1471
+ utxos = yield this.getValidatedUtxos(sender, confirmedOnly);
1472
+ }
1453
1473
  const compiledMemo = memo ? this.compileMemo(memo) : null;
1454
1474
  const targetValue = amount.amount().toNumber();
1455
1475
  // Output count: recipient + change + optional memo
@@ -1482,7 +1502,7 @@ class Client extends BaseXChainClient {
1482
1502
  * @returns Prepared transaction with maximum sendable amount
1483
1503
  */
1484
1504
  prepareMaxTx(_a) {
1485
- return __awaiter(this, arguments, void 0, function* ({ sender, recipient, memo, feeRate, spendPendingUTXO = true, utxoSelectionPreferences, }) {
1505
+ return __awaiter(this, arguments, void 0, function* ({ sender, recipient, memo, feeRate, spendPendingUTXO = true, utxoSelectionPreferences, selectedUtxos, }) {
1486
1506
  try {
1487
1507
  // Basic validation
1488
1508
  if (!(recipient === null || recipient === void 0 ? void 0 : recipient.trim())) {
@@ -1499,9 +1519,16 @@ class Client extends BaseXChainClient {
1499
1519
  throw UtxoError.invalidFeeRate(feeRate, 'Fee rate must be a positive finite number');
1500
1520
  }
1501
1521
  const validatedFeeRate = Math.ceil(feeRate);
1502
- // Get validated UTXOs
1503
- const confirmedOnly = !spendPendingUTXO;
1504
- const utxos = yield this.getValidatedUtxos(sender, confirmedOnly);
1522
+ // Use provided UTXOs (coin control) or fetch from chain
1523
+ let utxos;
1524
+ if (selectedUtxos && selectedUtxos.length > 0) {
1525
+ UtxoTransactionValidator.validateUtxoSet(selectedUtxos);
1526
+ utxos = selectedUtxos;
1527
+ }
1528
+ else {
1529
+ const confirmedOnly = !spendPendingUTXO;
1530
+ utxos = yield this.getValidatedUtxos(sender, confirmedOnly);
1531
+ }
1505
1532
  // Calculate maximum sendable amount
1506
1533
  const maxCalc = this.calculateMaxSendableAmount(utxos, validatedFeeRate, !!memo, utxoSelectionPreferences);
1507
1534
  const compiledMemo = memo ? this.compileMemo(memo) : null;
package/lib/index.js CHANGED
@@ -1128,6 +1128,19 @@ class Client extends xchainClient.BaseXChainClient {
1128
1128
  return this.roundRobinGetUnspentTxs(address, confirmedOnly);
1129
1129
  });
1130
1130
  }
1131
+ /**
1132
+ * Get UTXOs for a given address.
1133
+ * Public wrapper around the protected scanUTXOs method for coin control.
1134
+ *
1135
+ * @param {string} address The address to get UTXOs for.
1136
+ * @param {boolean} confirmedOnly Whether to only return confirmed UTXOs. Default: true.
1137
+ * @returns {Promise<UTXO[]>} The UTXOs for the address.
1138
+ */
1139
+ getUTXOs(address_1) {
1140
+ return __awaiter(this, arguments, void 0, function* (address, confirmedOnly = true) {
1141
+ return this.scanUTXOs(address, confirmedOnly);
1142
+ });
1143
+ }
1131
1144
  /**
1132
1145
  * Get estimated fees with fee rates.
1133
1146
  *
@@ -1439,7 +1452,7 @@ class Client extends xchainClient.BaseXChainClient {
1439
1452
  * @returns Prepared transaction with UTXO details
1440
1453
  */
1441
1454
  prepareTxEnhanced(_a) {
1442
- return __awaiter(this, arguments, void 0, function* ({ sender, memo, amount, recipient, spendPendingUTXO = true, feeRate, utxoSelectionPreferences, }) {
1455
+ return __awaiter(this, arguments, void 0, function* ({ sender, memo, amount, recipient, spendPendingUTXO = true, feeRate, utxoSelectionPreferences, selectedUtxos, }) {
1443
1456
  try {
1444
1457
  // Comprehensive input validation
1445
1458
  this.validateTransactionInputs({
@@ -1449,9 +1462,16 @@ class Client extends xchainClient.BaseXChainClient {
1449
1462
  sender,
1450
1463
  feeRate,
1451
1464
  });
1452
- // Get validated UTXOs
1453
- const confirmedOnly = !spendPendingUTXO;
1454
- const utxos = yield this.getValidatedUtxos(sender, confirmedOnly);
1465
+ // Use provided UTXOs (coin control) or fetch from chain
1466
+ let utxos;
1467
+ if (selectedUtxos && selectedUtxos.length > 0) {
1468
+ UtxoTransactionValidator.validateUtxoSet(selectedUtxos);
1469
+ utxos = selectedUtxos;
1470
+ }
1471
+ else {
1472
+ const confirmedOnly = !spendPendingUTXO;
1473
+ utxos = yield this.getValidatedUtxos(sender, confirmedOnly);
1474
+ }
1455
1475
  const compiledMemo = memo ? this.compileMemo(memo) : null;
1456
1476
  const targetValue = amount.amount().toNumber();
1457
1477
  // Output count: recipient + change + optional memo
@@ -1484,7 +1504,7 @@ class Client extends xchainClient.BaseXChainClient {
1484
1504
  * @returns Prepared transaction with maximum sendable amount
1485
1505
  */
1486
1506
  prepareMaxTx(_a) {
1487
- return __awaiter(this, arguments, void 0, function* ({ sender, recipient, memo, feeRate, spendPendingUTXO = true, utxoSelectionPreferences, }) {
1507
+ return __awaiter(this, arguments, void 0, function* ({ sender, recipient, memo, feeRate, spendPendingUTXO = true, utxoSelectionPreferences, selectedUtxos, }) {
1488
1508
  try {
1489
1509
  // Basic validation
1490
1510
  if (!(recipient === null || recipient === void 0 ? void 0 : recipient.trim())) {
@@ -1501,9 +1521,16 @@ class Client extends xchainClient.BaseXChainClient {
1501
1521
  throw UtxoError.invalidFeeRate(feeRate, 'Fee rate must be a positive finite number');
1502
1522
  }
1503
1523
  const validatedFeeRate = Math.ceil(feeRate);
1504
- // Get validated UTXOs
1505
- const confirmedOnly = !spendPendingUTXO;
1506
- const utxos = yield this.getValidatedUtxos(sender, confirmedOnly);
1524
+ // Use provided UTXOs (coin control) or fetch from chain
1525
+ let utxos;
1526
+ if (selectedUtxos && selectedUtxos.length > 0) {
1527
+ UtxoTransactionValidator.validateUtxoSet(selectedUtxos);
1528
+ utxos = selectedUtxos;
1529
+ }
1530
+ else {
1531
+ const confirmedOnly = !spendPendingUTXO;
1532
+ utxos = yield this.getValidatedUtxos(sender, confirmedOnly);
1533
+ }
1507
1534
  // Calculate maximum sendable amount
1508
1535
  const maxCalc = this.calculateMaxSendableAmount(utxos, validatedFeeRate, !!memo, utxoSelectionPreferences);
1509
1536
  const compiledMemo = memo ? this.compileMemo(memo) : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-utxo",
3
- "version": "2.1.0",
3
+ "version": "2.2.1",
4
4
  "description": "Genereic UTXO client for XChainJS",
5
5
  "keywords": [
6
6
  "XChain",
@@ -37,6 +37,6 @@
37
37
  "dependencies": {
38
38
  "@xchainjs/xchain-client": "2.0.10",
39
39
  "@xchainjs/xchain-util": "2.0.5",
40
- "@xchainjs/xchain-utxo-providers": "2.0.10"
40
+ "@xchainjs/xchain-utxo-providers": "2.0.11"
41
41
  }
42
42
  }