commit
8e1f9e0b83
3 changed files with 1196 additions and 471 deletions
|
|
@ -11,12 +11,14 @@ const NAME = 'BitGo'
|
|||
|
||||
function buildBitgo (account) {
|
||||
const env = account.environment === 'test' ? 'test' : 'prod'
|
||||
return new BitGo.BitGo({accessToken: account.token, env, userAgent: userAgent})
|
||||
return new BitGo.BitGo({ accessToken: account.token, env, userAgent: userAgent })
|
||||
}
|
||||
|
||||
function getWallet (account) {
|
||||
const bitgo = buildBitgo(account)
|
||||
return bitgo.wallets().get({ id: account.walletId })
|
||||
const coin = account.environment === 'test' ? 'tbtc' : 'btc'
|
||||
|
||||
return bitgo.coin(coin).wallets().get({ id: account.walletId })
|
||||
}
|
||||
|
||||
function checkCryptoCode (cryptoCode) {
|
||||
|
|
@ -36,13 +38,13 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
|||
amount: cryptoAtoms.toNumber(),
|
||||
walletPassphrase: account.walletPassphrase
|
||||
}
|
||||
return wallet.sendCoins(params)
|
||||
return wallet.send(params)
|
||||
})
|
||||
.then(result => {
|
||||
return result.hash
|
||||
})
|
||||
.catch(err => {
|
||||
if (err.message === 'Insufficient funds') throw new E.InsufficientFundsError()
|
||||
if (err.message === 'insufficient funds') throw new E.InsufficientFundsError()
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
|
@ -50,7 +52,7 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
|||
function balance (account, cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => getWallet(account))
|
||||
.then(wallet => BN(wallet.wallet.spendableConfirmedBalance))
|
||||
.then(wallet => BN(wallet._wallet.spendableBalanceString))
|
||||
}
|
||||
|
||||
function newAddress (account, info) {
|
||||
|
|
@ -63,7 +65,7 @@ function newAddress (account, info) {
|
|||
|
||||
// If a label was provided, set the label
|
||||
if (info.label) {
|
||||
return wallet.setLabel({ address: address, label: info.label })
|
||||
return wallet.updateAddress({ address: address, label: info.label })
|
||||
.then(() => address)
|
||||
}
|
||||
|
||||
|
|
@ -75,12 +77,12 @@ function newAddress (account, info) {
|
|||
function getStatus (account, toAddress, requested, cryptoCode) {
|
||||
const bitgo = buildBitgo(account)
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => bitgo.blockchain().getAddress({address: toAddress}))
|
||||
.then(() => bitgo.blockchain().getAddress({ address: toAddress }))
|
||||
.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'}
|
||||
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' }
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -92,10 +94,10 @@ function newFunding (account, cryptoCode) {
|
|||
return wallet.createAddress()
|
||||
.then(result => {
|
||||
const fundingAddress = result.address
|
||||
return wallet.setLabel({address: fundingAddress, label: 'Funding Address'})
|
||||
return wallet.updateAddress({ address: fundingAddress, label: 'Funding Address' })
|
||||
.then(() => ({
|
||||
fundingPendingBalance: BN(wallet.wallet.balance),
|
||||
fundingConfirmedBalance: BN(wallet.wallet.confirmedBalance),
|
||||
fundingPendingBalance: BN(wallet._wallet.balanceString),
|
||||
fundingConfirmedBalance: BN(wallet._wallet.confirmedBalanceString),
|
||||
fundingAddress
|
||||
}))
|
||||
})
|
||||
|
|
|
|||
1635
package-lock.json
generated
1635
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -14,7 +14,7 @@
|
|||
"bitcoind-rpc": "^0.7.0",
|
||||
"bitcore-lib": "^0.15.0",
|
||||
"bitcore-lib-cash": "git+https://github.com/bitpay/bitcore-lib.git#cash",
|
||||
"bitgo": "3.4.11",
|
||||
"bitgo": "4.40.2",
|
||||
"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