minimal-xec-wallet 1.0.3 → 1.0.4
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/consolidate-utxos.js +17 -6
- package/package.json +1 -1
package/lib/consolidate-utxos.js
CHANGED
|
@@ -91,8 +91,8 @@ class ConsolidateUtxos {
|
|
|
91
91
|
|
|
92
92
|
// Filter UTXOs that should be consolidated (smaller ones first)
|
|
93
93
|
const utxosToConsolidate = pureXecUtxos
|
|
94
|
-
.filter(utxo => utxo
|
|
95
|
-
.sort((a, b) => a
|
|
94
|
+
.filter(utxo => this._getUtxoValue(utxo) <= options.consolidationThreshold)
|
|
95
|
+
.sort((a, b) => this._getUtxoValue(a) - this._getUtxoValue(b)) // Sort by value ascending
|
|
96
96
|
|
|
97
97
|
if (utxosToConsolidate.length < this.minUtxosForConsolidation) {
|
|
98
98
|
return {
|
|
@@ -267,7 +267,17 @@ class ConsolidateUtxos {
|
|
|
267
267
|
// Helper methods
|
|
268
268
|
|
|
269
269
|
_calculateTotalValue (utxos) {
|
|
270
|
-
return utxos.reduce((total, utxo) => total + utxo
|
|
270
|
+
return utxos.reduce((total, utxo) => total + this._getUtxoValue(utxo), 0)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
_getUtxoValue (utxo) {
|
|
274
|
+
if (utxo.sats !== undefined) {
|
|
275
|
+
return typeof utxo.sats === 'bigint' ? Number(utxo.sats) : parseInt(utxo.sats)
|
|
276
|
+
}
|
|
277
|
+
if (utxo.value !== undefined) {
|
|
278
|
+
return typeof utxo.value === 'bigint' ? Number(utxo.value) : parseInt(utxo.value)
|
|
279
|
+
}
|
|
280
|
+
return 0
|
|
271
281
|
}
|
|
272
282
|
|
|
273
283
|
_calculateConsolidationFee (numInputs, numOutputs, satsPerByte) {
|
|
@@ -317,11 +327,12 @@ class ConsolidateUtxos {
|
|
|
317
327
|
|
|
318
328
|
// Only analyze pure XEC UTXOs for consolidation
|
|
319
329
|
for (const utxo of pureXecUtxos) {
|
|
320
|
-
|
|
330
|
+
const value = this._getUtxoValue(utxo)
|
|
331
|
+
if (value < 1000) {
|
|
321
332
|
distribution.dust++
|
|
322
|
-
} else if (
|
|
333
|
+
} else if (value < 10000) {
|
|
323
334
|
distribution.small++
|
|
324
|
-
} else if (
|
|
335
|
+
} else if (value < 100000) {
|
|
325
336
|
distribution.medium++
|
|
326
337
|
} else {
|
|
327
338
|
distribution.large++
|
package/package.json
CHANGED