diff --git a/package.json b/package.json index eadb790..e35c79f 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,8 @@ "bip39": "^2.4.0", "bitcoinforksjs-lib": "git://github.com/SuperNETorg/bitcoinjs-lib#opt-in-bitcoincash-sighash", "bitcoinjs-lib": "git://github.com/SuperNETorg/bitcoinjs-lib", - "bitcoinjs-lib-zcash": "git://github.com/pbca26/bitcoinjs-lib#zcash", "bitcoinjs-lib-pos": "git://github.com/KomodoPlatform/bitcoinjs-lib-pos", + "bitcoinjs-lib-zcash": "git://github.com/pbca26/bitcoinjs-lib#zcash", "bluebird": "^3.4.7", "body-parser": "^1.15.2", "buffer-reverse": "^1.0.1", @@ -48,7 +48,7 @@ "js-sha256": "^0.7.1", "marketmaker": "git://github.com/pbca26/marketmaker", "nodejs-aes256": "^1.0.1", - "passwd-strength": "https://github.com/pbca26/passwd-strength", + "passwd-strength": "git+https://github.com/pbca26/passwd-strength.git", "portscanner": "^2.1.1", "ps-node": "^0.1.5", "remote-file-size": "^3.0.3", diff --git a/routes/shepherd/addCoinShortcuts.js b/routes/shepherd/addCoinShortcuts.js index 79d2249..a2a7906 100644 --- a/routes/shepherd/addCoinShortcuts.js +++ b/routes/shepherd/addCoinShortcuts.js @@ -21,19 +21,30 @@ module.exports = (shepherd) => { } shepherd.startKMDNative = (selection, isManual) => { - if (isManual) { - shepherd.kmdMainPassiveMode = true; - } - - if (selection === 'KMD') { - const herdData = { - 'ac_name': 'komodod', - 'ac_options': [ - '-daemon=0', - '-addnode=78.47.196.146', - ], - }; - + let herdData; + const acHerdData = { + REVS: { + name: 'REVS', + seedNode: '78.47.196.146', + supply: 1300000, + }, + JUMBLR: { + name: 'JUMBLR', + seedNode: '78.47.196.146', + supply: 999999, + }, + MNZ: { + name: 'MNZ', + seedNode: '78.47.196.146', + supply: 257142858, + }, + BTCH: { + name: 'BTCH', + seedNode: '78.47.196.146', + supply: 20998641, + }, + }; + const httpRequest = () => { const options = { url: `http://127.0.0.1:${shepherd.appConfig.agamaPort}/shepherd/herd`, method: 'POST', @@ -48,157 +59,49 @@ module.exports = (shepherd) => { }; request(options, (error, response, body) => { - if (response && - response.statusCode && - response.statusCode === 200) { - //resolve(body); - } else { - //resolve(body); - } + // resolve(body); }); - } else if (selection === 'REVS') { - const herdData = { - 'ac_name': 'REVS', - 'ac_options': [ - '-daemon=0', - '-server', - `-ac_name=REVS`, - '-addnode=78.47.196.146', - '-ac_supply=1300000' - ] - }; + }; - const options = { - url: `http://127.0.0.1:${shepherd.appConfig.agamaPort}/shepherd/herd`, - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - herd: 'komodod', - options: herdData, - token: shepherd.appSessionHash, - }), - }; - - request(options, (error, response, body) => { - if (response && - response.statusCode && - response.statusCode === 200) { - //resolve(body); - } else { - //resolve(body); - } - }); - } else if (selection === 'JUMRLR') { - const herdData = { - 'ac_name': 'JUMRLR', - 'ac_options': [ - '-daemon=0', - '-server', - `-ac_name=JUMRLR`, - '-addnode=78.47.196.146', - '-ac_supply=999999' - ] - }; - - const options = { - url: `http://127.0.0.1:${shepherd.appConfig.agamaPort}/shepherd/herd`, - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - herd: 'komodod', - options: herdData, - token: shepherd.appSessionHash, - }), - }; + if (isManual) { + shepherd.kmdMainPassiveMode = true; + } - request(options, (error, response, body) => { - if (response && - response.statusCode && - response.statusCode === 200) { - //resolve(body); - } else { - //resolve(body); - } - }); - } else if (selection === 'MNZ') { - const herdData = { - 'ac_name': 'MNZ', + if (selection === 'KMD') { + herdData = { + 'ac_name': 'komodod', 'ac_options': [ '-daemon=0', - '-server', - `-ac_name=MNZ`, '-addnode=78.47.196.146', - '-ac_supply=257142858' - ] - }; - - const options = { - url: `http://127.0.0.1:${shepherd.appConfig.agamaPort}/shepherd/herd`, - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - herd: 'komodod', - options: herdData, - token: shepherd.appSessionHash, - }), + ], }; - request(options, (error, response, body) => { - if (response && - response.statusCode && - response.statusCode === 200) { - //resolve(body); - } else { - //resolve(body); - } - }); - } else if (selection === 'BTCH') { - const herdData = { - 'ac_name': 'BTCH', + httpRequest(); + } else if ( + selection === 'REVS' || + selection === 'JUMRLR' || + selection === 'MNZ' || + selection === 'BTCH' + ) { + herdData = { + 'ac_name': acHerdData[selection].name, 'ac_options': [ '-daemon=0', '-server', - `-ac_name=BTCH`, - '-addnode=78.47.196.146', - '-ac_supply=20998641' - ] - }; - - const options = { - url: `http://127.0.0.1:${shepherd.appConfig.agamaPort}/shepherd/herd`, - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - herd: 'komodod', - options: herdData, - token: shepherd.appSessionHash, - }), + `-ac_name=${acHerdData[selection].name}`, + `-addnode=${acHerdData[selection].seedNode}`, + `-ac_supply=${acHerdData[selection].supply}`, + ], }; - request(options, (error, response, body) => { - if (response && - response.statusCode && - response.statusCode === 200) { - //resolve(body); - } else { - //resolve(body); - } - }); + httpRequest(); } else { const herdData = [{ 'ac_name': 'komodod', 'ac_options': [ '-daemon=0', '-addnode=78.47.196.146', - ] + ], }, { 'ac_name': 'REVS', 'ac_options': [ @@ -206,8 +109,8 @@ module.exports = (shepherd) => { '-server', `-ac_name=REVS`, '-addnode=78.47.196.146', - '-ac_supply=1300000' - ] + '-ac_supply=1300000', + ], }, { 'ac_name': 'JUMBLR', 'ac_options': [ @@ -215,8 +118,8 @@ module.exports = (shepherd) => { '-server', `-ac_name=JUMBLR`, '-addnode=78.47.196.146', - '-ac_supply=999999' - ] + '-ac_supply=999999', + ], }]; for (let i = 0; i < herdData.length; i++) { @@ -235,13 +138,7 @@ module.exports = (shepherd) => { }; request(options, (error, response, body) => { - if (response && - response.statusCode && - response.statusCode === 200) { - //resolve(body); - } else { - //resolve(body); - } + // resolve(body); }); }, 100); } diff --git a/routes/shepherd/auth.js b/routes/shepherd/auth.js index 9c1ff73..44c7516 100644 --- a/routes/shepherd/auth.js +++ b/routes/shepherd/auth.js @@ -14,12 +14,21 @@ module.exports = (shepherd) => { if (Object.keys(shepherd.electrumCoins).length > 1 && shepherd.electrumCoins.auth) { _status = true; - } else if (Object.keys(shepherd.electrumCoins).length === 1 && !shepherd.electrumCoins.auth) { + } else if ( + Object.keys(shepherd.electrumCoins).length === 1 && + !shepherd.electrumCoins.auth + ) { _status = true; } - } else if (Object.keys(shepherd.electrumCoins).length > 1 && shepherd.electrumCoins.auth) { + } else if ( + Object.keys(shepherd.electrumCoins).length > 1 && + shepherd.electrumCoins.auth + ) { _status = true; - } else if (Object.keys(shepherd.electrumCoins).length === 1 && !Object.keys(shepherd.coindInstanceRegistry).length) { + } else if ( + Object.keys(shepherd.electrumCoins).length === 1 && + !Object.keys(shepherd.coindInstanceRegistry).length + ) { _status = true; } diff --git a/routes/shepherd/daemonControl.js b/routes/shepherd/daemonControl.js index bf9d719..86e9e77 100644 --- a/routes/shepherd/daemonControl.js +++ b/routes/shepherd/daemonControl.js @@ -359,14 +359,14 @@ module.exports = (shepherd) => { shepherd.log(`daemon param ${data.ac_custom_param}`); - shepherd.coindInstanceRegistry['CHIPS'] = true; + shepherd.coindInstanceRegistry.CHIPS = true; let _arg = `${_customParam}`; _arg = _arg.trim().split(' '); if (_arg && _arg.length > 1) { execFile(`${shepherd.chipsBin}`, _arg, { - maxBuffer: 1024 * 1000000 // 1000 mb + maxBuffer: 1024 * 1000000, // 1000 mb }, (error, stdout, stderr) => { shepherd.writeLog(`stdout: ${stdout}`); shepherd.writeLog(`stderr: ${stderr}`); @@ -464,7 +464,7 @@ module.exports = (shepherd) => { let _arg = `${data.ac_options.join(' ')}`; _arg = _arg.trim().split(' '); execFile(`${coindBin}`, _arg, { - maxBuffer: 1024 * 1000000 // 1000 mb + maxBuffer: 1024 * 1000000, // 1000 mb }, (error, stdout, stderr) => { shepherd.writeLog(`stdout: ${stdout}`); shepherd.writeLog(`stderr: ${stderr}`); @@ -651,7 +651,6 @@ module.exports = (shepherd) => { shepherd.writeLog(`append daemon conf err: ${err}`); shepherd.log(`append daemon conf err: ${err}`); } - // throw err; shepherd.log('rpcpassword: ADDED'); shepherd.writeLog('rpcpassword: ADDED'); }); @@ -678,7 +677,6 @@ module.exports = (shepherd) => { shepherd.writeLog(`append daemon conf err: ${err}`); shepherd.log(`append daemon conf err: ${err}`); } - // throw err; shepherd.log('rpcport: ADDED'); shepherd.writeLog('rpcport: ADDED'); }); @@ -754,7 +752,6 @@ module.exports = (shepherd) => { shepherd.writeLog(`append daemon conf err: ${err}`); shepherd.log(`append daemon conf err: ${err}`); } - // throw err; shepherd.log('addnode: ADDED'); shepherd.writeLog('addnode: ADDED'); }); diff --git a/routes/shepherd/dashboardUpdate.js b/routes/shepherd/dashboardUpdate.js index 1557db2..117a622 100644 --- a/routes/shepherd/dashboardUpdate.js +++ b/routes/shepherd/dashboardUpdate.js @@ -277,13 +277,7 @@ module.exports = (shepherd) => { }; request(options, (error, response, body) => { - if (response && - response.statusCode && - response.statusCode === 200) { - resolve(body); - } else { - resolve(body); - } + resolve(body); }); }); } diff --git a/routes/shepherd/debugLog.js b/routes/shepherd/debugLog.js index 9658f81..f2deab3 100644 --- a/routes/shepherd/debugLog.js +++ b/routes/shepherd/debugLog.js @@ -1,6 +1,7 @@ const path = require('path'); const _fs = require('graceful-fs'); const Promise = require('bluebird'); +const os = require('os'); module.exports = (shepherd) => { /* @@ -13,18 +14,19 @@ module.exports = (shepherd) => { let _ac = req.body.ac; let _lastNLines = req.body.lastLines; let _location; - - if (shepherd.os.platform() === 'darwin') { - shepherd.komodoDir = shepherd.appConfig.dataDir.length ? shepherd.appConfig.dataDir : `${process.env.HOME}/Library/Application Support/Komodo`; - } - - if (shepherd.os.platform() === 'linux') { - shepherd.komodoDir = shepherd.appConfig.dataDir.length ? shepherd.appConfig.dataDir : `${process.env.HOME}/.komodo`; - } - - if (shepherd.os.platform() === 'win32') { - shepherd.komodoDir = shepherd.appConfig.dataDir.length ? shepherd.appConfig.dataDir : `${process.env.APPDATA}/Komodo`; - shepherd.komodoDir = path.normalize(shepherd.komodoDir); + const _platform = os.platform(); + + switch (_platform) { + case 'darwin': + shepherd.komodoDir = shepherd.appConfig.dataDir.length ? shepherd.appConfig.dataDir : `${process.env.HOME}/Library/Application Support/Komodo`; + break; + case 'linux': + shepherd.komodoDir = shepherd.appConfig.dataDir.length ? shepherd.appConfig.dataDir : `${process.env.HOME}/.komodo`; + break; + case 'win32': + shepherd.komodoDir = shepherd.appConfig.dataDir.length ? shepherd.appConfig.dataDir : `${process.env.APPDATA}/Komodo`; + shepherd.komodoDir = path.normalize(shepherd.komodoDir); + break; } if (_herd === 'komodo') { @@ -97,44 +99,42 @@ module.exports = (shepherd) => { }); shepherd.readDebugLog = (fileLocation, lastNLines) => { - return new Promise( - (resolve, reject) => { - if (lastNLines) { - try { - _fs.access(fileLocation, shepherd.fs.constants.R_OK, (err) => { - if (err) { - shepherd.log(`error reading ${fileLocation}`); - shepherd.writeLog(`error reading ${fileLocation}`); - reject(`readDebugLog error: ${err}`); - } else { - shepherd.log(`reading ${fileLocation}`); - _fs.readFile(fileLocation, 'utf-8', (err, data) => { - if (err) { - shepherd.writeLog(`readDebugLog err: ${err}`); - shepherd.log(`readDebugLog err: ${err}`); - } - - const lines = data.trim().split('\n'); - let lastLine; - - if (lastNLines === 'all') { - lastLine = data.trim(); - } else { - lastLine = lines.slice(lines.length - lastNLines, lines.length).join('\n'); - } - - resolve(lastLine); - }); - } - }); - } catch (e) { - reject(`readDebugLog error: ${e}`); - } - } else { - reject('readDebugLog error: lastNLines param is not provided!'); + return new Promise((resolve, reject) => { + if (lastNLines) { + try { + _fs.access(fileLocation, shepherd.fs.constants.R_OK, (err) => { + if (err) { + shepherd.log(`error reading ${fileLocation}`); + shepherd.writeLog(`error reading ${fileLocation}`); + reject(`readDebugLog error: ${err}`); + } else { + shepherd.log(`reading ${fileLocation}`); + _fs.readFile(fileLocation, 'utf-8', (err, data) => { + if (err) { + shepherd.writeLog(`readDebugLog err: ${err}`); + shepherd.log(`readDebugLog err: ${err}`); + } + + const lines = data.trim().split('\n'); + let lastLine; + + if (lastNLines === 'all') { + lastLine = data.trim(); + } else { + lastLine = lines.slice(lines.length - lastNLines, lines.length).join('\n'); + } + + resolve(lastLine); + }); + } + }); + } catch (e) { + reject(`readDebugLog error: ${e}`); } + } else { + reject('readDebugLog error: lastNLines param is not provided!'); } - ); + }); }; return shepherd; diff --git a/routes/shepherd/elections.js b/routes/shepherd/elections.js index ac27e1c..192aabb 100644 --- a/routes/shepherd/elections.js +++ b/routes/shepherd/elections.js @@ -5,12 +5,12 @@ const Promise = require('bluebird'); module.exports = (shepherd) => { shepherd.elections = {}; - shepherd.hex2str = (hexx) => { - const hex = hexx.toString(); // force conversion + shepherd.hex2str = (hex) => { + const _hex = hex.toString(); // force conversion let str = ''; - for (let i = 0; i < hex.length; i += 2) { - str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); + for (let i = 0; i < _hex.length; i += 2) { + str += String.fromCharCode(parseInt(_hex.substr(i, 2), 16)); } return str; @@ -167,7 +167,11 @@ module.exports = (shepherd) => { shepherd.get('/elections/listtransactions', (req, res, next) => { if (shepherd.checkToken(req.query.token)) { const network = req.query.network || shepherd.findNetworkObj(req.query.coin); - const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[network].port, shepherd.electrumServers[network].address, shepherd.electrumServers[network].proto); // tcp or tls + const ecl = new shepherd.electrumJSCore( + shepherd.electrumServers[network].port, + shepherd.electrumServers[network].address, + shepherd.electrumServers[network].proto + ); // tcp or tls const type = req.query.type; const _address = req.query.address; @@ -299,7 +303,10 @@ module.exports = (shepherd) => { .then((res) => { if (decodedTx.outputs[i].scriptPubKey.addresses[0] === _address) { _candidate.amount = decodedTx.outputs[i].value; - } else if (decodedTx.outputs[i].scriptPubKey.addresses[0] !== _address && decodedTx.outputs[i].scriptPubKey.asm.indexOf('OP_RETURN') === -1) { + } else if ( + decodedTx.outputs[i].scriptPubKey.addresses[0] !== _address && + decodedTx.outputs[i].scriptPubKey.asm.indexOf('OP_RETURN') === -1 + ) { _candidate.address = decodedTx.outputs[i].scriptPubKey.addresses[0]; _candidate.region = _region; _candidate.timestamp = blockInfo.timestamp; diff --git a/routes/shepherd/electrum/auth.js b/routes/shepherd/electrum/auth.js index 182a52b..95944d5 100644 --- a/routes/shepherd/electrum/auth.js +++ b/routes/shepherd/electrum/auth.js @@ -39,7 +39,11 @@ module.exports = (shepherd) => { break; } } else { - keys = shepherd.seedToWif(_seed, shepherd.findNetworkObj(_abbr), req.body.iguana); + keys = shepherd.seedToWif( + _seed, + shepherd.findNetworkObj(_abbr), + req.body.iguana + ); } shepherd.electrumKeys[_abbr] = { diff --git a/routes/shepherd/electrum/balance.js b/routes/shepherd/electrum/balance.js index b580c5a..415e400 100644 --- a/routes/shepherd/electrum/balance.js +++ b/routes/shepherd/electrum/balance.js @@ -47,7 +47,12 @@ module.exports = (shepherd) => { // decode tx const _network = shepherd.getNetworkData(network); - const decodedTx = shepherd.electrumJSTxDecoder(_rawtxJSON, network, _network, shepherd.electrumServers[network].proto === 'insight'); + const decodedTx = shepherd.electrumJSTxDecoder( + _rawtxJSON, + network, + _network, + shepherd.electrumServers[network].proto === 'insight' + ); if (decodedTx && decodedTx.format && diff --git a/routes/shepherd/electrum/block.js b/routes/shepherd/electrum/block.js index 5ac9a3c..979bb7a 100644 --- a/routes/shepherd/electrum/block.js +++ b/routes/shepherd/electrum/block.js @@ -24,7 +24,11 @@ module.exports = (shepherd) => { shepherd.electrumGetBlockInfo = (height, network) => { return new Promise((resolve, reject) => { - const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[network].port, shepherd.electrumServers[network].address, shepherd.electrumServers[network].proto); // tcp or tls + const ecl = new shepherd.electrumJSCore( + shepherd.electrumServers[network].port, + shepherd.electrumServers[network].address, + shepherd.electrumServers[network].proto + ); // tcp or tls ecl.connect(); ecl.blockchainBlockGetHeader(height) @@ -61,7 +65,11 @@ module.exports = (shepherd) => { shepherd.electrumGetCurrentBlock = (network) => { return new Promise((resolve, reject) => { - const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[network].port, shepherd.electrumServers[network].address, shepherd.electrumServers[network].proto); // tcp or tls + const ecl = new shepherd.electrumJSCore( + shepherd.electrumServers[network].port, + shepherd.electrumServers[network].address, + shepherd.electrumServers[network].proto + ); // tcp or tls ecl.connect(); ecl.blockchainNumblocksSubscribe() diff --git a/routes/shepherd/electrum/btcFees.js b/routes/shepherd/electrum/btcFees.js index 25f25be..b42293c 100644 --- a/routes/shepherd/electrum/btcFees.js +++ b/routes/shepherd/electrum/btcFees.js @@ -35,7 +35,11 @@ module.exports = (shepherd) => { if (shepherd.checkToken(req.query.token)) { if (checkTimestamp(btcFees.lastUpdated) > BTC_FEES_MIN_ELAPSED_TIME) { const _randomServer = shepherd.electrumServers.btc.serverList[getRandomIntInclusive(0, shepherd.electrumServers.btc.serverList.length - 1)].split(':'); - const ecl = new shepherd.electrumJSCore(_randomServer[1], _randomServer[0], 'tcp'); + const ecl = new shepherd.electrumJSCore( + _randomServer[1], + _randomServer[0], + 'tcp' + ); let _btcFeeEstimates = []; console.log(`btc fees server ${_randomServer.join(':')}`); @@ -56,12 +60,7 @@ module.exports = (shepherd) => { .then(result => { ecl.close(); - if (result && - result.length) { - btcFees.electrum = _btcFeeEstimates; - } else { - btcFees.electrum = 'error'; - } + btcFees.electrum = result && result.length ? _btcFeeEstimates : 'error'; let options = { url: `https://bitcoinfees.earn.com/api/v1/fees/recommended`, diff --git a/routes/shepherd/electrum/coins.js b/routes/shepherd/electrum/coins.js index 295fadb..6dca0dd 100644 --- a/routes/shepherd/electrum/coins.js +++ b/routes/shepherd/electrum/coins.js @@ -15,7 +15,7 @@ module.exports = (shepherd) => { max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1)) + min; // the maximum is inclusive and the minimum is inclusive - } + }; let randomServer; // pick a random server to communicate with @@ -43,7 +43,7 @@ module.exports = (shepherd) => { port: randomServer ? randomServer.port : shepherd.electrumServers[key].port, }, serverList: shepherd.electrumServers[key].serverList ? shepherd.electrumServers[key].serverList : 'none', - txfee: 'calculated' /*shepherd.electrumServers[key].txfee*/, + txfee: key === 'btc' ? 'calculated' : shepherd.electrumServers[key].txfee, }; shepherd.log(`default ${coin} electrum server ${shepherd.electrumServers[key].address + ':' + shepherd.electrumServers[key].port}`, true); diff --git a/routes/shepherd/electrum/createtx-multi.js b/routes/shepherd/electrum/createtx-multi.js index 92b91ad..8224e1f 100644 --- a/routes/shepherd/electrum/createtx-multi.js +++ b/routes/shepherd/electrum/createtx-multi.js @@ -15,16 +15,20 @@ module.exports = (shepherd) => { // TODO: 1) unconf output(s) error message // 2) check targets integrity const network = req.body.network || shepherd.findNetworkObj(req.body.coin); - const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[network].port, shepherd.electrumServers[network].address, shepherd.electrumServers[network].proto); // tcp or tls + const ecl = new shepherd.electrumJSCore( + shepherd.electrumServers[network].port, + shepherd.electrumServers[network].address, + shepherd.electrumServers[network].proto + ); // tcp or tls const initTargets = JSON.parse(JSON.stringify(req.body.targets)); - let targets = req.body.targets; const changeAddress = req.body.change; const push = req.body.push; const opreturn = req.body.opreturn; const btcFee = req.body.btcfee ? Number(req.body.btcfee) : null; let fee = shepherd.electrumServers[network].txfee; let wif = req.body.wif; - + let targets = req.body.targets; + if (req.body.gui) { wif = shepherd.electrumKeys[req.body.coin].priv; } @@ -40,7 +44,13 @@ module.exports = (shepherd) => { shepherd.log('electrum createrawtx =>', true); ecl.connect(); - shepherd.listunspent(ecl, changeAddress, network, true, req.body.verify === 'true' ? true : null) + shepherd.listunspent( + ecl, + changeAddress, + network, + true, + req.body.verify === 'true' ? true : null + ) .then((utxoList) => { ecl.close(); @@ -96,7 +106,11 @@ module.exports = (shepherd) => { // default coin selection algo blackjack with fallback to accumulative // make a first run, calc approx tx fee // if ins and outs are empty reduce max spend by txfee - const firstRun = coinSelect(utxoListFormatted, targets, btcFee ? btcFee : 0); + const firstRun = coinSelect( + utxoListFormatted, + targets, + btcFee ? btcFee : 0 + ); let inputs = firstRun.inputs; let outputs = firstRun.outputs; @@ -119,7 +133,11 @@ module.exports = (shepherd) => { shepherd.log('coinselect adjusted targets =>', true); shepherd.log(targets, true); - const secondRun = coinSelect(utxoListFormatted, targets, 0); + const secondRun = coinSelect( + utxoListFormatted, + targets, + 0 + ); inputs = secondRun.inputs; outputs = secondRun.outputs; fee = fee ? fee : secondRun.fee; @@ -333,7 +351,11 @@ module.exports = (shepherd) => { res.end(JSON.stringify(successObj)); } else { - const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[network].port, shepherd.electrumServers[network].address, shepherd.electrumServers[network].proto); // tcp or tls + const ecl = new shepherd.electrumJSCore( + shepherd.electrumServers[network].port, + shepherd.electrumServers[network].address, + shepherd.electrumServers[network].proto + ); // tcp or tls ecl.connect(); ecl.blockchainTransactionBroadcast(_rawtx) @@ -451,7 +473,11 @@ module.exports = (shepherd) => { for (let i = 0; i < sendTo.length; i++) { if (shepherd.isPos(network)) { - tx.addOutput(sendTo[i].address, Number(sendTo[i].value), shepherd.getNetworkData(network)); + tx.addOutput( + sendTo[i].address, + Number(sendTo[i].value), + shepherd.getNetworkData(network) + ); } else { tx.addOutput(sendTo[i].address, Number(sendTo[i].value)); } @@ -459,7 +485,11 @@ module.exports = (shepherd) => { if (changeValue > 0) { if (shepherd.isPos(network)) { - tx.addOutput(changeAddress, Number(changeValue), shepherd.getNetworkData(network)); + tx.addOutput( + changeAddress, + Number(changeValue), + shepherd.getNetworkData(network) + ); } else { tx.addOutput(changeAddress, Number(changeValue)); } @@ -492,7 +522,11 @@ module.exports = (shepherd) => { for (let i = 0; i < utxo.length; i++) { if (shepherd.isPos(network)) { - tx.sign(shepherd.getNetworkData(network), i, key); + tx.sign( + shepherd.getNetworkData(network), + i, + key + ); } else { tx.sign(i, key); } diff --git a/routes/shepherd/electrum/createtx-split.js b/routes/shepherd/electrum/createtx-split.js index bce7cac..58698d6 100644 --- a/routes/shepherd/electrum/createtx-split.js +++ b/routes/shepherd/electrum/createtx-split.js @@ -35,7 +35,11 @@ module.exports = (shepherd) => { for (let i = 0; i < targets.length; i++) { if (shepherd.isPos(network)) { - tx.addOutput(outputAddress, Number(targets[i]), shepherd.getNetworkData(network)); + tx.addOutput( + outputAddress, + Number(targets[i]), + shepherd.getNetworkData(network) + ); } else { tx.addOutput(outputAddress, Number(targets[i])); } @@ -43,7 +47,11 @@ module.exports = (shepherd) => { if (Number(change) > 0) { if (shepherd.isPos(network)) { - tx.addOutput(changeAddress, Number(change), shepherd.getNetworkData(network)); + tx.addOutput( + changeAddress, + Number(change), + shepherd.getNetworkData(network) + ); } else { shepherd.log(`change ${change}`, true); tx.addOutput(changeAddress, Number(change)); @@ -59,7 +67,11 @@ module.exports = (shepherd) => { for (let i = 0; i < utxo.length; i++) { if (shepherd.isPos(network)) { - tx.sign(shepherd.getNetworkData(network), i, key); + tx.sign( + shepherd.getNetworkData(network), + i, + key + ); } else { tx.sign(i, key); } diff --git a/routes/shepherd/electrum/createtx.js b/routes/shepherd/electrum/createtx.js index e824d0f..9705f6b 100644 --- a/routes/shepherd/electrum/createtx.js +++ b/routes/shepherd/electrum/createtx.js @@ -78,14 +78,22 @@ module.exports = (shepherd) => { } if (shepherd.isPos(network)) { - tx.addOutput(sendTo, Number(spendValue), shepherd.getNetworkData(network)); + tx.addOutput( + sendTo, + Number(spendValue), + shepherd.getNetworkData(network) + ); } else { tx.addOutput(sendTo, Number(spendValue)); } if (changeValue > 0) { if (shepherd.isPos(network)) { - tx.addOutput(changeAddress, Number(changeValue), shepherd.getNetworkData(network)); + tx.addOutput( + changeAddress, + Number(changeValue), + shepherd.getNetworkData(network) + ); } else { tx.addOutput(changeAddress, Number(changeValue)); } @@ -114,7 +122,11 @@ module.exports = (shepherd) => { for (let i = 0; i < utxo.length; i++) { if (shepherd.isPos(network)) { - tx.sign(shepherd.getNetworkData(network), i, key); + tx.sign( + shepherd.getNetworkData(network), + i, + key + ); } else { tx.sign(i, key); } @@ -144,7 +156,12 @@ module.exports = (shepherd) => { shepherd.log(`buildSignedTx${network.toUpperCase()}`, true); for (let i = 0; i < utxo.length; i++) { - tx.addInput(utxo[i].txid, utxo[i].vout, bitcoinJSForks.Transaction.DEFAULT_SEQUENCE, spk); + tx.addInput( + utxo[i].txid, + utxo[i].vout, + bitcoinJSForks.Transaction.DEFAULT_SEQUENCE, + spk + ); } tx.addOutput(sendTo, Number(spendValue)); @@ -171,7 +188,13 @@ module.exports = (shepherd) => { const hashType = bitcoinJSForks.Transaction.SIGHASH_ALL | bitcoinJSForks.Transaction.SIGHASH_BITCOINCASHBIP143; for (let i = 0; i < utxo.length; i++) { - tx.sign(i, keyPair, null, hashType, utxo[i].value); + tx.sign( + i, + keyPair, + null, + hashType, + utxo[i].value + ); } const rawtx = tx.build().toHex(); @@ -200,7 +223,11 @@ module.exports = (shepherd) => { if (shepherd.checkToken(req.query.token)) { // TODO: unconf output(s) error message const network = req.query.network || shepherd.findNetworkObj(req.query.coin); - const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[network].port, shepherd.electrumServers[network].address, shepherd.electrumServers[network].proto); // tcp or tls + const ecl = new shepherd.electrumJSCore( + shepherd.electrumServers[network].port, + shepherd.electrumServers[network].address, + shepherd.electrumServers[network].proto + ); // tcp or tls const outputAddress = req.query.address; const changeAddress = req.query.change; const push = req.query.push; @@ -225,7 +252,13 @@ module.exports = (shepherd) => { shepherd.log('electrum createrawtx =>', true); ecl.connect(); - shepherd.listunspent(ecl, changeAddress, network, true, req.query.verify === 'true' ? true : null) + shepherd.listunspent( + ecl, + changeAddress, + network, + true, + req.query.verify === 'true' ? true : null + ) .then((utxoList) => { ecl.close(); @@ -281,7 +314,11 @@ module.exports = (shepherd) => { // default coin selection algo blackjack with fallback to accumulative // make a first run, calc approx tx fee // if ins and outs are empty reduce max spend by txfee - const firstRun = coinSelect(utxoListFormatted, targets, btcFee ? btcFee : 0); + const firstRun = coinSelect( + utxoListFormatted, + targets, + btcFee ? btcFee : 0 + ); let inputs = firstRun.inputs; let outputs = firstRun.outputs; @@ -304,7 +341,11 @@ module.exports = (shepherd) => { shepherd.log('coinselect adjusted targets =>', true); shepherd.log(targets, true); - const secondRun = coinSelect(utxoListFormatted, targets, 0); + const secondRun = coinSelect( + utxoListFormatted, + targets, + 0 + ); inputs = secondRun.inputs; outputs = secondRun.outputs; fee = fee ? fee : secondRun.fee; @@ -493,7 +534,11 @@ module.exports = (shepherd) => { res.end(JSON.stringify(successObj)); } else { - const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[network].port, shepherd.electrumServers[network].address, shepherd.electrumServers[network].proto); // tcp or tls + const ecl = new shepherd.electrumJSCore( + shepherd.electrumServers[network].port, + shepherd.electrumServers[network].address, + shepherd.electrumServers[network].proto + ); // tcp or tls ecl.connect(); ecl.blockchainTransactionBroadcast(_rawtx) @@ -591,7 +636,11 @@ module.exports = (shepherd) => { if (shepherd.checkToken(req.body.token)) { const rawtx = req.body.rawtx; const _network = req.body.network; - const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[_network].port, shepherd.electrumServers[_network].address, shepherd.electrumServers[_network].proto); // tcp or tls + const ecl = new shepherd.electrumJSCore( + shepherd.electrumServers[_network].port, + shepherd.electrumServers[_network].address, + shepherd.electrumServers[_network].proto + ); // tcp or tls ecl.connect(); ecl.blockchainTransactionBroadcast(rawtx) diff --git a/routes/shepherd/electrum/estimate.js b/routes/shepherd/electrum/estimate.js index f065414..4f080b3 100644 --- a/routes/shepherd/electrum/estimate.js +++ b/routes/shepherd/electrum/estimate.js @@ -1,7 +1,11 @@ module.exports = (shepherd) => { shepherd.get('/electrum/estimatefee', (req, res, next) => { if (shepherd.checkToken(req.query.token)) { - const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[req.query.network].port, shepherd.electrumServers[req.query.network].address, shepherd.electrumServers[req.query.network].proto); // tcp or tls + const ecl = new shepherd.electrumJSCore( + shepherd.electrumServers[req.query.network].port, + shepherd.electrumServers[req.query.network].address, + shepherd.electrumServers[req.query.network].proto + ); // tcp or tls ecl.connect(); ecl.blockchainEstimatefee(req.query.blocks) diff --git a/routes/shepherd/electrum/network.js b/routes/shepherd/electrum/network.js index 7175fe8..08ba17d 100644 --- a/routes/shepherd/electrum/network.js +++ b/routes/shepherd/electrum/network.js @@ -178,7 +178,7 @@ module.exports = (shepherd) => { }; for (let key in shepherd.electrumServers) { - if (shepherd.electrumServers[key].abbr === req.query.coin) { // a bit risky + if (shepherd.electrumServers[key].abbr === req.query.coin) { shepherd.electrumServers[key].address = req.query.address; shepherd.electrumServers[key].port = req.query.port; break; diff --git a/routes/shepherd/electrum/transactions.js b/routes/shepherd/electrum/transactions.js index 40f81ad..45bdb07 100644 --- a/routes/shepherd/electrum/transactions.js +++ b/routes/shepherd/electrum/transactions.js @@ -1,7 +1,7 @@ const async = require('async'); const Promise = require('bluebird'); -const MAX_VOUT_LENGTH = 10; +const MAX_VIN_LENGTH = 150; // parse up to MAX_VIN_LENGTH vins module.exports = (shepherd) => { shepherd.sortTransactions = (transactions, sortBy) => { @@ -145,7 +145,8 @@ module.exports = (shepherd) => { const checkLoop = () => { index2++; - if (index2 === decodedTx.inputs.length || index2 === MAX_VOUT_LENGTH) { + if (index2 === decodedTx.inputs.length || + index2 === MAX_VIN_LENGTH) { shepherd.log(`tx history decode inputs ${decodedTx.inputs.length} | ${index2} => main callback`, true); const _parsedTx = { network: decodedTx.network, @@ -167,6 +168,8 @@ module.exports = (shepherd) => { formattedTx.inputs = decodedTx.inputs; formattedTx.outputs = decodedTx.outputs; formattedTx.locktime = decodedTx.format.locktime; + formattedTx.vinLen = decodedTx.inputs.length; + formattedTx.vinMaxLen = MAX_VIN_LENGTH; _rawtx.push(formattedTx); } else { formattedTx[0].height = transaction.height; @@ -176,6 +179,8 @@ module.exports = (shepherd) => { formattedTx[0].inputs = decodedTx.inputs; formattedTx[0].outputs = decodedTx.outputs; formattedTx[0].locktime = decodedTx.format.locktime; + formattedTx[0].vinLen = decodedTx.inputs.length; + formattedTx[0].vinMaxLen = MAX_VIN_LENGTH; formattedTx[1].height = transaction.height; formattedTx[1].blocktime = blockInfo.timestamp; formattedTx[1].timereceived = blockInfo.timereceived; @@ -183,6 +188,8 @@ module.exports = (shepherd) => { formattedTx[1].inputs = decodedTx.inputs; formattedTx[1].outputs = decodedTx.outputs; formattedTx[1].locktime = decodedTx.format.locktime; + formattedTx[1].vinLen = decodedTx.inputs.length; + formattedTx[1].vinMaxLen = MAX_VIN_LENGTH; _rawtx.push(formattedTx[0]); _rawtx.push(formattedTx[1]); } @@ -313,7 +320,11 @@ module.exports = (shepherd) => { shepherd.get('/electrum/gettransaction', (req, res, next) => { if (shepherd.checkToken(req.query.token)) { const network = req.query.network || shepherd.findNetworkObj(req.query.coin); - const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[network].port, shepherd.electrumServers[network].address, shepherd.electrumServers[network].proto); // tcp or tls + const ecl = new shepherd.electrumJSCore( + shepherd.electrumServers[network].port, + shepherd.electrumServers[network].address, + shepherd.electrumServers[network].proto + ); // tcp or tls shepherd.log('electrum gettransaction =>', true); @@ -551,7 +562,11 @@ module.exports = (shepherd) => { res.end(JSON.stringify(successObj)); } else { - const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[req.query.network].port, shepherd.electrumServers[req.query.network].address, shepherd.electrumServers[req.query.network].proto); // tcp or tls + const ecl = new shepherd.electrumJSCore( + shepherd.electrumServers[req.query.network].port, + shepherd.electrumServers[req.query.network].address, + shepherd.electrumServers[req.query.network].proto + ); // tcp or tls shepherd.log(decodedTx.inputs[0]); shepherd.log(decodedTx.inputs[0].txid); diff --git a/routes/shepherd/log.js b/routes/shepherd/log.js index 3a09445..30d55ce 100644 --- a/routes/shepherd/log.js +++ b/routes/shepherd/log.js @@ -8,17 +8,10 @@ module.exports = (shepherd) => { console.log(msg); } - if (!isSpvOut) { - shepherd.appRuntimeLog.push({ - time: Date.now(), - msg: msg, - }); - } else { - shepherd.appRuntimeSPVLog.push({ - time: Date.now(), - msg: msg, - }); - } + shepherd[!isSpvOut ? 'appRuntimeLog' : 'appRuntimeSPVLog'].push({ + time: Date.now(), + msg: msg, + }); } shepherd.writeLog = (data) => { @@ -73,16 +66,17 @@ module.exports = (shepherd) => { shepherd.post('/guilog', (req, res, next) => { if (shepherd.checkToken(req.body.token)) { const logLocation = `${shepherd.agamaDir}/shepherd`; + const timestamp = req.body.timestamp; if (!shepherd.guiLog[shepherd.appSessionHash]) { shepherd.guiLog[shepherd.appSessionHash] = {}; } - if (shepherd.guiLog[shepherd.appSessionHash][req.body.timestamp]) { - shepherd.guiLog[shepherd.appSessionHash][req.body.timestamp].status = req.body.status; - shepherd.guiLog[shepherd.appSessionHash][req.body.timestamp].response = req.body.response; + if (shepherd.guiLog[shepherd.appSessionHash][timestamp]) { + shepherd.guiLog[shepherd.appSessionHash][timestamp].status = req.body.status; + shepherd.guiLog[shepherd.appSessionHash][timestamp].response = req.body.response; } else { - shepherd.guiLog[shepherd.appSessionHash][req.body.timestamp] = { + shepherd.guiLog[shepherd.appSessionHash][timestamp] = { function: req.body.function, type: req.body.type, url: req.body.url, diff --git a/routes/shepherd/quitDaemon.js b/routes/shepherd/quitDaemon.js index 45fa7b8..7ab65d2 100644 --- a/routes/shepherd/quitDaemon.js +++ b/routes/shepherd/quitDaemon.js @@ -31,7 +31,10 @@ module.exports = (shepherd) => { if (shepherd.appConfig.dataDir.length) { _arg.push(`-datadir=${shepherd.appConfig.dataDir + (key !== 'komodod' ? '/' + key : '')}`); } - } else if (key === 'komodod' && shepherd.appConfig.dataDir.length) { + } else if ( + key === 'komodod' && + shepherd.appConfig.dataDir.length + ) { _arg.push(`-datadir=${shepherd.appConfig.dataDir}`); }