From 73aa26c1e6b3d486b402915594479bb4ff8683e1 Mon Sep 17 00:00:00 2001 From: cgeek <cem.moreau@gmail.com> Date: Sun, 15 Jan 2017 13:14:50 +0100 Subject: [PATCH] [enh] ESLint cleaning --- .eslintrc | 2 +- app/cli.js | 59 +++++++++++------------- app/controllers/blockchain.js | 1 - app/controllers/network.js | 1 - app/controllers/transactions.js | 26 +++++------ app/controllers/uds.js | 1 - app/controllers/wot.js | 2 +- app/lib/cfs.js | 3 +- app/lib/computation/blockGenerator.js | 5 +- app/lib/computation/blockProver.js | 9 +--- app/lib/computation/blockchainContext.js | 8 +--- app/lib/computation/permanentProver.js | 4 +- app/lib/crypto/base58.js | 2 +- app/lib/dal/drivers/sqlite.js | 12 ++--- app/lib/dal/fileDAL.js | 45 ++++++++---------- app/lib/dal/sqliteDAL/AbstractIndex.js | 2 +- app/lib/dal/sqliteDAL/AbstractSQLite.js | 2 +- app/lib/dal/sqliteDAL/CertDAL.js | 2 +- app/lib/dal/sqliteDAL/IdentityDAL.js | 2 - app/lib/dal/sqliteDAL/MembershipDAL.js | 1 - app/lib/dal/sqliteDAL/MetaDAL.js | 1 - app/lib/dal/sqliteDAL/SandBox.js | 6 +-- app/lib/dal/sqliteDAL/index/BIndexDAL.js | 1 - app/lib/dal/sqliteDAL/index/SIndexDAL.js | 4 +- app/lib/dup/indexer.js | 10 ++-- app/lib/entity/block.js | 33 +++++++------ app/lib/entity/certification.js | 2 +- app/lib/entity/peer.js | 3 +- app/lib/entity/revocation.js | 3 +- app/lib/entity/source.js | 2 +- app/lib/entity/stat.js | 2 +- app/lib/entity/transaction.js | 3 +- app/lib/logger/index.js | 1 - app/lib/pow/engine.js | 2 +- app/lib/rules/global_rules.js | 2 - app/lib/rules/index.js | 2 +- app/lib/rules/local_rules.js | 8 ++-- app/lib/streams/jsoner.js | 2 +- app/lib/streams/parsers/GenericParser.js | 2 +- app/lib/streams/parsers/block.js | 2 +- app/lib/streams/parsers/certification.js | 2 - app/lib/streams/parsers/identity.js | 1 - app/lib/streams/parsers/revocation.js | 2 - app/lib/streams/parsers/transaction.js | 2 +- app/lib/streams/router.js | 1 - app/lib/streams/routes.js | 1 - app/lib/sync.js | 12 ++--- app/lib/system/limiter.js | 2 +- app/lib/system/upnp.js | 2 +- app/lib/wizard.js | 3 +- app/lib/wot.js | 2 +- app/modules/config.js | 2 +- app/modules/gen.js | 2 +- app/modules/synchronization.js | 2 +- app/service/BlockchainService.js | 7 +-- app/service/PeeringService.js | 2 +- test/dal/triming.js | 12 ++--- test/eslint.js | 6 +-- test/fast/javascript_test.js | 37 --------------- test/integration/proof-of-work.js | 14 ------ 60 files changed, 143 insertions(+), 251 deletions(-) delete mode 100644 test/fast/javascript_test.js diff --git a/.eslintrc b/.eslintrc index 5c8edccf2..9bab7d318 100644 --- a/.eslintrc +++ b/.eslintrc @@ -22,6 +22,7 @@ "no-trailing-spaces": 0, "no-unused-expressions": 0, "comma-spacing": 0, + "semi": 0, "quotes": [0, "double"], "linebreak-style": [1,"unix"], @@ -37,7 +38,6 @@ "no-unused-vars": [1], "space-infix-ops": [1], "handle-callback-err": [1], - "semi": [1,"always"], "no-extra-semi": [1] }, "env": { diff --git a/app/cli.js b/app/cli.js index 1ccaaded7..885ea4134 100644 --- a/app/cli.js +++ b/app/cli.js @@ -2,7 +2,6 @@ const co = require('co'); const logger = require('../app/lib/logger')('cli'); -const async = require('async'); const Q = require('q'); const _ = require('underscore'); const Command = require('commander').Command; @@ -10,7 +9,6 @@ const contacter = require('../app/lib/contacter'); const directory = require('../app/lib/system/directory'); const wizard = require('../app/lib/wizard'); const multicaster = require('../app/lib/streams/multicaster'); -const keyring = require('../app/lib/crypto/keyring'); const pjson = require('../package.json'); const duniter = require('../index'); const Peer = require('../app/lib/entity/peer'); @@ -94,8 +92,8 @@ module.exports = () => { const args = Array.from(arguments); return co(function*() { try { - const res = yield cmd.executionCallback.apply(null, [program].concat(args)); - onResolve(res); + const resOfExecution = yield cmd.executionCallback.apply(null, [program].concat(args)); + onResolve(resOfExecution); } catch (e) { onReject(e); } @@ -275,7 +273,7 @@ module.exports = () => { .command('reset [config|data|peers|tx|stats|all]') .description('Reset configuration, data, peers, transactions or everything in the database') .action(subCommand((type) => { - let init = ['data', 'all'].indexOf(type) !== -1 ? server.bind(server, program) : connect; + let init = ['data', 'all'].indexOf(type) !== -1 ? getServer.bind(getServer, program) : connect; return init(function (server) { if (!~['config', 'data', 'peers', 'stats', 'all'].indexOf(type)) { throw constants.ERRORS.CLI_CALLERR_RESET; @@ -335,12 +333,12 @@ module.exports = () => { function connect(callback, useDefaultConf) { return function () { - var cbArgs = arguments; - var dbName = program.mdb || "duniter_default"; - var dbHome = program.home; + const cbArgs = arguments; + const dbName = program.mdb || "duniter_default"; + const dbHome = program.home; const home = directory.getHome(dbName, dbHome); - var server = duniter(home, program.memory === true, commandLineConf(program)); + const theServer = duniter(home, program.memory === true, commandLineConf(program)); // If ever the process gets interrupted let isSaving = false; @@ -348,21 +346,21 @@ module.exports = () => { if (!isSaving) { isSaving = true; // Save DB - return server.disconnect(); + return theServer.disconnect(); } }); // Initialize server (db connection, ...) - return server.plugFileSystem(useDefaultConf) - .then(() => server.loadConf()) + return theServer.plugFileSystem(useDefaultConf) + .then(() => theServer.loadConf()) .then(function () { try { cbArgs.length--; - cbArgs[cbArgs.length++] = server; - cbArgs[cbArgs.length++] = server.conf; + cbArgs[cbArgs.length++] = theServer; + cbArgs[cbArgs.length++] = theServer.conf; return callback.apply(this, cbArgs); } catch(e) { - server.disconnect(); + theServer.disconnect(); throw e; } }); @@ -378,15 +376,15 @@ module.exports = () => { require('../app/lib/logger')().mute(); } - var cbArgs = arguments; - var dbName = program.mdb; - var dbHome = program.home; + const cbArgs = arguments; + const dbName = program.mdb; + const dbHome = program.home; // Add log files for this instance logger.addHomeLogs(directory.getHome(dbName, dbHome)); const home = directory.getHome(dbName, dbHome); - var server = duniter(home, program.memory === true, commandLineConf(program)); + const theServer = duniter(home, program.memory === true, commandLineConf(program)); // If ever the process gets interrupted let isSaving = false; @@ -394,7 +392,7 @@ module.exports = () => { if (!isSaving) { isSaving = true; // Save DB - return server.disconnect(); + return theServer.disconnect(); } }); @@ -403,17 +401,17 @@ module.exports = () => { // Initialize server (db connection, ...) return co(function*() { try { - yield server.initWithDAL(); - yield configure(program, server, server.conf || {}); - yield server.loadConf(); + yield theServer.initWithDAL(); + yield configure(program, theServer, theServer.conf || {}); + yield theServer.loadConf(); cbArgs.length--; - cbArgs[cbArgs.length++] = server; - cbArgs[cbArgs.length++] = server.conf; + cbArgs[cbArgs.length++] = theServer; + cbArgs[cbArgs.length++] = theServer.conf; cbArgs[cbArgs.length++] = program; - onService && onService(server); + onService && onService(theServer); return callback.apply(that, cbArgs); } catch (e) { - server.disconnect(); + theServer.disconnect(); throw e; } }); @@ -511,10 +509,9 @@ function commandLineConf(program, conf) { * Super basic server with only its home path set * @param program * @param callback - * @param useDefaultConf * @returns {Function} */ -function server(program, callback, useDefaultConf) { +function getServer(program, callback) { return function () { var cbArgs = arguments; var dbName = program.mdb || "duniter_default"; @@ -536,8 +533,8 @@ function parsePercent(s) { } function needsToBeLaunchedByScript() { - logger.error('This command must not be launched directly, using duniter.sh script'); - return Promise.resolve(); + logger.error('This command must not be launched directly, using duniter.sh script'); + return Promise.resolve(); } function configure(program, server, conf) { diff --git a/app/controllers/blockchain.js b/app/controllers/blockchain.js index e0a3e4a37..b920b8c5c 100644 --- a/app/controllers/blockchain.js +++ b/app/controllers/blockchain.js @@ -2,7 +2,6 @@ const co = require('co'); const _ = require('underscore'); -const rules = require('../lib/rules'); const constants = require('../lib/constants'); const http2raw = require('../lib/helpers/http2raw'); const Membership = require('../lib/entity/membership'); diff --git a/app/controllers/network.js b/app/controllers/network.js index 328e084df..8aaf57fdf 100644 --- a/app/controllers/network.js +++ b/app/controllers/network.js @@ -1,7 +1,6 @@ "use strict"; const _ = require('underscore'); const co = require('co'); -const Q = require('q'); const http2raw = require('../lib/helpers/http2raw'); const constants = require('../lib/constants'); const Peer = require('../lib/entity/peer'); diff --git a/app/controllers/transactions.js b/app/controllers/transactions.js index ed2e19ed0..b942455b6 100644 --- a/app/controllers/transactions.js +++ b/app/controllers/transactions.js @@ -78,7 +78,7 @@ function TransactionBinding(server) { }); }); - this.getPending = (req) => co(function *() { + this.getPending = () => co(function *() { const pending = yield server.dal.getTransactionsPending(); const res = { "currency": conf.currency, @@ -91,19 +91,19 @@ function TransactionBinding(server) { }); const getFilteredHistory = (pubkey, filter) => co(function*() { - let history = yield server.dal.getTransactionsHistory(pubkey); - let result = { - "currency": conf.currency, - "pubkey": pubkey, - "history": history - }; - _.keys(history).map((key) => { - history[key].map((tx, index) => { - history[key][index] = _.omit(new Transaction(tx).json(), 'currency', 'raw'); - _.extend(history[key][index], {block_number: tx && tx.block_number, time: tx && tx.time}); - }); + let history = yield server.dal.getTransactionsHistory(pubkey); + let result = { + "currency": conf.currency, + "pubkey": pubkey, + "history": history + }; + _.keys(history).map((key) => { + history[key].map((tx, index) => { + history[key][index] = _.omit(new Transaction(tx).json(), 'currency', 'raw'); + _.extend(history[key][index], {block_number: tx && tx.block_number, time: tx && tx.time}); }); - return filter(result); + }); + return filter(result); }); return this; diff --git a/app/controllers/uds.js b/app/controllers/uds.js index 6afeabace..b8c4378ba 100644 --- a/app/controllers/uds.js +++ b/app/controllers/uds.js @@ -1,6 +1,5 @@ "use strict"; const co = require('co'); -const Q = require('q'); const _ = require('underscore'); module.exports = function (server) { diff --git a/app/controllers/wot.js b/app/controllers/wot.js index fb8979a7a..6a7d653cd 100644 --- a/app/controllers/wot.js +++ b/app/controllers/wot.js @@ -220,7 +220,7 @@ function WOTBinding (server) { this.revoke = (req) => this.pushEntity(req, http2raw.revocation, constants.ENTITY_REVOCATION); - this.pendingMemberships = (req) => co(function*() { + this.pendingMemberships = () => co(function*() { const memberships = yield server.dal.findNewcomers(); const json = { memberships: [] diff --git a/app/lib/cfs.js b/app/lib/cfs.js index a6eab9a60..e1821e79f 100644 --- a/app/lib/cfs.js +++ b/app/lib/cfs.js @@ -1,6 +1,5 @@ "use strict"; -const Q = require('q'); const _ = require('underscore'); const co = require('co'); const path = require('path'); @@ -24,7 +23,7 @@ function CFSCore(rootPath, qfs, parent) { /** * Creates the deletion folder before effective deletion. - * @returns {*|any|Q.Promise<void>} Promise of creation. + * @returns {*|any|Promise<void>} Promise of creation. */ const createDeletionFolder = () => deletionFolderPromise || (deletionFolderPromise = that.makeTree('.deleted')); diff --git a/app/lib/computation/blockGenerator.js b/app/lib/computation/blockGenerator.js index e3194aa1d..7922bd59f 100644 --- a/app/lib/computation/blockGenerator.js +++ b/app/lib/computation/blockGenerator.js @@ -23,12 +23,11 @@ module.exports = (mainContext, prover) => { function BlockGenerator(mainContext, prover) { const that = this; - let conf, dal, keyPair, selfPubkey, logger; + let conf, dal, selfPubkey, logger; this.setConfDAL = (newConf, newDAL, newKeyPair) => { dal = newDAL; conf = newConf; - keyPair = newKeyPair; selfPubkey = newKeyPair.publicKey; logger = require('../logger')(dal.profile); }; @@ -435,7 +434,7 @@ function BlockGenerator(mainContext, prover) { block.medianTime = vHEAD.medianTime; } // Choose the version - block.version = (manualValues && manualValues.version) || (yield rules.HELPERS.getMaxPossibleVersionNumber(current, block)); + block.version = (manualValues && manualValues.version) || (yield rules.HELPERS.getMaxPossibleVersionNumber(current)); block.currency = current ? current.currency : conf.currency; block.nonce = 0; block.parameters = block.number > 0 ? '' : [ diff --git a/app/lib/computation/blockProver.js b/app/lib/computation/blockProver.js index bb66e2e28..96f17ff43 100644 --- a/app/lib/computation/blockProver.js +++ b/app/lib/computation/blockProver.js @@ -3,7 +3,6 @@ const co = require('co'); const _ = require('underscore'); const constants = require('../constants'); const engine = require('../pow/engine'); -const path = require('path'); const Block = require('../entity/block'); const querablep = require('../querablep'); @@ -14,7 +13,7 @@ module.exports = (server) => new BlockGenerator(server); function BlockGenerator(notifier) { - let conf, pair, logger, wait = null, waitResolve; + let conf, pair, logger, waitResolve; let workerFarmPromise; @@ -36,10 +35,6 @@ function BlockGenerator(notifier) { process.execArgv = []; } - this.waitForNewAsking = () => wait = new Promise((resolve) => { - waitResolve = resolve; - }); - this.cancel = (gottenBlock) => co(function*() { // If no farm was instanciated, tehre is nothing to do yet if (workerFarmPromise) { @@ -50,7 +45,6 @@ function BlockGenerator(notifier) { if (waitResolve) { waitResolve(); waitResolve = null; - wait = null; } } }); @@ -60,7 +54,6 @@ function BlockGenerator(notifier) { if (waitResolve) { waitResolve(); waitResolve = null; - wait = null; } const remainder = difficulty % 16; diff --git a/app/lib/computation/blockchainContext.js b/app/lib/computation/blockchainContext.js index dbc66ec86..54d31fb87 100644 --- a/app/lib/computation/blockchainContext.js +++ b/app/lib/computation/blockchainContext.js @@ -3,8 +3,6 @@ const _ = require('underscore'); const co = require('co'); const Q = require('q'); const indexer = require('../dup/indexer'); -const hashf = require('../ucp/hashf'); -const rawer = require('../ucp/rawer'); const constants = require('../constants'); const rules = require('../rules/index'); const Identity = require('../entity/identity'); @@ -263,9 +261,7 @@ function BlockchainContext() { } const block = forks[0]; yield that.checkBlock(block, constants.WITH_SIGNATURES_AND_POW); - const res = yield that.addBlock(block); logger.debug('Applied block #%s', block.number); - // return res; }); this.revertBlock = (block) => co(function *() { @@ -383,7 +379,7 @@ function BlockchainContext() { // Delete eventually present transactions yield that.deleteTransactions(block); - yield dal.trimSandboxes(block, conf); + yield dal.trimSandboxes(block); return block; }); @@ -455,7 +451,7 @@ function BlockchainContext() { dal.wotb.setEnabled(false, idty.wotb_id); } // Undo newcomers - for (const identity of block.identities) { + for (let i = 0; i < block.identities.length; i++) { // Does not matter which one it really was, we pop the last X identities dal.wotb.removeNode(); } diff --git a/app/lib/computation/permanentProver.js b/app/lib/computation/permanentProver.js index 536c51536..d2de48569 100644 --- a/app/lib/computation/permanentProver.js +++ b/app/lib/computation/permanentProver.js @@ -2,8 +2,6 @@ const co = require('co'); const constants = require('../constants'); -const rules = require('../rules'); -const parsers = require('../streams/parsers'); module.exports = (server) => new PermanentProver(server); @@ -49,7 +47,7 @@ function PermanentProver(server) { if (!selfPubkey) { throw 'No self pubkey found.'; } - let block, current; + let current; const isMember = yield dal.isMember(selfPubkey); if (!isMember) { throw 'Local node is not a member. Waiting to be a member before computing a block.'; diff --git a/app/lib/crypto/base58.js b/app/lib/crypto/base58.js index 3b88f9d48..acfeef7d0 100644 --- a/app/lib/crypto/base58.js +++ b/app/lib/crypto/base58.js @@ -75,4 +75,4 @@ Base58.decode = function(string) { return (new Uint8Array(bytes)) } -module.exports = Base58; \ No newline at end of file +module.exports = Base58; diff --git a/app/lib/dal/drivers/sqlite.js b/app/lib/dal/drivers/sqlite.js index 2aaccbb58..107004f80 100644 --- a/app/lib/dal/drivers/sqlite.js +++ b/app/lib/dal/drivers/sqlite.js @@ -19,11 +19,11 @@ function SQLiteDriver(path) { function getDB() { return dbPromise || (dbPromise = co(function*() { - logger.debug('Opening SQLite database "%s"...', path); - let sqlite = new sqlite3.Database(path); - yield new Promise((resolve) => sqlite.once('open', resolve)); - // Database is opened and ready - return sqlite; + logger.debug('Opening SQLite database "%s"...', path); + let sqlite = new sqlite3.Database(path); + yield new Promise((resolve) => sqlite.once('open', resolve)); + // Database is opened and ready + return sqlite; })); } @@ -88,4 +88,4 @@ function SQLiteDriver(path) { } }); }); -} \ No newline at end of file +} diff --git a/app/lib/dal/fileDAL.js b/app/lib/dal/fileDAL.js index 164415e88..65158fc52 100644 --- a/app/lib/dal/fileDAL.js +++ b/app/lib/dal/fileDAL.js @@ -3,10 +3,7 @@ const Q = require('q'); const co = require('co'); const _ = require('underscore'); const indexer = require('../dup/indexer'); -const hashf = require('../ucp/hashf'); -const wotb = require('../wot'); const logger = require('../logger')('filedal'); -const directory = require('../system/directory'); const Configuration = require('../entity/configuration'); const Merkle = require('../entity/merkle'); const Transaction = require('../entity/transaction'); @@ -62,8 +59,6 @@ function FileDAL(params) { 'cindexDAL': that.cindexDAL }; - let currency = ''; - this.init = () => co(function *() { const dalNames = _.keys(that.newDals); for (const dalName of dalNames) { @@ -300,14 +295,14 @@ function FileDAL(params) { let matching = certs; links.map((entry) => { entry.from = entry.issuer; - const co = entry.created_on.split('-'); - const wo = entry.written_on.split('-'); - entry.block = parseInt(co[0]); - entry.block_number = parseInt(co[0]); - entry.block_hash = co[1]; + const cbt = entry.created_on.split('-'); + const wbt = entry.written_on.split('-'); + entry.block = parseInt(cbt[0]); + entry.block_number = parseInt(cbt[0]); + entry.block_hash = cbt[1]; entry.linked = true; - entry.written_block = parseInt(wo[0]); - entry.written_hash = wo[1]; + entry.written_block = parseInt(wbt[0]); + entry.written_hash = wbt[1]; matching.push(entry); }); matching = _.sortBy(matching, (c) => -c.block); @@ -323,15 +318,15 @@ function FileDAL(params) { const idty = yield that.getWrittenIdtyByPubkey(entry.receiver); entry.from = entry.issuer; entry.to = entry.receiver; - const co = entry.created_on.split('-'); - const wo = entry.written_on.split('-'); - entry.block = parseInt(co[0]); - entry.block_number = parseInt(co[0]); - entry.block_hash = co[1]; + const cbt = entry.created_on.split('-'); + const wbt = entry.written_on.split('-'); + entry.block = parseInt(cbt[0]); + entry.block_number = parseInt(cbt[0]); + entry.block_hash = cbt[1]; entry.target = idty.hash; entry.linked = true; - entry.written_block = parseInt(wo[0]); - entry.written_hash = wo[1]; + entry.written_block = parseInt(wbt[0]); + entry.written_hash = wbt[1]; matching.push(entry); })); matching = _.sortBy(matching, (c) => -c.block); @@ -452,7 +447,7 @@ function FileDAL(params) { .indexOf(p.status) !== -1).value(); }); - this.listAllPeersWithStatusNewUPWithtout = (pubkey) => co(function *() { + this.listAllPeersWithStatusNewUPWithtout = () => co(function *() { const peers = yield that.peerDAL.listAll(); return _.chain(peers).filter((p) => p.status == 'UP').filter((p) => p.pubkey); }); @@ -506,7 +501,7 @@ function FileDAL(params) { this.saveBlock = (block) => co(function*() { block.wrong = false; yield [ - that.saveBlockInFile(block, true), + that.saveBlockInFile(block), that.saveTxsInFiles(block.transactions, {block_number: block.number, time: block.medianTime, currency: block.currency }) ]; }); @@ -552,7 +547,7 @@ function FileDAL(params) { return true; }); - this.trimSandboxes = (block, conf) => co(function*() { + this.trimSandboxes = (block) => co(function*() { yield that.certDAL.trimExpiredCerts(block.medianTime); yield that.msDAL.trimExpiredMemberships(block.medianTime); yield that.idtyDAL.trimExpiredIdentities(block.medianTime); @@ -561,7 +556,7 @@ function FileDAL(params) { this.savePendingMembership = (ms) => that.msDAL.savePendingMembership(ms); - this.saveBlockInFile = (block, check) => co(function *() { + this.saveBlockInFile = (block) => co(function *() { yield that.writeFileOfBlock(block); }); @@ -680,8 +675,6 @@ function FileDAL(params) { const savedConf = yield that.confDAL.loadConf(); conf = _(savedConf).extend(overrideConf || {}); } - // TODO: Do something about the currency global variable - currency = conf.currency; if (that.loadConfHook) { yield that.loadConfHook(conf); } @@ -690,8 +683,6 @@ function FileDAL(params) { this.saveConf = (confToSave) => { return co(function*() { - // TODO: Do something about the currency global variable - currency = confToSave.currency; // Save the conf in file let theConf = confToSave; if (that.saveConfHook) { diff --git a/app/lib/dal/sqliteDAL/AbstractIndex.js b/app/lib/dal/sqliteDAL/AbstractIndex.js index 4bfce7b82..c4f00a27f 100644 --- a/app/lib/dal/sqliteDAL/AbstractIndex.js +++ b/app/lib/dal/sqliteDAL/AbstractIndex.js @@ -33,4 +33,4 @@ function AbstractIndex() { } } }); -} \ No newline at end of file +} diff --git a/app/lib/dal/sqliteDAL/AbstractSQLite.js b/app/lib/dal/sqliteDAL/AbstractSQLite.js index cf2ea2f65..2551ce2ea 100644 --- a/app/lib/dal/sqliteDAL/AbstractSQLite.js +++ b/app/lib/dal/sqliteDAL/AbstractSQLite.js @@ -284,4 +284,4 @@ function AbstractSQLite(driver) { } return row; } -} \ No newline at end of file +} diff --git a/app/lib/dal/sqliteDAL/CertDAL.js b/app/lib/dal/sqliteDAL/CertDAL.js index 195168476..a6959ed70 100644 --- a/app/lib/dal/sqliteDAL/CertDAL.js +++ b/app/lib/dal/sqliteDAL/CertDAL.js @@ -111,4 +111,4 @@ function CertDAL(driver) { this.getSandboxRoom = () => this.sandbox.getSandboxRoom(); this.setSandboxSize = (maxSize) => this.sandbox.maxSize = maxSize; -} \ No newline at end of file +} diff --git a/app/lib/dal/sqliteDAL/IdentityDAL.js b/app/lib/dal/sqliteDAL/IdentityDAL.js index 8befe1751..11d273675 100644 --- a/app/lib/dal/sqliteDAL/IdentityDAL.js +++ b/app/lib/dal/sqliteDAL/IdentityDAL.js @@ -2,9 +2,7 @@ * Created by cgeek on 22/08/15. */ -const Q = require('q'); const co = require('co'); -const logger = require('../../logger')('idtyDAL'); const constants = require('../../constants'); const AbstractSQLite = require('./AbstractSQLite'); const SandBox = require('./SandBox'); diff --git a/app/lib/dal/sqliteDAL/MembershipDAL.js b/app/lib/dal/sqliteDAL/MembershipDAL.js index d4338a4ce..e3f5564a7 100644 --- a/app/lib/dal/sqliteDAL/MembershipDAL.js +++ b/app/lib/dal/sqliteDAL/MembershipDAL.js @@ -2,7 +2,6 @@ * Created by cgeek on 22/08/15. */ -const Q = require('q'); const co = require('co'); const _ = require('underscore'); const AbstractSQLite = require('./AbstractSQLite'); diff --git a/app/lib/dal/sqliteDAL/MetaDAL.js b/app/lib/dal/sqliteDAL/MetaDAL.js index 79b6b1ecb..69244c74b 100644 --- a/app/lib/dal/sqliteDAL/MetaDAL.js +++ b/app/lib/dal/sqliteDAL/MetaDAL.js @@ -5,7 +5,6 @@ */ const co = require('co'); -const _ = require('underscore'); const logger = require('../../logger')('metaDAL'); const AbstractSQLite = require('./AbstractSQLite'); diff --git a/app/lib/dal/sqliteDAL/SandBox.js b/app/lib/dal/sqliteDAL/SandBox.js index e452310a3..4e7d836ee 100644 --- a/app/lib/dal/sqliteDAL/SandBox.js +++ b/app/lib/dal/sqliteDAL/SandBox.js @@ -1,8 +1,6 @@ "use strict"; const co = require('co'); -const colors = require('colors'); -const logger = require('../../logger')('sqlite'); module.exports = SandBox; @@ -24,8 +22,8 @@ function SandBox(maxSize, findElements, compareElements) { return comparison > 0; }); - this.getSandboxRoom = (underBlock) => co(function *() { + this.getSandboxRoom = () => co(function *() { const elems = yield findElements(); return that.maxSize - elems.length; }); -} \ No newline at end of file +} diff --git a/app/lib/dal/sqliteDAL/index/BIndexDAL.js b/app/lib/dal/sqliteDAL/index/BIndexDAL.js index dfc2cb3b0..9d5b80b74 100644 --- a/app/lib/dal/sqliteDAL/index/BIndexDAL.js +++ b/app/lib/dal/sqliteDAL/index/BIndexDAL.js @@ -3,7 +3,6 @@ */ const co = require('co'); -const _ = require('underscore'); const AbstractSQLite = require('./../AbstractSQLite'); module.exports = BIndexDAL; diff --git a/app/lib/dal/sqliteDAL/index/SIndexDAL.js b/app/lib/dal/sqliteDAL/index/SIndexDAL.js index c6fce27cb..d1b3ea817 100644 --- a/app/lib/dal/sqliteDAL/index/SIndexDAL.js +++ b/app/lib/dal/sqliteDAL/index/SIndexDAL.js @@ -99,8 +99,8 @@ function SIndexDAL(driver) { }); this.findLowerThan = (amount, base) => co(function*() { - const baseConditions = Array.from({ length: (base +1) }).map((el, index) => { - return '(base = ' + index + ' and amount < ' + (amount*Math.pow(10, base - index)) + ')'; + const baseConditions = Array.from({ length: (base + 1) }).map((el, index) => { + return '(base = ' + index + ' and amount < ' + (amount * Math.pow(10, base - index)) + ')'; }).join(' OR '); const potentials = yield that.query('SELECT * FROM ' + that.table + ' s1 ' + 'WHERE s1.op = ? ' + diff --git a/app/lib/dup/indexer.js b/app/lib/dup/indexer.js index 2ce31dfdc..2e0235489 100644 --- a/app/lib/dup/indexer.js +++ b/app/lib/dup/indexer.js @@ -468,8 +468,8 @@ const indexer = module.exports = { const ratio = constants.POW_DIFFICULTY_RANGE_RATIO; const maxGenTime = Math.ceil(conf.avgGenTime * ratio); const minGenTime = Math.floor(conf.avgGenTime / ratio); - const minSpeed = 1/ maxGenTime; - const maxSpeed = 1/ minGenTime; + const minSpeed = 1 / maxGenTime; + const maxSpeed = 1 / minGenTime; if (HEAD.diffNumber != HEAD_1.diffNumber && HEAD.speed >= maxSpeed && (HEAD_1.powMin + 2) % 16 == 0) { HEAD.powMin = HEAD_1.powMin + 2; @@ -784,11 +784,11 @@ const indexer = module.exports = { } else { const issuersVar = (HEAD.issuersCount - HEAD_1.issuersCount); if (HEAD_1.issuersFrameVar > 0) { - HEAD.issuersFrameVar = HEAD_1.issuersFrameVar + 5*issuersVar - 1; + HEAD.issuersFrameVar = HEAD_1.issuersFrameVar + 5 * issuersVar - 1; } else if (HEAD_1.issuersFrameVar < 0) { - HEAD.issuersFrameVar = HEAD_1.issuersFrameVar + 5*issuersVar + 1; + HEAD.issuersFrameVar = HEAD_1.issuersFrameVar + 5 * issuersVar + 1; } else { - HEAD.issuersFrameVar = HEAD_1.issuersFrameVar + 5*issuersVar; + HEAD.issuersFrameVar = HEAD_1.issuersFrameVar + 5 * issuersVar; } } }, diff --git a/app/lib/entity/block.js b/app/lib/entity/block.js index 743c16206..d25478df7 100644 --- a/app/lib/entity/block.js +++ b/app/lib/entity/block.js @@ -1,6 +1,5 @@ "use strict"; const _ = require('underscore'); -const constants = require('../constants'); const hashf = require('../ucp/hashf'); const Transaction = require('./transaction'); @@ -69,8 +68,8 @@ function Block(json) { "issuersFrameVar", "len" ].forEach((field) => { - json[field] = parseInt(this[field], 10); - }); + json[field] = parseInt(this[field], 10); + }); [ "currency", "issuer", @@ -78,20 +77,20 @@ function Block(json) { "hash", "parameters" ].forEach((field) => { - json[field] = this[field] || ""; - }); + json[field] = this[field] || ""; + }); [ "previousHash", "previousIssuer", "inner_hash" ].forEach((field) => { - json[field] = this[field] || null; - }); + json[field] = this[field] || null; + }); [ "dividend" ].forEach((field) => { - json[field] = parseInt(this[field]) || null; - }); + json[field] = parseInt(this[field]) || null; + }); [ "identities", "joiners", @@ -101,19 +100,19 @@ function Block(json) { "excluded", "certifications" ].forEach((field) => { - json[field] = []; - this[field].forEach((raw) => { - json[field].push(raw); - }); + json[field] = []; + this[field].forEach((raw) => { + json[field].push(raw); }); + }); [ "transactions" ].forEach((field) => { - json[field] = []; - this[field].forEach((obj) => { - json[field].push(_(obj).omit('raw', 'certifiers', 'hash')); - }); + json[field] = []; + this[field].forEach((obj) => { + json[field].push(_(obj).omit('raw', 'certifiers', 'hash')); }); + }); json.raw = this.getRaw(); return json; }; diff --git a/app/lib/entity/certification.js b/app/lib/entity/certification.js index 7f1d5776f..d724ce91a 100644 --- a/app/lib/entity/certification.js +++ b/app/lib/entity/certification.js @@ -8,7 +8,7 @@ const Certification = function(json) { this.linked = false; _(json).keys().forEach((key) => { - this[key] = json[key]; + this[key] = json[key]; }); this.from = this.pubkey = this.from || this.pubkey || this.issuer; diff --git a/app/lib/entity/peer.js b/app/lib/entity/peer.js index 4be05dd88..b54e4563b 100644 --- a/app/lib/entity/peer.js +++ b/app/lib/entity/peer.js @@ -1,5 +1,4 @@ "use strict"; -const Q = require('q'); const _ = require('underscore'); const contacter = require('../contacter'); const rawer = require('../ucp/rawer'); @@ -14,7 +13,7 @@ function Peer(json) { this.documentType = 'peer'; _(json).keys().forEach((key) => { - this[key] = json[key]; + this[key] = json[key]; }); this.endpoints = this.endpoints || []; diff --git a/app/lib/entity/revocation.js b/app/lib/entity/revocation.js index 8187a624b..e3c54fed1 100644 --- a/app/lib/entity/revocation.js +++ b/app/lib/entity/revocation.js @@ -1,13 +1,12 @@ "use strict"; const _ = require('underscore'); const rawer = require('../ucp/rawer'); -const ucp = require('../ucp/buid'); const Identity = require('./identity'); const Revocation = function(json) { _(json).keys().forEach((key) => { - this[key] = json[key]; + this[key] = json[key]; }); this.getRaw = () => rawer.getOfficialRevocation(this); diff --git a/app/lib/entity/source.js b/app/lib/entity/source.js index a903563ac..05b6fcf45 100644 --- a/app/lib/entity/source.js +++ b/app/lib/entity/source.js @@ -35,4 +35,4 @@ function Source(json) { "base": this.base }; }; -} \ No newline at end of file +} diff --git a/app/lib/entity/stat.js b/app/lib/entity/stat.js index 09e9f5330..1b459dbd9 100644 --- a/app/lib/entity/stat.js +++ b/app/lib/entity/stat.js @@ -3,7 +3,7 @@ const _ = require('underscore'); const Stat = function(json) { _(json).keys().forEach((key) => { - this[key] = json[key]; + this[key] = json[key]; }); this.json = function () { diff --git a/app/lib/entity/transaction.js b/app/lib/entity/transaction.js index 868e4addb..32458ec4d 100644 --- a/app/lib/entity/transaction.js +++ b/app/lib/entity/transaction.js @@ -2,7 +2,6 @@ let _ = require('underscore'); let rawer = require('../ucp/rawer'); let hashf = require('../ucp/hashf'); -let constants = require('../constants'); let Transaction = function(obj, currency) { @@ -15,7 +14,7 @@ let Transaction = function(obj, currency) { this.issuers = []; _(json).keys().forEach((key) => { - this[key] = json[key]; + this[key] = json[key]; }); // Store the maximum output base diff --git a/app/lib/logger/index.js b/app/lib/logger/index.js index 5c149af28..81f9e37da 100644 --- a/app/lib/logger/index.js +++ b/app/lib/logger/index.js @@ -3,7 +3,6 @@ const moment = require('moment'); const path = require('path'); const winston = require('winston'); const cbLogger = require('./callbackLogger'); -const directory = require('../system/directory'); const customLevels = { levels: { diff --git a/app/lib/pow/engine.js b/app/lib/pow/engine.js index 07674f03f..c2f9416fd 100644 --- a/app/lib/pow/engine.js +++ b/app/lib/pow/engine.js @@ -96,4 +96,4 @@ function PowEngine() { this.isConnected = () => powProcess ? powProcess.connected : false; this.setOnInfoMessage = (callback) => onInfoMessage = callback; -} \ No newline at end of file +} diff --git a/app/lib/rules/global_rules.js b/app/lib/rules/global_rules.js index e837eb2ae..a067bdd6c 100644 --- a/app/lib/rules/global_rules.js +++ b/app/lib/rules/global_rules.js @@ -8,8 +8,6 @@ const keyring = require('../crypto/keyring'); const rawer = require('../ucp/rawer'); const indexer = require('../dup/indexer'); const Identity = require('../entity/identity'); -const Membership = require('../entity/membership'); -const Certification = require('../entity/certification'); const Transaction = require('../entity/transaction'); const logger = require('../logger')('globr'); const unlock = require('../ucp/txunlock'); diff --git a/app/lib/rules/index.js b/app/lib/rules/index.js index ff8e25af4..284ce198a 100644 --- a/app/lib/rules/index.js +++ b/app/lib/rules/index.js @@ -78,7 +78,7 @@ rules.ALIAS = { rules.CHECK = { ASYNC: { ALL_LOCAL: checkLocal(rules.ALIAS.ALL_LOCAL), - ALL_LOCAL_BUT_POW: checkLocal(rules.ALIAS.ALL_LOCAL_BUT_POW_AND_SIGNATURE), + ALL_LOCAL_BUT_POW: checkLocal(rules.ALIAS.ALL_LOCAL_BUT_POW_AND_SIGNATURE) } }; diff --git a/app/lib/rules/local_rules.js b/app/lib/rules/local_rules.js index c7f4d95d7..b713db855 100644 --- a/app/lib/rules/local_rules.js +++ b/app/lib/rules/local_rules.js @@ -143,7 +143,7 @@ rules.FUNCTIONS = { .pluck('pub') .value(); for (const pub of revocations) { - const exclusions = _(iindex).where({ op: constants.IDX_UPDATE, member: false }); + const exclusions = _(iindex).where({ op: constants.IDX_UPDATE, member: false, pub }); if (exclusions.length == 0) { throw Error('A revoked member must be excluded'); } @@ -313,7 +313,7 @@ rules.FUNCTIONS = { return true; }), - checkTxSources: (block, conf) => co(function *() { + checkTxSources: (block) => co(function *() { const txs = block.getTransactions(); for (const tx of txs) { if (!tx.inputs || tx.inputs.length == 0) { @@ -379,7 +379,7 @@ function checkSingleMembershipSignature(ms) { return keyring.verify(ms.getRaw(), ms.signature, ms.issuer); } -function getSigResult(tx, a) { +function getSigResult(tx) { let sigResult = { sigs: {}, matching: true }; let json = { "version": tx.version, "currency": tx.currency, "blockstamp": tx.blockstamp, "locktime": tx.locktime, "inputs": [], "outputs": [], "issuers": tx.issuers, "signatures": [], "comment": tx.comment }; tx.inputs.forEach(function (input) { @@ -489,7 +489,7 @@ rules.HELPERS = { } }, - getMaxPossibleVersionNumber: (current, block) => co(function*() { + getMaxPossibleVersionNumber: (current) => co(function*() { // Looking at current blockchain, find what is the next maximum version we can produce // 1. We follow previous block's version diff --git a/app/lib/streams/jsoner.js b/app/lib/streams/jsoner.js index 2b342e35a..e24820a3b 100644 --- a/app/lib/streams/jsoner.js +++ b/app/lib/streams/jsoner.js @@ -16,6 +16,6 @@ function JSONer () { that.push(entity.json()); done(); }; -}; +} util.inherits(JSONer, stream.Transform); diff --git a/app/lib/streams/parsers/GenericParser.js b/app/lib/streams/parsers/GenericParser.js index e5b60948c..b0768144b 100644 --- a/app/lib/streams/parsers/GenericParser.js +++ b/app/lib/streams/parsers/GenericParser.js @@ -14,7 +14,7 @@ function GenericParser (captures, multipleLinesFields, rawerFunc) { this.rawerFunc = rawerFunc; - this._simpleLineExtraction = (pr, rawEntry, cap, parser) => { + this._simpleLineExtraction = (pr, rawEntry, cap) => { const fieldValue = rawEntry.match(cap.regexp); if(fieldValue && fieldValue.length >= 2){ pr[cap.prop] = cap.parser ? cap.parser(fieldValue[1], pr) : fieldValue[1]; diff --git a/app/lib/streams/parsers/block.js b/app/lib/streams/parsers/block.js index eebd6528c..d7c5366e3 100644 --- a/app/lib/streams/parsers/block.js +++ b/app/lib/streams/parsers/block.js @@ -163,7 +163,7 @@ function splitAndMatch (separator, regexp) { }; } -function extractTransactions(raw, obj) { +function extractTransactions(raw) { const regexps = { "issuers": constants.TRANSACTION.SENDER, "inputs": constants.TRANSACTION.SOURCE_V3, diff --git a/app/lib/streams/parsers/certification.js b/app/lib/streams/parsers/certification.js index 814fe80cb..adebc6e89 100644 --- a/app/lib/streams/parsers/certification.js +++ b/app/lib/streams/parsers/certification.js @@ -1,9 +1,7 @@ "use strict"; const GenericParser = require('./GenericParser'); const util = require('util'); -const ucp = require('../../ucp/buid'); const rawer = require('../../ucp/rawer'); -const hashf = require('../../ucp/hashf'); const constants = require('../../constants'); module.exports = CertificationParser; diff --git a/app/lib/streams/parsers/identity.js b/app/lib/streams/parsers/identity.js index bdc2c7510..5f405bb3a 100644 --- a/app/lib/streams/parsers/identity.js +++ b/app/lib/streams/parsers/identity.js @@ -1,7 +1,6 @@ "use strict"; const GenericParser = require('./GenericParser'); const util = require('util'); -const ucp = require('../../ucp/buid'); const rawer = require('../../ucp/rawer'); const hashf = require('../../ucp/hashf'); const constants = require('../../constants'); diff --git a/app/lib/streams/parsers/revocation.js b/app/lib/streams/parsers/revocation.js index 52903ce60..83f863022 100644 --- a/app/lib/streams/parsers/revocation.js +++ b/app/lib/streams/parsers/revocation.js @@ -1,8 +1,6 @@ "use strict"; const GenericParser = require('./GenericParser'); const util = require('util'); -const moment = require('moment'); -const ucp = require('../../ucp/buid'); const rawer = require('../../ucp/rawer'); const hashf = require('../../ucp/hashf'); const constants = require('../../constants'); diff --git a/app/lib/streams/parsers/transaction.js b/app/lib/streams/parsers/transaction.js index 06e3358be..74d3d1b22 100644 --- a/app/lib/streams/parsers/transaction.js +++ b/app/lib/streams/parsers/transaction.js @@ -72,7 +72,7 @@ function extractIssuers(raw) { return issuers; } -function extractInputs(raw, obj) { +function extractInputs(raw) { const inputs = []; const lines = raw.split(/\n/); for (const line of lines) { diff --git a/app/lib/streams/router.js b/app/lib/streams/router.js index c646dc64a..0ad9fb6eb 100644 --- a/app/lib/streams/router.js +++ b/app/lib/streams/router.js @@ -1,7 +1,6 @@ "use strict"; const co = require('co'); -const _ = require('underscore'); const util = require('util'); const stream = require('stream'); const Peer = require('../entity/peer'); diff --git a/app/lib/streams/routes.js b/app/lib/streams/routes.js index a6cf8ad9c..39b980d1b 100644 --- a/app/lib/streams/routes.js +++ b/app/lib/streams/routes.js @@ -5,7 +5,6 @@ const es = require('event-stream'); const dtos = require('./dtos'); const sanitize = require('./sanitize'); const limiter = require('../system/limiter'); -const constants = require('../../lib/constants'); const logger = require('../logger')('routes'); const WebSocketServer = require('ws').Server; diff --git a/app/lib/sync.js b/app/lib/sync.js index 6ea67b3b6..6180d2b26 100644 --- a/app/lib/sync.js +++ b/app/lib/sync.js @@ -77,12 +77,12 @@ function Synchroniser (server, host, port, conf, interactive) { if (to > 1 && speed > 0) { const remain = (to - (localNumber + 1 + blocksApplied)); const secondsLeft = remain / speed; - const momDuration = moment.duration(secondsLeft*1000); + const momDuration = moment.duration(secondsLeft * 1000); watcher.writeStatus('Remaining ' + momDuration.humanize() + ''); } }); - this.test = (to, chunkLen, askedCautious, nopeers) => co(function*() { + this.test = (to, chunkLen, askedCautious) => co(function*() { const peering = yield contacter.statics.fetchPeer(host, port, contacterOptions); const peer = new Peer(peering); const node = yield peer.connect(); @@ -197,7 +197,7 @@ function Synchroniser (server, host, port, conf, interactive) { }), // Get the remote blockchain (bc) current block - remoteCurrent: (peer) => Promise.resolve(rCurrent), + remoteCurrent: () => Promise.resolve(rCurrent), // Get the remote peers to be pulled remotePeers: () => co(function*() { @@ -775,7 +775,7 @@ function P2PDownloader(localNumber, to, toHash, peers, watcher) { * Triggers for starting the download. */ let startResolver; - const downloadStarter = new Promise((resolve, reject) => startResolver = resolve); + const downloadStarter = new Promise((resolve) => startResolver = resolve); const chainsCorrectly = (blocks, index) => co(function*() { @@ -874,7 +874,7 @@ function P2PDownloader(localNumber, to, toHash, peers, watcher) { if (doneIndex !== null) { const realIndex = slots[doneIndex]; if (downloads[realIndex].isResolved()) { - const p = new Promise((resolve, reject) => co(function*() { + co(function*() { const blocks = yield downloads[realIndex]; if (realIndex < chunks.length - 1) { // We must wait for NEXT blocks to be STRONGLY validated before going any further, otherwise we @@ -894,7 +894,7 @@ function P2PDownloader(localNumber, to, toHash, peers, watcher) { // Need a retry processing[realIndex] = false; } - })); + }); } else { processing[realIndex] = false; // Need a retry } diff --git a/app/lib/system/limiter.js b/app/lib/system/limiter.js index 29959e83d..6fe411e35 100644 --- a/app/lib/system/limiter.js +++ b/app/lib/system/limiter.js @@ -111,4 +111,4 @@ function createObject(strategy) { obj.reqsMin = []; obj.reqsMinLen = 0; return obj; -} \ No newline at end of file +} diff --git a/app/lib/system/upnp.js b/app/lib/system/upnp.js index 5a562290c..fda7375ee 100644 --- a/app/lib/system/upnp.js +++ b/app/lib/system/upnp.js @@ -63,4 +63,4 @@ function openPort (localPort, remotePort) { resolve(); }); }); -} \ No newline at end of file +} diff --git a/app/lib/wizard.js b/app/lib/wizard.js index 77d2908ab..7e8f0c93e 100644 --- a/app/lib/wizard.js +++ b/app/lib/wizard.js @@ -1,6 +1,5 @@ "use strict"; const co = require('co'); -const Q = require('q'); const constants = require('./constants'); const network = require('./system/network'); const async = require('async'); @@ -348,7 +347,7 @@ function getLocalNetworkOperations(conf, autoconf) { ]; } -function getRemoteNetworkOperations(conf, remoteipv4, remoteipv6, autoconf) { +function getRemoteNetworkOperations(conf, remoteipv4) { return [ function (next){ if (!conf.ipv4) { diff --git a/app/lib/wot.js b/app/lib/wot.js index 359096a23..d2173e31e 100644 --- a/app/lib/wot.js +++ b/app/lib/wot.js @@ -45,7 +45,7 @@ function WoTBWrapper(instance) { instance.addLink(from, to); }; - this.removeLink = (from, to, debug) => { + this.removeLink = (from, to) => { logger.trace('Link %s X> %s', from, to); instance.removeLink(from, to); }; diff --git a/app/modules/config.js b/app/modules/config.js index 40920684f..a3f320b76 100644 --- a/app/modules/config.js +++ b/app/modules/config.js @@ -6,7 +6,7 @@ module.exports = { name: 'config', desc: 'Register configuration in database', // The command does nothing particular, it just stops the process right after configuration phase is over - onConfiguredExecute: (server, conf, program, params, wizardTasks) => Promise.resolve(conf) + onConfiguredExecute: (server, conf) => Promise.resolve(conf) }] } } diff --git a/app/modules/gen.js b/app/modules/gen.js index 3fd46d132..4f185f49e 100644 --- a/app/modules/gen.js +++ b/app/modules/gen.js @@ -18,7 +18,7 @@ module.exports = { cli: [{ name: 'gen-next [host] [port] [difficulty]', desc: 'Tries to generate the next block of the blockchain.', - onPluggedDALExecute: (server, conf, program, params, startServices, stopServices) => co(function*() { + onPluggedDALExecute: (server, conf, program, params) => co(function*() { const host = params[0]; const port = params[1]; const difficulty = params[2]; diff --git a/app/modules/synchronization.js b/app/modules/synchronization.js index 87871f12f..c389a3c13 100644 --- a/app/modules/synchronization.js +++ b/app/modules/synchronization.js @@ -7,7 +7,7 @@ module.exports = { cli: [{ name: 'sync [host] [port] [to]', desc: 'Synchronize blockchain from a remote Duniter node', - onPluggedDALExecute: (server, conf, program, params, startServices, stopServices) => co(function*() { + onPluggedDALExecute: (server, conf, program, params) => co(function*() { const host = params[0]; const port = params[1]; const to = params[2]; diff --git a/app/service/BlockchainService.js b/app/service/BlockchainService.js index 704517dc9..307b3f525 100644 --- a/app/service/BlockchainService.js +++ b/app/service/BlockchainService.js @@ -1,12 +1,10 @@ "use strict"; -const async = require('async'); const _ = require('underscore'); const co = require('co'); const Q = require('q'); const parsers = require('../lib/streams/parsers'); const rules = require('../lib/rules'); -const keyring = require('../lib/crypto/keyring'); const constants = require('../lib/constants'); const blockchainCtx = require('../lib/computation/blockchainContext'); const blockGenerator = require('../lib/computation/blockGenerator'); @@ -30,14 +28,13 @@ function BlockchainService (server) { const mainContext = blockchainCtx(); const prover = this.prover = blockProver(server); const generator = blockGenerator(mainContext, prover); - let conf, dal, keyPair, logger, selfPubkey; + let conf, dal, logger, selfPubkey; this.getContext = () => mainContext; this.setConfDAL = (newConf, newDAL, newKeyPair) => { dal = newDAL; conf = newConf; - keyPair = newKeyPair; mainContext.setConfDAL(conf, dal); prover.setConfDAL(conf, dal, newKeyPair); generator.setConfDAL(conf, dal, newKeyPair); @@ -140,7 +137,7 @@ function BlockchainService (server) { Transaction.statics.cleanSignatories(obj.transactions); } catch (e) { - throw e; + throw e; } let existing = yield dal.getBlockByNumberAndHashOrNull(obj.number, obj.hash); if (existing) { diff --git a/app/service/PeeringService.js b/app/service/PeeringService.js index d5ee12d3e..787fbfb0f 100644 --- a/app/service/PeeringService.js +++ b/app/service/PeeringService.js @@ -273,7 +273,7 @@ function PeeringService(server) { logger.error('It seems there is an issue with your configuration.'); logger.error('Please restart your node with:'); logger.error('$ duniter restart'); - return Q.Promise((resolve) => null); + return Q.Promise(() => null); } // Choosing next based-block for our peer record: we basically want the most distant possible from current let minBlock = current ? current.number - 30 : 0; diff --git a/test/dal/triming.js b/test/dal/triming.js index 4fb4fc258..85678ea5c 100644 --- a/test/dal/triming.js +++ b/test/dal/triming.js @@ -1,10 +1,8 @@ "use strict"; const co = require('co'); -const _ = require('underscore'); const should = require('should'); const FileDAL = require('../../app/lib/dal/fileDAL'); const dir = require('../../app/lib/system/directory'); -const constants = require('../../app/lib/constants'); const indexer = require('../../app/lib/dup/indexer'); const toolbox = require('../integration/tools/toolbox'); const limiter = require('../../app/lib/system/limiter'); @@ -46,7 +44,7 @@ describe("Triming", function(){ yield dal.iindexDAL.insertBatch([ { op: 'CREATE', pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', uid: 'cat', created_on: '121-H', written_on: '122-H', member: true, wasMember: true, kick: false }, { op: 'UPDATE', pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', uid: null, created_on: '121-H', written_on: '123-H', member: null, wasMember: null, kick: true }, - { op: 'UPDATE', pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', uid: null, created_on: '121-H', written_on: '124-H', member: false, wasMember: null, kick: false }, + { op: 'UPDATE', pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', uid: null, created_on: '121-H', written_on: '124-H', member: false, wasMember: null, kick: false } ]); let lignes = yield dal.iindexDAL.reducable('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'); lignes.should.have.length(3); @@ -74,7 +72,7 @@ describe("Triming", function(){ { op: 'CREATE', pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', created_on: '121-H', written_on: '122-H', expires_on: 1000, expired_on: null }, { op: 'UPDATE', pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', created_on: '121-H', written_on: '123-H', expires_on: 1200, expired_on: null }, { op: 'UPDATE', pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', created_on: '121-H', written_on: '124-H', expires_on: null, expired_on: null }, - { op: 'UPDATE', pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', created_on: '121-H', written_on: '125-H', expires_on: 1400, expired_on: null }, + { op: 'UPDATE', pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', created_on: '121-H', written_on: '125-H', expires_on: 1400, expired_on: null } ]); const lignes = yield dal.mindexDAL.reducable('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'); lignes.should.have.length(4); @@ -93,7 +91,7 @@ describe("Triming", function(){ yield dal.cindexDAL.insertBatch([ { op: 'CREATE', issuer: 'HgTT', receiver: 'DNan', created_on: '121-H', written_on: '126-H', expires_on: 1000, expired_on: null }, { op: 'UPDATE', issuer: 'HgTT', receiver: 'DNan', created_on: '121-H', written_on: '126-H', expires_on: null, expired_on: 3000 }, - { op: 'CREATE', issuer: 'DNan', receiver: 'HgTT', created_on: '125-H', written_on: '126-H', expires_on: null, expired_on: null }, + { op: 'CREATE', issuer: 'DNan', receiver: 'HgTT', created_on: '125-H', written_on: '126-H', expires_on: null, expired_on: null } ]); (yield dal.cindexDAL.sqlFind({ issuer: 'HgTT' })).should.have.length(2); (yield dal.cindexDAL.sqlFind({ issuer: 'DNan' })).should.have.length(1); @@ -112,7 +110,7 @@ describe("Triming", function(){ { op: 'CREATE', identifier: 'SOURCE_1', pos: 4, written_on: '126-H', written_time: 2000, consumed: false }, { op: 'UPDATE', identifier: 'SOURCE_1', pos: 4, written_on: '139-H', written_time: 4500, consumed: true }, { op: 'CREATE', identifier: 'SOURCE_2', pos: 4, written_on: '126-H', written_time: 2000, consumed: false }, - { op: 'CREATE', identifier: 'SOURCE_3', pos: 4, written_on: '126-H', written_time: 2000, consumed: false }, + { op: 'CREATE', identifier: 'SOURCE_3', pos: 4, written_on: '126-H', written_time: 2000, consumed: false } ]); (yield dal.sindexDAL.sqlFind({ identifier: 'SOURCE_1' })).should.have.length(2); (yield dal.sindexDAL.sqlFind({ pos: 4 })).should.have.length(4); @@ -138,7 +136,7 @@ describe("Triming", function(){ medianTimeBlocks: 3 })).s1; // const s1 = server.s1; - for (const i of new Array(13)) { + for (let i = 0; i < 13; i++) { yield server.commit(); } (yield server.dal.bindexDAL.head(1)).should.have.property('number').equal(12); diff --git a/test/eslint.js b/test/eslint.js index bcb4e0fbf..24994f994 100644 --- a/test/eslint.js +++ b/test/eslint.js @@ -1,16 +1,16 @@ -var lint = require('mocha-eslint'); +const lint = require('mocha-eslint'); // Array of paths to lint // Note: a seperate Mocha test will be run for each path and each file which // matches a glob pattern -var paths = [ +const paths = [ 'app', 'bin/duniter', 'test' ]; // Specify style of output -var options = {}; +const options = {}; options.formatter = 'stylish'; // Run the tests diff --git a/test/fast/javascript_test.js b/test/fast/javascript_test.js deleted file mode 100644 index c0063cbdc..000000000 --- a/test/fast/javascript_test.js +++ /dev/null @@ -1,37 +0,0 @@ -"use strict"; -var should = require('should'); -var co = require('co'); - -describe('JavaScript', () => { - - describe('for loops', () => { - - const array1 = [1, 2, 3]; - array1.abc = 2; - - it('for (.. in ..)', () => { - array1.abc = 2; - let sum = 0; - for (const i in array1) { - sum += array1[i]; - } - sum.should.equal(8); // <-- Yes, it does not equal 6! Because `for .. in` is not `hasOwnProperty` checked. - }); - - it('for (.. of ..)', () => { - let sum = 0; - for (const value of array1) { - sum += value; - } - sum.should.equal(6); - }); - - it('with promises', () => co(function*() { - let sum = 0; - for (const value of array1) { - sum += yield Promise.resolve(value); - } - sum.should.equal(6); - })); - }); -}); diff --git a/test/integration/proof-of-work.js b/test/integration/proof-of-work.js index 472ddd4e1..7a14a0c9d 100644 --- a/test/integration/proof-of-work.js +++ b/test/integration/proof-of-work.js @@ -55,20 +55,6 @@ describe("Proof-of-work", function() { intermediateProofs[intermediateProofs.length - 1].pow.should.have.property('hash').equal(block.hash); })); - it('should be possible to make the prover make us wait until we trigger it again', () => co(function*() { - let waitPromise = prover.waitForNewAsking(); - return Promise.all([ - waitPromise, - co(function*() { - yield new Promise((resolve) => setTimeout(resolve, 10)); - yield prover.prove({ - issuer: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', - number: 2 - }, MUST_START_WITH_A_ZERO, now); - }) - ]); - })); - // Too randomly successing test // it('should be able to cancel a proof-of-work on other PoW receival', () => co(function*() { // const now = 1474464489; -- GitLab