@exodus/bitcoin-api 2.3.8 → 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.8",
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": "9e53c6305dd83860b2db0ea8bfc261c043d8509b"
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
@@ -346,13 +346,15 @@ export class BitcoinMonitorScanner {
346
346
  ['bitcoin', 'bitcoinregtest', 'bitcointestnet'].includes(asset.name)
347
347
  ) {
348
348
  txLogItem.data.inputs = UtxoCollection.fromArray(
349
- txItem.vin.map((vin) => ({
350
- address: addrMap[vin.addr],
351
- script: asset.address.toScriptPubKey(vin.addr).toString('hex'),
352
- txId: vin.txid,
353
- vout: vin.vout,
354
- value: currency.defaultUnit(vin.value || 0),
355
- }))
349
+ txItem.vin
350
+ .filter((vin) => addrMap[vin.addr])
351
+ .map((vin) => ({
352
+ address: addrMap[vin.addr],
353
+ script: asset.address.toScriptPubKey(vin.addr).toString('hex'),
354
+ txId: vin.txid,
355
+ vout: vin.vout,
356
+ value: currency.defaultUnit(vin.value || 0),
357
+ }))
356
358
  ).toJSON()
357
359
  }
358
360
 
@@ -514,12 +516,12 @@ export class BitcoinMonitorScanner {
514
516
 
515
517
  const accountState = await aci.getAccountState({ assetName, walletAccount })
516
518
 
517
- const allStoredUtxos = getUtxos({ accountState, asset })
519
+ const storedUtxos = getUtxos({ accountState, asset })
518
520
 
519
521
  const currentTxs = Array.from(await aci.getTxLog({ assetName, walletAccount }))
520
522
 
521
523
  const unconfirmedTxIds = uniq([
522
- ...allStoredUtxos
524
+ ...storedUtxos
523
525
  .toArray()
524
526
  .filter((utxos) => !utxos.confirmations)
525
527
  .map((utxos) => utxos.txId),
@@ -549,12 +551,13 @@ export class BitcoinMonitorScanner {
549
551
  })
550
552
  .filter((tx) => Object.keys(tx).length > 1)
551
553
 
552
- const txConfirmedUtxos = confirmationsList.length
553
- ? allStoredUtxos.updateConfirmations(confirmationsList)
554
+ // Note about storedUtxos.clone(): updateConfirmations mutates the ordinal utxos, it's not possible to perform the equals below if not cloned
555
+ const updatedUtxos = confirmationsList.length
556
+ ? storedUtxos.clone().updateConfirmations(confirmationsList)
554
557
  : null
555
558
 
556
559
  return {
557
- utxos: txConfirmedUtxos,
560
+ utxos: !updatedUtxos || updatedUtxos.equals(storedUtxos) ? null : updatedUtxos,
558
561
  txsToUpdate: updatedPropertiesTxs,
559
562
  }
560
563
  }
@@ -81,7 +81,18 @@ export async function getNonWitnessTxs(asset, utxos, insightClient) {
81
81
  return rawTxs
82
82
  }
83
83
 
84
- export const getSizeAndChangeScriptFactory = ({ bitcoinJsLib = defaultBitcoinjsLib } = {}) => ({
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
+
95
+ export const getSizeAndChangeScriptFactory = ({ bitcoinjsLib = defaultBitcoinjsLib } = {}) => ({
85
96
  assetName,
86
97
  tx,
87
98
  rawTx,
@@ -94,16 +105,16 @@ 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!
102
- const parsedTx = bitcoinJsLib.Transaction.fromBuffer(Buffer.from(rawTx, 'hex'))
113
+ const parsedTx = bitcoinjsLib.Transaction.fromBuffer(Buffer.from(rawTx, 'hex'))
103
114
  try {
104
115
  return {
105
116
  script: parsedTx.outs?.[changeUtxoIndex]?.script.toString('hex'),
106
- size: tx.virtualSize?.(),
117
+ size: getSize(parsedTx),
107
118
  }
108
119
  } catch (e) {
109
120
  console.warn(