bug fixes
This commit is contained in:
parent
f2a95e291a
commit
985e3811e3
14 changed files with 758 additions and 78 deletions
|
|
@ -1,27 +1,10 @@
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
const fs = require('fs')
|
|
||||||
const path = require('path')
|
|
||||||
|
|
||||||
const options = require('../options')
|
|
||||||
const db = require('../db')
|
const db = require('../db')
|
||||||
const config = require('./config')
|
const config = require('./config')
|
||||||
|
const pu = require('../plugin-helper')
|
||||||
|
|
||||||
const accountRoot = options.pluginPath
|
const schemas = pu.loadSchemas()
|
||||||
const schemas = {}
|
|
||||||
|
|
||||||
function fetchSchemas () {
|
|
||||||
const files = fs.readdirSync(accountRoot)
|
|
||||||
|
|
||||||
files.forEach(file => {
|
|
||||||
if (file.indexOf('lamassu-') !== 0) return
|
|
||||||
|
|
||||||
try {
|
|
||||||
const schema = JSON.parse(fs.readFileSync(path.resolve(accountRoot, file, 'schema.json')))
|
|
||||||
schemas[schema.code] = schema
|
|
||||||
} catch (_) {
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchAccounts () {
|
function fetchAccounts () {
|
||||||
return db.oneOrNone('select data from user_config where type=$1', ['accounts'])
|
return db.oneOrNone('select data from user_config where type=$1', ['accounts'])
|
||||||
|
|
@ -121,8 +104,6 @@ function updateAccount (account) {
|
||||||
.then(() => getAccount(account.code))
|
.then(() => getAccount(account.code))
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchSchemas()
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
selectedAccounts,
|
selectedAccounts,
|
||||||
getAccount,
|
getAccount,
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,10 @@ function sendNoAlerts (plugins) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkNotification (plugins) {
|
function checkNotification (plugins) {
|
||||||
|
console.log('DEBUG444')
|
||||||
return checkStatus(plugins)
|
return checkStatus(plugins)
|
||||||
.then(alertRec => {
|
.then(alertRec => {
|
||||||
|
console.log('DEBUG445: %j', alertRec)
|
||||||
const currentAlertFingerprint = buildAlertFingerprint(alertRec)
|
const currentAlertFingerprint = buildAlertFingerprint(alertRec)
|
||||||
if (!currentAlertFingerprint) {
|
if (!currentAlertFingerprint) {
|
||||||
const inAlert = !!alertFingerprint
|
const inAlert = !!alertFingerprint
|
||||||
|
|
@ -67,6 +69,7 @@ function checkNotification (plugins) {
|
||||||
alertFingerprint = currentAlertFingerprint
|
alertFingerprint = currentAlertFingerprint
|
||||||
lastAlertTime = Date.now()
|
lastAlertTime = Date.now()
|
||||||
|
|
||||||
|
console.log('DEBUG446: %j', rec)
|
||||||
return plugins.sendMessage(rec)
|
return plugins.sendMessage(rec)
|
||||||
})
|
})
|
||||||
.then(results => {
|
.then(results => {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
|
const path = require('path')
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
|
|
||||||
module.exports = {
|
const pluginCodes = {
|
||||||
load,
|
|
||||||
TICKER: 'ticker',
|
TICKER: 'ticker',
|
||||||
EXCHANGE: 'exchange',
|
EXCHANGE: 'exchange',
|
||||||
WALLET: 'wallet',
|
WALLET: 'wallet',
|
||||||
|
|
@ -9,9 +11,10 @@ module.exports = {
|
||||||
EMAIL: 'email'
|
EMAIL: 'email'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = _.assign({load, loadSchemas}, pluginCodes)
|
||||||
|
|
||||||
function load (type, pluginCode) {
|
function load (type, pluginCode) {
|
||||||
const me = module.exports
|
if (!_.includes(type, _.values(pluginCodes))) {
|
||||||
if (!_.includes(type, [me.TICKER, me.EXCHANGE, me.WALLET, me.SMS, me.EMAIL])) {
|
|
||||||
throw new Error(`Unallowed plugin type: ${type}`)
|
throw new Error(`Unallowed plugin type: ${type}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,3 +24,11 @@ function load (type, pluginCode) {
|
||||||
|
|
||||||
return require(`./plugins/${type}/${pluginCode}/${pluginCode}`)
|
return require(`./plugins/${type}/${pluginCode}/${pluginCode}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadSchemas () {
|
||||||
|
const schemasRoot = path.resolve(__dirname, '..', 'schemas')
|
||||||
|
const schemaFiles = fs.readdirSync(schemasRoot)
|
||||||
|
const stripJson = fileName => fileName.slice(0, -5)
|
||||||
|
const readSchema = fileName => JSON.parse(fs.readFileSync(path.resolve(schemasRoot, fileName)))
|
||||||
|
return _.zipObject(_.map(stripJson, schemaFiles), _.map(readSchema, schemaFiles))
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,17 @@ function sendMessage (account, rec) {
|
||||||
const body = rec.sms.body
|
const body = rec.sms.body
|
||||||
const _toNumber = rec.sms.toNumber || account.toNumber
|
const _toNumber = rec.sms.toNumber || account.toNumber
|
||||||
|
|
||||||
return client.sendMessage({
|
const opts = {
|
||||||
body: body,
|
body: body,
|
||||||
to: _toNumber,
|
to: _toNumber,
|
||||||
from: account.fromNumber
|
from: account.fromNumber
|
||||||
})
|
}
|
||||||
|
|
||||||
|
console.log('DEBUG111: %j', opts)
|
||||||
|
|
||||||
|
return client.sendMessage(opts)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
console.log('DEBUG113: %s', err)
|
||||||
if (_.includes(err.code, BAD_NUMBER_CODES)) {
|
if (_.includes(err.code, BAD_NUMBER_CODES)) {
|
||||||
const badNumberError = new Error(err.message)
|
const badNumberError = new Error(err.message)
|
||||||
badNumberError.name = 'BadNumberError'
|
badNumberError.name = 'BadNumberError'
|
||||||
|
|
@ -25,6 +30,7 @@ function sendMessage (account, rec) {
|
||||||
|
|
||||||
throw new Error(err.message)
|
throw new Error(err.message)
|
||||||
})
|
})
|
||||||
|
.then(_.tap(() => console.log('DEBUG112')))
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
const BitGo = require('bitgo')
|
const BitGo = require('bitgo')
|
||||||
const BN = require('../../../bn')
|
const BN = require('../../../bn')
|
||||||
|
|
||||||
const pjson = require('../../../package.json')
|
const pjson = require('../../../../package.json')
|
||||||
const userAgent = 'Lamassu-Server/' + pjson.version
|
const userAgent = 'Lamassu-Server/' + pjson.version
|
||||||
|
|
||||||
const NAME = 'BitGo'
|
const NAME = 'BitGo'
|
||||||
|
|
@ -51,8 +51,8 @@ function balance (account, cryptoCode) {
|
||||||
.then(wallet => BN(wallet.wallet.spendableConfirmedBalance))
|
.then(wallet => BN(wallet.wallet.spendableConfirmedBalance))
|
||||||
}
|
}
|
||||||
|
|
||||||
function newAddress (account, cryptoCode, info) {
|
function newAddress (account, info) {
|
||||||
return checkCryptoCode(cryptoCode)
|
return checkCryptoCode(info.cryptoCode)
|
||||||
.then(() => getWallet(account))
|
.then(() => getWallet(account))
|
||||||
.then(wallet => {
|
.then(wallet => {
|
||||||
return wallet.createAddress()
|
return wallet.createAddress()
|
||||||
|
|
|
||||||
|
|
@ -13,33 +13,37 @@ const PONG_INTERVAL = 10 * T.seconds
|
||||||
const PONG_CLEAR_INTERVAL = 1 * T.day
|
const PONG_CLEAR_INTERVAL = 1 * T.day
|
||||||
const CHECK_NOTIFICATION_INTERVAL = 30 * T.seconds
|
const CHECK_NOTIFICATION_INTERVAL = 30 * T.seconds
|
||||||
|
|
||||||
let pi
|
let _pi, _settings
|
||||||
|
|
||||||
function reload (settings) {
|
function reload (__settings) {
|
||||||
pi = plugins(settings)
|
_settings = __settings
|
||||||
|
_pi = plugins(_settings)
|
||||||
logger.debug('settings reloaded in poller')
|
logger.debug('settings reloaded in poller')
|
||||||
}
|
}
|
||||||
|
|
||||||
function start (settings) {
|
function pi () { return _pi }
|
||||||
reload(settings)
|
function settings () { return _settings }
|
||||||
|
|
||||||
pi.executeTrades()
|
function start (__settings) {
|
||||||
pi.pong()
|
reload(__settings)
|
||||||
pi.pongClear()
|
|
||||||
cashOutTx.monitorLiveIncoming(settings)
|
|
||||||
cashOutTx.monitorStaleIncoming(settings)
|
|
||||||
cashOutTx.monitorUnnotified(settings)
|
|
||||||
pi.sweepHd()
|
|
||||||
notifier.checkNotification(pi)
|
|
||||||
|
|
||||||
setInterval(() => pi.executeTrades(), TRADE_INTERVAL)
|
pi().executeTrades()
|
||||||
setInterval(() => cashOutTx.monitorLiveIncoming(settings), LIVE_INCOMING_TX_INTERVAL)
|
pi().pong()
|
||||||
setInterval(() => cashOutTx.monitorStaleIncoming(settings), INCOMING_TX_INTERVAL)
|
pi().pongClear()
|
||||||
setInterval(() => cashOutTx.monitorUnnotified(settings), UNNOTIFIED_INTERVAL)
|
cashOutTx.monitorLiveIncoming(settings())
|
||||||
setInterval(() => pi.sweepHd(), SWEEP_HD_INTERVAL)
|
cashOutTx.monitorStaleIncoming(settings())
|
||||||
setInterval(() => pi.pong(), PONG_INTERVAL)
|
cashOutTx.monitorUnnotified(settings())
|
||||||
setInterval(() => pi.pongClear(), PONG_CLEAR_INTERVAL)
|
pi().sweepHd()
|
||||||
setInterval(() => notifier.checkNotification(pi), CHECK_NOTIFICATION_INTERVAL)
|
notifier.checkNotification(pi())
|
||||||
|
|
||||||
|
setInterval(() => pi().executeTrades(), TRADE_INTERVAL)
|
||||||
|
setInterval(() => cashOutTx.monitorLiveIncoming(settings()), LIVE_INCOMING_TX_INTERVAL)
|
||||||
|
setInterval(() => cashOutTx.monitorStaleIncoming(settings()), INCOMING_TX_INTERVAL)
|
||||||
|
setInterval(() => cashOutTx.monitorUnnotified(settings()), UNNOTIFIED_INTERVAL)
|
||||||
|
setInterval(() => pi().sweepHd(), SWEEP_HD_INTERVAL)
|
||||||
|
setInterval(() => pi().pong(), PONG_INTERVAL)
|
||||||
|
setInterval(() => pi().pongClear(), PONG_CLEAR_INTERVAL)
|
||||||
|
setInterval(() => notifier.checkNotification(pi()), CHECK_NOTIFICATION_INTERVAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {start, reload}
|
module.exports = {start, reload}
|
||||||
|
|
|
||||||
|
|
@ -304,10 +304,14 @@ function populateDeviceId (req, res, next) {
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let oldVersionId = 'initial'
|
||||||
|
|
||||||
function populateSettings (req, res, next) {
|
function populateSettings (req, res, next) {
|
||||||
const versionId = req.headers['config-version']
|
const versionId = req.headers['config-version']
|
||||||
|
if (versionId !== oldVersionId) {
|
||||||
console.log('DEBUG300: %s', versionId)
|
console.log('DEBUG611: %s', versionId)
|
||||||
|
oldVersionId = versionId
|
||||||
|
}
|
||||||
|
|
||||||
if (!versionId) {
|
if (!versionId) {
|
||||||
return settingsLoader.loadLatest()
|
return settingsLoader.loadLatest()
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ function fetchWallet (settings, cryptoCode) {
|
||||||
.then(hex => {
|
.then(hex => {
|
||||||
const masterSeed = Buffer.from(hex.trim(), 'hex')
|
const masterSeed = Buffer.from(hex.trim(), 'hex')
|
||||||
const plugin = configManager.cryptoScoped(cryptoCode, settings.config).wallet
|
const plugin = configManager.cryptoScoped(cryptoCode, settings.config).wallet
|
||||||
|
console.log('DEBUG555: %s', plugin)
|
||||||
const wallet = ph.load(ph.WALLET, plugin)
|
const wallet = ph.load(ph.WALLET, plugin)
|
||||||
const account = settings.accounts[plugin]
|
const account = settings.accounts[plugin]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
"bignumber.js": "^4.0.1",
|
"bignumber.js": "^4.0.1",
|
||||||
"bip39": "^2.3.0",
|
"bip39": "^2.3.0",
|
||||||
"bitcoind-rpc": "^0.7.0",
|
"bitcoind-rpc": "^0.7.0",
|
||||||
|
"bitgo": "^2.2.4",
|
||||||
"body-parser": "^1.15.1",
|
"body-parser": "^1.15.1",
|
||||||
"cookie-parser": "^1.4.3",
|
"cookie-parser": "^1.4.3",
|
||||||
"express": "^4.13.4",
|
"express": "^4.13.4",
|
||||||
|
|
@ -36,6 +37,7 @@
|
||||||
"serve-static": "^1.11.1",
|
"serve-static": "^1.11.1",
|
||||||
"socket.io": "^1.7.1",
|
"socket.io": "^1.7.1",
|
||||||
"socket.io-client": "^1.7.1",
|
"socket.io-client": "^1.7.1",
|
||||||
|
"twilio": "^2.11.1",
|
||||||
"uuid": "^3.0.0",
|
"uuid": "^3.0.0",
|
||||||
"winston": "^2.3.0"
|
"winston": "^2.3.0"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue