Skip to content

Commit

Permalink
Merge pull request #53 from Adamant-im/update-dependencies
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
martiliones authored Oct 10, 2022
2 parents 0e3866d + 0889651 commit cdea8af
Show file tree
Hide file tree
Showing 74 changed files with 6,601 additions and 353 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module.exports = function (grunt) {

eslint: {
options: {
configFile: '.eslintrc.json',
overrideConfigFile: '.eslintrc.json',
format: 'codeframe',
fix: false
},
Expand Down
38 changes: 23 additions & 15 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,26 @@ program
.option('-s, --snapshot <round>', 'verify snapshot')
.parse(process.argv);

var programOpts = program.opts();

/**
* @property {object} - The default list of configuration options. Can be updated by CLI.
* @default 'config.json'
*/
var appConfig = require('./helpers/config.js')(program.config);
var genesisblock = require(path.resolve(process.cwd(), (program.genesis || 'genesisBlock.json')));
var appConfig = require('./helpers/config.js')(programOpts.config);
var genesisblock = require(path.resolve(process.cwd(), (programOpts.genesis || 'genesisBlock.json')));

if (program.port) {
appConfig.port = program.port;
if (programOpts.port) {
appConfig.port = programOpts.port;
}

if (program.address) {
appConfig.address = program.address;
if (programOpts.address) {
appConfig.address = programOpts.address;
}

if (program.peers) {
if (typeof program.peers === 'string') {
appConfig.peers.list = program.peers.split(',').map(function (peer) {
if (programOpts.peers) {
if (typeof programOpts.peers === 'string') {
appConfig.peers.list = programOpts.peers.split(',').map(function (peer) {
peer = peer.split(':');
return {
ip: peer.shift(),
Expand All @@ -94,13 +96,13 @@ if (program.peers) {
}
}

if (program.log) {
appConfig.consoleLogLevel = program.log;
if (programOpts.log) {
appConfig.consoleLogLevel = programOpts.log;
}

if (program.snapshot) {
if (programOpts.snapshot) {
appConfig.loading.snapshot = Math.abs(
Math.floor(program.snapshot)
Math.floor(programOpts.snapshot)
);
}

Expand Down Expand Up @@ -309,7 +311,11 @@ d.run(function () {
app.options('*', cors());

var server = require('http').createServer(app);
var io = require('socket.io')(server);

const { Server } = require('socket.io');
const io = new Server(server, {
allowEIO3: true
});

var privateKey, certificate, https, https_io;

Expand All @@ -323,7 +329,9 @@ d.run(function () {
ciphers: 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:' + 'ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:' + '!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA'
}, app);

https_io = require('socket.io')(https);
https_io = new Server(https, {
allowEIO3: true
});
}

cb(null, {
Expand Down
8 changes: 3 additions & 5 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
]
},
"redis": {
"host": "127.0.0.1",
"port": 6379,
"db": 0,
"url": "redis://127.0.0.1:6379/0",
"password": null
},
"api": {
Expand Down Expand Up @@ -100,8 +98,8 @@
"options": {
"port": 443,
"address": "0.0.0.0",
"key": "./ssl/lisk.key",
"cert": "./ssl/lisk.crt"
"key": "./ssl/adamant.key",
"cert": "./ssl/adamant.crt"
}
},
"dapp": {
Expand Down
15 changes: 10 additions & 5 deletions helpers/RoundChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ function RoundChanges (scope) {
if (exceptions.rounds[scope.round]) {
// Apply rewards factor
this.roundRewards.forEach(function (reward, index) {
this.roundRewards[index] = new bignum(reward.toPrecision(15)).times(exceptions.rounds[scope.round].rewards_factor).floor();
this.roundRewards[index] = new bignum(reward.toPrecision(15))
.times(exceptions.rounds[scope.round].rewards_factor)
.integerValue(bignum.ROUND_FLOOR);
}.bind(this));

// Apply fees factor and bonus
this.roundFees = new bignum(this.roundFees.toPrecision(15)).times(exceptions.rounds[scope.round].fees_factor).plus(exceptions.rounds[scope.round].fees_bonus).floor();
this.roundFees = new bignum(this.roundFees.toPrecision(15))
.times(exceptions.rounds[scope.round].fees_factor)
.plus(exceptions.rounds[scope.round].fees_bonus)
.integerValue(bignum.ROUND_FLOOR);
}
}

Expand All @@ -39,15 +44,15 @@ function RoundChanges (scope) {
* @return {Object} Contains fees, feesRemaining, rewards, balance
*/
RoundChanges.prototype.at = function (index) {
var fees = new bignum(this.roundFees.toPrecision(15)).dividedBy(slots.delegates).floor();
var fees = new bignum(this.roundFees.toPrecision(15)).dividedBy(slots.delegates).integerValue(bignum.ROUND_FLOOR);
var feesRemaining = new bignum(this.roundFees.toPrecision(15)).minus(fees.times(slots.delegates));
var rewards = new bignum(this.roundRewards[index].toPrecision(15)).floor() || 0;
var rewards = new bignum(this.roundRewards[index].toPrecision(15)).integerValue(bignum.ROUND_FLOOR) || 0;

return {
fees: Number(fees.toFixed()),
feesRemaining: Number(feesRemaining.toFixed()),
rewards: Number(rewards.toFixed()),
balance: Number(fees.add(rewards).toFixed())
balance: Number(fees.plus(rewards).toFixed())
};
};

Expand Down
34 changes: 18 additions & 16 deletions helpers/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ module.exports.connect = function (cacheEnabled, config, logger, cb) {
if (config.password === null) {
delete config.password;
}
var client = redis.createClient(config);

client.on('ready', function () {
logger.info('App connected with redis server');
var client = redis.createClient(config);

if (!isRedisLoaded) {
isRedisLoaded = true;
return cb(null, { cacheEnabled: cacheEnabled, client: client });
}
});
client.connect()
.then(() => {
logger.info('App connected with redis server');

client.on('error', function (err) {
logger.error('Redis:', err);
// Only throw an error if cache was enabled in config but were unable to load it properly
if (!isRedisLoaded) {
isRedisLoaded = true;
return cb(null, { cacheEnabled: cacheEnabled, client: null });
}
});
if (!isRedisLoaded) {
isRedisLoaded = true;
client.ready = isRedisLoaded;
return cb(null, { cacheEnabled: cacheEnabled, client: client });
}
})
.catch((err) => {
logger.error('Redis:', err);
// Only throw an error if cache was enabled in config but were unable to load it properly
if (!isRedisLoaded) {
isRedisLoaded = true;
return cb(null, { cacheEnabled: cacheEnabled, client: null });
}
});
};
6 changes: 3 additions & 3 deletions helpers/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function Migrator (pgp, db) {
(file.id && file.name) && fs.statSync(file.path).isFile() && /\.sql$/.test(file.path)
);
}).forEach(function (file) {
if (!lastMigration || file.id.greaterThan(lastMigration.id)) {
if (!lastMigration || file.id.isGreaterThan(lastMigration.id)) {
pendingMigrations.push(file);
}
});
Expand Down Expand Up @@ -190,10 +190,10 @@ module.exports.connect = function (config, logger, cb) {
monitor.attach(pgOptions, config.logEvents);
monitor.setTheme('matrix');

monitor.log = function (msg, info) {
monitor.setLog(function (msg, info) {
logger.log(info.event, info.text);
info.display = false;
};
});

config.user = config.user || process.env.USER;

Expand Down
4 changes: 2 additions & 2 deletions helpers/inserts.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ function Inserts (record, values, concat) {
return pgp.as.format('INSERT INTO $1~($2^) VALUES $3^', [record.table, fields, values]);
};

this._rawDBType = true;
this.rawType = true;

this.formatDBType = function () {
this.toPostgres = function () {
return values.map(function (v) {
return '(' + pgp.as.format(self._template, v) + ')';
}).join(',');
Expand Down
7 changes: 4 additions & 3 deletions helpers/request-limiter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var RateLimit = require('express-rate-limit');
var rateLimit = require('express-rate-limit');
var slowDown = require('express-slow-down');

var defaults = {
max: 0, // Disabled
Expand Down Expand Up @@ -54,8 +55,8 @@ module.exports = function (app, config) {
};

limits.middleware = {
client: app.use('/api/', new RateLimit(limits.client)),
peer: app.use('/peer/', new RateLimit(limits.peer))
client: app.use('/api/', rateLimit(limits.client), slowDown(limits.client)),
peer: app.use('/peer/', rateLimit(limits.peer), slowDown(limits.peer))
};

return limits;
Expand Down
1 change: 1 addition & 0 deletions legacy/json-sql/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
19 changes: 19 additions & 0 deletions legacy/json-sql/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"node": true,
"freeze": true,
"maxlen": 100,
"smarttabs": true,
"indent": 1,
"quotmark": "single",
"strict": true,
"globalstrict": true,
// use es3 to get 'extra comma' at object literal error
"es3": true,
"undef": true,
"unused": true,
"immed": true,
"eqeqeq": true,
"globals": {
"JSON": false
}
}
2 changes: 2 additions & 0 deletions legacy/json-sql/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.npmignore
test
22 changes: 22 additions & 0 deletions legacy/json-sql/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2013-2014 Oleg Korobenko <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Loading

0 comments on commit cdea8af

Please sign in to comment.