@exodus/bitcoin-api 2.0.1 → 2.1.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bitcoin-api",
3
- "version": "2.0.1",
3
+ "version": "2.1.1",
4
4
  "description": "Exodus bitcoin-api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -40,5 +40,5 @@
40
40
  "@exodus/bip-schnorr": "0.6.6-fork-1",
41
41
  "@noble/secp256k1": "~1.5.3"
42
42
  },
43
- "gitHead": "de014dde36e372655e982879a4c217cb4c4f9f07"
43
+ "gitHead": "d74d7ee6a7ca8da4373ea7b6aad6b245a50cae27"
44
44
  }
package/src/move-funds.js CHANGED
@@ -2,21 +2,28 @@ import wif from 'wif'
2
2
  import { UtxoCollection, Address } from '@exodus/models'
3
3
  import { createInputs, createOutput, getNonWitnessTxs } from './tx-send'
4
4
  import assert from 'minimalistic-assert'
5
- import assets from '@exodus/assets'
6
5
 
7
- export const moveFundsFactory = ({ insightClient, getFeeEstimator, keys, signTx, address }) => {
6
+ export const moveFundsFactory = ({
7
+ asset,
8
+ insightClient,
9
+ getFeeEstimator,
10
+ keys,
11
+ signTx,
12
+ address,
13
+ }) => {
14
+ assert(asset, 'asset is required')
8
15
  assert(insightClient, 'insightClient is required')
9
16
  assert(getFeeEstimator, 'getFeeEstimator is required')
10
17
  assert(address, 'address is required')
11
18
  assert(keys, 'keys is required')
12
19
  assert(signTx, 'signTx is required')
13
20
  async function prepareFunds(assetName, input, options = {}) {
14
- const asset = assets[assetName]
15
21
  const { toAddress, assetClientInterface, MoveFundsError, walletAccount } = options
16
22
  assert(MoveFundsError, 'MoveFundsError is required') // should we move MoveFundsError to asset libs?
17
23
  assert(toAddress, 'toAddress is required')
18
24
  assert(assetClientInterface, 'assetClientInterface is required')
19
25
  assert(walletAccount, 'walletAccount is required')
26
+ assert(asset.name === assetName, `expected asset ${asset.name} but got assetName ${assetName}`)
20
27
 
21
28
  const formatProps = {
22
29
  asset,
@@ -375,15 +375,17 @@ export class BitcoinMonitorScanner {
375
375
  // this is an array because legacy multisig has multiple addresses
376
376
  if (!Array.isArray(vout.scriptPubKey.addresses)) return
377
377
  if (vout.scriptPubKey.addresses.length === 0) return
378
- if (!addrMap[vout.scriptPubKey.addresses[0]]) {
378
+ const sentAddress = vout.scriptPubKey.addresses[0]
379
+ if (!addrMap[sentAddress]) {
379
380
  if (isSent && !txLogItem.to) {
380
381
  const val = currency.defaultUnit(vout.value)
381
- txLogItem.data.sent.push({ address: vout.scriptPubKey.addresses[0], amount: val })
382
+ const sentDisplayAddress = asset.address.displayAddress?.(sentAddress) || sentAddress
383
+ txLogItem.data.sent.push({ address: sentDisplayAddress, amount: val })
382
384
  }
383
385
  return
384
386
  }
385
387
 
386
- const address = addrMap[vout.scriptPubKey.addresses[0]]
388
+ const address = addrMap[sentAddress]
387
389
  if (isReceiveAddress(address)) {
388
390
  txLogItem.addresses.push(address)
389
391
  }
@@ -130,9 +130,10 @@ export const createAndBroadcastTXFactory = ({
130
130
 
131
131
  let replaceableTxs = findUnconfirmedSentRbfTxs(txSet)
132
132
 
133
- if (assetName === 'bcash') {
133
+ if (asset.address.toLegacyAddress) {
134
134
  address = asset.address.toLegacyAddress(address)
135
135
  }
136
+
136
137
  if (assetName === 'digibyte') {
137
138
  if (asset.address.isP2SH2(address)) {
138
139
  address = asset.address.P2SH2ToP2SH(address)
@@ -216,7 +217,7 @@ export const createAndBroadcastTXFactory = ({
216
217
  const change = selectedUtxos.value.sub(totalAmount).sub(fee)
217
218
  const dust = getDustValue(asset)
218
219
  let ourAddress = replaceTx?.data?.changeAddress || changeAddress
219
- if (['bcash'].includes(assetName)) {
220
+ if (asset.address.toLegacyAddress) {
220
221
  const legacyAddress = asset.address.toLegacyAddress(ourAddress.address)
221
222
  ourAddress = Address.create(legacyAddress, ourAddress.meta)
222
223
  }