Fix deprecated api call on bitgo api (#255)

* Fix deprecated api call on bitgo api

* Change filterUnconfirmed to filterPending
This commit is contained in:
Rafael Taranto 2019-03-07 07:03:48 -03:00 committed by Josh Harvey
parent 8af67cf030
commit 61ad8a9eba
2 changed files with 26 additions and 9 deletions

View file

@ -1,3 +1,5 @@
const _ = require('lodash/fp')
const BitGo = require('bitgo')
const { toLegacyAddress, toCashAddress } = require('bchaddrjs')
@ -52,7 +54,8 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
const params = {
address: getLegacyAddress(address, cryptoCode),
amount: cryptoAtoms.toNumber(),
walletPassphrase: account[`${cryptoCode}WalletPassphrase`]
walletPassphrase: account[`${cryptoCode}WalletPassphrase`],
enforceMinConfirmsForChange: false
}
return wallet.send(params)
})
@ -94,14 +97,28 @@ function newAddress (account, info) {
}
function getStatus (account, toAddress, requested, cryptoCode) {
const bitgo = buildBitgo(account)
return checkCryptoCode(cryptoCode)
.then(() => bitgo.blockchain().getAddress({ address: getLegacyAddress(toAddress, cryptoCode) }))
.then(rec => {
if (rec.balance === 0) return { status: 'notSeen' }
if (requested.gt(rec.balance)) return { status: 'insufficientFunds' }
if (requested.gt(rec.confirmedBalance)) return { status: 'authorized' }
return { status: 'confirmed' }
.then(() => getWallet(account, cryptoCode))
.then(wallet => wallet.transfers({ type: 'receive', address: toAddress }))
.then(({ transfers }) => {
const filterConfirmed = _.filter(it =>
it.state === 'confirmed' && it.type === 'receive'
)
const filterPending = _.filter(it =>
(it.state === 'confirmed' || it.state === 'unconfirmed') &&
it.type === 'receive'
)
const sum = _.reduce((acc, val) => val.add(acc), BN(0))
const toBn = _.map(it => BN(it.valueString))
const confirmed = _.compose(sum, toBn, filterConfirmed)(transfers)
const pending = _.compose(sum, toBn, filterPending)(transfers)
if (confirmed.gte(requested)) return { status: 'confirmed' }
if (pending.gte(requested)) return { status: 'authorized' }
if (pending.gt(0)) return { status: 'insufficientFunds' }
return { status: 'notSeen' }
})
}

View file

@ -15,7 +15,7 @@
"bitcoind-rpc": "^0.7.0",
"bitcore-lib": "^0.15.0",
"bitcore-lib-cash": "git+https://github.com/bitpay/bitcore-lib.git#cash",
"bitgo": "4.40.2",
"bitgo": "4.47.0",
"body-parser": "^1.15.1",
"coinbase": "^2.0.6",
"console-log-level": "^1.4.0",