@exodus/bitcoin-api 5.2.0 → 5.2.2
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/CHANGELOG.md +18 -0
- package/package.json +2 -2
- package/src/balances.js +4 -8
- package/src/fee/utxo-selector.js +13 -22
- package/src/tx-create/create-tx.js +8 -2
- package/src/tx-log/bitcoin-monitor-scanner.js +9 -5
- package/src/tx-send/batch-tx.js +7 -1
- package/src/utxos-utils.js +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [5.2.2](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.2.1...@exodus/bitcoin-api@5.2.2) (2026-11-26)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **bitcoin-api:** include own pending change in spendable balances ([#9450](https://github.com/ExodusMovement/assets/issues/9450)) ([4d55ad2](https://github.com/ExodusMovement/assets/commit/4d55ad2e48c20ba66b6f51f511affc1882808e73))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## [5.2.1](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.2.0...@exodus/bitcoin-api@5.2.1) (2026-11-26)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* speed up Bitcoin history refreshes and report scan failures ([#9439](https://github.com/ExodusMovement/assets/issues/9439)) ([3e5034f](https://github.com/ExodusMovement/assets/commit/3e5034f11c37ea6b7683bdbe45d995d92b40b280))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
6
24
|
## [5.2.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.1.3...@exodus/bitcoin-api@5.2.0) (2026-11-23)
|
|
7
25
|
|
|
8
26
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-api",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.2",
|
|
4
4
|
"description": "Bitcoin transaction and fee monitors, RPC with the blockchain node, other networking code.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"type": "git",
|
|
61
61
|
"url": "git+https://github.com/ExodusMovement/assets.git"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "ee68ceadf6392aa8c2ff2a8ae2c6a7d7600e9ad7"
|
|
64
64
|
}
|
package/src/balances.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { getUnconfirmedSentBalance } from '@exodus/asset-lib'
|
|
2
2
|
import assert from 'minimalistic-assert'
|
|
3
3
|
|
|
4
|
+
import { findUnconfirmedSentRbfTxs } from './tx-utils.js'
|
|
4
5
|
import { getUnconfirmedTxAncestorMap } from './unconfirmed-ancestor-data.js'
|
|
5
|
-
import {
|
|
6
|
-
getConfirmedOrRfbDisabledUtxos,
|
|
7
|
-
getUnconfirmedUtxos,
|
|
8
|
-
getUsableUtxos,
|
|
9
|
-
getUtxos,
|
|
10
|
-
} from './utxos-utils.js'
|
|
6
|
+
import { getSpendableUtxos, getUnconfirmedUtxos, getUsableUtxos, getUtxos } from './utxos-utils.js'
|
|
11
7
|
|
|
12
8
|
export const getBalancesFactory = ({
|
|
13
9
|
feeData: defaultFeeData,
|
|
@@ -38,9 +34,9 @@ export const getBalancesFactory = ({
|
|
|
38
34
|
unconfirmedTxAncestor,
|
|
39
35
|
})
|
|
40
36
|
|
|
41
|
-
const spendableUtxos =
|
|
42
|
-
asset,
|
|
37
|
+
const spendableUtxos = getSpendableUtxos({
|
|
43
38
|
utxos: usableUtxos,
|
|
39
|
+
replaceableTxs: findUnconfirmedSentRbfTxs(txLog),
|
|
44
40
|
allowUnconfirmedRbfEnabledUtxos,
|
|
45
41
|
})
|
|
46
42
|
|
package/src/fee/utxo-selector.js
CHANGED
|
@@ -3,7 +3,7 @@ import lodash from 'lodash'
|
|
|
3
3
|
import assert from 'minimalistic-assert'
|
|
4
4
|
|
|
5
5
|
import { getChangeDustValue } from '../dust.js'
|
|
6
|
-
import {
|
|
6
|
+
import { getConfirmedUtxos, getSpendableUtxos } from '../utxos-utils.js'
|
|
7
7
|
import { getExtraFee } from './fee-utils.js'
|
|
8
8
|
|
|
9
9
|
const { sortBy } = lodash
|
|
@@ -47,6 +47,7 @@ export const selectUtxos = ({
|
|
|
47
47
|
asset,
|
|
48
48
|
utxosDescendingOrder,
|
|
49
49
|
usableUtxos,
|
|
50
|
+
spendableUtxos,
|
|
50
51
|
replaceableTxs,
|
|
51
52
|
amount,
|
|
52
53
|
feeRate,
|
|
@@ -224,25 +225,15 @@ export const selectUtxos = ({
|
|
|
224
225
|
|
|
225
226
|
if (!spendUtxos) spendUtxos = UtxoCollection.createEmpty({ currency })
|
|
226
227
|
|
|
227
|
-
|
|
228
|
-
let ourRbfUtxos = UtxoCollection.createEmpty({ currency })
|
|
229
|
-
if (replaceableTxs) {
|
|
230
|
-
for (const tx of replaceableTxs) {
|
|
231
|
-
if (!tx.data.internalOutputs?.length && !tx.data.changeAddress) continue
|
|
232
|
-
const internalUtxos = usableUtxos.getTxIdUtxos(tx.txId)
|
|
233
|
-
ourRbfUtxos = ourRbfUtxos.union(internalUtxos)
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const spendableUtxos = getConfirmedOrRfbDisabledUtxos({
|
|
238
|
-
asset,
|
|
228
|
+
spendableUtxos ??= getSpendableUtxos({
|
|
239
229
|
utxos: usableUtxos,
|
|
230
|
+
replaceableTxs,
|
|
240
231
|
allowUnconfirmedRbfEnabledUtxos,
|
|
241
232
|
})
|
|
242
233
|
|
|
243
234
|
const utxosArray = _toPriorityOrderedArray({
|
|
244
235
|
utxosDescendingOrder,
|
|
245
|
-
utxos: spendableUtxos
|
|
236
|
+
utxos: spendableUtxos,
|
|
246
237
|
})
|
|
247
238
|
|
|
248
239
|
if (isSendAll) {
|
|
@@ -267,7 +258,7 @@ export const selectUtxos = ({
|
|
|
267
258
|
)
|
|
268
259
|
const remainingUtxosArray = _toPriorityOrderedArray({
|
|
269
260
|
utxosDescendingOrder,
|
|
270
|
-
utxos: spendableUtxos.
|
|
261
|
+
utxos: spendableUtxos.difference(spendUtxos),
|
|
271
262
|
})
|
|
272
263
|
|
|
273
264
|
while (selectedUtxosValue.lte(amount) && remainingUtxosArray.length > 0) {
|
|
@@ -330,6 +321,11 @@ export const getUtxosData = ({
|
|
|
330
321
|
taprootInputWitnessSize,
|
|
331
322
|
changeAddressType,
|
|
332
323
|
}) => {
|
|
324
|
+
const spendableUtxos = getSpendableUtxos({
|
|
325
|
+
utxos: usableUtxos,
|
|
326
|
+
replaceableTxs,
|
|
327
|
+
allowUnconfirmedRbfEnabledUtxos,
|
|
328
|
+
})
|
|
333
329
|
const {
|
|
334
330
|
selectedUtxos,
|
|
335
331
|
replaceTx,
|
|
@@ -337,6 +333,7 @@ export const getUtxosData = ({
|
|
|
337
333
|
} = selectUtxos({
|
|
338
334
|
asset,
|
|
339
335
|
usableUtxos,
|
|
336
|
+
spendableUtxos,
|
|
340
337
|
replaceableTxs,
|
|
341
338
|
amount,
|
|
342
339
|
feeRate,
|
|
@@ -358,13 +355,7 @@ export const getUtxosData = ({
|
|
|
358
355
|
|
|
359
356
|
const replaceUtxos = replaceTx ? usableUtxos.getTxIdUtxos(replaceTx.txId) : empty
|
|
360
357
|
|
|
361
|
-
const
|
|
362
|
-
asset,
|
|
363
|
-
utxos: usableUtxos,
|
|
364
|
-
allowUnconfirmedRbfEnabledUtxos,
|
|
365
|
-
}).union(replaceUtxos)
|
|
366
|
-
|
|
367
|
-
const spendableBalance = spendableUtxos.value
|
|
358
|
+
const spendableBalance = spendableUtxos.union(replaceUtxos).value
|
|
368
359
|
|
|
369
360
|
const extraFeeCpfp = selectedUtxos?.size
|
|
370
361
|
? asset.currency.baseUnit(
|
|
@@ -10,7 +10,7 @@ import { selectUtxos } from '../fee/utxo-selector.js'
|
|
|
10
10
|
import { createPsbtWithMetadata } from '../psbt-builder.js'
|
|
11
11
|
import { findUnconfirmedSentRbfTxs } from '../tx-utils.js'
|
|
12
12
|
import { getUnconfirmedTxAncestorMap } from '../unconfirmed-ancestor-data.js'
|
|
13
|
-
import { getUsableUtxos, getUtxos } from '../utxos-utils.js'
|
|
13
|
+
import { getSpendableUtxos, getUsableUtxos, getUtxos } from '../utxos-utils.js'
|
|
14
14
|
import { authenticateReplacement } from './authenticate-replacement.js'
|
|
15
15
|
import { createInputs, createOutput, getBlockHeight, getNonWitnessTxs } from './tx-create-utils.js'
|
|
16
16
|
|
|
@@ -399,8 +399,13 @@ const transferHandler = {
|
|
|
399
399
|
|
|
400
400
|
const { processedAddress, useCashAddress } = processAddress({ asset, toAddress })
|
|
401
401
|
|
|
402
|
-
//
|
|
402
|
+
// Chaining spends existing change; only replacing the parent requires authentication.
|
|
403
403
|
let replaceableTxs = findUnconfirmedSentRbfTxs(context.txSet)
|
|
404
|
+
const spendableUtxos = getSpendableUtxos({
|
|
405
|
+
utxos: context.usableUtxos,
|
|
406
|
+
replaceableTxs,
|
|
407
|
+
allowUnconfirmedRbfEnabledUtxos,
|
|
408
|
+
})
|
|
404
409
|
|
|
405
410
|
if (authenticateReplacementTransactions) {
|
|
406
411
|
const authenticated = []
|
|
@@ -450,6 +455,7 @@ const transferHandler = {
|
|
|
450
455
|
} = selectUtxos({
|
|
451
456
|
asset,
|
|
452
457
|
usableUtxos: context.usableUtxos,
|
|
458
|
+
spendableUtxos,
|
|
453
459
|
replaceableTxs,
|
|
454
460
|
amount: utxoParams.sendAmount,
|
|
455
461
|
feeRate: utxoParams.feeRate,
|
|
@@ -297,11 +297,12 @@ export class BitcoinMonitorScanner {
|
|
|
297
297
|
}
|
|
298
298
|
const items = listOfTxs.flat()
|
|
299
299
|
if (!this.#verifyNewSentTransactions) return items
|
|
300
|
-
|
|
301
|
-
for (const item of items) {
|
|
302
|
-
|
|
300
|
+
// Only pending history needs authentication. RBF creation checks it again before use.
|
|
301
|
+
for (const [index, item] of items.entries()) {
|
|
302
|
+
if (item.confirmations > 0) continue
|
|
303
|
+
items[index] = await readAuthenticatedHistory({ item, asset, loadTransaction })
|
|
303
304
|
}
|
|
304
|
-
return
|
|
305
|
+
return items
|
|
305
306
|
}
|
|
306
307
|
|
|
307
308
|
const gapSearchParameters = newChains.map(({ purpose, chain }) => {
|
|
@@ -485,7 +486,9 @@ export class BitcoinMonitorScanner {
|
|
|
485
486
|
})
|
|
486
487
|
|
|
487
488
|
allTxs.forEach((txItem) => {
|
|
488
|
-
const isCoinbase =
|
|
489
|
+
const isCoinbase =
|
|
490
|
+
txItem.vin.length === 0 ||
|
|
491
|
+
(txItem.vin.length === 1 && Object.keys(txItem.vin[0]).length === 0)
|
|
489
492
|
|
|
490
493
|
const txLogItem = {
|
|
491
494
|
txId: txItem.txid,
|
|
@@ -827,6 +830,7 @@ export class BitcoinMonitorScanner {
|
|
|
827
830
|
// The extra refresh results can remove stored UTXOs outside today's gap
|
|
828
831
|
// range. Match those outpoints even when their addresses are absent from addrMap.
|
|
829
832
|
for (const item of [...allTxs, ...storedUtxoAddressTxs]) {
|
|
833
|
+
if (item.confirmations > 0) continue
|
|
830
834
|
if (verifiedIds.has(item.wtxid)) continue
|
|
831
835
|
if (
|
|
832
836
|
!item.vin.some(
|
package/src/tx-send/batch-tx.js
CHANGED
|
@@ -6,8 +6,9 @@ import assert from 'minimalistic-assert'
|
|
|
6
6
|
|
|
7
7
|
import { setBtcErrorCode, toBtcSendError } from '../errors.js'
|
|
8
8
|
import { selectUtxos } from '../fee/utxo-selector.js'
|
|
9
|
+
import { findUnconfirmedSentRbfTxs } from '../tx-utils.js'
|
|
9
10
|
import { getUnconfirmedTxAncestorMap } from '../unconfirmed-ancestor-data.js'
|
|
10
|
-
import { getUsableUtxos, getUtxos } from '../utxos-utils.js'
|
|
11
|
+
import { getSpendableUtxos, getUsableUtxos, getUtxos } from '../utxos-utils.js'
|
|
11
12
|
|
|
12
13
|
const DUST_VALUES = {
|
|
13
14
|
P2WPKH: 294,
|
|
@@ -48,6 +49,11 @@ export const getCreateBatchTransaction = ({
|
|
|
48
49
|
const { selectedUtxos, fee } = selectUtxos({
|
|
49
50
|
asset,
|
|
50
51
|
usableUtxos,
|
|
52
|
+
spendableUtxos: getSpendableUtxos({
|
|
53
|
+
utxos: usableUtxos,
|
|
54
|
+
replaceableTxs: findUnconfirmedSentRbfTxs(txSet),
|
|
55
|
+
allowUnconfirmedRbfEnabledUtxos,
|
|
56
|
+
}),
|
|
51
57
|
amount,
|
|
52
58
|
feeRate: feeData.feePerKB,
|
|
53
59
|
receiveAddresses,
|
package/src/utxos-utils.js
CHANGED
|
@@ -225,6 +225,16 @@ export function getConfirmedOrRfbDisabledUtxos({ utxos, allowUnconfirmedRbfEnabl
|
|
|
225
225
|
return utxos.filter((utxo) => utxo.confirmations > 0 || !utxo.rbfEnabled)
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
+
// Our pending outgoing transactions can still be chained.
|
|
229
|
+
export function getSpendableUtxos({ utxos, replaceableTxs, allowUnconfirmedRbfEnabledUtxos }) {
|
|
230
|
+
let spendableUtxos = getConfirmedOrRfbDisabledUtxos({ utxos, allowUnconfirmedRbfEnabledUtxos })
|
|
231
|
+
for (const tx of replaceableTxs ?? []) {
|
|
232
|
+
if (!tx.data.internalOutputs?.length && !tx.data.changeAddress) continue
|
|
233
|
+
spendableUtxos = spendableUtxos.union(utxos.getTxIdUtxos(tx.txId))
|
|
234
|
+
}
|
|
235
|
+
return spendableUtxos
|
|
236
|
+
}
|
|
237
|
+
|
|
228
238
|
function filterDustUtxos({ utxos, feeData }) {
|
|
229
239
|
if (feeData.utxoDustValue) {
|
|
230
240
|
return utxos.filter((utxo) => utxo.value.toBaseNumber() > feeData.utxoDustValue)
|