@exodus/bitcoin-api 4.15.10 → 4.16.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,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.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@4.15.10...@exodus/bitcoin-api@4.16.0) (2026-06-29)
7
+
8
+
9
+ ### Features
10
+
11
+
12
+ * feat: add optional getHistoricalBalance to asset api (#8247)
13
+
14
+
15
+
6
16
  ## [4.15.10](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@4.15.9...@exodus/bitcoin-api@4.15.10) (2026-06-18)
7
17
 
8
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bitcoin-api",
3
- "version": "4.15.10",
3
+ "version": "4.16.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",
@@ -63,5 +63,5 @@
63
63
  "type": "git",
64
64
  "url": "git+https://github.com/ExodusMovement/assets.git"
65
65
  },
66
- "gitHead": "e307446f4085795c9eb2085c4a2bf009b7d2297d"
66
+ "gitHead": "d57432d4ef29f2dc1bc269d501fd29d9a0063f1c"
67
67
  }
@@ -0,0 +1,63 @@
1
+ import assert from 'minimalistic-assert'
2
+
3
+ const toAddressString = (address) => (typeof address === 'string' ? address : address?.address)
4
+
5
+ /**
6
+ * Builds the historical balance as of `date`, entirely from the tx log: per
7
+ * address, sum the outputs paying into the wallet (`data.internalOutputs`) and
8
+ * subtract the inputs it spent (`data.inputs`). Every address used by `date` is
9
+ * retained, including ones fully spent (so with a zero balance). Entries are
10
+ * coalesced by address.
11
+ *
12
+ * Only bitcoin, bitcoinregtest and bitcointestnet populate `data.inputs`, so
13
+ * the plugin wires this in for those assets only.
14
+ */
15
+ export const getHistoricalBalanceFactory = ({ assetClientInterface }) => {
16
+ assert(assetClientInterface, 'assetClientInterface is required')
17
+
18
+ return async ({ asset, walletAccount, date }) => {
19
+ assert(asset, 'asset is required')
20
+ assert(walletAccount, 'walletAccount is required')
21
+ assert(date instanceof Date, 'date is required')
22
+
23
+ const txLog = await assetClientInterface.getTxLog({ assetName: asset.name, walletAccount })
24
+
25
+ const byAddress = new Map()
26
+ const apply = (address, amount, txDate) => {
27
+ if (!address) return
28
+ const existing = byAddress.get(address)
29
+ if (existing) {
30
+ existing.amount = existing.amount.add(amount)
31
+ if (txDate < existing.date) existing.date = txDate
32
+ } else {
33
+ byAddress.set(address, { address, amount, date: txDate })
34
+ }
35
+ }
36
+
37
+ const cutoff = date.getTime()
38
+
39
+ for (const tx of txLog) {
40
+ const txDate = new Date(tx.date).getTime()
41
+ if (txDate > cutoff || tx.failed || tx.pending) continue
42
+
43
+ for (const out of tx.data.internalOutputs ?? []) {
44
+ apply(toAddressString(out.address), asset.currency.baseUnit(out.amount || 0), txDate)
45
+ }
46
+
47
+ for (const group of Object.values(tx.data.inputs ?? {})) {
48
+ for (const utxo of group.utxos ?? []) {
49
+ apply(toAddressString(group.address), asset.currency.parse(utxo.value).negate(), txDate)
50
+ }
51
+ }
52
+ }
53
+
54
+ let total = asset.currency.ZERO
55
+ const entries = []
56
+ for (const entry of byAddress.values()) {
57
+ total = total.add(entry.amount)
58
+ entries.push(entry)
59
+ }
60
+
61
+ return { total: total.clampLowerZero(), entries }
62
+ }
63
+ }
package/src/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './account-state.js'
2
2
  export * from './balances.js'
3
+ export { getHistoricalBalanceFactory } from './get-historical-balance.js'
3
4
  export * from './btc-address.js'
4
5
  export * from './btc-like-address.js'
5
6
  export * from './btc-like-keys.js'