Skip to content

Commit

Permalink
Merge pull request #149 from samparsky/whitelist-adapter
Browse files Browse the repository at this point in the history
Whitelist adapter
  • Loading branch information
Ivo Georgiev authored May 16, 2019
2 parents 25ef5f2 + 2e6e04d commit cd598ba
Show file tree
Hide file tree
Showing 17 changed files with 205 additions and 1,742 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ EXPOSE ${PORT}

ADD . .

RUN npm install --production && npm install -g pm2
RUN npm install --production

CMD PORT=${PORT} pm2-docker start bin/sentry.js -- --adapter=${ADAPTER} --keystoreFile=${KEYSTORE_FILE} && \
pm2 start -x bin/validatorWorker.js -- --adapter=${ADAPTER} --keystoreFile=${KEYSTORE_FILE} --keystorePwd=${KEYSTORE_PASSWORD} --sentryUrl=http://127.0.0.1:${PORT}
CMD PORT=${PORT} node bin/sentry.js --adapter=${ADAPTER} --keystoreFile=${KEYSTORE_FILE} && \
node bin/validatorWorker.js --adapter=${ADAPTER} --keystoreFile=${KEYSTORE_FILE} --keystorePwd=${KEYSTORE_PASSWORD} --sentryUrl=http://127.0.0.1:${PORT}

6 changes: 6 additions & 0 deletions adapters/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ async function isChannelValid(cfg, channel, address) {
'channel.creator is not whitelisted'
)
}
if (cfg.TOKEN_ADDRESS_WHITELIST && cfg.TOKEN_ADDRESS_WHITELIST.length) {
assert.ok(
cfg.TOKEN_ADDRESS_WHITELIST.includes(channel.depositAsset.toLowerCase()),
'channel.depositAsset is not whitelisted'
)
}
assert.ok(
new BN(channel.depositAmount).gte(new BN(cfg.MINIMAL_DEPOSIT || 0)),
'channel.depositAmount is less than MINIMAL_DEPOSIT'
Expand Down
36 changes: 24 additions & 12 deletions bin/sentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const adapters = require('../adapters')
const authMiddleware = require('../middlewares/auth')
const channelRoutes = require('../routes/channel')
const channelCreate = require('../routes/channelCreate')
const logger = require('../services/lib')('sentry')
const logger = require('../services/logger')('sentry')
const createCluster = require('../services/cluster')

const { argv } = yargs
.usage('Usage $0 [options]')
Expand All @@ -19,6 +20,8 @@ const { argv } = yargs
.default('adapter', 'ethereum')
.describe('keystoreFile', 'path to JSON Ethereum keystore file')
.describe('dummyIdentity', 'the identity to use with the dummy adapter')
.boolean('clustered')
.describe('clustered', 'run app in cluster mode with multiple workers')
.demandOption(['adapter'])

const adapter = new adapters[argv.adapter].Adapter(argv, cfg)
Expand All @@ -33,14 +36,23 @@ app.use('/channel', channelCreate.forAdapter(adapter))
app.use('/cfg', (_, res) => res.send(cfg))
app.use(errors())

db.connect()
.then(function() {
return adapter.init()
})
.then(function() {
app.listen(port, () => logger.info(`Sentry listening on port ${port}!`))
})
.catch(function(err) {
logger.error(err)
process.exit(1)
})
if (argv.clustered) {
createCluster(run)
} else {
// dont run in cluster mode
run()
}

function run() {
db.connect()
.then(function() {
return adapter.init()
})
.then(function() {
app.listen(port, () => logger.info(`Sentry listening on port ${port}!`))
})
.catch(function(err) {
logger.error(err)
process.exit(1)
})
}
2 changes: 1 addition & 1 deletion bin/validatorWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const adapters = require('../adapters')
const leader = require('../services/validatorWorker/leader')
const follower = require('../services/validatorWorker/follower')
const SentryInterface = require('../services/validatorWorker/lib/sentryInterface')
const logger = require('../services/lib')('validatorWorker')
const logger = require('../services/logger')('validatorWorker')

const { argv } = yargs
.usage('Usage $0 [options]')
Expand Down
Loading

0 comments on commit cd598ba

Please sign in to comment.