periodically update sanctions db
This commit is contained in:
parent
43ac3f5923
commit
d3b7e7c2ad
3 changed files with 12 additions and 14 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue