From 4c45cd6d727c830609422acdb263f4df116dbcc8 Mon Sep 17 00:00:00 2001 From: zeroxbt <89495162+zeroxbt@users.noreply.github.com> Date: Mon, 4 Apr 2022 12:12:34 +0200 Subject: [PATCH] Fix issues on develop branch (#1888) * add default database name to sequelizeConfig * modify config database name * Updated user configuration update with private key * fix reading of dotenv file Co-authored-by: Djordje Kovacevic --- config/sequelizeConfig.js | 1 + external/libp2p-service.js | 4 ++-- index.js | 1 + models/index.js | 3 ++- modules/command/common/keep-alive-command.js | 7 +------ ot-node.js | 9 +++++++-- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/config/sequelizeConfig.js b/config/sequelizeConfig.js index 3a8e56b1a3..6018c87885 100644 --- a/config/sequelizeConfig.js +++ b/config/sequelizeConfig.js @@ -3,6 +3,7 @@ require('dotenv').config(); module.exports = { username: 'root', password: '', + database: 'operationaldb', dialect: 'mysql', host: 'localhost', port: 3306, diff --git a/external/libp2p-service.js b/external/libp2p-service.js index b87afbd715..deb19bdda3 100644 --- a/external/libp2p-service.js +++ b/external/libp2p-service.js @@ -84,8 +84,8 @@ class Libp2pService { this.config.id = peerId; this.logger.info(`Network ID is ${peerId}, connection port is ${port}`); resolve({ - peerId: id, - privateKey: privKey, + peerId: this.config.peerId, + privateKey: this.config.privateKey, }); }) .catch((err) => { diff --git a/index.js b/index.js index 6d5fd9ac3c..f1e989927a 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +require('dotenv').config(); const fs = require('fs-extra'); const path = require('path'); const appRootPath = require('app-root-path'); diff --git a/models/index.js b/models/index.js index 3f8068eb80..eb40b315fc 100644 --- a/models/index.js +++ b/models/index.js @@ -12,6 +12,7 @@ let sequelize = {}; const OPERATIONAL_DB_NAME = process.env.OPERATIONAL_DB_NAME || 'operationaldb'; const OPERATIONAL_DB_PASSWORD = process.env.OPERATIONAL_DB_PASSWORD || ''; +config.database = OPERATIONAL_DB_NAME; config.password = OPERATIONAL_DB_PASSWORD; const connection = mysql.createConnection({ @@ -25,7 +26,7 @@ connection.query(`CREATE DATABASE IF NOT EXISTS \`${OPERATIONAL_DB_NAME}\`;`); if (config.use_env_variable) { sequelize = new Sequelize(process.env[config.use_env_variable], config); } else { - sequelize = new Sequelize(OPERATIONAL_DB_NAME, config.username, config.password, config); + sequelize = new Sequelize(config.database, config.username, config.password, config); } fs diff --git a/modules/command/common/keep-alive-command.js b/modules/command/common/keep-alive-command.js index 974ab577ec..477337b010 100644 --- a/modules/command/common/keep-alive-command.js +++ b/modules/command/common/keep-alive-command.js @@ -35,13 +35,8 @@ class KeepAliveCommand extends Command { }, }; try { - if (!this.config.network.privateKey) { - const configFile = JSON.parse(fs.readFileSync(this.config.config ? this.config.config : '.origintrail_noderc')); - this.config.network.privateKey = configFile.network.privateKey; - } - const peerId = await PeerId.createFromPrivKey(this.config.network.privateKey); signalingMessage.issuerWallet = this.config.blockchain[0].publicKey; - signalingMessage.kademliaNodeId = peerId._idB58String; + signalingMessage.kademliaNodeId = this.config.network.peerId._idB58String; signalingMessage.nodeVersion = pjson.version; signalingMessage.telemetry.latestAssertions = (await Models.assertions.findAll({ limit: 5, diff --git a/ot-node.js b/ot-node.js index f5d7383798..4036f0f8fc 100644 --- a/ot-node.js +++ b/ot-node.js @@ -135,8 +135,13 @@ class OTNode { const networkService = this.container.resolve('networkService'); const result = await networkService.initialize(); - if (process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test') { - this.savePrivateKeyInUserConfigurationFile(result.privateKey); + this.config.network.peerId = result.peerId; + if (!this.config.network.privateKey + && (this.config.network.privateKey !== result.privateKey)) { + this.config.network.privateKey = result.privateKey; + if (process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test') { + this.savePrivateKeyInUserConfigurationFile(result.privateKey); + } } const rankingService = this.container.resolve('rankingService');