db bug fix; sweep fixes
This commit is contained in:
parent
44188aa5ba
commit
751067bace
3 changed files with 17 additions and 24 deletions
|
|
@ -6,7 +6,7 @@ var async = require('async')
|
|||
var HKDF = require('node-hkdf-sync')
|
||||
var BigNumber = require('bignumber.js')
|
||||
BigNumber.config({CRYPTO: true})
|
||||
|
||||
var db = require('./postgresql_interface')
|
||||
var logger = require('./logger')
|
||||
var notifier = require('./notifier')
|
||||
|
||||
|
|
@ -25,8 +25,7 @@ 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
|
||||
var TRADE_INTERVAL = 60 * 1000
|
||||
|
||||
var cryptoCodes = null
|
||||
|
||||
|
|
@ -57,9 +56,11 @@ var coins = {
|
|||
var alertFingerprint = null
|
||||
var lastAlertTime = null
|
||||
|
||||
exports.init = function init () {
|
||||
const masterSeed = fs.readFileSync('seeds/seed.txt').trim()
|
||||
exports.init = function init (connectionString) {
|
||||
const masterSeed = fs.readFileSync('seeds/seed.txt', 'utf8').trim()
|
||||
hkdf = new HKDF('sha256', 'lamassu-server-salt', masterSeed)
|
||||
|
||||
db.init(connectionString)
|
||||
}
|
||||
|
||||
function loadPlugin (name, config) {
|
||||
|
|
@ -401,20 +402,13 @@ exports.fiatBalance = function fiatBalance (cryptoCode) {
|
|||
}
|
||||
|
||||
function processTxStatus (tx) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const cryptoCode = tx.cryptoCode
|
||||
const walletPlugin = walletPlugins[cryptoCode]
|
||||
const cryptoCode = tx.cryptoCode
|
||||
const walletPlugin = walletPlugins[cryptoCode]
|
||||
|
||||
if (!walletPlugin) throw new Error('No wallet plugins for: ' + cryptoCode)
|
||||
walletPlugin.getStatus(tx.toAddress, tx.cryptoAtoms, function (err, res) {
|
||||
if (err) {
|
||||
logger.error(err)
|
||||
return resolve() // Resolve on error because we ignore errors
|
||||
}
|
||||
if (!walletPlugin) return console.error('No wallet plugins for: ' + cryptoCode)
|
||||
|
||||
db.updateTxStatus(tx, res.status).then(resolve).catch(reject)
|
||||
})
|
||||
})
|
||||
return walletPlugin.getStatus(tx.toAddress, tx.cryptoAtoms)
|
||||
.then(res => db.updateTxStatus(tx, res.status))
|
||||
}
|
||||
|
||||
function notifyConfirmation (tx) {
|
||||
|
|
@ -473,6 +467,7 @@ exports.startPolling = function startPolling () {
|
|||
monitorLiveIncoming()
|
||||
monitorIncoming()
|
||||
monitorUnnotified()
|
||||
sweepLiveHD()
|
||||
}
|
||||
|
||||
function startTrader (cryptoCode) {
|
||||
|
|
@ -487,7 +482,7 @@ function startTrader (cryptoCode) {
|
|||
|
||||
tradeIntervals[cryptoCode] = setInterval(
|
||||
function () { executeTrades(cryptoCode) },
|
||||
cachedConfig.exchanges.settings.tradeInterval
|
||||
TRADE_INTERVAL
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -783,14 +778,14 @@ exports.cacheResponse = function (session, path, method, body) {
|
|||
function sweepHD (row) {
|
||||
const cryptoCode = row.crypto_code
|
||||
const walletPlugin = walletPlugins[cryptoCode]
|
||||
return walletPlugin.sweep(row.hdSerial)
|
||||
return walletPlugin.sweep(row.hd_serial)
|
||||
.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))
|
||||
.catch(err => logger.error(err))
|
||||
}
|
||||
|
||||
function sweepLiveHD () {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue