@exodus/bitcoin-api 2.2.2 → 2.3.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/package.json +2 -3
- package/src/balances.js +26 -0
- package/src/fee/can-bump-tx.js +4 -3
- package/src/fee/get-fee-resolver.js +6 -8
- package/src/fee/utxo-selector.js +6 -3
- package/src/index.js +1 -0
- package/src/utxos-utils.js +0 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-api",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
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": "
|
|
43
|
+
"gitHead": "f8d65434ff4e35d66c1da37051f2dae30da419b7"
|
|
45
44
|
}
|
package/src/balances.js
ADDED
|
@@ -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
|
+
}
|
package/src/fee/can-bump-tx.js
CHANGED
|
@@ -78,7 +78,7 @@ const _canBumpTx = ({
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
if (bumpTx) {
|
|
81
|
-
const { replaceTx } = selectUtxos({
|
|
81
|
+
const { replaceTx, fee } = selectUtxos({
|
|
82
82
|
asset,
|
|
83
83
|
usableUtxos,
|
|
84
84
|
replaceableTxs: [bumpTx],
|
|
@@ -87,7 +87,7 @@ const _canBumpTx = ({
|
|
|
87
87
|
getFeeEstimator,
|
|
88
88
|
allowUnconfirmedRbfEnabledUtxos,
|
|
89
89
|
})
|
|
90
|
-
if (replaceTx) return { bumpType: BumpType.RBF }
|
|
90
|
+
if (replaceTx) return { bumpType: BumpType.RBF, bumpFee: fee.sub(replaceTx.feeAmount) }
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
const { fee } = selectUtxos({
|
|
@@ -108,8 +108,9 @@ const validateIsNumber = (number, name) => {
|
|
|
108
108
|
return number
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
const wrapResponseToObject = ({ bumpType = BumpType.NONE, errorMessage = null } = {}) => ({
|
|
111
|
+
const wrapResponseToObject = ({ bumpType = BumpType.NONE, bumpFee, errorMessage = null } = {}) => ({
|
|
112
112
|
bumpType,
|
|
113
|
+
bumpFee,
|
|
113
114
|
errorMessage,
|
|
114
115
|
})
|
|
115
116
|
|
|
@@ -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 {
|
|
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
|
-
|
|
44
|
-
const spendableUtxos = getSpendableUtxos({
|
|
43
|
+
return this.#getUtxosData({
|
|
45
44
|
asset,
|
|
46
|
-
|
|
47
|
-
feeData,
|
|
45
|
+
accountState,
|
|
48
46
|
txSet,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
feeData,
|
|
48
|
+
isSendAll: true,
|
|
49
|
+
}).spendableBalance
|
|
52
50
|
}
|
|
53
51
|
|
|
54
52
|
#getUtxosData = ({ asset, accountState, txSet, feeData, amount, customFee, isSendAll }) => {
|
package/src/fee/utxo-selector.js
CHANGED
|
@@ -209,12 +209,15 @@ export const getUtxosData = ({
|
|
|
209
209
|
})
|
|
210
210
|
|
|
211
211
|
const resolvedFee = replaceTx ? fee.sub(replaceTx.feeAmount) : fee
|
|
212
|
-
|
|
213
|
-
const
|
|
212
|
+
const empty = UtxoCollection.createEmpty({ currency: asset.currency })
|
|
213
|
+
const spendableUtxos = getConfirmedOrRfbDisabledUtxos({
|
|
214
214
|
asset,
|
|
215
215
|
utxos: usableUtxos,
|
|
216
216
|
allowUnconfirmedRbfEnabledUtxos,
|
|
217
|
-
}).
|
|
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
package/src/utxos-utils.js
CHANGED
|
@@ -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
|
-
}
|