@exodus/bitcoin-api 2.3.4 → 2.3.5

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.4",
3
+ "version": "2.3.5",
4
4
  "description": "Exodus bitcoin-api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -42,5 +42,5 @@
42
42
  "@exodus/bitcoin-meta": "^1.0.1",
43
43
  "@noble/secp256k1": "~1.5.3"
44
44
  },
45
- "gitHead": "ae212da85b29d90a3656bcfa034608950f883df1"
45
+ "gitHead": "3dd9a1846d6f34252c12e966e1ee1f851cca4173"
46
46
  }
@@ -91,15 +91,30 @@ export const getSizeAndChangeScriptFactory = ({ bitcoinJsLib = defaultBitcoinjsL
91
91
  assert(assetName, 'assetName is required')
92
92
  assert(rawTx, 'rawTx is required')
93
93
  assert(typeof changeUtxoIndex === 'number', 'changeUtxoIndex must be a number')
94
+
95
+ const getSize = (tx) => {
96
+ if (typeof tx.size === 'number') return tx.size
97
+ if (typeof tx.virtualSize === 'function') {
98
+ return tx.virtualSize()
99
+ }
100
+ if (typeof tx.virtualSize === 'number') {
101
+ return tx.virtualSize
102
+ }
103
+ return undefined
104
+ }
105
+
94
106
  if (tx) {
95
- return { script: tx.outs?.[changeUtxoIndex]?.script.toString('hex'), size: tx.virtualSize }
107
+ return {
108
+ script: tx.outs?.[changeUtxoIndex]?.script.toString('hex'),
109
+ size: getSize(tx),
110
+ }
96
111
  }
97
112
  // Trezor doesn't return tx!! we need to reparse it!
98
113
  const parsedTx = bitcoinJsLib.Transaction.fromBuffer(Buffer.from(rawTx, 'hex'))
99
114
  try {
100
115
  return {
101
116
  script: parsedTx.outs?.[changeUtxoIndex]?.script.toString('hex'),
102
- size: parsedTx.virtualSize(),
117
+ size: getSize(parsedTx),
103
118
  }
104
119
  } catch (e) {
105
120
  console.warn(