Fix deprecated api call on bitgo api (#255)
* Fix deprecated api call on bitgo api * Change filterUnconfirmed to filterPending
This commit is contained in:
parent
8af67cf030
commit
61ad8a9eba
2 changed files with 26 additions and 9 deletions
|
|
@ -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' }
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue