@exodus/bitcoin-api 4.16.0 → 4.16.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,16 @@
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.16.1](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@4.16.0...@exodus/bitcoin-api@4.16.1) (2026-07-09)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * cache mempool tip height with short TTL to dedup reqs ([#8333](https://github.com/ExodusMovement/assets/issues/8333)) ([77e2c40](https://github.com/ExodusMovement/assets/commit/77e2c4025b728e6992f037dabf9a636bfbca829e))
12
+ * **decred-plugin:** fail fast on unresponsive dcrdata endpoint to speed up restore ([#8351](https://github.com/ExodusMovement/assets/issues/8351)) ([9346786](https://github.com/ExodusMovement/assets/commit/934678607553a740786ba3fe906dfd38c2fdd040))
13
+
14
+
15
+
6
16
  ## [4.16.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@4.15.10...@exodus/bitcoin-api@4.16.0) (2026-06-29)
7
17
 
8
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bitcoin-api",
3
- "version": "4.16.0",
3
+ "version": "4.16.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": "d57432d4ef29f2dc1bc269d501fd29d9a0063f1c"
66
+ "gitHead": "dd519241ca0e24a4bbb93aeec3c9ff540c7e71f7"
67
67
  }
@@ -66,29 +66,48 @@ const fetchJson = async (
66
66
  }
67
67
  }
68
68
 
69
- async function fetchJsonRetry(url, fetchOptions, httpErrorMessage) {
70
- const waitTimes = ['2s', '5s', '10s', '20s']
69
+ const DEFAULT_ADDRESS_TXS_TIMEOUT = 25_000
70
+ const DEFAULT_ADDRESS_TXS_RETRY_WAIT_TIMES = ['2s', '5s', '10s', '20s']
71
+
72
+ async function fetchJsonRetry(
73
+ url,
74
+ fetchOptions,
75
+ httpErrorMessage,
76
+ waitTimes = DEFAULT_ADDRESS_TXS_RETRY_WAIT_TIMES
77
+ ) {
71
78
  const fetchWithRetry = retry(fetchJson, { delayTimesMs: waitTimes })
72
79
  return fetchWithRetry(url, fetchOptions, false, httpErrorMessage)
73
80
  }
74
81
 
75
82
  export default class InsightAPIClient {
76
- constructor(baseURL) {
77
- this._baseURL = baseURL
83
+ #baseURL
84
+ #addressTxsTimeout
85
+ #addressTxsRetryWaitTimes
86
+
87
+ constructor(
88
+ baseURL,
89
+ {
90
+ addressTxsTimeout = DEFAULT_ADDRESS_TXS_TIMEOUT,
91
+ addressTxsRetryWaitTimes = DEFAULT_ADDRESS_TXS_RETRY_WAIT_TIMES,
92
+ } = Object.create(null)
93
+ ) {
94
+ this.#baseURL = baseURL
95
+ this.#addressTxsTimeout = addressTxsTimeout
96
+ this.#addressTxsRetryWaitTimes = addressTxsRetryWaitTimes
78
97
  }
79
98
 
80
99
  setBaseUrl(baseURL) {
81
- this._baseURL = baseURL
100
+ this.#baseURL = baseURL
82
101
  }
83
102
 
84
103
  async fetchBalance(address) {
85
104
  const encodedAddress = encodeURIComponent(address)
86
- const url = urlJoin(this._baseURL, `/balance/${encodedAddress}`)
105
+ const url = urlJoin(this.#baseURL, `/balance/${encodedAddress}`)
87
106
  return fetchJson(url, undefined, false, INSIGHT_HTTP_ERROR_BALANCE_MESSAGE)
88
107
  }
89
108
 
90
109
  async fetchBlockHeight() {
91
- const url = urlJoin(this._baseURL, '/status')
110
+ const url = urlJoin(this.#baseURL, '/status')
92
111
  const status = await fetchJson(
93
112
  url,
94
113
  { timeout: 10_000 },
@@ -105,7 +124,7 @@ export default class InsightAPIClient {
105
124
  query.set('assetNames', assetNames.join(','))
106
125
  }
107
126
 
108
- const url = urlJoin(this._baseURL, `/addrs/${encodedAddress}/utxo?${query}`)
127
+ const url = urlJoin(this.#baseURL, `/addrs/${encodedAddress}/utxo?${query}`)
109
128
  const utxos = await fetchJson(url, undefined, false, INSIGHT_HTTP_ERROR_UTXO_MESSAGE)
110
129
 
111
130
  return utxos.map((utxo) => ({
@@ -122,12 +141,12 @@ export default class InsightAPIClient {
122
141
 
123
142
  async fetchTx(txId) {
124
143
  const encodedTxId = encodeURIComponent(txId)
125
- const url = urlJoin(this._baseURL, `/tx/${encodedTxId}`)
144
+ const url = urlJoin(this.#baseURL, `/tx/${encodedTxId}`)
126
145
  return fetchJson(url, undefined, true, INSIGHT_HTTP_ERROR_TX_MESSAGE)
127
146
  }
128
147
 
129
148
  async fetchTxObject(txId) {
130
- const url = urlJoin(this._baseURL, `/fulltx?${new URLSearchParams({ hash: txId })}`)
149
+ const url = urlJoin(this.#baseURL, `/fulltx?${new URLSearchParams({ hash: txId })}`)
131
150
  const object = await fetchJson(url, undefined, true, INSIGHT_HTTP_ERROR_FULLTX_MESSAGE)
132
151
  if (!object || isEmpty(object)) {
133
152
  return null
@@ -138,7 +157,7 @@ export default class InsightAPIClient {
138
157
 
139
158
  async fetchRawTx(txId) {
140
159
  const encodedTxId = encodeURIComponent(txId)
141
- const url = urlJoin(this._baseURL, `/rawtx/${encodedTxId}`)
160
+ const url = urlJoin(this.#baseURL, `/rawtx/${encodedTxId}`)
142
161
  const { rawtx } = await fetchJson(url, undefined, false, INSIGHT_HTTP_ERROR_RAWTX_MESSAGE)
143
162
  return rawtx
144
163
  }
@@ -147,7 +166,7 @@ export default class InsightAPIClient {
147
166
  if (!Array.isArray(addrs) || addrs.length === 0) return { items: [], totalItems: 0 }
148
167
 
149
168
  options = { noScriptSig: 1, noAsm: 1, noSpent: 0, from: 0, to: 10, ...options }
150
- const url = `${urlJoin(this._baseURL, '/addrs/txs')}?${new URLSearchParams(options)}`
169
+ const url = `${urlJoin(this.#baseURL, '/addrs/txs')}?${new URLSearchParams(options)}`
151
170
 
152
171
  const fetchOptions = {
153
172
  method: 'post',
@@ -156,10 +175,15 @@ export default class InsightAPIClient {
156
175
  'Content-Type': 'application/json',
157
176
  },
158
177
  body: JSON.stringify({ addrs: addrs.join(',') }),
159
- timeout: 25_000,
178
+ timeout: this.#addressTxsTimeout,
160
179
  }
161
180
 
162
- return fetchJsonRetry(url, fetchOptions, INSIGHT_HTTP_ERROR_ADDRS_TXS_MESSAGE)
181
+ return fetchJsonRetry(
182
+ url,
183
+ fetchOptions,
184
+ INSIGHT_HTTP_ERROR_ADDRS_TXS_MESSAGE,
185
+ this.#addressTxsRetryWaitTimes
186
+ )
163
187
  }
164
188
 
165
189
  async fetchAllTxData(addrs = [], chunk = 25, httpDelay = 2000, shouldStopFetching = () => {}) {
@@ -181,19 +205,19 @@ export default class InsightAPIClient {
181
205
 
182
206
  async fetchUnconfirmedAncestorData(txId) {
183
207
  const encodedTxId = encodeURIComponent(txId)
184
- const url = urlJoin(this._baseURL, `/unconfirmed_ancestor/${encodedTxId}`)
208
+ const url = urlJoin(this.#baseURL, `/unconfirmed_ancestor/${encodedTxId}`)
185
209
  return fetchJson(url, undefined, false, INSIGHT_HTTP_ERROR_UNCONFIRMED_ANCESTOR_MESSAGE)
186
210
  }
187
211
 
188
212
  async fetchFeeRate() {
189
- const url = urlJoin(this._baseURL, '/v2/fees')
213
+ const url = urlJoin(this.#baseURL, '/v2/fees')
190
214
  return fetchJson(url, undefined, false, INSIGHT_HTTP_ERROR_FEES_MESSAGE)
191
215
  }
192
216
 
193
217
  async broadcastTx(rawTx) {
194
218
  const _rawTx = rawTx instanceof Uint8Array ? Buffer.from(rawTx).toString('hex') : rawTx
195
219
  console.log('gonna broadcastTx')
196
- const url = urlJoin(this._baseURL, '/tx/send')
220
+ const url = urlJoin(this.#baseURL, '/tx/send')
197
221
  const fetchOptions = {
198
222
  method: 'post',
199
223
  headers: {
@@ -9,6 +9,11 @@ import fetchWithTimeout from './fetch-with-timeout.js'
9
9
  const API_PAGE_SIZE = 25
10
10
  const DEFAULT_PAGE_SIZE = 10
11
11
  const RETRY_WAIT_TIMES = ['5s', '10s', '20s', '30s']
12
+ // A monitor tick scans every wallet account in parallel and each scan asks for the
13
+ // tip height, producing identical /blocks/tip/height requests within the same second.
14
+ // Serving them from a short-lived cache keeps one request per tick without letting
15
+ // confirmation counts go meaningfully stale.
16
+ const TIP_HEIGHT_CACHE_TTL_MS = 10_000
12
17
 
13
18
  const MEMPOOL_HTTP_ERROR_MESSAGE = safeString`mempool-api-http-error`
14
19
  const MEMPOOL_INSIGHT_JSON_ERROR_MESSAGE = safeString`mempool-insight-api-invalid-json`
@@ -218,9 +223,14 @@ export default class MempoolRestClient {
218
223
  this._clarityBaseURL = clarityBaseURL
219
224
  this._retryWaitTimes = retryWaitTimes
220
225
  this._configMinFeeRate = configMinFeeRate
226
+ this._tipHeightCache = null
221
227
  }
222
228
 
223
229
  setMempoolBaseUrl(mempoolBaseURL) {
230
+ if (mempoolBaseURL !== this._mempoolBaseURL) {
231
+ this._tipHeightCache = null
232
+ }
233
+
224
234
  this._mempoolBaseURL = mempoolBaseURL
225
235
  }
226
236
 
@@ -233,6 +243,29 @@ export default class MempoolRestClient {
233
243
  }
234
244
 
235
245
  async _fetchTipHeight() {
246
+ const now = Date.now()
247
+ if (this._tipHeightCache && now - this._tipHeightCache.startedAt < TIP_HEIGHT_CACHE_TTL_MS) {
248
+ return this._tipHeightCache.promise
249
+ }
250
+
251
+ // Start one fetch and cache its promise right away, before it finishes.
252
+ // Anyone who asks for the tip height while it's still loading gets the same
253
+ // promise back, so N concurrent callers result in exactly one network request.
254
+ const promise = this._fetchTipHeightFresh()
255
+ const cacheEntry = { promise, startedAt: now }
256
+ this._tipHeightCache = cacheEntry
257
+ promise.catch(() => {
258
+ // The fetch failed, so throw this entry away — otherwise every caller for
259
+ // the next TTL would receive the same error instead of a retry. Only clear
260
+ // it if it's still ours: a newer fetch may have replaced it already.
261
+ if (this._tipHeightCache === cacheEntry) {
262
+ this._tipHeightCache = null
263
+ }
264
+ })
265
+ return promise
266
+ }
267
+
268
+ async _fetchTipHeightFresh() {
236
269
  const tipText = await fetchText(
237
270
  this._mempoolApiUrl('/blocks/tip/height'),
238
271
  { timeout: 10_000 },