From ce31e82f4416c411c370db848b52ac1ccda7e444 Mon Sep 17 00:00:00 2001 From: emi Date: Thu, 16 Jul 2020 13:57:44 -0600 Subject: [PATCH] Build 1.1.1 --- CHANGELOG.md | 17 +++++++++++++++++ dist/api/api.config.js | 19 +++++++++++++++++++ dist/api/modules/ContractVerification.js | 2 +- dist/lib/config.js | 7 ++++--- dist/lib/defaultConfig.js | 3 ++- dist/services/blocks.config.js | 12 ++++++++++-- dist/services/classes/BlockBalances.js | 7 ++++--- .../userEvents/ContractVerifierModule.js | 6 +++++- package-lock.json | 14 +++++++------- package.json | 2 +- public/swagger.json | 2 +- 11 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 dist/api/api.config.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 272c957c..10ac012a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ # Changelog +## [1.1.1] - 2020-07-16 + +### Changed + +- Default config, remove logging to files as default +- blocksBalances service, get balances one by one. + +### Added + +- Log configuration instructions to README +- config.log.dir as PM2 log folder in blocks.config.js +- api.config.js, PM2 config file to start api + +### Fixed + +- Unhandled promise rejection on API start + ## [1.1.0] - 2020-07-13 ### Added diff --git a/dist/api/api.config.js b/dist/api/api.config.js new file mode 100644 index 00000000..c279ec85 --- /dev/null +++ b/dist/api/api.config.js @@ -0,0 +1,19 @@ +"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.apps = void 0;var _config = _interopRequireDefault(require("../lib/config"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} + +const cwd = `${__dirname}`; +const name = 'explorer-api'; +const script = 'index.js'; +const { log } = _config.default; + +const conf = { script, name, cwd }; + +if (log && log.dir) { + let { dir } = log; + conf.error_file = `${dir}/${name}-error.log`; + conf.out_file = `${dir}/${name}-out.log`; +} + + +const apps = [conf];exports.apps = apps; + +console.log(apps); \ No newline at end of file diff --git a/dist/api/modules/ContractVerification.js b/dist/api/modules/ContractVerification.js index 6f63003d..f6105e20 100644 --- a/dist/api/modules/ContractVerification.js +++ b/dist/api/modules/ContractVerification.js @@ -27,7 +27,7 @@ class ContractVerification extends _DataCollector.DataCollectorItem { * $ref: '#/responses/NotFound' */ getVerifiedContracts: params => { - params.fields = ['address']; + params.fields = { address: 1 }; let query = { match: true }; return this.getPageData(query, params); }, diff --git a/dist/lib/config.js b/dist/lib/config.js index bd836663..8fe2d480 100644 --- a/dist/lib/config.js +++ b/dist/lib/config.js @@ -37,9 +37,10 @@ function makeConfig(config = {}) { config.blocks.source = config.source; // defaults log files - - defaultLogs('api'); - defaultLogs('blocks'); + if (config.log.logToFiles === true) { + defaultLogs('api'); + defaultLogs('blocks'); + } config.api.collectionsNames = config.collectionsNames; return config; diff --git a/dist/lib/defaultConfig.js b/dist/lib/defaultConfig.js index b5374711..62b199cb 100644 --- a/dist/lib/defaultConfig.js +++ b/dist/lib/defaultConfig.js @@ -26,7 +26,8 @@ reduce((a, v, i) => { }, log: { dir: '/var/log/rsk-explorer', - level: 'info' }, + level: 'info', + logToFiles: false }, db: { server: 'localhost', diff --git a/dist/services/blocks.config.js b/dist/services/blocks.config.js index 11b5c23f..64f56c91 100644 --- a/dist/services/blocks.config.js +++ b/dist/services/blocks.config.js @@ -1,15 +1,23 @@ "use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.apps = exports.paths = void 0; -var _servicesConfig = require("./servicesConfig"); +var _config = _interopRequireDefault(require("../lib/config")); +var _servicesConfig = require("./servicesConfig");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} const scripts = Object.values(_servicesConfig.servicesNames); const scriptName = name => `${name}.js`; const cwd = `${__dirname}/blocks/`; +const { log } = _config.default; const paths = scripts.map(name => cwd + scriptName(name));exports.paths = paths; const apps = scripts.map(name => { let script = scriptName(name); - return { name, script, cwd }; + let conf = { name, script, cwd }; + if (log && log.dir) { + let { dir } = log; + conf.error_file = `${dir}/${name}-error.log`; + conf.out_file = `${dir}/${name}-out.log`; + } + return conf; });exports.apps = apps; \ No newline at end of file diff --git a/dist/services/classes/BlockBalances.js b/dist/services/classes/BlockBalances.js index 9551af95..004b6f61 100644 --- a/dist/services/classes/BlockBalances.js +++ b/dist/services/classes/BlockBalances.js @@ -22,13 +22,14 @@ class BlockBalances extends _BcThing.BcThing { try { if (this.balances) return this.balances; let { addresses, blockHash, blockNumber, timestamp } = this; - let balances = await Promise.all(addresses.map(async Addr => { + const balances = []; + for (let Addr of addresses) { let { address } = Addr; let balance = await Addr.getBalance(blockNumber); balance = parseInt(balance) ? balance : 0; let _created = Date.now(); - return { address, balance, blockHash, blockNumber, timestamp, _created }; - })); + balances.push({ address, balance, blockHash, blockNumber, timestamp, _created }); + } this.balances = balances; return this.balances; } catch (err) { diff --git a/dist/services/userEvents/ContractVerifierModule.js b/dist/services/userEvents/ContractVerifierModule.js index 58caf99a..5224fbd6 100644 --- a/dist/services/userEvents/ContractVerifierModule.js +++ b/dist/services/userEvents/ContractVerifierModule.js @@ -30,7 +30,11 @@ function ContractVerifierModule(db, collections, { url } = {}, { log } = {}) { case 'versions': log.debug(`Updating solc versions list`); versions = Object.assign({}, data); - storedConfig.update(versionsId, versions, { create: true }); + // temporal solution to '.' in field names + await storedConfig.update(versionsId, {}, { create: true }); + storedConfig.update(versionsId, versions).catch(err => { + log.warn(err); + }); break; // verification result case 'verify': diff --git a/package-lock.json b/package-lock.json index 32c09c48..91c2c57b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "rsk-explorer-api", - "version": "1.1.0", + "version": "1.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1051,9 +1051,9 @@ } }, "@babel/runtime-corejs2": { - "version": "7.10.4", - "resolved": "https://registry.npmjs.org/@babel/runtime-corejs2/-/runtime-corejs2-7.10.4.tgz", - "integrity": "sha512-9sArmpZDQsnR1yyAcU51DxQrntWxt0LUKjPp3pIyo7kVLfaqKt8muppcT87QmFkXV5H50qXAF8JWOjk0jaXRYA==", + "version": "7.10.5", + "resolved": "https://registry.npmjs.org/@babel/runtime-corejs2/-/runtime-corejs2-7.10.5.tgz", + "integrity": "sha512-LJwyb1ac//Jr2zrGTTaNJhrP1wYCgVw9rzHbQPogKXCTLQ60EEWgeNtuqs6cLsq64O557SYzziCrOxNp0rRi8w==", "requires": { "core-js": "^2.6.5", "regenerator-runtime": "^0.13.4" @@ -1116,9 +1116,9 @@ } }, "@braintree/sanitize-url": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@braintree/sanitize-url/-/sanitize-url-4.0.1.tgz", - "integrity": "sha512-THIQtVN491hY2rTZ/h5boj0CwDKrZQIUnfaj6RbpGwRJKfmEIgNpgcCJC3KZl1Vux9bQmdE2P4Q7cYUoSUQ4MA==" + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@braintree/sanitize-url/-/sanitize-url-4.1.0.tgz", + "integrity": "sha512-YuhkpYEdhJ/6l8sGKEGsRMu+dZ6W/ZZvGWBB07FkKY2Of67SQt2IXjo/F0dWsr+ABm+MyJRx44Spr5yqwH+9LA==" }, "@jsdevtools/ono": { "version": "7.1.2", diff --git a/package.json b/package.json index 98efd554..543cd8ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rsk-explorer-api", - "version": "1.1.0", + "version": "1.1.1", "description": "", "main": "index.js", "scripts": { diff --git a/public/swagger.json b/public/swagger.json index 57537a93..9b525b1e 100644 --- a/public/swagger.json +++ b/public/swagger.json @@ -1,7 +1,7 @@ { "info": { "title": "rsk-explorer-api", - "version": "1.1.0", + "version": "1.1.1", "description": "explorer API Documentation" }, "swagger": "2.0",