Code cleanup
-Replace tabs with double-spaces -Betting spacing and lining up of code functions -Add missing semi-colons -Remove extra characters and spaces where applicable -Remove commented-out code fragments -Add missing 2021 date to LICENSE -Small touchups and other misc nitpickings
This commit is contained in:
+119
-72
@@ -1,22 +1,19 @@
|
||||
var request = require('postman-request')
|
||||
, settings = require('./settings')
|
||||
, Address = require('../models/address');
|
||||
var request = require('postman-request'),
|
||||
settings = require('./settings'),
|
||||
Address = require('../models/address');
|
||||
|
||||
var base_server = 'http://127.0.0.1:' + settings.webserver.port + "/";
|
||||
|
||||
var base_url = base_server + 'api/';
|
||||
|
||||
const onode = require('./node');
|
||||
const client = new onode.Client(settings.wallet);
|
||||
|
||||
// returns coinbase total sent as current coin supply
|
||||
function coinbase_supply(cb) {
|
||||
Address.findOne({a_id: 'coinbase'}, function(err, address) {
|
||||
if (address) {
|
||||
if (address)
|
||||
return cb(address.sent);
|
||||
} else {
|
||||
else
|
||||
return cb(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -38,8 +35,8 @@ function prepareRpcCommand(cmd, addParams) {
|
||||
// Split cmd by spaces
|
||||
var split = cmd.split(' ');
|
||||
|
||||
for (i=0; i<split.length; i++) {
|
||||
if (i==0)
|
||||
for (i = 0; i < split.length; i++) {
|
||||
if (i == 0)
|
||||
method_name = split[i];
|
||||
else
|
||||
params.push(split[i]);
|
||||
@@ -81,7 +78,8 @@ module.exports = {
|
||||
|
||||
get_hashrate: function(cb) {
|
||||
// check if hash rate should be hidden
|
||||
if (settings.shared_pages.show_hashrate == false) return cb('-');
|
||||
if (settings.shared_pages.show_hashrate == false)
|
||||
return cb('-');
|
||||
// check how to acquire network hashrate
|
||||
if (settings.shared_pages.page_header.panels.network_panel.nethash == 'netmhashps') {
|
||||
// load getmininginfo rpc call from settings
|
||||
@@ -93,7 +91,8 @@ module.exports = {
|
||||
// get data from wallet via rpc cmd
|
||||
rpcCommand([{method:cmd.method, parameters: cmd.parameters}], function(response) {
|
||||
// check if an error msg was received from the rpc server
|
||||
if (response == 'There was an error. Check your console.') return cb('-');
|
||||
if (response == 'There was an error. Check your console.')
|
||||
return cb('-');
|
||||
|
||||
var net_hash = null;
|
||||
// check for different implementations of the net has value
|
||||
@@ -117,6 +116,7 @@ module.exports = {
|
||||
} else {
|
||||
// get data via internal web api request
|
||||
var uri = base_url + 'getmininginfo';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.') {
|
||||
@@ -158,7 +158,8 @@ module.exports = {
|
||||
// get data from wallet via rpc cmd
|
||||
rpcCommand([{method:cmd.method, parameters: cmd.parameters}], function(response) {
|
||||
// check if an error msg was received from the rpc server
|
||||
if (response == 'There was an error. Check your console.') return cb('-');
|
||||
if (response == 'There was an error. Check your console.')
|
||||
return cb('-');
|
||||
// check if the response has a value
|
||||
if (response) {
|
||||
// return hash value with proper units
|
||||
@@ -171,6 +172,7 @@ module.exports = {
|
||||
} else {
|
||||
// get data via internal web api request
|
||||
var uri = base_url + 'getnetworkhashps';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.') {
|
||||
@@ -206,6 +208,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getdifficulty';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -234,6 +237,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getconnectioncount';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -262,6 +266,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getmasternodelist';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -290,6 +295,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getmasternodecount';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -318,6 +324,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getblockcount';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -346,6 +353,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getblockhash?height=' + (height ? height : '');
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -374,6 +382,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getblock?hash=' + hash;
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -402,6 +411,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getrawtransaction?txid=' + hash + '&decrypt=1';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -430,6 +440,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getmaxmoney';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -458,6 +469,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getmaxvote';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -486,6 +498,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getvote';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -514,6 +527,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getphase';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -542,6 +556,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getreward';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -570,6 +585,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getnextrewardestimate';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -598,6 +614,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getnextrewardwhenstr';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -614,51 +631,73 @@ module.exports = {
|
||||
|
||||
// synchonous loop used to interate through an array,
|
||||
// avoid use unless absolutely neccessary
|
||||
syncLoop: function(iterations, process, exit){
|
||||
syncLoop: function(iterations, process, exit) {
|
||||
var index = 0,
|
||||
done = false,
|
||||
shouldExit = false;
|
||||
|
||||
var loop = {
|
||||
next:function(){
|
||||
if(done){
|
||||
if(shouldExit && exit){
|
||||
exit(); // Exit if we're done
|
||||
}
|
||||
return; // Stop the loop if we're done
|
||||
}
|
||||
// If we're not finished
|
||||
if(index < iterations){
|
||||
index++; // Increment our index
|
||||
if (index % 100 === 0) { //clear stack
|
||||
setTimeout(function() {
|
||||
process(loop); // Run our process, pass in the loop
|
||||
}, 1);
|
||||
} else {
|
||||
process(loop); // Run our process, pass in the loop
|
||||
}
|
||||
// Otherwise we're done
|
||||
next: function() {
|
||||
if (done) {
|
||||
if (shouldExit && exit) {
|
||||
// exit if we're done
|
||||
exit();
|
||||
} else {
|
||||
done = true; // Make sure we say we're done
|
||||
if(exit) exit(); // Call the callback on exit
|
||||
// stop the loop if we're done
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// if we're not finished
|
||||
if (index < iterations) {
|
||||
// increment our index
|
||||
index++;
|
||||
|
||||
if (index % 100 === 0) {
|
||||
// clear stack
|
||||
setTimeout(function() {
|
||||
// run our process, pass in the loop
|
||||
process(loop);
|
||||
}, 1);
|
||||
} else {
|
||||
// run our process, pass in the loop
|
||||
process(loop);
|
||||
}
|
||||
} else {
|
||||
// otherwise we're done
|
||||
// make sure we say we're done
|
||||
done = true;
|
||||
|
||||
if (exit) {
|
||||
// call the callback on exit
|
||||
exit();
|
||||
}
|
||||
}
|
||||
},
|
||||
iteration:function() {
|
||||
return index - 1; // Return the loop number we're on
|
||||
iteration: function() {
|
||||
// return the loop number we're on
|
||||
return index - 1;
|
||||
},
|
||||
break:function(end) {
|
||||
done = true; // End the loop
|
||||
shouldExit = end; // Passing end as true means we still call the exit callback
|
||||
break: function(end) {
|
||||
// end the loop
|
||||
done = true;
|
||||
// passing end as true means we still call the exit callback
|
||||
shouldExit = end;
|
||||
}
|
||||
};
|
||||
|
||||
loop.next();
|
||||
|
||||
return loop;
|
||||
},
|
||||
|
||||
balance_supply: function(cb) {
|
||||
Address.find({}, 'balance').where('balance').gt(0).exec(function(err, docs) {
|
||||
var count = 0;
|
||||
|
||||
module.exports.syncLoop(docs.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
|
||||
count = count + docs[i].balance;
|
||||
loop.next();
|
||||
}, function() {
|
||||
@@ -683,6 +722,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getsupply';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -710,6 +750,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getinfo';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (!body || !body.moneysupply ||body == 'There was an error. Check your console.')
|
||||
@@ -742,6 +783,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'gettxoutsetinfo';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (!body || !body.total_amount ||body == 'There was an error. Check your console.')
|
||||
@@ -776,6 +818,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getpeerinfo';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -804,6 +847,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'verifymessage?address=' + address + '&signature=' + signature + '&message=' + message;
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -817,7 +861,7 @@ module.exports = {
|
||||
return cb(null);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
get_geo_location: function(address, cb) {
|
||||
request({uri: 'https://freegeoip.app/json/' + address, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, geo) {
|
||||
return cb(error, geo);
|
||||
@@ -827,38 +871,39 @@ module.exports = {
|
||||
is_unique: function(array, object, cb) {
|
||||
var unique = true;
|
||||
var index = null;
|
||||
|
||||
module.exports.syncLoop(array.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
|
||||
if (array[i].addresses == object) {
|
||||
unique = false;
|
||||
index = i;
|
||||
loop.break(true);
|
||||
loop.next();
|
||||
} else {
|
||||
} else
|
||||
loop.next();
|
||||
}
|
||||
}, function(){
|
||||
}, function() {
|
||||
return cb(unique, index);
|
||||
});
|
||||
},
|
||||
|
||||
calculate_total: function(vout, cb) {
|
||||
var total = 0;
|
||||
|
||||
module.exports.syncLoop(vout.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
//module.exports.convert_to_satoshi(parseFloat(vout[i].amount), function(amount_sat){
|
||||
total = total + vout[i].amount;
|
||||
loop.next();
|
||||
//});
|
||||
}, function(){
|
||||
|
||||
total = total + vout[i].amount;
|
||||
loop.next();
|
||||
}, function() {
|
||||
return cb(total);
|
||||
});
|
||||
},
|
||||
|
||||
prepare_vout: function(vout, txid, vin, vhidden, cb) {
|
||||
var arr_vout = [];
|
||||
var arr_vin = [];
|
||||
arr_vin = vin;
|
||||
var arr_vin = vin;
|
||||
|
||||
module.exports.syncLoop(vout.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
// make sure vout has an address
|
||||
@@ -906,6 +951,7 @@ module.exports = {
|
||||
// the sent and received values are not known in this case. only the fee paid is known and subtracted from the sender.
|
||||
arr_vout.push({addresses: "private_tx", amount: 0});
|
||||
}
|
||||
|
||||
// add a private send address with the known amount sent
|
||||
arr_vin.push({addresses: "private_tx", amount: amount_sat});
|
||||
});
|
||||
@@ -919,6 +965,7 @@ module.exports = {
|
||||
//PoS
|
||||
arr_vout[0].amount = arr_vout[0].amount - arr_vin[0].amount;
|
||||
arr_vin.shift();
|
||||
|
||||
return cb(arr_vout, arr_vin);
|
||||
} else
|
||||
return cb(arr_vout, arr_vin);
|
||||
@@ -931,67 +978,67 @@ module.exports = {
|
||||
|
||||
get_input_addresses: function(input, vout, cb) {
|
||||
var addresses = [];
|
||||
|
||||
if (input.coinbase) {
|
||||
var amount = 0;
|
||||
|
||||
module.exports.syncLoop(vout.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
amount = amount + parseFloat(vout[i].value);
|
||||
loop.next();
|
||||
}, function(){
|
||||
|
||||
amount = amount + parseFloat(vout[i].value);
|
||||
loop.next();
|
||||
}, function() {
|
||||
addresses.push({hash: 'coinbase', amount: amount});
|
||||
return cb(addresses);
|
||||
});
|
||||
} else {
|
||||
module.exports.get_rawtransaction(input.txid, function(tx){
|
||||
module.exports.get_rawtransaction(input.txid, function(tx) {
|
||||
if (tx) {
|
||||
module.exports.syncLoop(tx.vout.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
|
||||
if (tx.vout[i].n == input.vout) {
|
||||
//module.exports.convert_to_satoshi(parseFloat(tx.vout[i].value), function(amount_sat){
|
||||
if (tx.vout[i].scriptPubKey.addresses) {
|
||||
if (tx.vout[i].scriptPubKey.addresses)
|
||||
addresses.push({hash: tx.vout[i].scriptPubKey.addresses[0], amount:tx.vout[i].value});
|
||||
}
|
||||
loop.break(true);
|
||||
loop.next();
|
||||
//});
|
||||
} else {
|
||||
|
||||
loop.break(true);
|
||||
loop.next();
|
||||
}
|
||||
}, function(){
|
||||
} else
|
||||
loop.next();
|
||||
}, function() {
|
||||
return cb(addresses);
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
prepare_vin: function(tx, cb) {
|
||||
var arr_vin = [];
|
||||
|
||||
module.exports.syncLoop(tx.vin.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
module.exports.get_input_addresses(tx.vin[i], tx.vout, function(addresses){
|
||||
|
||||
module.exports.get_input_addresses(tx.vin[i], tx.vout, function(addresses) {
|
||||
if (addresses && addresses.length) {
|
||||
//console.log('vin');
|
||||
module.exports.is_unique(arr_vin, addresses[0].hash, function(unique, index) {
|
||||
if (unique == true) {
|
||||
module.exports.convert_to_satoshi(parseFloat(addresses[0].amount), function(amount_sat){
|
||||
module.exports.convert_to_satoshi(parseFloat(addresses[0].amount), function(amount_sat) {
|
||||
arr_vin.push({addresses:addresses[0].hash, amount:amount_sat});
|
||||
loop.next();
|
||||
});
|
||||
} else {
|
||||
module.exports.convert_to_satoshi(parseFloat(addresses[0].amount), function(amount_sat){
|
||||
module.exports.convert_to_satoshi(parseFloat(addresses[0].amount), function(amount_sat) {
|
||||
arr_vin[index].amount = arr_vin[index].amount + amount_sat;
|
||||
loop.next();
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
loop.next();
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
}, function() {
|
||||
return cb(arr_vin);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user