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

@ -21,7 +21,8 @@ module.exports = {
getStatus,
sweep,
defaultAddress,
supportsHd: true
supportsHd: true,
newFunding
}
if (!web3.isConnected()) {
@ -36,13 +37,13 @@ function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {
.then(pify(web3.eth.sendRawTransaction))
}
function validateCrypto (cryptoCode) {
function checkCryptoCode (cryptoCode) {
if (cryptoCode === 'ETH') return Promise.resolve()
return Promise.reject(new Error('cryptoCode must be ETH'))
}
function balance (account, cryptoCode) {
return validateCrypto(cryptoCode)
return checkCryptoCode(cryptoCode)
.then(() => pendingBalance(defaultAddress(account)))
}
@ -136,7 +137,7 @@ function newAddress (account, info) {
}
function getStatus (account, toAddress, cryptoAtoms, cryptoCode) {
return validateCrypto(cryptoCode)
return checkCryptoCode(cryptoCode)
.then(() => confirmedBalance(toAddress))
.then(confirmed => {
if (confirmed.gte(cryptoAtoms)) return {status: 'confirmed'}
@ -164,3 +165,22 @@ function defaultHdNode (account) {
const key = hdkey.fromMasterSeed(masterSeed)
return key.derivePath(defaultPrefixPath)
}
function newFunding (account, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => {
const fundingAddress = defaultAddress(account)
const promises = [
pendingBalance(fundingAddress),
confirmedBalance(fundingAddress)
]
return Promise.all(promises)
.then(([fundingPendingBalance, fundingConfirmedBalance]) => ({
fundingPendingBalance,
fundingConfirmedBalance,
fundingAddress
}))
})
}