Merge pull request #908 from jessopb/accountBal
updates wallet_balance to account_balance
This commit is contained in:
commit
b19269509a
2 changed files with 98 additions and 66 deletions
|
@ -13,7 +13,7 @@ const httpContext = require('express-http-context');
|
|||
const db = require('./models');
|
||||
const requestLogger = require('./middleware/requestLogger');
|
||||
const createDatabaseIfNotExists = require('./models/utils/createDatabaseIfNotExists');
|
||||
const { getWalletBalance } = require('./lbrynet/index');
|
||||
const { getAccountBalance } = require('./lbrynet/index');
|
||||
const configureLogging = require('./utils/configureLogging');
|
||||
const configureSlack = require('./utils/configureSlack');
|
||||
const { setupBlockList } = require('./utils/blockList');
|
||||
|
@ -27,10 +27,7 @@ const {
|
|||
|
||||
const {
|
||||
details: { port: PORT, blockListEndpoint },
|
||||
startup: {
|
||||
performChecks,
|
||||
performUpdates,
|
||||
},
|
||||
startup: { performChecks, performUpdates },
|
||||
} = require('@config/siteConfig');
|
||||
|
||||
const { sessionKey } = require('@private/authConfig.json');
|
||||
|
@ -53,12 +50,16 @@ function Server () {
|
|||
const webpack = require('webpack');
|
||||
const webpackDevMiddleware = require('webpack-dev-middleware');
|
||||
|
||||
const webpackClientConfig = require('../webpack/webpack.client.config')(null, { mode: 'development' });
|
||||
const webpackClientConfig = require('../webpack/webpack.client.config')(null, {
|
||||
mode: 'development',
|
||||
});
|
||||
const clientCompiler = webpack(webpackClientConfig);
|
||||
|
||||
app.use(webpackDevMiddleware(clientCompiler, {
|
||||
app.use(
|
||||
webpackDevMiddleware(clientCompiler, {
|
||||
publicPath: webpackClientConfig.output.publicPath,
|
||||
}));
|
||||
})
|
||||
);
|
||||
|
||||
app.use(require('webpack-hot-middleware')(clientCompiler));
|
||||
}
|
||||
|
@ -67,8 +68,15 @@ function Server () {
|
|||
app.enable('trust proxy');
|
||||
|
||||
app.use((req, res, next) => {
|
||||
if (req.get('User-Agent') === 'Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120405 Firefox/14.0a1') {
|
||||
res.status(403).send('<h1>Forbidden</h1>If you are seeing this by mistake, please contact us using <a href="https://chat.lbry.io/">https://chat.lbry.io/</a>');
|
||||
if (
|
||||
req.get('User-Agent') ===
|
||||
'Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120405 Firefox/14.0a1'
|
||||
) {
|
||||
res
|
||||
.status(403)
|
||||
.send(
|
||||
'<h1>Forbidden</h1>If you are seeing this by mistake, please contact us using <a href="https://chat.lbry.io/">https://chat.lbry.io/</a>'
|
||||
);
|
||||
res.end();
|
||||
} else {
|
||||
next();
|
||||
|
@ -101,38 +109,45 @@ function Server () {
|
|||
app.use(requestLogger);
|
||||
|
||||
// initialize passport
|
||||
app.use(cookieSession({
|
||||
app.use(
|
||||
cookieSession({
|
||||
name: 'session',
|
||||
keys: [sessionKey],
|
||||
}));
|
||||
})
|
||||
);
|
||||
app.use(speechPassport.initialize());
|
||||
app.use(speechPassport.session());
|
||||
|
||||
// configure handlebars & register it with express app
|
||||
const viewsPath = Path.resolve(process.cwd(), 'server/views');
|
||||
app.engine('handlebars', expressHandlebars({
|
||||
app.engine(
|
||||
'handlebars',
|
||||
expressHandlebars({
|
||||
async: false,
|
||||
dataType: 'text',
|
||||
defaultLayout: 'embed',
|
||||
partialsDir: Path.join(viewsPath, '/partials'),
|
||||
layoutsDir: Path.join(viewsPath, '/layouts'),
|
||||
}));
|
||||
})
|
||||
);
|
||||
app.set('views', viewsPath);
|
||||
app.set('view engine', 'handlebars');
|
||||
|
||||
// set the routes on the app
|
||||
const routes = require('./routes');
|
||||
|
||||
Object.keys(routes).map((routePath) => {
|
||||
Object.keys(routes).map(routePath => {
|
||||
let routeData = routes[routePath];
|
||||
let routeMethod = routeData.hasOwnProperty('method') ? routeData.method : 'get';
|
||||
let controllers = Array.isArray(routeData.controller) ? routeData.controller : [routeData.controller];
|
||||
let controllers = Array.isArray(routeData.controller)
|
||||
? routeData.controller
|
||||
: [routeData.controller];
|
||||
|
||||
app[routeMethod](
|
||||
routePath,
|
||||
logMetricsMiddleware,
|
||||
setRouteDataInContextMiddleware(routePath, routeData),
|
||||
...controllers,
|
||||
...controllers
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -153,8 +168,7 @@ function Server () {
|
|||
};
|
||||
this.syncDatabase = () => {
|
||||
logger.info(`Syncing database...`);
|
||||
return createDatabaseIfNotExists()
|
||||
.then(() => {
|
||||
return createDatabaseIfNotExists().then(() => {
|
||||
db.sequelize.sync();
|
||||
});
|
||||
};
|
||||
|
@ -163,11 +177,8 @@ function Server () {
|
|||
return;
|
||||
}
|
||||
logger.info(`Performing checks...`);
|
||||
return Promise.all([
|
||||
getWalletBalance(),
|
||||
])
|
||||
.then(([walletBalance]) => {
|
||||
logger.info('Starting LBC balance:', walletBalance);
|
||||
return Promise.all([getAccountBalance()]).then(([accountBalance]) => {
|
||||
logger.info('Starting LBC balance:', accountBalance);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -178,24 +189,26 @@ function Server () {
|
|||
if (blockListEndpoint) {
|
||||
finalBlockListEndpoint = blockListEndpoint;
|
||||
} else if (!blockListEndpoint) {
|
||||
if (typeof (blockListEndpoint) !== 'string') {
|
||||
logger.warn('blockListEndpoint is null due to outdated siteConfig file. \n' +
|
||||
if (typeof blockListEndpoint !== 'string') {
|
||||
logger.warn(
|
||||
'blockListEndpoint is null due to outdated siteConfig file. \n' +
|
||||
'Continuing with default LBRY blocklist api endpoint. \n ' +
|
||||
'(Specify /"blockListEndpoint" : ""/ to disable.');
|
||||
'(Specify /"blockListEndpoint" : ""/ to disable.'
|
||||
);
|
||||
finalBlockListEndpoint = 'https://api.lbry.io/file/list_blocked';
|
||||
}
|
||||
}
|
||||
logger.info(`Peforming updates...`);
|
||||
if (!finalBlockListEndpoint) {
|
||||
logger.info('Configured for no Block List');
|
||||
db.Tor.refreshTable().then((updatedTorList) => {
|
||||
db.Tor.refreshTable().then(updatedTorList => {
|
||||
logger.info('Tor list updated, length:', updatedTorList.length);
|
||||
});
|
||||
} else {
|
||||
return Promise.all([
|
||||
db.Blocked.refreshTable(finalBlockListEndpoint),
|
||||
db.Tor.refreshTable()])
|
||||
.then(([updatedBlockedList, updatedTorList]) => {
|
||||
db.Tor.refreshTable(),
|
||||
]).then(([updatedBlockedList, updatedTorList]) => {
|
||||
logger.info('Blocked list updated, length:', updatedBlockedList.length);
|
||||
logger.info('Tor list updated, length:', updatedTorList.length);
|
||||
});
|
||||
|
@ -210,10 +223,7 @@ function Server () {
|
|||
return this.startServerListening();
|
||||
})
|
||||
.then(() => {
|
||||
return Promise.all([
|
||||
this.performChecks(),
|
||||
this.performUpdates(),
|
||||
]);
|
||||
return Promise.all([this.performChecks(), this.performUpdates()]);
|
||||
})
|
||||
.then(() => {
|
||||
return setupBlockList();
|
||||
|
|
|
@ -18,7 +18,13 @@ module.exports = {
|
|||
params: publishParams,
|
||||
})
|
||||
.then(response => {
|
||||
sendGATimingEvent('lbrynet', 'publish', chooseGaLbrynetPublishLabel(publishParams), gaStartTime, Date.now());
|
||||
sendGATimingEvent(
|
||||
'lbrynet',
|
||||
'publish',
|
||||
chooseGaLbrynetPublishLabel(publishParams),
|
||||
gaStartTime,
|
||||
Date.now()
|
||||
);
|
||||
handleLbrynetResponse(response, resolve, reject);
|
||||
})
|
||||
.catch(error => {
|
||||
|
@ -97,9 +103,11 @@ module.exports = {
|
|||
db.Claim.findOne({ where: { claimId: uri.split('#')[1] } })
|
||||
.then(() => reject('This claim has not yet been confirmed on the LBRY blockchain'))
|
||||
.catch(() => reject(`Claim ${uri} does not exist`));
|
||||
} else if (data.result[uri].error) { // check for errors
|
||||
} else if (data.result[uri].error) {
|
||||
// check for errors
|
||||
reject(data.result[uri].error);
|
||||
} else { // if no errors, resolve
|
||||
} else {
|
||||
// if no errors, resolve
|
||||
resolve(data.result[uri]);
|
||||
}
|
||||
})
|
||||
|
@ -117,11 +125,19 @@ module.exports = {
|
|||
method: 'settings_get',
|
||||
})
|
||||
.then(({ data }) => {
|
||||
sendGATimingEvent('lbrynet', 'getDownloadDirectory', 'SETTINGS_GET', gaStartTime, Date.now());
|
||||
sendGATimingEvent(
|
||||
'lbrynet',
|
||||
'getDownloadDirectory',
|
||||
'SETTINGS_GET',
|
||||
gaStartTime,
|
||||
Date.now()
|
||||
);
|
||||
if (data.result) {
|
||||
resolve(data.result.download_directory);
|
||||
} else {
|
||||
return new Error('Successfully connected to lbry daemon, but unable to retrieve the download directory.');
|
||||
return new Error(
|
||||
'Successfully connected to lbry daemon, but unable to retrieve the download directory.'
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
|
@ -151,15 +167,21 @@ module.exports = {
|
|||
});
|
||||
});
|
||||
},
|
||||
getWalletBalance () {
|
||||
getAccountBalance() {
|
||||
const gaStartTime = Date.now();
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(lbrynetUri, {
|
||||
method: 'wallet_balance',
|
||||
method: 'account_balance',
|
||||
})
|
||||
.then(response => {
|
||||
sendGATimingEvent('lbrynet', 'getWalletBalance', 'SETTINGS_GET', gaStartTime, Date.now());
|
||||
sendGATimingEvent(
|
||||
'lbrynet',
|
||||
'getAccountBalance',
|
||||
'SETTINGS_GET',
|
||||
gaStartTime,
|
||||
Date.now()
|
||||
);
|
||||
handleLbrynetResponse(response, resolve, reject);
|
||||
})
|
||||
.catch(error => {
|
||||
|
|
Loading…
Reference in a new issue