Browse Source

dex mm control

v0.25
pbca26 7 years ago
parent
commit
e5989333ca
  1. 1
      main.js
  2. 5
      package.json
  3. 1
      routes/shepherd.js
  4. 1
      routes/shepherd/dex/coins.json
  5. 142
      routes/shepherd/dex/mmControl.js
  6. 14
      routes/shepherd/dex/mmRequest.js
  7. 66
      routes/shepherd/paths.js
  8. 2
      version
  9. 2
      version_build

1
main.js

@ -476,6 +476,7 @@ function createWindow(status) {
let _appClosingInterval;
shepherd.killRogueProcess('marketmaker');
if (!Object.keys(shepherd.coindInstanceRegistry).length ||
!appConfig.stopNativeDaemonsOnQuit) {
closeApp();

5
package.json

@ -21,7 +21,7 @@
"author": "SuperNET",
"license": "MIT",
"devDependencies": {
"electron": "^1.6.15",
"electron": "1.6.5",
"electron-installer-debian": "^0.6.0",
"electron-installer-redhat": "^0.5.0"
},
@ -33,10 +33,11 @@
"buffer-reverse": "^1.0.1",
"coinkey": "^2.0.0",
"coinselect": "github:bitcoinjs/coinselect",
"marketmaker": "git://github.com/pbca26/marketmaker",
"electron": "1.6.5",
"express": "^4.14.0",
"fix-path": "^2.1.0",
"fs-extra": "^1.0.0",
"fs-extra": "^4.0.2",
"graceful-fs": "^4.1.11",
"js-sha256": "^0.7.1",
"nodejs-aes256": "^1.0.1",

1
routes/shepherd.js

@ -86,6 +86,7 @@ shepherd = require('./shepherd/electrum/estimate.js')(shepherd);
// dex
shepherd = require('./shepherd/dex/coind.js')(shepherd);
shepherd = require('./shepherd/dex/mmControl.js')(shepherd);
// core
shepherd = require('./shepherd/addCoinShortcuts.js')(shepherd);

1
routes/shepherd/dex/coins.json

File diff suppressed because one or more lines are too long

142
routes/shepherd/dex/mmControl.js

@ -0,0 +1,142 @@
const os = require('os');
const fs = require('fs-extra');
const portscanner = require('portscanner');
const exec = require('child_process').exec;
const execFile = require('child_process').execFile;
const path = require('path');
module.exports = (shepherd) => {
shepherd.get('/mm/start', (req, res, next) => {
shepherd.log('mm start is called');
shepherd.startMarketMaker({ passphrase: req.query.passphrase });
const successObj = {
msg: 'success',
result: 'started',
};
res.end(JSON.stringify(successObj));
});
shepherd.get('/mm/stop', (req, res, next) => {
shepherd.log('mm stop is called');
shepherd.killRogueProcess('marketmaker');
const successObj = {
msg: 'success',
result: 'executed',
};
res.end(JSON.stringify(successObj));
});
shepherd.get('/mm/restart', (req, res, next) => {
shepherd.log('mm restart is called');
shepherd.killRogueProcess('marketmaker');
setTimeout(() => {
shepherd.startMarketMaker({ passphrase: req.query.passphrase });
}, 1000);
const successObj = {
msg: 'success',
result: 'restarting',
};
res.end(JSON.stringify(successObj));
});
shepherd.startMarketMaker = (data) => {
const defaultCoinsListFile = path.join(__dirname, '../dex/coins.json');
try {
// check if marketmaker instance is already running
portscanner.checkPortStatus(7783, '127.0.0.1', (error, status) => {
// Status is 'open' if currently in use or 'closed' if available
if (status === 'closed') {
// add BarterDEX check
const _coinsListFile = shepherd.agamaDir + '/coins.json';
fs.pathExists(_coinsListFile, (err, exists) => {
if (exists) {
shepherd.log('dex coins file exist');
data.coinslist = fs.readJsonSync(_coinsListFile, { throws: false });
shepherd.execMarketMaker(data);
} else if (!exists) {
shepherd.log(`dex coins file doesnt exist`);
fs.copy(defaultCoinsListFile, _coinsListFile)
.then(() => {
shepherd.log(`dex coins file copied to ${shepherd.agamaDir}`);
data.coinslist = fs.readJsonSync(_coinsListFile, { throws: false });
shepherd.execMarketMaker(data);
})
.catch(err => {
shepherd.log(`unable to copy dex coins file, ${err}`);
});
} else if (err) {
shepherd.log(`dex coins file doesnt exist, ${err}`);
}
});
} else {
shepherd.log(`port 7783 marketmaker is already in use`);
}
});
} catch(e) {
shepherd.log(`failed to start marketmaker err: ${e}`);
}
}
shepherd.execMarketMaker = (data) => {
const _customParam = {
gui: 'agama-buildog',
client: 1,
profitmargin: 0.01, // (?)
userhome: `${process.env.HOME}`,
passphrase: data.passphrase,
coins: data.coinslist,
};
//console.log(JSON.stringify(_customParam))
//console.log(`exec ${BarterDEXBin} ${JSON.stringify(_customParam)}`);
let params = _customParam;
if (os.platform() !== 'win32') {
params = `'${JSON.stringify(_customParam)}'`;
} else {
shepherd.mmBin = `"${shepherd.mmBin}"`;
params.userhome = process.env.APPDATA;
if (!!params.coins) { // if not undefined and true
delete params.coins; // for Windows we should use coins.json file, and don't pass coins in command line
}
params = JSON.stringify(_customParam);
params = params.replace(/"/g, '\\"');
params = `"${params}"`;
}
const logStream = fs.createWriteStream(`${shepherd.agamaDir}/logFile.log`, { flags: 'a' });
shepherd.log('starting mm');
const mmid = exec(`${shepherd.mmBin} ${params}`, {
cwd: shepherd.agamaDir,
maxBuffer: 1024 * 50000 // 50 mb
}, function(error, stdout, stderr) {
// console.log(`stdout: ${stdout}`);
// console.log(`stderr: ${stderr}`);
if (error !== null) {
shepherd.log(`mm exec error: ${error}`);
}
});
mmid.stdout.on('data', (data) => {
// console.log(`child stdout:\n${data}`);
}).pipe(logStream);
mmid.stderr.on('data', (data) => {
// console.error(`child stderr:\n${data}`);
}).pipe(logStream);
}
return shepherd;
};

14
routes/shepherd/dex/mmRequest.js

@ -0,0 +1,14 @@
module.exports = (shepherd) => {
// payload
// record all calls
shepherd.get('/mm/request', (req, res, next) => {
const successObj = {
msg: 'success',
result: 'started',
};
res.end(JSON.stringify(successObj));
});
return shepherd;
};

66
routes/shepherd/paths.js

@ -1,8 +1,12 @@
const path = require('path');
const fixPath = require('fix-path');
const os = require('os');
module.exports = (shepherd) => {
shepherd.pathsAgama = () => {
switch (shepherd.os.platform()) {
switch (os.platform()) {
case 'darwin':
shepherd.fixPath();
fixPath();
shepherd.agamaDir = `${process.env.HOME}/Library/Application Support/Agama`;
break;
@ -12,60 +16,64 @@ module.exports = (shepherd) => {
case 'win32':
shepherd.agamaDir = `${process.env.APPDATA}/Agama`;
shepherd.agamaDir = shepherd.path.normalize(shepherd.agamaDir);
shepherd.agamaDir = path.normalize(shepherd.agamaDir);
break;
}
}
shepherd.pathsDaemons = () => {
switch (shepherd.os.platform()) {
switch (os.platform()) {
case 'darwin':
shepherd.fixPath();
fixPath();
shepherd.agamaTestDir = `${process.env.HOME}/Library/Application Support/Agama/test`,
shepherd.komododBin = shepherd.path.join(__dirname, '../../assets/bin/osx/komodod'),
shepherd.komodocliBin = shepherd.path.join(__dirname, '../../assets/bin/osx/komodo-cli'),
shepherd.komododBin = path.join(__dirname, '../../assets/bin/osx/komodod'),
shepherd.komodocliBin = path.join(__dirname, '../../assets/bin/osx/komodo-cli'),
shepherd.komodoDir = shepherd.appConfig.dataDir.length ? shepherd.appConfig.dataDir : `${process.env.HOME}/Library/Application Support/Komodo`,
shepherd.zcashdBin = '/Applications/ZCashSwingWalletUI.app/Contents/MacOS/zcashd',
shepherd.zcashcliBin = '/Applications/ZCashSwingWalletUI.app/Contents/MacOS/zcash-cli',
shepherd.zcashDir = `${process.env.HOME}/Library/Application Support/Zcash`,
shepherd.zcashParamsDir = `${process.env.HOME}/Library/Application Support/ZcashParams`,
shepherd.chipsBin = shepherd.path.join(__dirname, '../../assets/bin/osx/chipsd'),
shepherd.chipscliBin = shepherd.path.join(__dirname, '../../assets/bin/osx/chips-cli'),
shepherd.chipsBin = path.join(__dirname, '../../assets/bin/osx/chipsd'),
shepherd.chipscliBin = path.join(__dirname, '../../assets/bin/osx/chips-cli'),
shepherd.chipsDir = `${process.env.HOME}/Library/Application Support/Chips`,
shepherd.coindRootDir = shepherd.path.join(__dirname, '../../assets/bin/osx/dex/coind');
shepherd.coindRootDir = path.join(__dirname, '../../assets/bin/osx/dex/coind'),
shepherd.mmBin = path.join(__dirname, '../../node_modules/marketmaker/bin/darwin/x64/marketmaker');
break;
case 'linux':
shepherd.agamaTestDir = `${process.env.HOME}/.agama/test`,
shepherd.komododBin = shepherd.path.join(__dirname, '../../assets/bin/linux64/komodod'),
shepherd.komodocliBin = shepherd.path.join(__dirname, '../../assets/bin/linux64/komodo-cli'),
shepherd.komododBin = path.join(__dirname, '../../assets/bin/linux64/komodod'),
shepherd.komodocliBin = path.join(__dirname, '../../assets/bin/linux64/komodo-cli'),
shepherd.komodoDir = shepherd.appConfig.dataDir.length ? shepherd.appConfig.dataDir : `${process.env.HOME}/.komodo`,
shepherd.zcashParamsDir = `${process.env.HOME}/.zcash-params`,
shepherd.chipsBin = shepherd.path.join(__dirname, '../../assets/bin/linux64/chipsd'),
shepherd.chipscliBin = shepherd.path.join(__dirname, '../../assets/bin/linux64/chips-cli'),
shepherd.chipsBin = path.join(__dirname, '../../assets/bin/linux64/chipsd'),
shepherd.chipscliBin = path.join(__dirname, '../../assets/bin/linux64/chips-cli'),
shepherd.chipsDir = `${process.env.HOME}/.chips`,
shepherd.coindRootDir = shepherd.path.join(__dirname, '../../assets/bin/linux64/dex/coind');
shepherd.coindRootDir = path.join(__dirname, '../../assets/bin/linux64/dex/coind'),
shepherd.mmBin = path.join(__dirname, '../../node_modules/marketmaker/bin/linux/x64/marketmaker');
break;
case 'win32':
shepherd.agamaTestDir = `${process.env.APPDATA}/Agama/test`;
shepherd.agamaTestDir = shepherd.path.normalize(shepherd.agamaTestDir);
shepherd.komododBin = shepherd.path.join(__dirname, '../../assets/bin/win64/komodod.exe'),
shepherd.komododBin = shepherd.path.normalize(shepherd.komododBin),
shepherd.komodocliBin = shepherd.path.join(__dirname, '../../assets/bin/win64/komodo-cli.exe'),
shepherd.komodocliBin = shepherd.path.normalize(shepherd.komodocliBin),
shepherd.agamaTestDir = path.normalize(shepherd.agamaTestDir);
shepherd.komododBin = path.join(__dirname, '../../assets/bin/win64/komodod.exe'),
shepherd.komododBin = path.normalize(shepherd.komododBin),
shepherd.komodocliBin = path.join(__dirname, '../../assets/bin/win64/komodo-cli.exe'),
shepherd.komodocliBin = path.normalize(shepherd.komodocliBin),
shepherd.komodoDir = shepherd.appConfig.dataDir.length ? shepherd.appConfig.dataDir : `${process.env.APPDATA}/Komodo`,
shepherd.komodoDir = shepherd.path.normalize(shepherd.komodoDir);
shepherd.chipsBin = shepherd.path.join(__dirname, '../../assets/bin/win64/chipsd.exe'),
shepherd.chipsBin = shepherd.path.normalize(shepherd.chipsBin),
shepherd.chipscliBin = shepherd.path.join(__dirname, '../../assets/bin/win64/chips-cli.exe'),
shepherd.chipscliBin = shepherd.path.normalize(shepherd.chipscliBin),
shepherd.komodoDir = path.normalize(shepherd.komodoDir);
shepherd.chipsBin = path.join(__dirname, '../../assets/bin/win64/chipsd.exe'),
shepherd.chipsBin = path.normalize(shepherd.chipsBin),
shepherd.chipscliBin = path.join(__dirname, '../../assets/bin/win64/chips-cli.exe'),
shepherd.chipscliBin = path.normalize(shepherd.chipscliBin),
shepherd.chipsDir = `${process.env.APPDATA}/Chips`,
shepherd.chipsDir = shepherd.path.normalize(shepherd.chipsDir);
shepherd.chipsDir = path.normalize(shepherd.chipsDir);
shepherd.zcashParamsDir = `${process.env.APPDATA}/ZcashParams`;
shepherd.zcashParamsDir = shepherd.path.normalize(shepherd.zcashParamsDir);
shepherd.coindRootDir = shepherd.path.join(__dirname, '../../assets/bin/osx/dex/coind');
shepherd.coindRootDir = shepherd.path.normalize(shepherd.coindRootDir);
shepherd.zcashParamsDir = path.normalize(shepherd.zcashParamsDir);
shepherd.coindRootDir = path.join(__dirname, '../../assets/bin/osx/dex/coind');
shepherd.coindRootDir = path.normalize(shepherd.coindRootDir);
shepherd.mmBin = path.join(__dirname, '../../node_modules/marketmaker/bin/win32/x64/marketmaker.exe');
shepherd.mmBin = path.normalize(shepherd.mmBin);
break;
}
}

2
version

@ -1,3 +1,3 @@
version=0.2.0.24g
version=0.2.0.25a
type=e-beta
minversion=0.2.0.2

2
version_build

@ -1 +1 @@
0.2.0.24g-beta
0.2.0.25a-beta
Loading…
Cancel
Save