Browse Source

Merge pull request #189 from SuperNETorg/master

update
pkg_automation_electrum
pbca26 7 years ago
committed by GitHub
parent
commit
59112d3968
  1. 220
      routes/shepherd.js

220
routes/shepherd.js

@ -253,92 +253,108 @@ shepherd.post('/native/dashboard/update', function(req, res, next) {
}); });
})) }))
.then(result => { .then(result => {
function calcBalance(result, json) { if (result[0] && result[0].length) {
if (json && function calcBalance(result, json) {
json.length) { if (json &&
const allAddrArray = json.map(res => res.address).filter((x, i, a) => a.indexOf(x) == i); json.length) {
const allAddrArray = json.map(res => res.address).filter((x, i, a) => a.indexOf(x) == i);
for (let a = 0; a < allAddrArray.length; a++) {
const filteredArray = json.filter(res => res.address === allAddrArray[a]).map(res => res.amount); for (let a = 0; a < allAddrArray.length; a++) {
const filteredArray = json.filter(res => res.address === allAddrArray[a]).map(res => res.amount);
let isNewAddr = true;
for (let x = 0; x < result.length && isNewAddr; x++) { let isNewAddr = true;
for (let y = 0; y < result[x].length && isNewAddr; y++) { for (let x = 0; x < result.length && isNewAddr; x++) {
if (allAddrArray[a] === result[x][y]) { for (let y = 0; y < result[x].length && isNewAddr; y++) {
isNewAddr = false; if (allAddrArray[a] === result[x][y]) {
isNewAddr = false;
}
} }
} }
}
if (isNewAddr && if (isNewAddr &&
(allAddrArray[a].substring(0, 2) === 'zc' || (allAddrArray[a].substring(0, 2) === 'zc' ||
allAddrArray[a].substring(0, 2) === 'zt')) { allAddrArray[a].substring(0, 2) === 'zt')) {
result[1][result[1].length] = allAddrArray[a]; result[1][result[1].length] = allAddrArray[a];
} else { } else {
result[0][result[0].length] = allAddrArray[a]; result[0][result[0].length] = allAddrArray[a];
}
} }
} }
}
// remove addr duplicates // remove addr duplicates
if (result[0]) { if (result[0] &&
result[0] = result[0].filter(function(elem, pos) { result[0].length) {
return result[0].indexOf(elem) === pos; result[0] = result[0].filter(function(elem, pos) {
}); return result[0].indexOf(elem) === pos;
} });
if (result[1]) { }
result[1] = result[1].filter(function(elem, pos) { if (result[1] &&
return result[1].indexOf(elem) === pos; result[1].length) {
}); result[1] = result[1].filter(function(elem, pos) {
} return result[1].indexOf(elem) === pos;
});
}
let newAddressArray = []; let newAddressArray = [];
for (let a = 0; a < result.length; a++) { for (let a = 0; a < result.length; a++) {
newAddressArray[a] = []; newAddressArray[a] = [];
if (result[a]) { if (result[a]) {
for (let b = 0; b < result[a].length; b++) { for (let b = 0; b < result[a].length; b++) {
let filteredArray; let filteredArray;
filteredArray = json.filter(res => res.address === result[a][b]).map(res => res.amount); filteredArray = json.filter(res => res.address === result[a][b]).map(res => res.amount);
let sum = 0; let sum = 0;
for (let i = 0; i < filteredArray.length; i++) { for (let i = 0; i < filteredArray.length; i++) {
sum += filteredArray[i]; sum += filteredArray[i];
} }
newAddressArray[a][b] = { newAddressArray[a][b] = {
address: result[a][b], address: result[a][b],
amount: sum, amount: sum,
type: a === 0 ? 'public': 'private', type: a === 0 ? 'public': 'private',
}; };
}
} }
} }
}
// get zaddr balance // get zaddr balance
if (result[1] && if (result[1] &&
result[1].length) { result[1].length) {
Promise.all(result[1].map((_address, index) => { Promise.all(result[1].map((_address, index) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
_bitcoinRPC(coin, 'z_getbalance', [_address]) _bitcoinRPC(coin, 'z_getbalance', [_address])
.then(function(__json) { .then(function(__json) {
__json = JSON.parse(__json); __json = JSON.parse(__json);
if (__json && if (__json &&
__json.error) { __json.error) {
resolve(0); resolve(0);
} else { } else {
resolve(__json.result) resolve(__json.result)
newAddressArray[1][index] = { newAddressArray[1][index] = {
address: _address, address: _address,
amount: __json.result, amount: __json.result,
type: 'private', type: 'private',
}; };
} }
});
}); });
}))
.then(zresult => {
_returnObj.addresses = {
public: newAddressArray[0],
private: newAddressArray[1],
};
const returnObj = {
msg: 'success',
result: _returnObj,
};
res.end(JSON.stringify(returnObj));
}); });
})) } else {
.then(zresult => {
_returnObj.addresses = { _returnObj.addresses = {
public: newAddressArray[0], public: newAddressArray[0],
private: newAddressArray[1], private: newAddressArray[1],
@ -350,41 +366,41 @@ shepherd.post('/native/dashboard/update', function(req, res, next) {
}; };
res.end(JSON.stringify(returnObj)); res.end(JSON.stringify(returnObj));
}); }
} else { }
_returnObj.addresses = {
public: newAddressArray[0],
private: newAddressArray[1],
};
const returnObj = { _bitcoinRPC(coin, 'listunspent')
msg: 'success', .then(function(__json) {
result: _returnObj, if (__json === 'Work queue depth exceeded' ||
}; !__json) {
const returnObj = {
msg: 'success',
result: _returnObj,
};
res.end(JSON.stringify(returnObj)); res.end(JSON.stringify(returnObj));
} } else {
} _returnObj.listunspent = JSON.parse(__json);
_bitcoinRPC(coin, 'listunspent') calcBalance(
.then(function(__json) { result,
if (__json === 'Work queue depth exceeded' || JSON.parse(__json).result
!__json) { );
const returnObj = { }
msg: 'success', });
result: _returnObj, } else {
}; _returnObj.addresses = {
public: {},
private: {},
};
res.end(JSON.stringify(returnObj)); const returnObj = {
} else { msg: 'success',
_returnObj.listunspent = JSON.parse(__json); result: _returnObj,
};
calcBalance( res.end(JSON.stringify(returnObj));
result, }
JSON.parse(__json).result
);
}
});
}) })
} }
@ -414,7 +430,7 @@ shepherd.post('/native/dashboard/update', function(req, res, next) {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify({ payload: _payload }), body: JSON.stringify({ payload: _payload }),
timeout: 10000, timeout: 60000,
}; };
request(options, function(error, response, body) { request(options, function(error, response, body) {
@ -2882,7 +2898,7 @@ function herder(flock, data) {
let _arg = `${coindACParam}${data.ac_options.join(' ')}${_customParam}`; let _arg = `${coindACParam}${data.ac_options.join(' ')}${_customParam}`;
_arg = _arg.trim().split(' '); _arg = _arg.trim().split(' ');
execFile(`${komododBin}`, _arg, { execFile(`${komododBin}`, _arg, {
maxBuffer: 1024 * 500000 // 500 mb maxBuffer: 1024 * 1000000 // 1000 mb
}, function(error, stdout, stderr) { }, function(error, stdout, stderr) {
shepherd.writeLog(`stdout: ${stdout}`); shepherd.writeLog(`stdout: ${stdout}`);
shepherd.writeLog(`stderr: ${stderr}`); shepherd.writeLog(`stderr: ${stderr}`);

Loading…
Cancel
Save