@exodus/bitcoin-api 2.2.2 → 2.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bitcoin-api",
3
- "version": "2.2.2",
3
+ "version": "2.3.0",
4
4
  "description": "Exodus bitcoin-api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -13,7 +13,6 @@
13
13
  "access": "restricted"
14
14
  },
15
15
  "scripts": {
16
- "build": "babel --root-mode upward --delete-dir-on-start --ignore '**/__tests__/**' src --out-dir lib",
17
16
  "test": "jest",
18
17
  "lint": "eslint ./src",
19
18
  "lint:fix": "yarn lint --fix"
@@ -41,5 +40,5 @@
41
40
  "@exodus/bitcoin-meta": "^1.0.0",
42
41
  "@noble/secp256k1": "~1.5.3"
43
42
  },
44
- "gitHead": "2d223c3c71d00fbd5246af3f39410eec113d0029"
43
+ "gitHead": "e2dd97caae4a23757f38f2156450f17d86fdce34"
45
44
  }
@@ -0,0 +1,26 @@
1
+ import assert from 'minimalistic-assert'
2
+ import { getUtxos } from './utxos-utils'
3
+
4
+ // known issue!! fee data is static here!
5
+ // Hydra's balances's module does not provide it when calling asset.api.getBalances
6
+ // https://github.com/ExodusMovement/exodus-hydra/blob/f9110f8e9e76b8b199bc4d40461cb1bed3a5be1e/modules/balances/module/index.js#L130
7
+ // feeData is required to know if an unconfirmed tx can or cannot be RBFed?
8
+ // This could be fixed once we allow all unconfirmed utxos to be RBFed or if we change the balance module to provide the feeData when calling asset.api.getBalances
9
+ export const getBalancesFactory = ({ feeData, getSpendableBalance }) => {
10
+ assert(feeData, 'feeData is required')
11
+ assert(getSpendableBalance, 'getSpendableBalance is required')
12
+ return ({ asset, accountState, txLog }) => {
13
+ assert(asset, 'asset is required')
14
+ assert(accountState, 'accountState is required')
15
+ assert(txLog, 'txLog is required')
16
+ const utxos = getUtxos({ asset, accountState })
17
+ const balance = utxos.value
18
+ const spendableBalance = getSpendableBalance({
19
+ asset,
20
+ accountState,
21
+ txSet: txLog,
22
+ feeData,
23
+ })
24
+ return { balance, spendableBalance }
25
+ }
26
+ }
@@ -1,7 +1,7 @@
1
1
  import assert from 'minimalistic-assert'
2
2
  import { getUtxosData } from './utxo-selector'
3
3
  import { findUnconfirmedSentRbfTxs } from '../tx-utils'
4
- import { getSpendableUtxos, getUsableUtxos, getUtxos } from '../utxos-utils'
4
+ import { getUsableUtxos, getUtxos } from '../utxos-utils'
5
5
  import { canBumpTx } from './can-bump-tx'
6
6
 
7
7
  export class GetFeeResolver {
@@ -40,15 +40,13 @@ export class GetFeeResolver {
40
40
  }
41
41
 
42
42
  getSpendableBalance = ({ asset, accountState, txSet, feeData }) => {
43
- const utxos = getUtxos({ accountState, asset })
44
- const spendableUtxos = getSpendableUtxos({
43
+ return this.#getUtxosData({
45
44
  asset,
46
- utxos,
47
- feeData,
45
+ accountState,
48
46
  txSet,
49
- allowUnconfirmedRbfEnabledUtxos: this.#allowUnconfirmedRbfEnabledUtxos,
50
- })
51
- return spendableUtxos.value
47
+ feeData,
48
+ isSendAll: true,
49
+ }).spendableBalance
52
50
  }
53
51
 
54
52
  #getUtxosData = ({ asset, accountState, txSet, feeData, amount, customFee, isSendAll }) => {
@@ -209,12 +209,15 @@ export const getUtxosData = ({
209
209
  })
210
210
 
211
211
  const resolvedFee = replaceTx ? fee.sub(replaceTx.feeAmount) : fee
212
-
213
- const spendableBalance = getConfirmedOrRfbDisabledUtxos({
212
+ const empty = UtxoCollection.createEmpty({ currency: asset.currency })
213
+ const spendableUtxos = getConfirmedOrRfbDisabledUtxos({
214
214
  asset,
215
215
  utxos: usableUtxos,
216
216
  allowUnconfirmedRbfEnabledUtxos,
217
- }).value
217
+ }).union(replaceTx ? usableUtxos.getTxIdUtxos(replaceTx.txId) : empty)
218
+ // .union(selectedUtxos || empty)
219
+
220
+ const spendableBalance = spendableUtxos.value
218
221
 
219
222
  const extraFee = selectedUtxos
220
223
  ? asset.currency.baseUnit(getExtraFee({ asset, inputs: selectedUtxos, feePerKB: feeRate }))
package/src/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './account-state'
2
+ export * from './balances'
2
3
  export * from './btc-address'
3
4
  export * from './btc-like-address'
4
5
  export * from './btc-like-keys'
@@ -12,26 +12,6 @@ export function getUtxos({ accountState, asset }) {
12
12
  )
13
13
  }
14
14
 
15
- export const getBalancesFactory = ({ feeData, allowUnconfirmedRbfEnabledUtxos }) => {
16
- assert(feeData, 'feeData is required')
17
- return ({ asset, accountState, txLog }) => {
18
- assert(asset, 'asset is required')
19
- assert(accountState, 'accountState is required')
20
- assert(txLog, 'txLog is required')
21
- const utxos = getUtxos({ asset, accountState })
22
- const balance = utxos.value
23
- const spendableBalance = getSpendableUtxos({
24
- asset,
25
- utxos,
26
- txSet: txLog,
27
- feeData,
28
-
29
- allowUnconfirmedRbfEnabledUtxos,
30
- }).value
31
- return { balance, spendableBalance }
32
- }
33
- }
34
-
35
15
  export function getConfirmedUtxos({ asset, utxos }) {
36
16
  assert(asset, 'asset is required')
37
17
  assert(utxos, 'utxos is required')
@@ -83,19 +63,3 @@ export function getUsableUtxos({ asset, utxos, feeData, txSet }) {
83
63
  { currency: asset.currency }
84
64
  )
85
65
  }
86
-
87
- export function getSpendableUtxos({
88
- asset,
89
- utxos,
90
- feeData,
91
- txSet,
92
-
93
- allowUnconfirmedRbfEnabledUtxos,
94
- }) {
95
- const usableUtxos = getUsableUtxos({ asset, utxos, feeData, txSet })
96
- return getConfirmedOrRfbDisabledUtxos({
97
- asset,
98
- utxos: usableUtxos,
99
- allowUnconfirmedRbfEnabledUtxos,
100
- })
101
- }