implement HD sweep

This commit is contained in:
Josh Harvey 2016-06-01 14:45:58 +03:00
parent 0140e01c9f
commit 8f081ebf00
4 changed files with 67 additions and 1 deletions

View file

@ -23,6 +23,8 @@ var UNNOTIFIED_INTERVAL = 60 * 1000
var MAX_NOTIFY_AGE = 48 * 60 * 60 * 1000
var MIN_NOTIFY_AGE = 5 * 60 * 1000
var TRANSACTION_EXPIRATION = 48 * 60 * 60 * 1000
var SWEEP_LIVE_HD_INTERVAL = 60 * 1000
var SWEEP_OLD_HD_INTERVAL = 60 * 60 * 1000
var db = null
@ -465,6 +467,8 @@ exports.startPolling = function startPolling () {
setInterval(monitorLiveIncoming, LIVE_INCOMING_TX_INTERVAL)
setInterval(monitorIncoming, INCOMING_TX_INTERVAL)
setInterval(monitorUnnotified, UNNOTIFIED_INTERVAL)
setInterval(sweepLiveHD, SWEEP_LIVE_HD_INTERVAL)
setInterval(sweepOldHD, SWEEP_OLD_HD_INTERVAL)
monitorLiveIncoming()
monitorIncoming()
@ -775,3 +779,26 @@ exports.cachedResponse = function (session, path, method) {
exports.cacheResponse = function (session, path, method, body) {
return db.cacheResponse(session, path, method, body)
}
function sweepHD (row) {
const cryptoCode = row.crypto_code
const walletPlugin = walletPlugins[cryptoCode]
return walletPlugin.sweep(row.hdSerial)
.then(txHash => {
if (txHash) {
logger.debug('[%s] Swept address with tx: %s', cryptoCode, txHash)
return db.markSwept(row.session_id)
}
})
.catch(err => console.error(err))
}
function sweepLiveHD () {
return db.fetchLiveHD()
.then(rows => Promise.all(rows.map(sweepHD)))
}
function sweepOldHD () {
return db.fetchOldHD()
.then(rows => Promise.all(rows.map(sweepHD)))
}