Browse Source

mm start, stop, rates

v0.25
pbca26 7 years ago
parent
commit
fa5077c938
  1. 9
      main.js
  2. 11
      routes/shepherd.js
  3. 118
      routes/shepherd/dex/mmControl.js

9
main.js

@ -393,10 +393,12 @@ function createWindow(status) {
mainWindow.getAppRuntimeLog = shepherd.getAppRuntimeLog;
mainWindow.nativeCoindList = nativeCoindList;
mainWindow.zcashParamsDownloadLinks = shepherd.zcashParamsDownloadLinks;
mainWindow.isWindows = os.platform() === 'win32' ? true : false;
mainWindow.isWindows = os.platform() === 'win32' ? true : false; // obsolete(?)
mainWindow.appExit = appExit;
mainWindow.getMaxconKMDConf = shepherd.getMaxconKMDConf;
mainWindow.setMaxconKMDConf = shepherd.setMaxconKMDConf;
mainWindow.getMMCacheData = shepherd.getMMCacheData;
mainWindow.activeSection = 'wallets';
if (appConfig.dev) {
mainWindow.loadURL('http://127.0.0.1:3000');
@ -512,8 +514,9 @@ app.on('window-all-closed', function() {
// Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
app.on('before-quit', function(event) {
shepherd.log('before-quit');
shepherd.killRogueProcess('marketmaker');
if (!forceQuitApp &&
/*if (!forceQuitApp &&
mainWindow === null &&
loadingWindow != null) { // mainWindow not intitialised and loadingWindow not dereferenced
// loading window is still open
@ -524,7 +527,7 @@ app.on('before-quit', function(event) {
let code = `$('#loading_status_text').html('Preparing to shutdown the wallet.<br/>Please wait while all daemons are closed...')`;
loadingWindow.webContents.executeJavaScript(code);
event.preventDefault();
}
}*/
});
// Emitted when all windows have been closed and the application will quit.

11
routes/shepherd.js

@ -37,6 +37,17 @@ shepherd.rpcConf = {};
shepherd.appRuntimeLog = [];
shepherd.appRuntimeSPVLog = [];
shepherd.lockDownAddCoin = false;
shepherd.mmupass = null;
shepherd.mmRatesInterval = null;
shepherd.mmPublic = {
coins: [],
mmupass: null,
swaps: [],
bids: [],
asks: [],
isAuth: false,
rates: {},
};
// spv vars and libs
shepherd.electrumCoins = {

118
routes/shepherd/dex/mmControl.js

@ -4,24 +4,108 @@ const portscanner = require('portscanner');
const exec = require('child_process').exec;
const execFile = require('child_process').execFile;
const path = require('path');
const request = require('request');
const Promise = require('bluebird');
const RATES_UPDATE_INTERVAL = 60000;
module.exports = (shepherd) => {
shepherd.get('/mm/start', (req, res, next) => {
shepherd.log('mm start is called');
shepherd.startMarketMaker({ passphrase: req.query.passphrase });
shepherd.mmupass = null;
shepherd.mmupass = setInterval(() => {
const options = {
url: `http://localhost:7783`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ method: 'balance' }),
};
// send back body on both success and error
// this bit replicates iguana core's behaviour
request(options, (error, response, body) => {
if (response &&
response.statusCode &&
response.statusCode === 200) {
const _parsedBody = JSON.parse(body);
if (_parsedBody.userpass) {
res.end(body);
clearInterval(shepherd.mmupass);
shepherd.mmupass = _parsedBody.userpass;
shepherd.mmPublic.mmupass = shepherd.mmupass;
shepherd.mmPublic.isAuth = true;
shepherd.mmPublic.coins = _parsedBody.coins;
shepherd.log(`mm start success`);
shepherd.log(`mm userpass ${_parsedBody.userpass}`);
shepherd.getRates();
}
} else {
shepherd.log(`mm start responded with error ${error}`);
/*res.end(body ? body : JSON.stringify({
result: 'error',
error: {
code: -777,
message: `unable to call method balance at port 7783`,
},
}));*/
}
});
}, 500);
});
const successObj = {
msg: 'success',
result: 'started',
};
shepherd.getRates = () => {
function _getRates() {
const options = {
url: `https://min-api.cryptocompare.com/data/price?fsym=KMD&tsyms=BTC,USD`,
method: 'GET',
};
// send back body on both success and error
// this bit replicates iguana core's behaviour
request(options, (error, response, body) => {
if (response &&
response.statusCode &&
response.statusCode === 200) {
const _parsedBody = JSON.parse(body);
shepherd.log(`rates ${body}`);
shepherd.mmPublic.rates = _parsedBody;
} else {
shepherd.log(`mm unable to retrieve KMD/BTC,USD rate`);
}
});
}
res.end(JSON.stringify(successObj));
});
_getRates();
shepherd.mmRatesInterval = setInterval(() => {
_getRates();
}, RATES_UPDATE_INTERVAL);
}
shepherd.getMMCacheData = () => {
return new Promise((resolve, reject) => {
resolve(shepherd.mmPublic);
});
}
shepherd.get('/mm/stop', (req, res, next) => {
shepherd.log('mm stop is called');
clearInterval(shepherd.mmRatesInterval);
shepherd.killRogueProcess('marketmaker');
shepherd.mmPublic = {
coins: [],
mmupass: null,
swaps: [],
bids: [],
asks: [],
isAuth: false,
rates: {},
};
const successObj = {
msg: 'success',
@ -34,15 +118,25 @@ module.exports = (shepherd) => {
shepherd.get('/mm/restart', (req, res, next) => {
shepherd.log('mm restart is called');
shepherd.killRogueProcess('marketmaker');
shepherd.mmPublic = {
coins: {},
mmupass: null,
swaps: [],
bids: [],
asks: [],
isAuth: false,
};
setTimeout(() => {
shepherd.startMarketMaker({ passphrase: req.query.passphrase });
}, 1000);
const successObj = {
msg: 'success',
result: 'restarting',
};
res.end(JSON.stringify(successObj));
const successObj = {
msg: 'success',
result: 'restarting',
};
res.end(JSON.stringify(successObj));
}, 1000);
});
shepherd.startMarketMaker = (data) => {

Loading…
Cancel
Save