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 BitGo = require('bitgo')
const { toLegacyAddress, toCashAddress } = require('bchaddrjs') const { toLegacyAddress, toCashAddress } = require('bchaddrjs')
@ -52,7 +54,8 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
const params = { const params = {
address: getLegacyAddress(address, cryptoCode), address: getLegacyAddress(address, cryptoCode),
amount: cryptoAtoms.toNumber(), amount: cryptoAtoms.toNumber(),
walletPassphrase: account[`${cryptoCode}WalletPassphrase`] walletPassphrase: account[`${cryptoCode}WalletPassphrase`],
enforceMinConfirmsForChange: false
} }
return wallet.send(params) return wallet.send(params)
}) })
@ -94,14 +97,28 @@ function newAddress (account, info) {
} }
function getStatus (account, toAddress, requested, cryptoCode) { function getStatus (account, toAddress, requested, cryptoCode) {
const bitgo = buildBitgo(account)
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => bitgo.blockchain().getAddress({ address: getLegacyAddress(toAddress, cryptoCode) })) .then(() => getWallet(account, cryptoCode))
.then(rec => { .then(wallet => wallet.transfers({ type: 'receive', address: toAddress }))
if (rec.balance === 0) return { status: 'notSeen' } .then(({ transfers }) => {
if (requested.gt(rec.balance)) return { status: 'insufficientFunds' } const filterConfirmed = _.filter(it =>
if (requested.gt(rec.confirmedBalance)) return { status: 'authorized' } it.state === 'confirmed' && it.type === 'receive'
return { status: 'confirmed' } )
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", "bitcoind-rpc": "^0.7.0",
"bitcore-lib": "^0.15.0", "bitcore-lib": "^0.15.0",
"bitcore-lib-cash": "git+https://github.com/bitpay/bitcore-lib.git#cash", "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", "body-parser": "^1.15.1",
"coinbase": "^2.0.6", "coinbase": "^2.0.6",
"console-log-level": "^1.4.0", "console-log-level": "^1.4.0",