@exodus/bitcoin-api 4.9.6 → 4.10.0
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
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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
|
+
## [4.10.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@4.9.6...@exodus/bitcoin-api@4.10.0) (2026-03-11)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
* feat: extract trace id in bitcoin (#7278)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
* fix(bitcoin-api): avoid restoring spent dropped inputs (#7559)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [4.9.6](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@4.9.5...@exodus/bitcoin-api@4.9.6) (2026-03-02)
|
|
7
23
|
|
|
8
24
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-api",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.0",
|
|
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",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@exodus/safe-string": "^1.4.0",
|
|
37
37
|
"@exodus/send-validation-model": "^1.0.0",
|
|
38
38
|
"@exodus/simple-retry": "^0.0.6",
|
|
39
|
+
"@exodus/traceparent": "^3.0.1",
|
|
39
40
|
"bech32": "^1.1.3",
|
|
40
41
|
"bip32-path": "^0.4.2",
|
|
41
42
|
"bs58check": "^3.0.1",
|
|
@@ -61,5 +62,5 @@
|
|
|
61
62
|
"type": "git",
|
|
62
63
|
"url": "git+https://github.com/ExodusMovement/assets.git"
|
|
63
64
|
},
|
|
64
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "2d0154787aed614543dcfcc0f4c216d7057fcbb2"
|
|
65
66
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { safeString } from '@exodus/safe-string'
|
|
2
2
|
import { retry } from '@exodus/simple-retry'
|
|
3
|
+
import { TraceId } from '@exodus/traceparent'
|
|
3
4
|
import delay from 'delay'
|
|
4
5
|
import lodash from 'lodash'
|
|
5
6
|
import urlJoin from 'url-join'
|
|
@@ -23,6 +24,19 @@ const INSIGHT_HTTP_ERROR_BROADCAST_MESSAGE = safeString`insight-api-http-error:b
|
|
|
23
24
|
const INSIGHT_HTTP_ERROR_CLAIMABLE_MESSAGE = safeString`insight-api-http-error:claimable`
|
|
24
25
|
const INSIGHT_HTTP_ERROR_UNCLAIMED_MESSAGE = safeString`insight-api-http-error:unclaimed`
|
|
25
26
|
|
|
27
|
+
const parseBroadcastErrorReason = (data) => {
|
|
28
|
+
if (!data) {
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const parsed = JSON.parse(data)
|
|
34
|
+
return parsed?.error || data
|
|
35
|
+
} catch {
|
|
36
|
+
return data
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
26
40
|
const fetchJson = async (
|
|
27
41
|
url,
|
|
28
42
|
fetchOptions,
|
|
@@ -35,8 +49,11 @@ const fetchJson = async (
|
|
|
35
49
|
return null
|
|
36
50
|
}
|
|
37
51
|
|
|
52
|
+
const traceId = TraceId.fromResponse(response)
|
|
53
|
+
|
|
38
54
|
if (!response.ok) {
|
|
39
55
|
const error = new Error(httpErrorMessage)
|
|
56
|
+
error.traceId = traceId
|
|
40
57
|
error.code = `${response.status}`
|
|
41
58
|
throw error
|
|
42
59
|
}
|
|
@@ -44,7 +61,9 @@ const fetchJson = async (
|
|
|
44
61
|
try {
|
|
45
62
|
return await response.json()
|
|
46
63
|
} catch (err) {
|
|
47
|
-
|
|
64
|
+
const error = new Error(INSIGHT_JSON_ERROR_MESSAGE, { cause: err })
|
|
65
|
+
error.traceId = traceId
|
|
66
|
+
throw error
|
|
48
67
|
}
|
|
49
68
|
}
|
|
50
69
|
|
|
@@ -204,12 +223,16 @@ export default class InsightAPIClient {
|
|
|
204
223
|
const response = await fetch(url, fetchOptions)
|
|
205
224
|
let data = await response.text()
|
|
206
225
|
|
|
226
|
+
const traceId = TraceId.fromResponse(response)
|
|
227
|
+
|
|
207
228
|
if (!response.ok) {
|
|
208
229
|
console.warn('Insight Broadcast HTTP Error:')
|
|
209
230
|
console.warn(response.statusText)
|
|
210
231
|
console.warn(data)
|
|
211
232
|
const error = new Error(INSIGHT_HTTP_ERROR_BROADCAST_MESSAGE)
|
|
233
|
+
error.traceId = traceId
|
|
212
234
|
error.code = `${response.status}`
|
|
235
|
+
error.reason = parseBroadcastErrorReason(data)
|
|
213
236
|
throw error
|
|
214
237
|
}
|
|
215
238
|
|
|
@@ -221,7 +244,9 @@ export default class InsightAPIClient {
|
|
|
221
244
|
}
|
|
222
245
|
|
|
223
246
|
if (!data.txid) {
|
|
224
|
-
|
|
247
|
+
const error = new Error(INSIGHT_MISSING_TXID_MESSAGE)
|
|
248
|
+
error.traceId = traceId
|
|
249
|
+
throw error
|
|
225
250
|
}
|
|
226
251
|
}
|
|
227
252
|
|
|
@@ -632,9 +632,16 @@ export class BitcoinMonitorScanner {
|
|
|
632
632
|
continue
|
|
633
633
|
}
|
|
634
634
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
635
|
+
let prevTx = null
|
|
636
|
+
try {
|
|
637
|
+
prevTx = await insightClient.fetchTxObject(utxo.txId)
|
|
638
|
+
} catch {
|
|
639
|
+
prevTx = null
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
const prevOutput = prevTx?.vout?.find((output) => output.n === utxo.vout)
|
|
643
|
+
if (prevOutput && !prevOutput.spentTxId) {
|
|
644
|
+
// Only readd inputs whose exact outpoint is still unspent.
|
|
638
645
|
utxosToAdd.push(utxo)
|
|
639
646
|
}
|
|
640
647
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { retry } from '@exodus/simple-retry'
|
|
2
2
|
|
|
3
|
+
const getErrorText = (error) => [error?.message, error?.reason].filter(Boolean).join(' ')
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Broadcast a signed transaction to the Bitcoin network with retry logic
|
|
5
7
|
* @param {Object} params
|
|
@@ -14,14 +16,15 @@ export async function broadcastTransaction({ asset, rawTx }) {
|
|
|
14
16
|
try {
|
|
15
17
|
return await asset.api.broadcastTx(rawTxHex)
|
|
16
18
|
} catch (e) {
|
|
19
|
+
const errorText = getErrorText(e)
|
|
17
20
|
// Mark certain errors as final (non-retryable)
|
|
18
21
|
if (
|
|
19
|
-
/missing inputs/i.test(
|
|
20
|
-
/absurdly-high-fee/.test(
|
|
21
|
-
/too-long-mempool-chain/.test(
|
|
22
|
-
/txn-mempool-conflict/.test(
|
|
23
|
-
/tx-size/.test(
|
|
24
|
-
/txn-already-in-mempool/.test(
|
|
22
|
+
/(missing inputs|missingorspent)/i.test(errorText) ||
|
|
23
|
+
/absurdly-high-fee/.test(errorText) ||
|
|
24
|
+
/too-long-mempool-chain/.test(errorText) ||
|
|
25
|
+
/txn-mempool-conflict/.test(errorText) ||
|
|
26
|
+
/tx-size/.test(errorText) ||
|
|
27
|
+
/txn-already-in-mempool/.test(errorText)
|
|
25
28
|
) {
|
|
26
29
|
e.finalError = true
|
|
27
30
|
}
|
|
@@ -37,7 +40,7 @@ export async function broadcastTransaction({ asset, rawTx }) {
|
|
|
37
40
|
try {
|
|
38
41
|
await broadcastTxWithRetry(rawTxHex)
|
|
39
42
|
} catch (err) {
|
|
40
|
-
if (err.
|
|
43
|
+
if (getErrorText(err).includes('txn-already-in-mempool')) {
|
|
41
44
|
// Not an error, transaction is already broadcast
|
|
42
45
|
console.log('Transaction is already in the mempool.')
|
|
43
46
|
return
|
package/src/tx-send/index.js
CHANGED
|
@@ -6,6 +6,8 @@ import { extractTransactionContext } from '../psbt-parser.js'
|
|
|
6
6
|
import { broadcastTransaction } from './broadcast-tx.js'
|
|
7
7
|
import { updateAccountState, updateTransactionLog } from './update-state.js'
|
|
8
8
|
|
|
9
|
+
const getErrorText = (error) => [error?.message, error?.reason].filter(Boolean).join(' ')
|
|
10
|
+
|
|
9
11
|
const checkTxExists = async ({ asset, txId }) => {
|
|
10
12
|
try {
|
|
11
13
|
const tx = await asset.insightClient.fetchTx(txId)
|
|
@@ -212,7 +214,7 @@ export const sendTxFactory = ({
|
|
|
212
214
|
if (txExists) {
|
|
213
215
|
console.warn(`tx-send: ${assetName} tx already broadcast`, txId)
|
|
214
216
|
} else {
|
|
215
|
-
if (/
|
|
217
|
+
if (/(missing inputs|missingorspent)/i.test(getErrorText(err))) {
|
|
216
218
|
err.txInfo = JSON.stringify({
|
|
217
219
|
amount: sendAmount.toDefaultString({ unit: true }),
|
|
218
220
|
fee: ((fee && fee.toDefaultString({ unit: true })) || 0).toString(),
|