diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f87492c..78e0927d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [1.1.4] - 2020-08-06 + +### Updated + +- Db.createCollection to the new mongodb driver behavior +- blocks checker service, delay before start. +- config: disable services in config + ## [1.1.3] - 2020-08-04 This release requires the regeneration of the DB follow the instructions in [UPDATES.md](UPDATES.md) before starting. diff --git a/dist/dbPatches/tokenAccountBalances.js b/dist/dbPatches/tokenAccountBalances.js index 4406ec07..dedfcf6e 100644 --- a/dist/dbPatches/tokenAccountBalances.js +++ b/dist/dbPatches/tokenAccountBalances.js @@ -2,7 +2,7 @@ var _dataSource = _interopRequireDefault(require("../lib/dataSource.js")); var _nod3Connect = _interopRequireDefault(require("../lib/nod3Connect")); var _rskContractParser = _interopRequireDefault(require("rsk-contract-parser")); -var _rskUtils = require("rsk-utils");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} +var _rskUtils = require("@rsksmart/rsk-utils");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} const parser = new _rskContractParser.default({ nod3: _nod3Connect.default }); diff --git a/dist/lib/Db.js b/dist/lib/Db.js index 04e34b0d..8fec06d3 100644 --- a/dist/lib/Db.js +++ b/dist/lib/Db.js @@ -54,7 +54,10 @@ class Db { try { const db = await this.db(); if (!collectionName) throw new Error('Invalid collection name'); - let collection = await db.createCollection(collectionName, options); + let list = await db.listCollections({}, { nameOnly: true }).toArray(); + let exists = list.find(c => c.name === collectionName); + if (!exists) await db.createCollection(collectionName, options); + let collection = db.collection(collectionName); if (dropIndexes) { this.log.info(`Removing indexes from ${collectionName}`); await collection.dropIndexes(); @@ -63,16 +66,18 @@ class Db { this.log.info(`Creating indexes to ${collectionName}`); await collection.createIndexes(indexes); } - if (validate) { - this.log.info(`Validating collection: ${collectionName}`); - await db.admin().validateCollection(collectionName); - } + if (validate) await this.validateCollection(db, collectionName); return collection; } catch (err) { return Promise.reject(err); } } + validateCollection(db, collectionName) { + this.log.info(`Validating collection: ${collectionName}`); + return db.admin().validateCollection(collectionName); + } + createCollections(collections, creationOptions = {}) { let queue = []; let names = creationOptions.names || {}; diff --git a/dist/lib/config.js b/dist/lib/config.js index 8fe2d480..a64a1938 100644 --- a/dist/lib/config.js +++ b/dist/lib/config.js @@ -32,6 +32,13 @@ function makeConfig(config = {}) { config.api.modules[module] = config.api.modules[module] !== false; } + // defaults services + const services = config.blocks.services || {}; + for (let s in _defaultConfig.default.blocks.services) { + services[s] = config.blocks.services[s] !== false; + } + services.ROUTER = true; + config.blocks.services = services; // defaults servers/ports config.source = nodeSources(config.source); config.blocks.source = config.source; diff --git a/dist/lib/defaultConfig.js b/dist/lib/defaultConfig.js index f7e12773..4ff1497e 100644 --- a/dist/lib/defaultConfig.js +++ b/dist/lib/defaultConfig.js @@ -3,10 +3,16 @@ var _types = require("./types"); -var _delayedFields = _interopRequireDefault(require("./delayedFields"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /** - * This file provides default values, - * use /config.json, to overwrite settings - */const setAllModules = (status) => Object.keys(_types.MODULES). +var _delayedFields = _interopRequireDefault(require("./delayedFields")); +var _servicesConfig = require("../services/servicesConfig");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /** + * This file provides default values, + * use /config.json, to overwrite settings + */const services = Object.assign({}, _servicesConfig.servicesNames);for (let s in services) { + services[s] = true; +} + +const setAllModules = (status) => +Object.keys(_types.MODULES). reduce((a, v, i) => { a[v] = status; return a; @@ -56,7 +62,8 @@ reduce((a, v, i) => { debug: false, updateTokenBalances: true, // Update token accounts balances on next block ports: [3010], // list of services ports, if the list runs out, the services will try to take the next ports starting from the last - address: '127.0.0.1' }, + address: '127.0.0.1', + services }, collectionsNames: { Config: 'config', diff --git a/dist/lib/utils.js b/dist/lib/utils.js index 51cc7714..d2083cd5 100644 --- a/dist/lib/utils.js +++ b/dist/lib/utils.js @@ -1,7 +1,7 @@ "use strict";Object.defineProperty(exports, "__esModule", { value: true });var _exportNames = { bigNumberDoc: true, isBigNumber: true, serializeBigNumber: true, isSerializedBigNumber: true, unSerializeBigNumber: true, bigNumberToSring: true, bigNumberSum: true, bigNumberDifference: true, newBigNumber: true, isObj: true, serialize: true, checkBlockHash: true, isBlockHash: true, blockQuery: true, getBestBlock: true, applyDecimals: true, isValidBlockNumber: true, isBlockObject: true, toAscii: true, quantityMarks: true, chunkArray: true, hash: true };exports.hash = exports.chunkArray = exports.quantityMarks = exports.toAscii = exports.isBlockObject = exports.isValidBlockNumber = exports.applyDecimals = exports.getBestBlock = exports.blockQuery = exports.isBlockHash = exports.checkBlockHash = exports.serialize = exports.isObj = exports.newBigNumber = exports.bigNumberDifference = exports.bigNumberSum = exports.bigNumberToSring = exports.unSerializeBigNumber = exports.isSerializedBigNumber = exports.serializeBigNumber = exports.isBigNumber = exports.bigNumberDoc = void 0;var _bignumber = require("bignumber.js"); var _types = require("./types"); var _mongodb = require("mongodb"); -var _rskUtils = require("rsk-utils"); +var _rskUtils = require("@rsksmart/rsk-utils"); Object.keys(_rskUtils).forEach(function (key) {if (key === "default" || key === "__esModule") return;if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;Object.defineProperty(exports, key, { enumerable: true, get: function () {return _rskUtils[key];} });});var _crypto = _interopRequireDefault(require("crypto"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} diff --git a/dist/services/blocks.config.js b/dist/services/blocks.config.js index 64f56c91..97dc11d5 100644 --- a/dist/services/blocks.config.js +++ b/dist/services/blocks.config.js @@ -1,8 +1,11 @@ "use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.apps = exports.paths = void 0; var _config = _interopRequireDefault(require("../lib/config")); var _servicesConfig = require("./servicesConfig");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} +const { services } = _config.default.blocks; -const scripts = Object.values(_servicesConfig.servicesNames); +const scripts = Object.entries(_servicesConfig.servicesNames). +filter(([service]) => services[service]). +map(([service, name]) => name); const scriptName = name => `${name}.js`; diff --git a/dist/services/blocks/blocksChecker.js b/dist/services/blocks/blocksChecker.js index 6491e7d2..53090c18 100644 --- a/dist/services/blocks/blocksChecker.js +++ b/dist/services/blocks/blocksChecker.js @@ -22,7 +22,7 @@ async function main() { const { startService, service } = await (0, _serviceFactory.createService)(serviceConfig, executor, { log }); const { emit } = service; await startService(); - checker.start(emit); + setTimeout(() => checker.start(emit), 5000); } catch (err) { console.error(err); process.exit(9); diff --git a/dist/services/classes/Address.js b/dist/services/classes/Address.js index d03c7d2e..54acfe6c 100644 --- a/dist/services/classes/Address.js +++ b/dist/services/classes/Address.js @@ -5,7 +5,7 @@ var _Contract = _interopRequireDefault(require("./Contract")); var _rskContractParser = require("rsk-contract-parser"); var _Tx = require("./Tx"); var _InternalTx = require("./InternalTx"); -var _rskUtils = require("rsk-utils");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} +var _rskUtils = require("@rsksmart/rsk-utils");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} class Address extends _BcThing.BcThing { constructor(address, { nod3, initConfig, collections, tx, block, log } = {}) { diff --git a/dist/services/classes/TokenAddress.js b/dist/services/classes/TokenAddress.js index d5e47877..99a2bea0 100644 --- a/dist/services/classes/TokenAddress.js +++ b/dist/services/classes/TokenAddress.js @@ -1,7 +1,7 @@ "use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = exports.TokenAddress = void 0;var _BcThing = require("./BcThing"); var _Contract = _interopRequireDefault(require("./Contract")); var _utils = require("../../lib/utils"); -var _rskUtils = require("rsk-utils");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} +var _rskUtils = require("@rsksmart/rsk-utils");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} class TokenAddress extends _BcThing.BcThing { constructor(address, contract) { diff --git a/dist/services/classes/UpdateTokenAccountBalances.js b/dist/services/classes/UpdateTokenAccountBalances.js index 3d09bfd4..477c0493 100644 --- a/dist/services/classes/UpdateTokenAccountBalances.js +++ b/dist/services/classes/UpdateTokenAccountBalances.js @@ -1,5 +1,5 @@ "use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.updateTokenAccountBalances = updateTokenAccountBalances; -var _rskUtils = require("rsk-utils"); +var _rskUtils = require("@rsksmart/rsk-utils"); var _rskContractParser = _interopRequireDefault(require("rsk-contract-parser"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} async function updateTokenAccountBalances(block, { nod3, collections, log }) { diff --git a/package-lock.json b/package-lock.json index a646e488..bf4d4cae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "rsk-explorer-api", - "version": "1.1.3", + "version": "1.1.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 53b18284..c57369d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rsk-explorer-api", - "version": "1.1.3", + "version": "1.1.4", "description": "", "main": "index.js", "scripts": { diff --git a/public/swagger.json b/public/swagger.json index cf51a8e2..575bd8ed 100644 --- a/public/swagger.json +++ b/public/swagger.json @@ -1,7 +1,7 @@ { "info": { "title": "rsk-explorer-api", - "version": "1.1.3", + "version": "1.1.4", "description": "explorer API Documentation" }, "swagger": "2.0",