Browse Source

dex request, cache

v0.25
pbca26 7 years ago
parent
commit
718835c7fb
  1. 4
      routes/shepherd.js
  2. 6
      routes/shepherd/dex/mmControl.js
  3. 35
      routes/shepherd/dex/mmRequest.js

4
routes/shepherd.js

@ -47,6 +47,9 @@ shepherd.mmPublic = {
asks: [],
isAuth: false,
rates: {},
prices: [],
coinsHelper: [],
stats: [],
};
// spv vars and libs
@ -98,6 +101,7 @@ shepherd = require('./shepherd/electrum/estimate.js')(shepherd);
// dex
shepherd = require('./shepherd/dex/coind.js')(shepherd);
shepherd = require('./shepherd/dex/mmControl.js')(shepherd);
shepherd = require('./shepherd/dex/mmRequest.js')(shepherd);
// core
shepherd = require('./shepherd/addCoinShortcuts.js')(shepherd);

6
routes/shepherd/dex/mmControl.js

@ -43,6 +43,7 @@ module.exports = (shepherd) => {
shepherd.mmPublic.coins = _parsedBody.coins;
shepherd.log(`mm start success`);
shepherd.log(`mm userpass ${_parsedBody.userpass}`);
shepherd.getCoinsHelper();
shepherd.getRates();
}
} else {
@ -59,6 +60,11 @@ module.exports = (shepherd) => {
}, 500);
});
shepherd.getCoinsHelper = () => {
const defaultCoinsListFile = path.join(__dirname, '../dex/coins.json');
shepherd.mmPublic.coinsHelper = fs.readJsonSync(defaultCoinsListFile, { throws: false });
}
shepherd.getRates = () => {
function _getRates() {
const options = {

35
routes/shepherd/dex/mmRequest.js

@ -1,13 +1,38 @@
const request = require('request');
module.exports = (shepherd) => {
// payload
// record all calls
shepherd.get('/mm/request', (req, res, next) => {
const successObj = {
msg: 'success',
result: 'started',
shepherd.post('/mm/request', (req, res, next) => {
let _payload = req.body.payload;
_payload.userpass = shepherd.mmupass;
const options = {
url: `http://localhost:7783`,
method: 'POST',
body: JSON.stringify(_payload),
};
res.end(JSON.stringify(successObj));
shepherd.log(_payload);
// 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.mmPublic[_payload.mapToProp] = _parsedBody;
res.end(body);
} else {
res.end(body ? body : JSON.stringify({
result: 'error',
error: {
code: -777,
message: `unable to call method ${_payload.method} at port 7783`,
},
}));
}
});
});
return shepherd;

Loading…
Cancel
Save