add blockcypher [WIP]

This commit is contained in:
Josh Harvey 2017-05-20 18:08:09 +03:00
parent b28c99aabb
commit 23458b6b56
10 changed files with 133 additions and 17 deletions

View file

@ -26,6 +26,7 @@ function computeSeed (masterSeed) {
}
function fetchWallet (settings, cryptoCode) {
console.log('DEBUG102')
return fs.readFile(options.seedPath, 'utf8')
.then(hex => {
const masterSeed = Buffer.from(hex.trim(), 'hex')
@ -66,11 +67,39 @@ function newAddress (settings, info) {
.then(r => r.wallet.newAddress(r.account, info))
}
function getStatus (settings, toAddress, cryptoAtoms, cryptoCode) {
function getWalletStatus (settings, toAddress, cryptoAtoms, cryptoCode) {
return fetchWallet(settings, cryptoCode)
.then(r => r.wallet.getStatus(r.account, toAddress, cryptoAtoms, cryptoCode))
}
function authorizeZeroConf (settings, toAddress, cryptoAtoms, cryptoCode, fiat, machineId) {
const cryptoConfig = configManager.cryptoScoped(cryptoCode, settings.config)
const machineConfig = configManager.machineScoped(machineId, settings.config)
const plugin = cryptoConfig.zeroConf
const zeroConfLimit = machineConfig.zeroConfLimit
if (fiat.gt(zeroConfLimit)) return Promise.resolve(false)
if (cryptoCode !== 'BTC' || plugin === 'all-zero-conf') return Promise.resolve(true)
const zeroConf = ph.load(ph.ZERO_CONF, plugin)
const account = settings.accounts[plugin]
return zeroConf.authorize(account, toAddress, cryptoAtoms, cryptoCode)
}
function getStatus (settings, toAddress, cryptoAtoms, cryptoCode, fiat, machineId) {
const promises = [
getWalletStatus(settings, toAddress, cryptoAtoms, cryptoCode),
authorizeZeroConf(settings, toAddress, cryptoAtoms, cryptoCode, fiat, machineId)
]
return Promise.all(promises)
.then(([status, isAuthorized]) => {
if (status === 'authorized') return isAuthorized ? 'authorized' : 'published'
return status
})
}
function sweep (settings, cryptoCode, hdIndex) {
return fetchWallet(settings, cryptoCode)
.then(r => r.wallet.sweep(r.account, cryptoCode, hdIndex))