@exodus/bitcoin-api 5.0.7 → 5.0.9

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,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.9](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.0.8...@exodus/bitcoin-api@5.0.9) (2026-10-19)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **bitcoin-api:** retry transient Insight read failures ([#9016](https://github.com/ExodusMovement/assets/issues/9016)) ([f8fbc95](https://github.com/ExodusMovement/assets/commit/f8fbc957a5fe1e9fe21fb28764246f28f3ff5133))
12
+
13
+
14
+
15
+ ## [5.0.8](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.0.7...@exodus/bitcoin-api@5.0.8) (2026-10-09)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * migrate to @exodus/basic-utils 5 ([#8894](https://github.com/ExodusMovement/assets/issues/8894)) ([ed125f3](https://github.com/ExodusMovement/assets/commit/ed125f3257785c92a3b8f8239a2e9eefe5dc6772))
21
+
22
+
23
+
6
24
  ## [5.0.7](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.0.6...@exodus/bitcoin-api@5.0.7) (2026-10-06)
7
25
 
8
26
 
package/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Transaction monitors, fee monitors, RPC with the blockchain node, and other networking code for Bitcoin and Bitcoin-like assets (e.g. dogecoin, litecoin, zcash). See [Asset Packages](../../docs/asset-packages.md) for more detail on this package's role.
4
4
 
5
+ ## Insight read recovery
6
+
7
+ Insight JSON reads retry malformed JSON, common transient network failures, and HTTP 500/502/503/504 responses at most twice. Retries wait one then two seconds with 0–20% positive jitter, respecting longer `Retry-After` seconds or HTTP dates. All attempts, response-body reads, and waits share a 30-second deadline, or a shorter caller timeout (ten seconds for block height). A retry that would exceed that deadline fails rather than waiting longer or retrying before the server permits it.
8
+
9
+ Cancellation and permanent HTTP errors, including 429, are not retried by this policy. Existing transaction-not-found behavior is preserved; malformed JSON is never treated as an empty balance or missing transaction. Address-history reads retain their separate configurable retry policy without nested retries. Broadcasts do not use the read-retry policy.
10
+
5
11
  ## Mempool WebSocket-assisted confirmation checks
6
12
 
7
13
  Confirmation-only scans reuse WebSocket transaction statuses and block heights for ten seconds, with at most 1,000 statuses per client. Missing or expired hints fall back to `/api/tx/:txid/status` instead of full transaction/outspend reads. New or replacement blocks, disconnect, stop, and backend changes invalidate the caches; standalone confirmations require a fresh tip lookup. Full history, UTXO, address-event, and reconnect reconciliation remain unchanged, as do Insight-backed monitors.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bitcoin-api",
3
- "version": "5.0.7",
3
+ "version": "5.0.9",
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": "^3.0.1",
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": "95f26b6479a44cb9272d39a83baaa56e2de7e263"
62
+ "gitHead": "2344cc95f78ce9e6f7f5b4367614b5fb09940a2f"
63
63
  }
@@ -6,6 +6,7 @@ import lodash from 'lodash'
6
6
  import urlJoin from 'url-join'
7
7
 
8
8
  import fetchWithTimeout from './fetch-with-timeout.js'
9
+ import fetchInsightRead from './insight-read-request.js'
9
10
 
10
11
  const { isEmpty } = lodash
11
12
 
@@ -41,14 +42,7 @@ const parseBroadcastErrorReason = (data) => {
41
42
  }
42
43
  }
43
44
 
44
- const fetchJson = async (
45
- url,
46
- fetchOptions,
47
- nullWhen404,
48
- httpErrorMessage = INSIGHT_HTTP_ERROR_MESSAGE
49
- ) => {
50
- const response = await fetchWithTimeout(url, fetchOptions)
51
-
45
+ const parseJsonResponse = async (response, nullWhen404, httpErrorMessage) => {
52
46
  if (nullWhen404 && response.status === 404) {
53
47
  return null
54
48
  }
@@ -65,12 +59,18 @@ const fetchJson = async (
65
59
  try {
66
60
  return await response.json()
67
61
  } catch (err) {
62
+ if (err?.name === 'AbortError') throw err
68
63
  const error = new Error(INSIGHT_JSON_ERROR_MESSAGE, { cause: err })
69
64
  error.traceId = traceId
70
65
  throw error
71
66
  }
72
67
  }
73
68
 
69
+ const fetchJson = (url, fetchOptions, nullWhen404, httpErrorMessage = INSIGHT_HTTP_ERROR_MESSAGE) =>
70
+ fetchInsightRead(url, fetchOptions, (response) =>
71
+ parseJsonResponse(response, nullWhen404, httpErrorMessage)
72
+ )
73
+
74
74
  const DEFAULT_ADDRESS_TXS_TIMEOUT = 25_000
75
75
  const DEFAULT_ADDRESS_TXS_RETRY_WAIT_TIMES = ['2s', '5s', '10s', '20s']
76
76
 
@@ -80,8 +80,14 @@ async function fetchJsonRetry(
80
80
  httpErrorMessage,
81
81
  waitTimes = DEFAULT_ADDRESS_TXS_RETRY_WAIT_TIMES
82
82
  ) {
83
- const fetchWithRetry = retry(fetchJson, { delayTimesMs: waitTimes })
84
- return fetchWithRetry(url, fetchOptions, false, httpErrorMessage)
83
+ const fetchWithRetry = retry(
84
+ () =>
85
+ fetchWithTimeout(url, fetchOptions, (response) =>
86
+ parseJsonResponse(response, false, httpErrorMessage)
87
+ ),
88
+ { delayTimesMs: waitTimes }
89
+ )
90
+ return fetchWithRetry()
85
91
  }
86
92
 
87
93
  export default class InsightAPIClient {
@@ -0,0 +1,81 @@
1
+ import delay from 'delay'
2
+
3
+ import fetchWithTimeout from './fetch-with-timeout.js'
4
+
5
+ const MAX_READ_TIMEOUT_MS = 30_000
6
+ const RETRY_DELAYS_MS = [1000, 2000]
7
+ const RETRYABLE_HTTP_CODES = new Set(['500', '502', '503', '504'])
8
+ const RETRYABLE_NETWORK_CODES = new Set([
9
+ 'ECONNRESET',
10
+ 'ECONNREFUSED',
11
+ 'ETIMEDOUT',
12
+ 'ENOTFOUND',
13
+ 'EAI_AGAIN',
14
+ 'ENETUNREACH',
15
+ 'EPIPE',
16
+ ])
17
+
18
+ const isRetryable = (error) =>
19
+ error?.name !== 'AbortError' &&
20
+ (error?.message === 'insight-api-invalid-json' ||
21
+ /^(network request failed|failed to fetch|fetch failed)$/iu.test(error?.message) ||
22
+ RETRYABLE_HTTP_CODES.has(error?.code) ||
23
+ RETRYABLE_NETWORK_CODES.has(error?.code))
24
+
25
+ const getRetryAfterMs = (response) => {
26
+ const header = response.headers?.get?.('retry-after')?.trim()
27
+ if (!header) return 0
28
+ if (/^\d+$/u.test(header)) return Number(header) * 1000
29
+ const serverDate = Date.parse(response.headers?.get?.('date'))
30
+ const remaining = Date.parse(header) - (Number.isFinite(serverDate) ? serverDate : Date.now())
31
+ return Number.isFinite(remaining) ? Math.max(0, remaining) : 0
32
+ }
33
+
34
+ export default async function fetchInsightRead(url, fetchOptions, consumeResponse) {
35
+ const { signal, timeout } = fetchOptions || Object.create(null)
36
+ const timeoutMs =
37
+ Number.isFinite(timeout) && timeout > 0
38
+ ? Math.min(timeout, MAX_READ_TIMEOUT_MS)
39
+ : MAX_READ_TIMEOUT_MS
40
+ const expiresAt = Date.now() + timeoutMs
41
+
42
+ for (let attempt = 0; ; attempt++) {
43
+ if (signal?.aborted) {
44
+ throw (
45
+ signal.reason ??
46
+ Object.assign(new Error('The operation was aborted.'), { name: 'AbortError' })
47
+ )
48
+ }
49
+ const remainingMs = expiresAt - Date.now()
50
+ if (remainingMs <= 0) {
51
+ throw Object.assign(new Error('The operation timed out.'), { name: 'AbortError' })
52
+ }
53
+
54
+ let retryAfterMs = 0
55
+ try {
56
+ return await fetchWithTimeout(
57
+ url,
58
+ { ...fetchOptions, timeout: remainingMs },
59
+ async (response) => {
60
+ retryAfterMs = getRetryAfterMs(response)
61
+ try {
62
+ return await consumeResponse(response)
63
+ } finally {
64
+ try {
65
+ await response.body?.cancel?.()
66
+ } catch {}
67
+ }
68
+ }
69
+ )
70
+ } catch (error) {
71
+ if (signal?.aborted || !isRetryable(error) || attempt >= RETRY_DELAYS_MS.length) throw error
72
+ const waitMs = Math.max(
73
+ Math.round(RETRY_DELAYS_MS[attempt] * (1 + Math.random() * 0.2)),
74
+ retryAfterMs
75
+ )
76
+ if (waitMs >= expiresAt - Date.now()) throw error
77
+ await delay(waitMs, { signal })
78
+ if (Date.now() >= expiresAt) throw error
79
+ }
80
+ }
81
+ }