add support for funding

This commit is contained in:
Josh Harvey 2017-06-17 01:38:51 +03:00
parent 8440fa3b1d
commit bf0dc3f7f3
15 changed files with 731 additions and 356 deletions

View file

@ -19,6 +19,24 @@ function balance (account, cryptoCode) {
})
}
function pendingBalance (account, cryptoCode) {
return Promise.resolve()
.then(() => {
if (cryptoCode === 'BTC') return BN(1e8 * 10.1)
if (cryptoCode === 'ETH') return BN(1e18 * 10.1)
throw new Error('Unsupported crypto: ' + cryptoCode)
})
}
function confirmedBalance (account, cryptoCode) {
return Promise.resolve()
.then(() => {
if (cryptoCode === 'BTC') return BN(1e8 * 10)
if (cryptoCode === 'ETH') return BN(1e18 * 10)
throw new Error('Unsupported crypto: ' + cryptoCode)
})
}
// Note: This makes it easier to test insufficient funds errors
let sendCount = 0
@ -50,6 +68,21 @@ function newAddress () {
return Promise.resolve('<Fake address, don\'t send>')
}
function newFunding (account, cryptoCode) {
const promises = [
pendingBalance(account, cryptoCode),
confirmedBalance(account, cryptoCode),
newAddress(account, {cryptoCode})
]
return Promise.all(promises)
.then(([fundingPendingBalance, fundingConfirmedBalance, fundingAddress]) => ({
fundingPendingBalance,
fundingConfirmedBalance,
fundingAddress
}))
}
function getStatus (account, toAddress, cryptoAtoms, cryptoCode) {
const elapsed = Date.now() - t0
@ -66,5 +99,6 @@ module.exports = {
balance,
sendCoins,
newAddress,
getStatus
getStatus,
newFunding
}