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