From d3b7e7c2adcc6a1e65b39aaef07cc40071434791 Mon Sep 17 00:00:00 2001 From: Josh Harvey Date: Fri, 4 May 2018 19:06:31 +0300 Subject: [PATCH] periodically update sanctions db --- lib/ofac/index.js | 2 -- lib/ofac/update.js | 12 ------------ lib/poller.js | 12 ++++++++++++ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/ofac/index.js b/lib/ofac/index.js index f2c1ead6..881ecdd8 100644 --- a/lib/ofac/index.js +++ b/lib/ofac/index.js @@ -14,8 +14,6 @@ let structs = null const readdir = util.promisify(fs.readdir) function load () { - // NOTE: Not sure how you push code updates to existing clients. This problem - // might pop up if new code is pushed, without re-doing setup. if (!options.ofacDataDir) { const message = 'The ofacDataDir option has not been set in lamassu.json' return Promise.reject(new Error(message)) diff --git a/lib/ofac/update.js b/lib/ofac/update.js index b812a4bf..b6de2eac 100644 --- a/lib/ofac/update.js +++ b/lib/ofac/update.js @@ -25,7 +25,6 @@ const rename = util.promisify(fs.rename) const unlink = util.promisify(fs.unlink) const remove = file => { - console.log('remove', file) return unlink(file) } @@ -51,7 +50,6 @@ const promiseGetEtag = (source) => { } const download = _.curry((dstDir, source) => { - console.log('download', source) const {name, url: sourceUrl} = source const dstFile = path.join(dstDir, name + '.xml') const file = fs.createWriteStream(dstFile) @@ -67,15 +65,11 @@ const download = _.curry((dstDir, source) => { }) const parseToJson = srcFile => { - console.log('parseToJson', srcFile) - const dstFile = srcFile.replace(/\.xml$/, '.json') const writeStream = fs.createWriteStream(dstFile) return new Promise((resolve, reject) => { parser.parse(srcFile, (err, profile) => { - console.log('callback', err, profile) - if (err) { reject(err) return @@ -96,7 +90,6 @@ const parseToJson = srcFile => { } const moveToSourcesDir = (srcFile, ofacSourcesDir) => { - console.log('moveToSourcesDir', srcFile) const name = path.basename(srcFile) const dstFile = path.join(ofacSourcesDir, name) return rename(srcFile, dstFile) @@ -133,9 +126,6 @@ function update () { return Promise.all([promiseOldEtags, promiseNewEtags]) .then(([oldEtags, newEtags]) => { - console.log('OLD', JSON.stringify(oldEtags, null, 4)) - console.log('NEW', JSON.stringify(newEtags, null, 4)) - const hasNotChanged = ({name, etag}) => oldEtags[name] === etag const downloads = _.flow( @@ -157,8 +147,6 @@ function update () { return Promise.all(downloads) .then(parsed => { - console.log('finished', parsed) - const moves = _.map(src => moveToSourcesDir(src, OFAC_SOURCES_DIR), parsed) const deletions = _.map(remove, missing) const updateEtags = writeFile(OFAC_ETAGS_FILE, etagsJson) diff --git a/lib/poller.js b/lib/poller.js index af0f9829..a3cbb783 100644 --- a/lib/poller.js +++ b/lib/poller.js @@ -4,6 +4,8 @@ const T = require('./time') const logger = require('./logger') const cashOutTx = require('./cash-out/cash-out-tx') const cashInTx = require('./cash-in/cash-in-tx') +const sanctionsUpdater = require('./ofac/update') +const sanctions = require('./ofac/index') const INCOMING_TX_INTERVAL = 30 * T.seconds const LIVE_INCOMING_TX_INTERVAL = 5 * T.seconds @@ -12,6 +14,7 @@ const SWEEP_HD_INTERVAL = T.minute const TRADE_INTERVAL = 60 * T.seconds const PONG_INTERVAL = 10 * T.seconds const PONG_CLEAR_INTERVAL = 1 * T.day +const SANCTIONS_UPDATE_INTERVAL = 1 * T.week const CHECK_NOTIFICATION_INTERVAL = 20 * T.seconds @@ -28,6 +31,13 @@ function reload (__settings) { function pi () { return _pi } function settings () { return _settings } +function updateAndLoadSanctions () { + logger.info('Updating sanctions database...') + return sanctionsUpdater.update() + .then(sanctions.load) + .then(() => logger.info('Sanctions database updated.')) +} + function start (__settings) { reload(__settings) @@ -39,6 +49,7 @@ function start (__settings) { cashOutTx.monitorUnnotified(settings()) pi().sweepHd() notifier.checkNotification(pi()) + updateAndLoadSanctions() setInterval(() => pi().executeTrades(), TRADE_INTERVAL) setInterval(() => cashOutTx.monitorLiveIncoming(settings()), LIVE_INCOMING_TX_INTERVAL) @@ -49,6 +60,7 @@ function start (__settings) { setInterval(() => pi().pong(), PONG_INTERVAL) setInterval(() => pi().pongClear(), PONG_CLEAR_INTERVAL) setInterval(() => notifier.checkNotification(pi()), CHECK_NOTIFICATION_INTERVAL) + setInterval(updateAndLoadSanctions, SANCTIONS_UPDATE_INTERVAL) } module.exports = {start, reload}