@exodus/bitcoin-api 2.3.10 → 2.3.11

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.11",
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": "0baba593527c3eb5bd558dd0a9d230e8aed03824"
45
45
  }
@@ -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(