@exodus/bitcoin-api 2.3.10 → 2.3.12

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.3.10",
3
+ "version": "2.3.12",
4
4
  "description": "Exodus bitcoin-api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -41,5 +41,5 @@
41
41
  "@exodus/bitcoin-meta": "^1.0.1",
42
42
  "jest-when": "^3.5.1"
43
43
  },
44
- "gitHead": "8d1b4e435fbb69abe1261aba737748d6443b759b"
44
+ "gitHead": "1fa02f677cba83cce320fd54be227a7a84411d93"
45
45
  }
@@ -38,7 +38,7 @@ const _canBumpTx = ({
38
38
  // Or the tx fee is below nextBlockMinimumFee if exists
39
39
  // Or the tx fee is below rbfBumpFeeThreshold * the current fee estimate
40
40
  if (tx.data.blocksSeen < rbfBumpFeeBlocks) {
41
- const feePerKB = asset.currency.baseUnit(tx.data.feePerKB)
41
+ const feePerKB = tx.data.feePerKB ? asset.currency.baseUnit(tx.data.feePerKB) : undefined
42
42
  if (!feePerKB) {
43
43
  return { errorMessage: 'fee rate is high enough' }
44
44
  } else if (feeData.nextBlockMinimumFee) {
@@ -5,7 +5,7 @@ import { resolveExtraFeeOfTx } from '../unconfirmed-ancestor-data'
5
5
  import { UtxoCollection } from '@exodus/models'
6
6
  import assert from 'minimalistic-assert'
7
7
 
8
- export const isHex = (s: string) => /[0-9a-f]*/.test(s.toLowerCase())
8
+ export const isHex = (s: string) => typeof s === 'string' && /[0-9a-f]*/.test(s.toLowerCase())
9
9
 
10
10
  export function getExtraFee({ asset, inputs, feePerKB }) {
11
11
  let extraFee = 0
@@ -81,6 +81,17 @@ export async function getNonWitnessTxs(asset, utxos, insightClient) {
81
81
  return rawTxs
82
82
  }
83
83
 
84
+ const getSize = (tx) => {
85
+ if (typeof tx.size === 'number') return tx.size
86
+ if (typeof tx.virtualSize === 'function') {
87
+ return tx.virtualSize()
88
+ }
89
+ if (typeof tx.virtualSize === 'number') {
90
+ return tx.virtualSize
91
+ }
92
+ return undefined
93
+ }
94
+
84
95
  export const getSizeAndChangeScriptFactory = ({ bitcoinjsLib = defaultBitcoinjsLib } = {}) => ({
85
96
  assetName,
86
97
  tx,
@@ -94,8 +105,8 @@ export const getSizeAndChangeScriptFactory = ({ bitcoinjsLib = defaultBitcoinjsL
94
105
 
95
106
  if (tx) {
96
107
  return {
97
- script: tx.outs?.[changeUtxoIndex]?.script,
98
- size: tx.virtualSize,
108
+ script: tx.outs?.[changeUtxoIndex]?.script.toString('hex'),
109
+ size: getSize(tx),
99
110
  }
100
111
  }
101
112
  // Trezor doesn't return tx!! we need to reparse it!
@@ -103,7 +114,7 @@ export const getSizeAndChangeScriptFactory = ({ bitcoinjsLib = defaultBitcoinjsL
103
114
  try {
104
115
  return {
105
116
  script: parsedTx.outs?.[changeUtxoIndex]?.script.toString('hex'),
106
- size: parsedTx.virtualSize?.(),
117
+ size: getSize(parsedTx),
107
118
  }
108
119
  } catch (e) {
109
120
  console.warn(