format for latest standard

This commit is contained in:
Josh Harvey 2018-03-10 18:59:40 +00:00
parent 4108efd9c7
commit c2af183911
77 changed files with 1697 additions and 1693 deletions

View file

@ -29,83 +29,83 @@ function checkCryptoCode (cryptoCode) {
function sendCoins (account, address, cryptoAtoms, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => getWallet(account))
.then(wallet => {
const params = {
address: address,
amount: cryptoAtoms.toNumber(),
walletPassphrase: account.walletPassphrase
}
return wallet.sendCoins(params)
})
.then(result => {
return result.hash
})
.catch(err => {
if (err.message === 'Insufficient funds') throw new E.InsufficientFundsError()
throw err
})
.then(() => getWallet(account))
.then(wallet => {
const params = {
address: address,
amount: cryptoAtoms.toNumber(),
walletPassphrase: account.walletPassphrase
}
return wallet.sendCoins(params)
})
.then(result => {
return result.hash
})
.catch(err => {
if (err.message === 'Insufficient funds') throw new E.InsufficientFundsError()
throw err
})
}
function balance (account, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => getWallet(account))
.then(wallet => BN(wallet.wallet.spendableConfirmedBalance))
.then(() => getWallet(account))
.then(wallet => BN(wallet.wallet.spendableConfirmedBalance))
}
function newAddress (account, info) {
return checkCryptoCode(info.cryptoCode)
.then(() => getWallet(account))
.then(wallet => {
return wallet.createAddress()
.then(result => {
const address = result.address
.then(() => getWallet(account))
.then(wallet => {
return wallet.createAddress()
.then(result => {
const address = result.address
// If a label was provided, set the label
if (info.label) {
return wallet.setLabel({ address: address, label: info.label })
.then(() => address)
}
// If a label was provided, set the label
if (info.label) {
return wallet.setLabel({ address: address, label: info.label })
.then(() => address)
}
return address
return address
})
})
})
}
function getStatus (account, toAddress, requested, cryptoCode) {
const bitgo = buildBitgo(account)
return checkCryptoCode(cryptoCode)
.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'}
})
.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'}
})
}
function newFunding (account, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => {
return getWallet(account)
.then(wallet => {
return wallet.createAddress()
.then(result => {
const fundingAddress = result.address
return wallet.setLabel({address: fundingAddress, label: 'Funding Address'})
.then(() => ({
fundingPendingBalance: BN(wallet.wallet.balance),
fundingConfirmedBalance: BN(wallet.wallet.confirmedBalance),
fundingAddress
}))
})
.then(() => {
return getWallet(account)
.then(wallet => {
return wallet.createAddress()
.then(result => {
const fundingAddress = result.address
return wallet.setLabel({address: fundingAddress, label: 'Funding Address'})
.then(() => ({
fundingPendingBalance: BN(wallet.wallet.balance),
fundingConfirmedBalance: BN(wallet.wallet.confirmedBalance),
fundingAddress
}))
})
})
})
})
}
function cryptoNetwork (account, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => account.environment === 'test' ? 'test' : 'main')
.then(() => account.environment === 'test' ? 'test' : 'main')
}
module.exports = {