added check for lbrynet via startup wallet balance check

This commit is contained in:
bill bittner 2018-05-17 18:11:22 -07:00
parent 10c6fb611f
commit 8118d5b196
3 changed files with 29 additions and 4 deletions

View file

@ -14,6 +14,7 @@ const mysqlConfig = require('./config/mysqlConfig.js');
const siteConfig = require('./config/siteConfig.js'); const siteConfig = require('./config/siteConfig.js');
const slackConfig = require('./config/slackConfig.js'); const slackConfig = require('./config/slackConfig.js');
const createDatabaseIfNotExists = require('./server/models/utils/createDatabaseIfNotExists.js'); const createDatabaseIfNotExists = require('./server/models/utils/createDatabaseIfNotExists.js');
const { getWalletBalance } = require('./server/lbrynet');
function Server () { function Server () {
this.configureLogger = loggerConfig.update; this.configureLogger = loggerConfig.update;
@ -83,6 +84,10 @@ function Server () {
const PORT = siteConfig.details.port; const PORT = siteConfig.details.port;
// sync sequelize // sync sequelize
createDatabaseIfNotExists() createDatabaseIfNotExists()
getWalletBalance()
.then(balance => {
logger.info('starting LBC balance:', balance);
})
.then(() => { .then(() => {
db.sequelize.sync() db.sequelize.sync()
}) })
@ -92,8 +97,13 @@ function Server () {
logger.info(`Server is listening on PORT ${PORT}`); logger.info(`Server is listening on PORT ${PORT}`);
}); });
}) })
.catch((error) => { .catch(error => {
logger.error(`Startup Error:`, error); if (error.code === 'ECONNREFUSED') {
return logger.error('Connection refused. The daemon may not be running.')
} else if (error.message) {
logger.error(error.message);
}
logger.error(error);
}); });
}; };
}; };

View file

@ -125,4 +125,20 @@ module.exports = {
}); });
}); });
}, },
getWalletBalance () {
const gaStartTime = Date.now();
return new Promise((resolve, reject) => {
axios
.post(lbrynetUri, {
method: 'wallet_balance',
})
.then(response => {
sendGATimingEvent('lbrynet', 'getWalletBalance', 'SETTINGS_GET', gaStartTime, Date.now());
handleLbrynetResponse(response, resolve, reject);
})
.catch(error => {
reject(error);
});
});
},
}; };

View file

@ -4,10 +4,9 @@ const createDatabaseIfNotExists = () => {
const {database, username, password} = require('../../../config/mysqlConfig.js'); const {database, username, password} = require('../../../config/mysqlConfig.js');
const sequelize = new Sequelize('', username, password, { const sequelize = new Sequelize('', username, password, {
dialect : 'mysql', dialect : 'mysql',
logging : true, logging : false,
operatorsAliases: false, operatorsAliases: false,
}); });
console.log('username:', username, 'password:', password);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
sequelize.query(`CREATE DATABASE IF NOT EXISTS ${database};`) sequelize.query(`CREATE DATABASE IF NOT EXISTS ${database};`)
.then(() => { .then(() => {