@exodus/bitcoin-api 4.16.1 → 5.0.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/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
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.1](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.0.0...@exodus/bitcoin-api@5.0.1) (2026-07-11)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **send-validation:** improve displayed amount format in validation messages ([#8366](https://github.com/ExodusMovement/assets/issues/8366)) ([940dcd4](https://github.com/ExodusMovement/assets/commit/940dcd4cbe75f4ab48e067bd033afd249caae9a4))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## [5.0.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@4.16.1...@exodus/bitcoin-api@5.0.0) (2026-07-10)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### ⚠ BREAKING CHANGES
|
|
19
|
+
|
|
20
|
+
* **bitcoin:** broadcast btc via mempool space send path (#8349)
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* **bitcoin:** broadcast btc via mempool space send path ([#8349](https://github.com/ExodusMovement/assets/issues/8349)) ([ff44736](https://github.com/ExodusMovement/assets/commit/ff44736b7aae845e5261bd60c8583d5871adb8f2))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [4.16.1](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@4.16.0...@exodus/bitcoin-api@4.16.1) (2026-07-09)
|
|
7
29
|
|
|
8
30
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
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",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"type": "git",
|
|
64
64
|
"url": "git+https://github.com/ExodusMovement/assets.git"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "07af9a0d2bda8262afce9aaabafabe0fa68286ba"
|
|
67
67
|
}
|
|
@@ -16,9 +16,8 @@ const RETRY_WAIT_TIMES = ['5s', '10s', '20s', '30s']
|
|
|
16
16
|
const TIP_HEIGHT_CACHE_TTL_MS = 10_000
|
|
17
17
|
|
|
18
18
|
const MEMPOOL_HTTP_ERROR_MESSAGE = safeString`mempool-api-http-error`
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const MEMPOOL_INSIGHT_HTTP_ERROR_BROADCAST_MESSAGE = safeString`mempool-insight-api-http-error:broadcast`
|
|
19
|
+
const MEMPOOL_MISSING_TXID_MESSAGE = safeString`mempool-api-missing-txid`
|
|
20
|
+
const MEMPOOL_HTTP_ERROR_BROADCAST_MESSAGE = safeString`mempool-api-http-error:broadcast`
|
|
22
21
|
const MEMPOOL_JSON_ERROR_MESSAGE = safeString`mempool-api-invalid-json`
|
|
23
22
|
const MEMPOOL_TEXT_ERROR_MESSAGE = safeString`mempool-api-invalid-text`
|
|
24
23
|
const MEMPOOL_HTTP_ERROR_TX_MESSAGE = safeString`mempool-api-http-error:tx`
|
|
@@ -34,6 +33,9 @@ const MEMPOOL_HTTP_ERROR_CPFP_MESSAGE = safeString`mempool-api-http-error:cpfp`
|
|
|
34
33
|
const MEMPOOL_FEES_PAYLOAD_ERROR_MESSAGE = safeString`mempool-api-invalid-fees-payload`
|
|
35
34
|
const MEMPOOL_INVALID_VALUE_ERROR_MESSAGE = safeString`mempool-api-invalid-value`
|
|
36
35
|
|
|
36
|
+
// A txid is a double-SHA256 hash: always exactly 32 bytes / 64 hex chars.
|
|
37
|
+
const TXID_HEX_PATTERN = /^[\da-f]{64}$/i
|
|
38
|
+
|
|
37
39
|
const parseBroadcastErrorReason = (data) => {
|
|
38
40
|
if (!data) {
|
|
39
41
|
return null
|
|
@@ -213,14 +215,8 @@ const normalizeTx = (tx, tipHeight, outspends) => {
|
|
|
213
215
|
}
|
|
214
216
|
|
|
215
217
|
export default class MempoolRestClient {
|
|
216
|
-
constructor({
|
|
217
|
-
mempoolBaseURL,
|
|
218
|
-
clarityBaseURL,
|
|
219
|
-
retryWaitTimes = RETRY_WAIT_TIMES,
|
|
220
|
-
configMinFeeRate = 10,
|
|
221
|
-
} = {}) {
|
|
218
|
+
constructor({ mempoolBaseURL, retryWaitTimes = RETRY_WAIT_TIMES, configMinFeeRate = 10 } = {}) {
|
|
222
219
|
this._mempoolBaseURL = mempoolBaseURL
|
|
223
|
-
this._clarityBaseURL = clarityBaseURL
|
|
224
220
|
this._retryWaitTimes = retryWaitTimes
|
|
225
221
|
this._configMinFeeRate = configMinFeeRate
|
|
226
222
|
this._tipHeightCache = null
|
|
@@ -234,10 +230,6 @@ export default class MempoolRestClient {
|
|
|
234
230
|
this._mempoolBaseURL = mempoolBaseURL
|
|
235
231
|
}
|
|
236
232
|
|
|
237
|
-
setClarityBaseUrl(clarityBaseURL) {
|
|
238
|
-
this._clarityBaseURL = clarityBaseURL
|
|
239
|
-
}
|
|
240
|
-
|
|
241
233
|
_mempoolApiUrl(path, { version } = {}) {
|
|
242
234
|
return urlJoin(this._mempoolBaseURL, version === 'v1' ? '/api/v1' : '/api', path)
|
|
243
235
|
}
|
|
@@ -655,47 +647,37 @@ export default class MempoolRestClient {
|
|
|
655
647
|
return { size, fees: Math.round(fees) }
|
|
656
648
|
}
|
|
657
649
|
|
|
658
|
-
//
|
|
659
|
-
//
|
|
660
|
-
//
|
|
661
|
-
//
|
|
650
|
+
// mempool.space/esplora broadcast: POST the raw hex as text, success is the
|
|
651
|
+
// txid as plain text, rejections are 400s whose text body carries bitcoind's
|
|
652
|
+
// sendrawtransaction reason (e.g. `txn-already-in-mempool`, `missing inputs`).
|
|
653
|
+
// That reason is preserved on `error.reason` because tx-send retry
|
|
654
|
+
// classification (broadcast-tx.js) pattern-matches it.
|
|
662
655
|
async broadcastTx(rawTx) {
|
|
663
656
|
const payload = rawTx instanceof Uint8Array ? Buffer.from(rawTx).toString('hex') : rawTx
|
|
664
|
-
const response = await fetch(
|
|
657
|
+
const response = await fetch(this._mempoolApiUrl('/tx'), {
|
|
665
658
|
method: 'post',
|
|
666
659
|
headers: {
|
|
667
|
-
Accept: '
|
|
668
|
-
'Content-Type': '
|
|
660
|
+
Accept: 'text/plain',
|
|
661
|
+
'Content-Type': 'text/plain',
|
|
669
662
|
},
|
|
670
|
-
body:
|
|
663
|
+
body: payload,
|
|
671
664
|
})
|
|
672
665
|
|
|
673
|
-
|
|
666
|
+
const data = await response.text()
|
|
674
667
|
|
|
675
668
|
if (!response.ok) {
|
|
676
|
-
console.warn(`Mempool Client's
|
|
669
|
+
console.warn(`Mempool Client's Broadcast HTTP Error:`)
|
|
677
670
|
console.warn(response.statusText)
|
|
678
671
|
console.warn(data)
|
|
679
|
-
const error = createHttpError(response,
|
|
672
|
+
const error = createHttpError(response, MEMPOOL_HTTP_ERROR_BROADCAST_MESSAGE)
|
|
680
673
|
error.reason = parseBroadcastErrorReason(data)
|
|
681
674
|
throw error
|
|
682
675
|
}
|
|
683
676
|
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
const error = new Error(MEMPOOL_INSIGHT_JSON_ERROR_MESSAGE, { cause: err })
|
|
689
|
-
const traceId = TraceId.fromResponse && TraceId.fromResponse(response)
|
|
690
|
-
if (traceId) {
|
|
691
|
-
error.traceId = traceId
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
throw error
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
if (!data.txid) {
|
|
698
|
-
const error = new Error(MEMPOOL_INSIGHT_MISSING_TXID_MESSAGE)
|
|
677
|
+
const txid = String(data).trim()
|
|
678
|
+
if (!TXID_HEX_PATTERN.test(txid)) {
|
|
679
|
+
console.warn(`Mempool Client's Broadcast Unexpected Payload:`, data)
|
|
680
|
+
const error = new Error(MEMPOOL_MISSING_TXID_MESSAGE)
|
|
699
681
|
const traceId = TraceId.fromResponse && TraceId.fromResponse(response)
|
|
700
682
|
if (traceId) {
|
|
701
683
|
error.traceId = traceId
|
|
@@ -704,7 +686,6 @@ export default class MempoolRestClient {
|
|
|
704
686
|
throw error
|
|
705
687
|
}
|
|
706
688
|
|
|
707
|
-
const { txid } = data
|
|
708
689
|
return { txid }
|
|
709
690
|
}
|
|
710
691
|
}
|
|
@@ -118,10 +118,9 @@ export function toMempoolWebSocketUrl(apiUrl) {
|
|
|
118
118
|
export function normalizeInsightConfig(config, monitorType) {
|
|
119
119
|
const apiUrl = config?.insightServers?.[0]
|
|
120
120
|
const mempoolApiUrl = config?.mempoolServer
|
|
121
|
-
const clarityApiUrl = config?.clarityServer
|
|
122
121
|
const wsUrl =
|
|
123
122
|
monitorType === 'mempool'
|
|
124
123
|
? config?.mempoolServerWS || toMempoolWebSocketUrl(mempoolApiUrl)
|
|
125
124
|
: config?.insightServersWS?.[0] || toWSUrl(apiUrl)
|
|
126
|
-
return { apiUrl, mempoolApiUrl,
|
|
125
|
+
return { apiUrl, mempoolApiUrl, wsUrl }
|
|
127
126
|
}
|
package/src/send-validation.js
CHANGED
|
@@ -35,7 +35,12 @@ const notEnoughOutputValidator = createValidator({
|
|
|
35
35
|
getMessage: ({ asset, getFiatValue, formatPrice }) => {
|
|
36
36
|
const dust = getDustValue(asset)
|
|
37
37
|
const dustValue =
|
|
38
|
-
formatPrice(getFiatValue(dust)) +
|
|
38
|
+
formatPrice(getFiatValue(dust)) +
|
|
39
|
+
' (' +
|
|
40
|
+
dust.toBaseString({ unit: false }) +
|
|
41
|
+
' ' +
|
|
42
|
+
asset.displayTicker +
|
|
43
|
+
')'
|
|
39
44
|
|
|
40
45
|
return t(`Sending ${dustValue} or less isn't supported on the ${asset.displayName} network`)
|
|
41
46
|
},
|
|
@@ -91,21 +91,12 @@ export class Monitor extends BaseMonitor {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
setServer(assetConfig = {}) {
|
|
94
|
-
const { apiUrl, mempoolApiUrl,
|
|
95
|
-
assetConfig,
|
|
96
|
-
this.#monitorType
|
|
97
|
-
)
|
|
94
|
+
const { apiUrl, mempoolApiUrl, wsUrl } = normalizeInsightConfig(assetConfig, this.#monitorType)
|
|
98
95
|
|
|
99
96
|
if (this.#monitorType === 'mempool') {
|
|
100
|
-
const clarityBaseUrl = clarityApiUrl || apiUrl
|
|
101
|
-
|
|
102
97
|
if (mempoolApiUrl) {
|
|
103
98
|
this.#insightClient.setMempoolBaseUrl(mempoolApiUrl)
|
|
104
99
|
}
|
|
105
|
-
|
|
106
|
-
if (clarityBaseUrl) {
|
|
107
|
-
this.#insightClient.setClarityBaseUrl(clarityBaseUrl)
|
|
108
|
-
}
|
|
109
100
|
} else if (apiUrl) {
|
|
110
101
|
this.#insightClient.setBaseUrl(apiUrl)
|
|
111
102
|
}
|