Migrate bitgo api to v2
This commit is contained in:
parent
e7bb29341d
commit
01153d0562
3 changed files with 1191 additions and 465 deletions
|
|
@ -16,7 +16,9 @@ function buildBitgo (account) {
|
||||||
|
|
||||||
function getWallet (account) {
|
function getWallet (account) {
|
||||||
const bitgo = buildBitgo(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) {
|
function checkCryptoCode (cryptoCode) {
|
||||||
|
|
@ -36,13 +38,13 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||||
amount: cryptoAtoms.toNumber(),
|
amount: cryptoAtoms.toNumber(),
|
||||||
walletPassphrase: account.walletPassphrase
|
walletPassphrase: account.walletPassphrase
|
||||||
}
|
}
|
||||||
return wallet.sendCoins(params)
|
return wallet.send(params)
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
return result.hash
|
return result.hash
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
if (err.message === 'Insufficient funds') throw new E.InsufficientFundsError()
|
if (err.message === 'insufficient funds') throw new E.InsufficientFundsError()
|
||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +52,8 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||||
function balance (account, cryptoCode) {
|
function balance (account, cryptoCode) {
|
||||||
return checkCryptoCode(cryptoCode)
|
return checkCryptoCode(cryptoCode)
|
||||||
.then(() => getWallet(account))
|
.then(() => getWallet(account))
|
||||||
.then(wallet => BN(wallet.wallet.spendableConfirmedBalance))
|
// TODO This was previously spendableConfirmedBalance, what happened to it on v2?
|
||||||
|
.then(wallet => BN(wallet._wallet.confirmedBalanceString))
|
||||||
}
|
}
|
||||||
|
|
||||||
function newAddress (account, info) {
|
function newAddress (account, info) {
|
||||||
|
|
@ -63,7 +66,7 @@ function newAddress (account, info) {
|
||||||
|
|
||||||
// If a label was provided, set the label
|
// If a label was provided, set the label
|
||||||
if (info.label) {
|
if (info.label) {
|
||||||
return wallet.setLabel({ address: address, label: info.label })
|
return wallet.updateAddress({ address: address, label: info.label })
|
||||||
.then(() => address)
|
.then(() => address)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,10 +95,10 @@ function newFunding (account, cryptoCode) {
|
||||||
return wallet.createAddress()
|
return wallet.createAddress()
|
||||||
.then(result => {
|
.then(result => {
|
||||||
const fundingAddress = result.address
|
const fundingAddress = result.address
|
||||||
return wallet.setLabel({address: fundingAddress, label: 'Funding Address'})
|
return wallet.updateAddress({address: fundingAddress, label: 'Funding Address'})
|
||||||
.then(() => ({
|
.then(() => ({
|
||||||
fundingPendingBalance: BN(wallet.wallet.balance),
|
fundingPendingBalance: BN(wallet._wallet.balanceString),
|
||||||
fundingConfirmedBalance: BN(wallet.wallet.confirmedBalance),
|
fundingConfirmedBalance: BN(wallet._wallet.confirmedBalanceString),
|
||||||
fundingAddress
|
fundingAddress
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
|
||||||
1597
package-lock.json
generated
1597
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -14,7 +14,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": "3.4.11",
|
"bitgo": "4.40.2",
|
||||||
"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",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue