Conflicts: assets/BitRock Installer Files/IgaunaApp-Linux.xml assets/BitRock Installer Files/IgaunaApp-OSX.xml assets/BitRock Installer Files/IgaunaApp-Win.xmlall-modes
@ -0,0 +1,3 @@ |
|||
[submodule "gui/EasyDEX-GUI"] |
|||
path = gui/EasyDEX-GUI |
|||
url = https://github.com/SuperNETorg/EasyDEX-GUI.git |
@ -0,0 +1,19 @@ |
|||
mkdir %AppData%\Komodo |
|||
|
|||
@echo off |
|||
|
|||
IF NOT EXIST %AppData%\Komodo\komodo.conf ( |
|||
( |
|||
echo rpcuser=kmdusr%random%%random% |
|||
echo rpcpassword=kmdpass%random%%random% |
|||
echo rpcbind=127.0.0.1 |
|||
echo txindex=1 |
|||
echo server=1 |
|||
echo addnode=5.9.102.210 |
|||
echo addnode=78.47.196.146 |
|||
echo addnode=178.63.69.164 |
|||
echo addnode=88.198.65.74 |
|||
echo addnode=5.9.122.241 |
|||
echo addnode=144.76.94.38 |
|||
) > %AppData%\Komodo\komodo.conf |
|||
) |
After Width: | Height: | Size: 6.1 KiB |
After Width: | Height: | Size: 693 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 4.6 KiB |
After Width: | Height: | Size: 361 KiB |
After Width: | Height: | Size: 41 KiB |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 2.8 KiB |
@ -0,0 +1,17 @@ |
|||
#!/bin/bash |
|||
### Build script for Iguana application for Linux x32 and x64 platform. |
|||
### Created by mmaxian, 3/2017 |
|||
|
|||
[ -z $IGUANA_VERSION ] && echo "IGUANA_VERSION variable is not set." && exit 0 |
|||
|
|||
echo "Preparing electron package $IGUANA_VERSION for Linux." |
|||
./buildscripts/electron-build-linux.sh |
|||
echo |
|||
|
|||
echo "Preparing electron package $IGUANA_VERSION for Windows." |
|||
./buildscripts/electron-build-win.sh |
|||
echo |
|||
|
|||
echo "Preparing electron package $IGUANA_VERSION for MacOS." |
|||
./buildscripts/electron-build-osx.sh |
|||
echo |
@ -0,0 +1,16 @@ |
|||
#!/bin/bash |
|||
### Build script for Iguana application for Linux x32 and x64 platform. |
|||
### Created by mmaxian, 3/2017 |
|||
|
|||
[ -z $IGUANA_VERSION ] && echo "IGUANA_VERSION variable is not set." && exit 0 |
|||
|
|||
echo "Build script for Iguana application for Linux x32 and x64 platform." |
|||
echo "Preparing electron package $IGUANA_VERSION" |
|||
electron-packager . --platform=linux --arch=ia32 \ |
|||
--icon=assets/icons/iguana_app_icon_png/128x128.png \ |
|||
--out=build/ --buildVersion=$IGUANA_VERSION \ |
|||
--ignore=assets/bin/win64 --ignore=assets/bin/osx --overwrite |
|||
electron-packager . --platform=linux --arch=x64 \ |
|||
--icon=assets/icons/iguana_app_icon_png/128x128.png \ |
|||
--out=build/ --buildVersion=$IGUANA_VERSION \ |
|||
--ignore=assets/bin/win64 --ignore=assets/bin/osx --overwrite |
@ -0,0 +1,12 @@ |
|||
#!/bin/bash |
|||
### Build script for Iguana application for MacOS platform. |
|||
### Created by mmaxian, 3/2017 |
|||
|
|||
[ -z $IGUANA_VERSION ] && echo "IGUANA_VERSION variable is not set." && exit 0 |
|||
|
|||
echo "Build script for Iguana application for MacOS platform." |
|||
echo "Preparing electron package $IGUANA_VERSION" |
|||
electron-packager . --platform=darwin --arch=x64 \ |
|||
--icon=assets/icons/iguana_app_icon.icns \ |
|||
--out=build/ --buildVersion=$IGUANA_VERSION \ |
|||
--ignore=assets/bin/win64 --ignore=assets/bin/linux64 --overwrite |
@ -0,0 +1,18 @@ |
|||
#!/bin/bash |
|||
### Build script for Iguana application for Windows ia32 and x64 platform. |
|||
### Created by mmaxian, 3/2017 |
|||
|
|||
[ -z $IGUANA_VERSION ] && echo "IGUANA_VERSION variable is not set." && exit 0 |
|||
|
|||
echo "Build script for Iguana application for Windows ia32 and x64 platform." |
|||
echo "Preparing electron package $IGUANA_VERSION" |
|||
|
|||
electron-packager . --platform=win32 --arch=x64 \ |
|||
--icon=assets/icons/iguana_app_icon.ico \ |
|||
--out=build/ --buildVersion=$IGUANA_VERSION \ |
|||
--ignore=assets/bin/osx --ignore=assets/bin/linux64 --overwrite |
|||
|
|||
electron-packager . --platform=win32 --arch=ia32 \ |
|||
--icon=assets/icons/iguana_app_icon.ico \ |
|||
--out=build/ --buildVersion=$IGUANA_VERSION \ |
|||
--ignore=assets/bin/osx --ignore=assets/bin/linux64 --overwrite |
@ -0,0 +1,14 @@ |
|||
#!/bin/bash |
|||
### Script will check EasyDEX-GUI submodule in gui folder. |
|||
### If you used git clone without --recursive option this is way to go. |
|||
|
|||
PWD=`pwd` |
|||
SIZE=`du -sk gui/EasyDEX-GUI` |
|||
|
|||
echo "Checking EasyDEX-GUI folder." |
|||
cd gui/EasyDEX-GUI && \ |
|||
git submodule update --recursive && \ |
|||
cd ../.. && \ |
|||
echo "Folder looks fine." || \ |
|||
echo "Some problem with cloning submodule EasyDEX-GUI." |
|||
echo |
@ -1,10 +0,0 @@ |
|||
#!/usr/bin/env bash |
|||
cd "tmp/Iguana-application" |
|||
|
|||
gulp prod |
|||
|
|||
cd ../../ |
|||
|
|||
rm "gui/Iguana-GUI" -rf |
|||
|
|||
cp -rf "tmp/Iguana-application/compiled/prod" "gui/Iguana-GUI" |
@ -1,36 +0,0 @@ |
|||
#!/usr/bin/env bash |
|||
if [ -d "tmp" ]; then |
|||
cd tmp |
|||
else |
|||
mkdir tmp |
|||
cd tmp |
|||
fi |
|||
|
|||
if [ -d "EasyDEX-GUI" ]; then |
|||
cd EasyDEX-GUI |
|||
git pull |
|||
cd ../ |
|||
else |
|||
git clone https://github.com/SuperNETorg/EasyDEX-GUI.git |
|||
fi |
|||
|
|||
#if [ -d "Iguana-application" ]; then |
|||
# cd Iguana-application |
|||
# git checkout 0.3.1 |
|||
# git pull |
|||
#else |
|||
# git clone https://github.com/SuperNETorg/Iguana-application.git -b 0.3.1 |
|||
# cd Iguana-application |
|||
#fi |
|||
|
|||
#bower install |
|||
#npm install |
|||
#gulp electron |
|||
|
|||
cd ../../ |
|||
|
|||
rm "gui/EasyDEX-GUI" -rf |
|||
#rm "gui/Iguana-GUI" -rf |
|||
|
|||
#cp -rf "tmp/Iguana-application/compiled/prod" "gui/Iguana-GUI" |
|||
cp -rf "tmp/EasyDEX-GUI" "gui/EasyDEX-GUI" |
@ -0,0 +1,589 @@ |
|||
const fs = require('fs-extra'), |
|||
request = require('request'), |
|||
async = require('async'); |
|||
|
|||
var cache = {}; |
|||
|
|||
cache.setVar = function(variable, value) { |
|||
cache[variable] = value; |
|||
} |
|||
|
|||
cache.get = function(req, res, next) { |
|||
var pubkey = req.query.pubkey; |
|||
|
|||
if (pubkey) { |
|||
if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json')) { |
|||
fs.readFile(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json', 'utf8', function (err, data) { |
|||
if (err) { |
|||
var errorObj = { |
|||
'msg': 'error', |
|||
'result': err |
|||
}; |
|||
|
|||
res.end(JSON.stringify(errorObj)); |
|||
} else { |
|||
var parsedJSON = 'JSON parse error'; |
|||
|
|||
try { |
|||
parsedJSON = JSON.parse(data); |
|||
} catch (e) { |
|||
console.log('JSON parse error'); |
|||
} |
|||
|
|||
var successObj = { |
|||
'msg': 'success', |
|||
'result': parsedJSON |
|||
}; |
|||
|
|||
res.end(JSON.stringify(successObj)); |
|||
} |
|||
}); |
|||
} else { |
|||
var errorObj = { |
|||
'msg': 'error', |
|||
'result': 'no file with handle ' + pubkey |
|||
}; |
|||
|
|||
res.end(JSON.stringify(errorObj)); |
|||
} |
|||
} else { |
|||
var errorObj = { |
|||
'msg': 'error', |
|||
'result': 'no pubkey provided' |
|||
}; |
|||
|
|||
res.end(JSON.stringify(errorObj)); |
|||
} |
|||
} |
|||
|
|||
cache.groomGet = function(req, res, next) { |
|||
var _filename = req.query.filename; |
|||
|
|||
if (_filename) { |
|||
if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json')) { |
|||
fs.readFile(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json', 'utf8', function (err, data) { |
|||
if (err) { |
|||
var errorObj = { |
|||
'msg': 'error', |
|||
'result': err |
|||
}; |
|||
|
|||
res.end(JSON.stringify(errorObj)); |
|||
} else { |
|||
var successObj = { |
|||
'msg': 'success', |
|||
'result': data ? JSON.parse(data) : '' |
|||
}; |
|||
|
|||
res.end(JSON.stringify(successObj)); |
|||
} |
|||
}); |
|||
} else { |
|||
var errorObj = { |
|||
'msg': 'error', |
|||
'result': 'no file with name ' + _filename |
|||
}; |
|||
|
|||
res.end(JSON.stringify(errorObj)); |
|||
} |
|||
} else { |
|||
var errorObj = { |
|||
'msg': 'error', |
|||
'result': 'no file name provided' |
|||
}; |
|||
|
|||
res.end(JSON.stringify(errorObj)); |
|||
} |
|||
} |
|||
|
|||
cache.groomDelete = function(req, res, next) { |
|||
var _filename = req.body.filename; |
|||
|
|||
if (_filename) { |
|||
if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json')) { |
|||
fs.unlink(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json', function(err) { |
|||
if (err) { |
|||
var errorObj = { |
|||
'msg': 'error', |
|||
'result': err |
|||
}; |
|||
|
|||
res.end(JSON.stringify(errorObj)); |
|||
} else { |
|||
var successObj = { |
|||
'msg': 'success', |
|||
'result': 'deleted' |
|||
}; |
|||
|
|||
res.end(JSON.stringify(successObj)); |
|||
} |
|||
}); |
|||
} else { |
|||
var errorObj = { |
|||
'msg': 'error', |
|||
'result': 'no file with name ' + _filename |
|||
}; |
|||
|
|||
res.end(JSON.stringify(errorObj)); |
|||
} |
|||
} else { |
|||
var errorObj = { |
|||
'msg': 'error', |
|||
'result': 'no file name provided' |
|||
}; |
|||
|
|||
res.end(JSON.stringify(errorObj)); |
|||
} |
|||
} |
|||
|
|||
cache.groomPost = function(req, res) { |
|||
var _filename = req.body.filename, |
|||
_payload = req.body.payload; |
|||
|
|||
if (_filename) { |
|||
if (!_payload) { |
|||
var errorObj = { |
|||
'msg': 'error', |
|||
'result': 'no payload provided' |
|||
}; |
|||
|
|||
res.end(JSON.stringify(errorObj)); |
|||
} else { |
|||
fs.writeFile(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json', _payload, function (err) { |
|||
if (err) { |
|||
var errorObj = { |
|||
'msg': 'error', |
|||
'result': err |
|||
}; |
|||
|
|||
res.end(JSON.stringify(errorObj)); |
|||
} else { |
|||
var successObj = { |
|||
'msg': 'success', |
|||
'result': 'done' |
|||
}; |
|||
|
|||
res.end(JSON.stringify(successObj)); |
|||
} |
|||
}); |
|||
} |
|||
} else { |
|||
var errorObj = { |
|||
'msg': 'error', |
|||
'result': 'no file name provided' |
|||
}; |
|||
|
|||
res.end(JSON.stringify(errorObj)); |
|||
} |
|||
} |
|||
|
|||
var cacheCallInProgress = false, |
|||
cacheGlobLifetime = 300; // sec
|
|||
|
|||
// TODO: reset calls' states on new /cache call start
|
|||
var mock = require('./mock'); |
|||
|
|||
/* |
|||
* type: GET |
|||
* params: userpass, pubkey, coin, address, skip |
|||
*/ |
|||
cache.one = function(req, res, next) { |
|||
if (req.query.pubkey && !fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + req.query.pubkey + '.json')) { |
|||
cacheCallInProgress = false; |
|||
} |
|||
|
|||
if (!cacheCallInProgress) { |
|||
// TODO: add check to allow only one cache call/sequence in progress
|
|||
cacheCallInProgress = true; |
|||
|
|||
var sessionKey = req.query.userpass, |
|||
coin = req.query.coin, |
|||
address = req.query.address, |
|||
pubkey = req.query.pubkey, |
|||
mock = req.query.mock, |
|||
skipTimeout = req.query.skip, |
|||
callsArray = req.query.calls.split(':'), |
|||
errorObj = { |
|||
'msg': 'error', |
|||
'result': 'error' |
|||
}, |
|||
outObj = {}, |
|||
pubkey, |
|||
writeCache = function(timeStamp) { |
|||
if (timeStamp) { |
|||
outObj.timestamp = timeStamp; |
|||
} |
|||
|
|||
fs.writeFile(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json', JSON.stringify(outObj), function(err) { |
|||
if (err) { |
|||
return console.log(err); |
|||
} |
|||
|
|||
console.log('file ' + cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json is updated'); |
|||
if (timeStamp) { |
|||
console.log('file ' + cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json is timestamped'); |
|||
} |
|||
}); |
|||
}, |
|||
callStack = {}, |
|||
checkCallStack = function() { |
|||
var total = 0; |
|||
|
|||
for (var coin in callStack) { |
|||
total =+ callStack[coin]; |
|||
} |
|||
|
|||
if (total / Object.keys(callStack).length === 1) { |
|||
cacheCallInProgress = false; |
|||
cache.io.emit('messages', { |
|||
'message': { |
|||
'shepherd': { |
|||
'method': 'cache-one', |
|||
'status': 'done', |
|||
'resp': 'success' |
|||
} |
|||
} |
|||
}); |
|||
// add timestamp to cache file
|
|||
// writeCache(Date.now());
|
|||
} |
|||
}, |
|||
checkTimestamp = function(dateToCheck) { |
|||
var currentEpochTime = new Date(Date.now()) / 1000, |
|||
secondsElapsed = Number(currentEpochTime) - Number(dateToCheck / 1000); |
|||
|
|||
return Math.floor(secondsElapsed); |
|||
}, |
|||
internalError = false; |
|||
|
|||
callStack[coin] = 1; |
|||
console.log(callsArray); |
|||
|
|||
if (!sessionKey) { |
|||
var errorObj = { |
|||
'msg': 'error', |
|||
'result': 'no session key provided' |
|||
}; |
|||
|
|||
res.end(JSON.stringify(errorObj)); |
|||
internalError = true; |
|||
} |
|||
|
|||
if (!pubkey) { |
|||
var errorObj = { |
|||
'msg': 'error', |
|||
'result': 'no pubkey provided' |
|||
}; |
|||
|
|||
res.end(JSON.stringify(errorObj)); |
|||
internalError = true; |
|||
} |
|||
|
|||
console.log('cache-one call started'); |
|||
|
|||
if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json') && coin !== 'all') { |
|||
var _file = fs.readFileSync(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json', 'utf8'); |
|||
outObj = _file ? JSON.parse(_file) : {}; |
|||
|
|||
if (!outObj || !outObj.basilisk) { |
|||
console.log('no local basilisk info'); |
|||
outObj['basilisk'] = {}; |
|||
outObj['basilisk'][coin] = {}; |
|||
} else { |
|||
if (!outObj['basilisk'][coin]) { |
|||
console.log('no local coin info'); |
|||
outObj['basilisk'][coin] = {}; |
|||
} |
|||
} |
|||
} else { |
|||
outObj['basilisk'] = {}; |
|||
outObj['basilisk'][coin] = {}; |
|||
} |
|||
|
|||
res.end(JSON.stringify({ |
|||
'msg': 'success', |
|||
'result': 'call is initiated' |
|||
})); |
|||
|
|||
if (!internalError) { |
|||
cache.io.emit('messages', { |
|||
'message': { |
|||
'shepherd': { |
|||
'method': 'cache-one', |
|||
'status': 'in progress' |
|||
} |
|||
} |
|||
}); |
|||
|
|||
function execDEXRequests(address, coin) { |
|||
let dexUrls = { |
|||
'listunspent': 'http://' + cache.appConfig.host + ':' + cache.appConfig.iguanaCorePort + '/api/dex/listunspent?userpass=' + sessionKey + '&symbol=' + coin + '&address=' + address, |
|||
'listtransactions': 'http://' + cache.appConfig.host + ':' + cache.appConfig.iguanaCorePort + '/api/dex/listtransactions?userpass=' + sessionKey + '&count=100&skip=0&symbol=' + coin + '&address=' + address, |
|||
'getbalance': 'http://' + cache.appConfig.host + ':' + cache.appConfig.iguanaCorePort + '/api/dex/getbalance?userpass=' + sessionKey + '&symbol=' + coin + '&address=' + address, |
|||
'refresh': 'http://' + cache.appConfig.host + ':' + cache.appConfig.iguanaCorePort + '/api/basilisk/refresh?userpass=' + sessionKey + '&timeout=600000&symbol=' + coin + '&address=' + address |
|||
}, |
|||
_dexUrls = {}; |
|||
|
|||
for (var a = 0; a < callsArray.length; a++) { |
|||
_dexUrls[callsArray[a]] = dexUrls[callsArray[a]]; |
|||
} |
|||
|
|||
if (coin === 'BTC' || coin === 'SYS') { |
|||
delete _dexUrls.refresh; |
|||
delete _dexUrls.getbalance; |
|||
} |
|||
|
|||
console.log(coin + ' address ' + address); |
|||
if (!outObj.basilisk[coin][address]) { |
|||
outObj.basilisk[coin][address] = {}; |
|||
writeCache(); |
|||
} |
|||
|
|||
// set current call status
|
|||
async.forEachOf(_dexUrls, function(dexUrl, key) { |
|||
if (!outObj.basilisk[coin][address][key]) { |
|||
outObj.basilisk[coin][address][key] = {}; |
|||
outObj.basilisk[coin][address][key].status = 'waiting'; |
|||
} else { |
|||
outObj.basilisk[coin][address][key].status = 'waiting'; |
|||
} |
|||
}); |
|||
writeCache(); |
|||
|
|||
async.forEachOf(_dexUrls, function(dexUrl, key) { |
|||
var tooEarly = false; |
|||
if (outObj.basilisk[coin][address][key] && |
|||
outObj.basilisk[coin][address][key].timestamp && |
|||
checkTimestamp(outObj.basilisk[coin][address][key].timestamp) < cacheGlobLifetime) { |
|||
tooEarly = true; |
|||
outObj.basilisk[coin][address][key].status = 'done'; |
|||
cache.io.emit('messages', { |
|||
'message': { |
|||
'shepherd': { |
|||
'method': 'cache-one', |
|||
'status': 'in progress', |
|||
'iguanaAPI': { |
|||
'method': key, |
|||
'coin': coin, |
|||
'address': address, |
|||
'status': 'done', |
|||
'resp': 'too early' |
|||
} |
|||
} |
|||
} |
|||
}); |
|||
} |
|||
if (!tooEarly) { |
|||
cache.io.emit('messages', { |
|||
'message': { |
|||
'shepherd': { |
|||
'method': 'cache-one', |
|||
'status': 'in progress', |
|||
'iguanaAPI': { |
|||
'method': key, |
|||
'coin': coin, |
|||
'address': address, |
|||
'status': 'in progress' |
|||
} |
|||
} |
|||
} |
|||
}); |
|||
outObj.basilisk[coin][address][key].status = 'in progress'; |
|||
request({ |
|||
url: mock ? 'http://localhost:17777/shepherd/mock?url=' + dexUrl : dexUrl, |
|||
method: 'GET' |
|||
}, function (error, response, body) { |
|||
if (response && response.statusCode && response.statusCode === 200) { |
|||
cache.io.emit('messages', { |
|||
'message': { |
|||
'shepherd': { |
|||
'method': 'cache-one', |
|||
'status': 'in progress', |
|||
'iguanaAPI': { |
|||
'method': key, |
|||
'coin': coin, |
|||
'address': address, |
|||
'status': 'done', |
|||
'resp': body |
|||
} |
|||
} |
|||
} |
|||
}); |
|||
outObj.basilisk[coin][address][key] = {}; |
|||
outObj.basilisk[coin][address][key].data = JSON.parse(body); |
|||
outObj.basilisk[coin][address][key].timestamp = Date.now(); // add timestamp
|
|||
outObj.basilisk[coin][address][key].status = 'done'; |
|||
console.log(dexUrl); |
|||
console.log(body); |
|||
callStack[coin]--; |
|||
console.log(coin + ' _stack len ' + callStack[coin]); |
|||
checkCallStack(); |
|||
|
|||
writeCache(); |
|||
} |
|||
if (error || !body || !response) { |
|||
outObj.basilisk[coin][address][key] = {}; |
|||
outObj.basilisk[coin][address][key].data = { 'error': 'request failed' }; |
|||
outObj.basilisk[coin][address][key].timestamp = 1471620867 // add timestamp
|
|||
outObj.basilisk[coin][address][key].status = 'done'; |
|||
callStack[coin]--; |
|||
console.log(coin + ' _stack len ' + callStack[coin]); |
|||
checkCallStack(); |
|||
writeCache(); |
|||
} |
|||
}); |
|||
} else { |
|||
console.log(key + ' is fresh, check back in ' + (cacheGlobLifetime - checkTimestamp(outObj.basilisk[coin][address][key].timestamp)) + 's'); |
|||
callStack[coin]--; |
|||
console.log(coin + ' _stack len ' + callStack[coin]); |
|||
checkCallStack(); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
function getAddresses(coin) { |
|||
var tempUrl = 'http://' + cache.appConfig.host + ':' + cache.appConfig.iguanaCorePort + '/api/bitcoinrpc/getaddressesbyaccount?userpass=' + sessionKey + '&coin=' + coin + '&account=*'; |
|||
request({ |
|||
url: mock ? 'http://localhost:17777/shepherd/mock?url=' + tempUrl : tempUrl, |
|||
method: 'GET' |
|||
}, function (error, response, body) { |
|||
if (response && response.statusCode && response.statusCode === 200) { |
|||
cache.io.emit('messages', { |
|||
'message': { |
|||
'shepherd': { |
|||
'method': 'cache-one', |
|||
'status': 'in progress', |
|||
'iguanaAPI': { |
|||
'method': 'getaddressesbyaccount', |
|||
'coin': coin, |
|||
'status': 'done', |
|||
'resp': body |
|||
} |
|||
} |
|||
} |
|||
}); |
|||
outObj.basilisk[coin].addresses = JSON.parse(body).result; |
|||
console.log(JSON.parse(body).result); |
|||
writeCache(); |
|||
var addrCount = outObj.basilisk[coin].addresses ? outObj.basilisk[coin].addresses.length : 0; |
|||
var callsArrayBTC = callsArray.length; |
|||
if (callsArray.indexOf('getbalance') > - 1) { |
|||
callsArrayBTC--; |
|||
} |
|||
if (callsArray.indexOf('refresh') > - 1) { |
|||
callsArrayBTC--; |
|||
} |
|||
callStack[coin] = callStack[coin] + addrCount * (coin === 'BTC' || coin === 'SYS' ? callsArrayBTC : callsArray.length); |
|||
console.log(coin + ' stack len ' + callStack[coin]); |
|||
|
|||
async.each(outObj.basilisk[coin].addresses, function(address) { |
|||
execDEXRequests(address, coin); |
|||
}); |
|||
} else { |
|||
// TODO: error
|
|||
} |
|||
}); |
|||
} |
|||
|
|||
// update all available coin addresses
|
|||
if (!address) { |
|||
cache.io.emit('messages', { |
|||
'message': { |
|||
'shepherd': { |
|||
'method': 'cache-one', |
|||
'status': 'in progress', |
|||
'iguanaAPI': { |
|||
'method': 'getaddressesbyaccount', |
|||
'coin': coin, |
|||
'status': 'in progress' |
|||
} |
|||
} |
|||
} |
|||
}); |
|||
|
|||
if (coin === 'all') { |
|||
var tempUrl = 'http://' + cache.appConfig.host + ':' + cache.appConfig.iguanaCorePort + '/api/InstantDEX/allcoins?userpass=' + sessionKey; |
|||
request({ |
|||
url: mock ? 'http://localhost:17777/shepherd/mock?url=' + tempUrl : tempUrl, |
|||
method: 'GET' |
|||
}, function (error, response, body) { |
|||
if (response && response.statusCode && response.statusCode === 200) { |
|||
console.log(JSON.parse(body).basilisk); |
|||
cache.io.emit('messages', { |
|||
'message': { |
|||
'shepherd': { |
|||
'method': 'cache-one', |
|||
'status': 'in progress', |
|||
'iguanaAPI': { |
|||
'method': 'allcoins', |
|||
'status': 'done', |
|||
'resp': body |
|||
} |
|||
} |
|||
} |
|||
}); |
|||
body = JSON.parse(body); |
|||
// basilisk coins
|
|||
if (body.basilisk && body.basilisk.length) { |
|||
// get coin addresses
|
|||
async.each(body.basilisk, function(coin) { |
|||
callStack[coin] = 1; |
|||
}); |
|||
|
|||
async.each(body.basilisk, function(coin) { |
|||
outObj.basilisk[coin] = {}; |
|||
writeCache(); |
|||
|
|||
cache.io.emit('messages', { |
|||
'message': { |
|||
'shepherd': { |
|||
'method': 'cache-one', |
|||
'status': 'in progress', |
|||
'iguanaAPI': { |
|||
'method': 'getaddressesbyaccount', |
|||
'coin': coin, |
|||
'status': 'in progress' |
|||
} |
|||
} |
|||
} |
|||
}); |
|||
|
|||
getAddresses(coin); |
|||
}); |
|||
} |
|||
} |
|||
if (error) { // stop further requests on failure, exit
|
|||
callStack[coin] = 1; |
|||
checkCallStack(); |
|||
} |
|||
}); |
|||
} else { |
|||
getAddresses(coin); |
|||
} |
|||
} else { |
|||
callStack[coin] = callStack[coin] + (coin === 'BTC' ? callsArray.length : callsArray.length - 2); |
|||
console.log(coin + ' stack len ' + callStack[coin]); |
|||
|
|||
execDEXRequests(coin, address); |
|||
} |
|||
} else { |
|||
cache.io.emit('messages', { |
|||
'message': { |
|||
'shepherd': { |
|||
'method': 'cache-all', |
|||
'status': 'done', |
|||
'resp': 'internal error' |
|||
} |
|||
} |
|||
}); |
|||
cacheCallInProgress = false; |
|||
} |
|||
} else { |
|||
res.end(JSON.stringify({ |
|||
'msg': 'error', |
|||
'result': 'another call is in progress already' |
|||
})); |
|||
} |
|||
}; |
|||
|
|||
module.exports = cache; |
@ -0,0 +1,39 @@ |
|||
const fs = require('fs-extra'), |
|||
request = require('request'), |
|||
async = require('async'), |
|||
url = require('url'); |
|||
|
|||
var mock = {}; |
|||
|
|||
mock.setVar = function(variable, value) { |
|||
mock[variable] = value; |
|||
} |
|||
|
|||
mock.get = function(req, res, next) { |
|||
var _url = req.query.url; |
|||
|
|||
if (_url.indexOf('/InstantDEX/allcoins') > -1) { |
|||
res.end(JSON.stringify({ |
|||
'native': [], |
|||
'basilisk': [ 'KMD', 'BTC'], |
|||
'full':[], |
|||
'tag': '18430609759584422959' |
|||
})); |
|||
} |
|||
if (_url.indexOf('/bitcoinrpc/getaddressesbyaccount') > -1) { |
|||
console.log(_url.indexOf('/bitcoinrpc/getaddressesbyaccount')); |
|||
res.end(JSON.stringify({ |
|||
'result': ["RDbGxL8QYdEp8sMULaVZS2E6XThcTKT9Jd","RL4orv22Xch7PhM5w9jUHhVQhX6kF6GkfS","RUrxvPTEKGWEDTvAtgiqbUTTFE53Xdpj8a","RPJoLDa7RezvfUUBr7R3U8wrP16AgUsNw3","RQPTpRJEeafNx5hkDzgjcsPyU4E8RFVApT"] |
|||
})); |
|||
} |
|||
if (_url.indexOf('/api/dex/listunspent') > -1 || |
|||
_url.indexOf('/api/dex/listtransactions') > -1 || |
|||
_url.indexOf('/api/ss/getbalance') > -1 || |
|||
_url.indexOf('/api/ww/refresh') > -1) { |
|||
res.end(JSON.stringify({ |
|||
'some key': 'some value' |
|||
})); |
|||
} |
|||
} |
|||
|
|||
module.exports = mock; |