@exodus/bitcoin-api 5.0.6 → 5.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/CHANGELOG.md +18 -0
- package/package.json +3 -3
- package/src/tx-log/bitcoin-monitor-scanner.js +36 -12
- package/src/tx-send/index.js +10 -3
- package/src/tx-send/update-state.js +12 -6
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.0.8](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.0.7...@exodus/bitcoin-api@5.0.8) (2026-10-09)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* migrate to @exodus/basic-utils 5 ([#8894](https://github.com/ExodusMovement/assets/issues/8894)) ([ed125f3](https://github.com/ExodusMovement/assets/commit/ed125f3257785c92a3b8f8239a2e9eefe5dc6772))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## [5.0.7](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.0.6...@exodus/bitcoin-api@5.0.7) (2026-10-06)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **bitcoin-api:** remove orphaned UTXOs on refresh ([#8873](https://github.com/ExodusMovement/assets/issues/8873)) ([3f169ec](https://github.com/ExodusMovement/assets/commit/3f169ecb2df12924182c04571221cf5356c801f3))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
6
24
|
## [5.0.6](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.0.5...@exodus/bitcoin-api@5.0.6) (2026-10-06)
|
|
7
25
|
|
|
8
26
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-api",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.8",
|
|
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",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@exodus/asset-lib": "^5.0.0",
|
|
23
|
-
"@exodus/basic-utils": "^
|
|
23
|
+
"@exodus/basic-utils": "^5.1.0",
|
|
24
24
|
"@exodus/bip32": "^4.1.0",
|
|
25
25
|
"@exodus/bip322-js": "^3.1.0",
|
|
26
26
|
"@exodus/bip44-constants": "^195.0.0",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"type": "git",
|
|
60
60
|
"url": "git+https://github.com/ExodusMovement/assets.git"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "41e6c1bb6a3d919f08cc3ee38068159259b335be"
|
|
63
63
|
}
|
|
@@ -105,11 +105,11 @@ export class BitcoinMonitorScanner {
|
|
|
105
105
|
const storedUtxos = getUtxos({ asset, accountState })
|
|
106
106
|
|
|
107
107
|
const currentTime = Date.now()
|
|
108
|
+
// Give local sends time to be indexed before checking whether their outputs still exist.
|
|
109
|
+
const isRecentSentTx = (tx) =>
|
|
110
|
+
tx?.sent && tx.date && currentTime - tx.date.getTime() <= SENT_TIME_TO_DROP
|
|
108
111
|
const unconfirmedTxsToCheck = [...currentTxs].reduce((txs, tx) => {
|
|
109
|
-
if (
|
|
110
|
-
tx.pending && // Don't check sent tx that is younger than 2 minutes, because server might not have indexed it yet
|
|
111
|
-
(!tx.sent || !tx.date || currentTime - tx.date.getTime() > SENT_TIME_TO_DROP)
|
|
112
|
-
) {
|
|
112
|
+
if (tx.pending && !isRecentSentTx(tx)) {
|
|
113
113
|
txs[tx.txId] = tx
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -677,28 +677,52 @@ export class BitcoinMonitorScanner {
|
|
|
677
677
|
// but vin.addr did not match our wallet address map.
|
|
678
678
|
utxoCol = utxoCol.union(storedUtxos).difference(utxosToRemoveCol).difference(spentStoredUtxos)
|
|
679
679
|
|
|
680
|
-
const
|
|
680
|
+
const txIdsToCheck = new Set(Object.keys(unconfirmedTxsToCheck))
|
|
681
|
+
if (refresh) {
|
|
682
|
+
const refreshedTxIds = new Set(newTxs.map((tx) => tx.txId))
|
|
683
|
+
const scannedTxIds = new Set([...allTxs, ...storedUtxoAddressTxs].map((tx) => tx.txid))
|
|
684
|
+
// Refresh overwrites the tx log. Keep unindexed recent sends, including their
|
|
685
|
+
// original date and inputs, so another refresh preserves the same grace period.
|
|
686
|
+
// The extra stored-UTXO-address scan does not emit entries to the refreshed log.
|
|
687
|
+
for (const tx of currentTxs) {
|
|
688
|
+
if (tx.pending && isRecentSentTx(tx) && !refreshedTxIds.has(tx.txId)) {
|
|
689
|
+
existingTxs.push({ ...tx })
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
// A previous refresh may have removed a funding tx from the log while retaining
|
|
694
|
+
// its UTXOs. Verify retained outputs independently of pending tx-log entries.
|
|
695
|
+
for (const { txId } of utxoCol.toArray()) {
|
|
696
|
+
if (!scannedTxIds.has(txId) && !isRecentSentTx(currentTxs.get(txId))) {
|
|
697
|
+
txIdsToCheck.add(txId)
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
681
702
|
const verificationResults = await Promise.all(
|
|
682
|
-
|
|
703
|
+
[...txIdsToCheck].map(async (txId) => {
|
|
683
704
|
try {
|
|
684
|
-
const txStatus = await insightClient.fetchTx(
|
|
685
|
-
return {
|
|
705
|
+
const txStatus = await insightClient.fetchTx(txId)
|
|
706
|
+
return { txId, shouldDrop: txStatus === null }
|
|
686
707
|
} catch (err) {
|
|
687
708
|
console.debug(
|
|
688
|
-
`${assetName}: failed to verify
|
|
709
|
+
`${assetName}: failed to verify tx ${txId} before drop check: ${
|
|
689
710
|
err?.message || 'unknown'
|
|
690
711
|
}`
|
|
691
712
|
)
|
|
692
|
-
return {
|
|
713
|
+
return { txId, shouldDrop: false }
|
|
693
714
|
}
|
|
694
715
|
})
|
|
695
716
|
)
|
|
696
717
|
|
|
697
|
-
for (const {
|
|
718
|
+
for (const { txId, shouldDrop } of verificationResults) {
|
|
698
719
|
if (!shouldDrop) continue
|
|
699
720
|
|
|
721
|
+
utxoCol = utxoCol.difference(utxoCol.getTxIdUtxos(txId))
|
|
722
|
+
const tx = unconfirmedTxsToCheck[txId]
|
|
723
|
+
if (!tx) continue
|
|
724
|
+
|
|
700
725
|
existingTxs.push({ ...tx, dropped: true }) // TODO: this will decrease the chain index, it shouldn't be an issue considering the gap limit
|
|
701
|
-
utxoCol = utxoCol.difference(utxoCol.getTxIdUtxos(tx.txId))
|
|
702
726
|
const utxosToAdd = []
|
|
703
727
|
if (tx.data.inputs) {
|
|
704
728
|
const prevUtxos = UtxoCollection.fromJSON(tx.data.inputs, { currency })
|
package/src/tx-send/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import assert from 'minimalistic-assert'
|
|
|
5
5
|
import { extractTransactionContext } from '../psbt-parser.js'
|
|
6
6
|
import { broadcastTransaction } from './broadcast-tx.js'
|
|
7
7
|
import { repairConfirmedSpentInputs } from './repair-spent-inputs.js'
|
|
8
|
-
import {
|
|
8
|
+
import { updateAccountStateBatch, updateTransactionLogBatch } from './update-state.js'
|
|
9
9
|
|
|
10
10
|
const getErrorText = (error) => [error?.message, error?.reason].filter(Boolean).join(' ')
|
|
11
11
|
|
|
@@ -259,7 +259,11 @@ export const sendTxFactory = ({
|
|
|
259
259
|
txId,
|
|
260
260
|
})
|
|
261
261
|
|
|
262
|
-
|
|
262
|
+
// Publish change and its recent-send history together so refresh cannot mistake
|
|
263
|
+
// newly created change for an orphan while transaction metadata is being derived.
|
|
264
|
+
const batch = assetClientInterface.createOperationsBatch()
|
|
265
|
+
updateAccountStateBatch({
|
|
266
|
+
batch,
|
|
263
267
|
assetClientInterface,
|
|
264
268
|
assetName,
|
|
265
269
|
walletAccount,
|
|
@@ -274,7 +278,8 @@ export const sendTxFactory = ({
|
|
|
274
278
|
rbfEnabled,
|
|
275
279
|
})
|
|
276
280
|
|
|
277
|
-
await
|
|
281
|
+
await updateTransactionLogBatch({
|
|
282
|
+
batch,
|
|
278
283
|
asset,
|
|
279
284
|
assetClientInterface,
|
|
280
285
|
walletAccount,
|
|
@@ -294,6 +299,8 @@ export const sendTxFactory = ({
|
|
|
294
299
|
size,
|
|
295
300
|
})
|
|
296
301
|
|
|
302
|
+
await assetClientInterface.executeOperationsBatch(batch)
|
|
303
|
+
|
|
297
304
|
return {
|
|
298
305
|
txId,
|
|
299
306
|
sendUtxoIndex,
|
|
@@ -102,7 +102,8 @@ const getWalletAddressObjects = async ({
|
|
|
102
102
|
return addresses
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
export
|
|
105
|
+
export function updateAccountStateBatch({
|
|
106
|
+
batch,
|
|
106
107
|
assetClientInterface,
|
|
107
108
|
assetName,
|
|
108
109
|
walletAccount,
|
|
@@ -116,7 +117,7 @@ export async function updateAccountState({
|
|
|
116
117
|
ourAddress,
|
|
117
118
|
rbfEnabled,
|
|
118
119
|
}) {
|
|
119
|
-
const knownBalanceUtxoIds = accountState.knownBalanceUtxoIds || []
|
|
120
|
+
const knownBalanceUtxoIds = [...(accountState.knownBalanceUtxoIds || [])]
|
|
120
121
|
// updateAccountState replaces the stored UTXO collection, so remove selected inputs
|
|
121
122
|
// from the full stored set.
|
|
122
123
|
let remainingUtxos = accountState.utxos.difference(selectedUtxos)
|
|
@@ -144,7 +145,9 @@ export async function updateAccountState({
|
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
// Update account state
|
|
147
|
-
|
|
148
|
+
assetClientInterface.updateAccountStateBatch({
|
|
149
|
+
batch,
|
|
150
|
+
accountState,
|
|
148
151
|
assetName,
|
|
149
152
|
walletAccount,
|
|
150
153
|
newData: {
|
|
@@ -154,7 +157,8 @@ export async function updateAccountState({
|
|
|
154
157
|
})
|
|
155
158
|
}
|
|
156
159
|
|
|
157
|
-
export async function
|
|
160
|
+
export async function updateTransactionLogBatch({
|
|
161
|
+
batch,
|
|
158
162
|
asset,
|
|
159
163
|
assetClientInterface,
|
|
160
164
|
walletAccount,
|
|
@@ -262,7 +266,8 @@ export async function updateTransactionLog({
|
|
|
262
266
|
const coinAmount = selfSend ? asset.currency.ZERO : totalAmount.abs().negate()
|
|
263
267
|
|
|
264
268
|
// Update transaction log
|
|
265
|
-
|
|
269
|
+
assetClientInterface.updateTxLogAndNotifyBatch({
|
|
270
|
+
batch,
|
|
266
271
|
assetName,
|
|
267
272
|
walletAccount,
|
|
268
273
|
txs: [
|
|
@@ -299,7 +304,8 @@ export async function updateTransactionLog({
|
|
|
299
304
|
replacedBy: txId,
|
|
300
305
|
},
|
|
301
306
|
}
|
|
302
|
-
|
|
307
|
+
assetClientInterface.updateTxLogAndNotifyBatch({
|
|
308
|
+
batch,
|
|
303
309
|
assetName,
|
|
304
310
|
walletAccount,
|
|
305
311
|
txs: [updatedReplaceTx],
|