Skip to content

Commit

Permalink
Fix issues on develop branch (#1888)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
zeroxbt and djordjekovac authored Apr 4, 2022
1 parent a9b73fb commit 4c45cd6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions config/sequelizeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require('dotenv').config();
module.exports = {
username: 'root',
password: '',
database: 'operationaldb',
dialect: 'mysql',
host: 'localhost',
port: 3306,
Expand Down
4 changes: 2 additions & 2 deletions external/libp2p-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('dotenv').config();
const fs = require('fs-extra');
const path = require('path');
const appRootPath = require('app-root-path');
Expand Down
3 changes: 2 additions & 1 deletion models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
Expand Down
7 changes: 1 addition & 6 deletions modules/command/common/keep-alive-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 4c45cd6

Please sign in to comment.