Massive overhaul and cleanup of settings
-Restructured the settings.json.template and settings.js files with better groupings -Added better comments for improved explanations of all settings -Better handling of page length options on all datatables; Page length options are now configurable and also only display options based on limits set by certain items_per_page and max_items_per_query settings -Markets have been extended to support unlimited trading pairs for each exchange -Added coin_symbol and pair_symbol to the markets schema to support multiple trading pairs -Added a burned field to the richlist schema for tracking burned coin addresses -Added a locale string for the new richlist wealth distribution "Top 1-100 Total" table row -Updated a couple locale strings that were incomplete or needed fixing (api_getblockhash and api_getnextrewardwhenstr) -Added a new css class to remove some redundant inline styles for the richlist wealth distribution color boxes -Richlist page now allows better separation of the top list(s) and the wealth distribution table and chart (you can now hide or show sections as desired) -Richlist page now allows for better burned coin support (Hide burned coin addresses from lists and totals even when the burned coin amounts are still included in the total coin supply value) -Block page now only displays the raw block link if the api_page.public_apis.rpc.getblock.enabled settings is set to true -Transaction page now only displays the raw tx link if the api_page.public_apis.rpc.getrawtransaction.enabled setting is set to true -Rate limiting class has been made global and is now used to limit market requests -getnetworkhashps rpc call now returns a '-' if shared_pages.show_hashrate is not set to true -Searching for unsycned blocks/txs no longer saves the data locally but instead still shows the data on screen. This helps prevent syncing data out-of-order (This eliminates the need for db_index.pid which has been removed) -Coin supply is now always taken from the stats collection database instead of from the wallet via rpc command in all cases except when syncing -Lots of misc fixes and code cleanup changes -List of changed settings: -title -> shared_pages.page_title -coin -> coin.name -symbol -> coin.symbol -logo -> shared_pages.logo -headerlogo -> shared_pages.page_header.home_link_logo -favicon -> shared_pages.favicon -homelink -> shared_pages.page_header.home_link -logoheight -> shared_pages.page_header.home_link_logo_height -sticky_header -> shared_pages.page_header.sticky_header -sticky_footer -> shared_pages.page_footer.sticky_footer -footer_height_desktop -> shared_pages.page_footer.footer_height_desktop -footer_height_tablet -> shared_pages.page_footer.footer_height_tablet -footer_height_mobile -> shared_pages.page_footer.footer_height_mobile -social_link_percent_height_desktop -> shared_pages.page_footer.social_link_percent_height_desktop -social_link_percent_height_tablet -> shared_pages.page_footer.social_link_percent_height_tablet -social_link_percent_height_mobile -> shared_pages.page_footer.social_link_percent_height_mobile -theme -> shared_pages.theme -port -> webserver.port -update_timeout -> sync.update_timeout -check_timeout -> sync.check_timeout -block_parallel_tasks -> sync.block_parallel_tasks -use_rpc -> api_cmds.use_rpc -confirmations -> shared_pages.confirmations -display.api -> api_page.enabled -display.markets -> markets_page.enabled -display.richlist -> richlist_page.enabled -display.search -> shared_pages.page_header.show_search -display.movement -> movement_page.enabled -display.network -> network_page.enabled -display.masternodes -> masternodes_page.enabled -display.claim_address -> claim_address_page.enabled -display.claim_address_header_menu -> claim_address_page.show_header_menu -display.page_header_bgcolor -> shared_pages.page_header.bgcolor -display.page_footer_bgcolor -> shared_pages.page_footer.bgcolor -display.table_header_bgcolor -> shared_pages.table_header_bgcolor -display.networkpnl -> shared_pages.page_header.panels.network_panel.display_order -display.difficultypnl -> shared_pages.page_header.panels.difficulty_panel.display_order -display.masternodespnl -> shared_pages.page_header.panels.masternodes_panel.display_order -display.coinsupplypnl -> shared_pages.page_header.panels.coin_supply_panel.display_order -display.pricepnl -> shared_pages.page_header.panels.price_panel.display_order -display.marketcappnl -> shared_pages.page_header.panels.market_cap_panel.display_order -display.logopnl -> shared_pages.page_header.panels.logo_panel.display_order -index.show_last_updated -> index_page.show_last_updated -index.show_hashrate -> shared_pages.show_hashrate -index.difficulty -> shared_pages.difficulty -index.last_txs -> api_page.public_apis.ext.getlasttxs.max_items_per_query -index.txs_per_page -> index_page.transaction_table.items_per_page (for index page) AND movement_page.movement_table.items_per_page (for movement page) -reward_page.show_last_updated -> blockchain_specific.heavycoin.reward_page.show_last_updated -api.blockindex -> api_page.sample_data.blockindex -api.blockhash -> api_page.sample_data.blockhash -api.txhash -> api_page.sample_data.txhash -api.address -> api_page.sample_data.address -markets.exchange -> markets_page.default_exchange.trading_pair -markets.default -> markets_page.default_exchange.exchange_name -markets.market_dropdown_menu -> markets_page.show_market_dropdown_menu -markets.market_select_visible -> markets_page.show_market_select -richlist.distribution -> richlist_page.wealth_distribution.show_distribution_chart -richlist.received -> richlist_page.show_received_coins -richlist.balance -> richlist_page.show_current_balance -movement.min_amount -> movement_page.movement_table.min_amount -movement.low_flag -> movement_page.movement_table.low_warning_flag -movement.high_flag -> movement_page.movement_table.high_warning_flag -social_links -> shared_pages.page_footer.social_links -social_links[x].image_url -> shared_pages.page_footer.social_links[x].image_path -genesis_tx -> transaction_page.genesis_tx -genesis_block -> block_page.genesis_block -heavy -> blockchain_specific.heavycoin.enabled -save_stats_after_sync_blocks -> sync.save_stats_after_sync_blocks -txcount -> api_page.public_apis.ext.getaddresstxs.max_items_per_query -txcount_per_page -> address_page.history_table.items_per_page -show_sent_received -> address_page.show_sent_received -supply -> sync.supply -nethash -> shared_pages.page_header.panels.network_panel.nethash -nethash_units -> shared_pages.page_header.panels.network_panel.nethash_units -usecors -> webserver.cors.enabled -corsorigin -> webserver.cors.corsorigin -burned_coins -> richlist_page.burned_coins.addresses -public_api.rpc.getdifficulty -> api_page.public_apis.rpc.getdifficulty.enabled -public_api.rpc.getconnectioncount -> api_page.public_apis.rpc.getconnectioncount.enabled -public_api.rpc.getblockcount -> api_page.public_apis.rpc.getblockcount.enabled -public_api.rpc.getblockhash -> api_page.public_apis.rpc.getblockhash.enabled -public_api.rpc.getblock -> api_page.public_apis.rpc.getblock.enabled -public_api.rpc.getrawtransaction -> api_page.public_apis.rpc.getrawtransaction.enabled -public_api.rpc.getnetworkhashps -> api_page.public_apis.rpc.getnetworkhashps.enabled -public_api.rpc.getvotelist -> api_page.public_apis.rpc.getvotelist.enabled -public_api.rpc.getmasternodecount -> api_page.public_apis.rpc.getmasternodecount.enabled -public_api.rpc.getmaxmoney -> blockchain_specific.heavycoin.public_apis.getmaxmoney.enabled -public_api.rpc.getmaxvote -> blockchain_specific.heavycoin.public_apis.getmaxvote.enabled -public_api.rpc.getvote -> blockchain_specific.heavycoin.public_apis.getvote.enabled -public_api.rpc.getphase -> blockchain_specific.heavycoin.public_apis.getphase.enabled -public_api.rpc.getreward -> blockchain_specific.heavycoin.public_apis.getreward.enabled -public_api.rpc.getsupply -> blockchain_specific.heavycoin.public_apis.getsupply.enabled -public_api.rpc.getnextrewardestimate -> blockchain_specific.heavycoin.public_apis.getnextrewardestimate.enabled -public_api.rpc.getnextrewardwhenstr -> blockchain_specific.heavycoin.public_apis.getnextrewardwhenstr.enabled -public_api.ext.getmoneysupply -> api_page.public_apis.ext.getmoneysupply.enabled -public_api.ext.getdistribution -> api_page.public_apis.ext.getdistribution.enabled -public_api.ext.getaddress -> api_page.public_apis.ext.getaddress.enabled -public_api.ext.getaddresstxs -> api_page.public_apis.ext.getaddresstxs.enabled -public_api.ext.gettx -> api_page.public_apis.ext.gettx.enabled -public_api.ext.getbalance -> api_page.public_apis.ext.getbalance.enabled -public_api.ext.getlasttxs -> api_page.public_apis.ext.getlasttxs.enabled -public_api.ext.getcurrentprice -> api_page.public_apis.ext.getcurrentprice.enabled -public_api.ext.getbasicstats -> api_page.public_apis.ext.getbasicstats.enabled -public_api.ext.getsummary -> api_page.public_apis.ext.getsummary.enabled -public_api.ext.getnetworkpeers -> api_page.public_apis.ext.getnetworkpeers.enabled -public_api.ext.getmasternodelist -> api_page.public_apis.ext.getmasternodelist.enabled -public_api.ext.getmasternoderewards -> api_page.public_apis.ext.getmasternoderewards.enabled -public_api.ext.getmasternoderewardstotal -> api_page.public_apis.ext.getmasternoderewardstotal.enabled -api_cmds.heavies.getmaxmoney -> blockchain_specific.heavycoin.api_cmds.getmaxmoney -api_cmds.heavies.getmaxvote -> blockchain_specific.heavycoin.api_cmds.getmaxvote -api_cmds.heavies.getvote -> blockchain_specific.heavycoin.api_cmds.getvote -api_cmds.heavies.getphase -> blockchain_specific.heavycoin.api_cmds.getphase -api_cmds.heavies.getreward -> blockchain_specific.heavycoin.api_cmds.getreward -api_cmds.heavies.getnextrewardestimate -> blockchain_specific.heavycoin.api_cmds.getnextrewardestimate -api_cmds.heavies.getnextrewardwhenstr -> blockchain_specific.heavycoin.api_cmds.getnextrewardwhenstr -api_cmds.heavies.getsupply -> blockchain_specific.heavycoin.api_cmds.getsupply -List of new settings: -shared_pages.page_header.panels.network_panel.enabled: allow enabling/disabling of the network panel -shared_pages.page_header.panels.difficulty_panel.enabled: allow enabling/disabling of the difficulty panel -shared_pages.page_header.panels.masternodes_panel.enabled: allow enabling/disabling of the masternodes panel -shared_pages.page_header.panels.coin_supply_panel.enabled: allow enabling/disabling of the coin supply panel -shared_pages.page_header.panels.price_panel.enabled: allow enabling/disabling of the price panel -shared_pages.page_header.panels.market_cap_panel.enabled: allow enabling/disabling of the market cap panel -shared_pages.page_header.panels.logo_panel.enabled: allow enabling/disabling of the logo panel -index_page.transaction_table.page_length_options: specify the page length options that determine how many items/records to display in the table at any given time -index_page.transaction_table.reload_table_seconds: the time in seconds to automatically reload the table data from the server -address_page.history_table.page_length_options: specify the page length options that determine how many items/records to display in the table at any given time -masternodes_page.masternode_table.page_length_options: specify the page length options that determine how many items/records to display in the table at any given time -masternodes_page.masternode_table.items_per_page: the default amount of items/records to display in the table at any given time -movement_page.movement_table.page_length_options: specify the page length options that determine how many items/records to display in the table at any given time -movement_page.movement_table.reload_table_seconds: the time in seconds to automatically reload the table data from the server -network_page.connections_table.page_length_options: specify the page length options that determine how many items/records to display in the table at any given time -network_page.connections_table.items_per_page: the default amount of items/records to display in the table at any given time -network_page.addnodes_table.page_length_options: specify the page length options that determine how many items/records to display in the table at any given time -network_page.addnodes_table.items_per_page: the default amount of items/records to display in the table at any given time -network_page.onetry_table.page_length_options: specify the page length options that determine how many items/records to display in the table at any given time -network_page.onetry_table.items_per_page: the default amount of items/records to display in the table at any given time -richlist_page.wealth_distribution.show_distribution_table: show/hide the wealth distribution summary table -richlist_page.wealth_distribution.colors: a list of html color codes to represent the top 100 groupings in the wealth distribution table and pie chart -richlist_page.burned_coins.include_burned_coins_in_distribution: determine whether to include burned coins in the wealth distribution section or not -markets_page.exchanges.altmarkets.enabled: enable/disable the altmarkets exchange -markets_page.exchanges.altmarkets.trading_pairs: a list of market trading pair symbols -markets_page.exchanges.bittrex.enabled: enable/disable the bittrex exchange -markets_page.exchanges.bittrex.trading_pairs: a list of market trading pair symbols -markets_page.exchanges.bleutrade.enabled: enable/disable the bleutrade exchange -markets_page.exchanges.bleutrade.trading_pairs: a list of market trading pair symbols -markets_page.exchanges.crex.enabled: enable/disable the crex exchange -markets_page.exchanges.crex.trading_pairs: a list of market trading pair symbols -markets_page.exchanges.poloniex.enabled: enable/disable the poloniex exchange -markets_page.exchanges.poloniex.trading_pairs: a list of market trading pair symbols -markets_page.exchanges.stex.enabled: enable/disable the stex exchange -markets_page.exchanges.stex.trading_pairs: a list of market trading pair symbols -markets_page.exchanges.yobit.enabled: enable/disable the yobit exchange -markets_page.exchanges.yobit.trading_pairs: a list of market trading pair symbols -claim_address_page.enable_bad_word_filter: enable/disable the "bad word" filter for claimed addresses, so that trying to claim an address with a bad word will fail -sync.show_sync_msg_when_syncing_more_than_blocks: show the sync msg at the top of all pages during index syncronization if there are more than this many blocks to process -labels[x].enabled: allow enabling/disabling of specific wallet address labels -blockchain_specific.heavycoin.reward_page.enabled: enable/disable the reward page -blockchain_specific.zksnarks.enabled: enable/disable Zcash zk-SNARKs private transaction support (WIP - 90% complete) -List of deleted settings -address: unnecessary setting has been replaced by dynamic values via http request -markets.coin: replaced by a richer set of settings that allow choosing the coin for each market -markets.enabled -> replaced by a richer set of settings that allow enabling/disabling each market specifically -lock_during_index: no longer possible to save unsynced blocks/txs via search so this settings is now obsolete/unused
This commit is contained in:
+189
-255
@@ -116,27 +116,26 @@ function find_tx(txid, cb) {
|
||||
}
|
||||
|
||||
function save_tx(txid, blockheight, cb) {
|
||||
lib.get_rawtransaction(txid, function(tx){
|
||||
lib.get_rawtransaction(txid, function(tx) {
|
||||
if (tx && tx != 'There was an error. Check your console.') {
|
||||
lib.prepare_vin(tx, function(vin) {
|
||||
lib.prepare_vout(tx.vout, txid, vin, ((typeof tx.vjoinsplit === 'undefined' || tx.vjoinsplit == null) ? [] : tx.vjoinsplit), function(vout, nvin) {
|
||||
lib.prepare_vout(tx.vout, txid, vin, ((!settings.blockchain_specific.zksnarks.enabled || typeof tx.vjoinsplit === 'undefined' || tx.vjoinsplit == null) ? [] : tx.vjoinsplit), function(vout, nvin) {
|
||||
lib.syncLoop(vin.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
update_address(nvin[i].addresses, blockheight, txid, nvin[i].amount, 'vin', function(){
|
||||
update_address(nvin[i].addresses, blockheight, txid, nvin[i].amount, 'vin', function() {
|
||||
loop.next();
|
||||
});
|
||||
}, function(){
|
||||
}, function() {
|
||||
lib.syncLoop(vout.length, function (subloop) {
|
||||
var t = subloop.iteration();
|
||||
if (vout[t].addresses) {
|
||||
update_address(vout[t].addresses, blockheight, txid, vout[t].amount, 'vout', function(){
|
||||
update_address(vout[t].addresses, blockheight, txid, vout[t].amount, 'vout', function() {
|
||||
subloop.next();
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
subloop.next();
|
||||
}
|
||||
}, function(){
|
||||
lib.calculate_total(vout, function(total){
|
||||
}, function() {
|
||||
lib.calculate_total(vout, function(total) {
|
||||
var newTx = new Tx({
|
||||
txid: tx.txid,
|
||||
vin: nvin,
|
||||
@@ -147,79 +146,29 @@ function save_tx(txid, blockheight, cb) {
|
||||
blockindex: blockheight,
|
||||
});
|
||||
newTx.save(function(err) {
|
||||
if (err) {
|
||||
if (err)
|
||||
return cb(err, false);
|
||||
} else {
|
||||
else
|
||||
return cb(null, vout.length > 0);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
return cb('tx not found: ' + txid, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function get_market_data(market, cb) {
|
||||
function get_market_data(market, coin_symbol, pair_symbol, cb) {
|
||||
if (fs.existsSync('./lib/markets/' + market + '.js')) {
|
||||
exMarket = require('./markets/' + market);
|
||||
exMarket.get_data(settings.markets, function(err, obj) {
|
||||
exMarket.get_data({coin: coin_symbol, exchange: pair_symbol}, function(err, obj) {
|
||||
return cb(err, obj);
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
return cb(null);
|
||||
}
|
||||
}
|
||||
|
||||
function create_lock(lockfile, cb) {
|
||||
if (settings.lock_during_index == true) {
|
||||
var fname = './tmp/' + lockfile + '.pid';
|
||||
fs.appendFile(fname, process.pid.toString(), function (err) {
|
||||
if (err) {
|
||||
console.log("Error: unable to create %s", fname);
|
||||
process.exit(1);
|
||||
} else {
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return cb();
|
||||
}
|
||||
}
|
||||
|
||||
function remove_lock(lockfile, cb) {
|
||||
if (settings.lock_during_index == true) {
|
||||
var fname = './tmp/' + lockfile + '.pid';
|
||||
fs.unlink(fname, function (err){
|
||||
if(err) {
|
||||
console.log("unable to remove lock: %s", fname);
|
||||
process.exit(1);
|
||||
} else {
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return cb();
|
||||
}
|
||||
}
|
||||
|
||||
function is_locked(lockfile, cb) {
|
||||
if (settings.lock_during_index == true) {
|
||||
var fname = './tmp/' + lockfile + '.pid';
|
||||
fs.exists(fname, function (exists){
|
||||
if(exists) {
|
||||
return cb(true);
|
||||
} else {
|
||||
return cb(false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return cb(false);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
@@ -230,23 +179,12 @@ module.exports = {
|
||||
console.log('Unable to connect to database: %s', database);
|
||||
console.log('Aborting');
|
||||
process.exit(1);
|
||||
|
||||
}
|
||||
//console.log('Successfully connected to MongoDB');
|
||||
|
||||
return cb();
|
||||
});
|
||||
},
|
||||
|
||||
is_locked: function(cb) {
|
||||
is_locked("db_index", function (exists) {
|
||||
if (exists) {
|
||||
return cb(true);
|
||||
} else {
|
||||
return cb(false);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
check_show_sync_message: function() {
|
||||
return fs.existsSync('./tmp/show_sync_message.tmp');
|
||||
},
|
||||
@@ -274,9 +212,9 @@ module.exports = {
|
||||
|
||||
update_richlist_claim_name: function(hash, claim_name, cb) {
|
||||
// check if the richlist is enabled
|
||||
if (settings.display.richlist) {
|
||||
if (settings.richlist_page.enabled == true) {
|
||||
// ensure that if this address exists in the richlist that it displays the new alias
|
||||
module.exports.get_richlist(settings.coin, function(richlist) {
|
||||
module.exports.get_richlist(settings.coin.name, function(richlist) {
|
||||
var updated = false;
|
||||
// loop through received addresses
|
||||
for (r = 0; r < richlist.received.length; r++) {
|
||||
@@ -301,7 +239,7 @@ module.exports = {
|
||||
// check if the address was updated in the richlist
|
||||
if (updated) {
|
||||
// save the richlist back to collection
|
||||
Richlist.updateOne({coin: settings.coin}, {
|
||||
Richlist.updateOne({coin: settings.coin.name}, {
|
||||
received: richlist.received,
|
||||
balance: richlist.balance
|
||||
}, function() {
|
||||
@@ -321,7 +259,7 @@ module.exports = {
|
||||
|
||||
update_masternode_claim_name: function(hash, claim_name, cb) {
|
||||
// check if the masternode list is enabled
|
||||
if (settings.display.masternodes) {
|
||||
if (settings.masternodes_page.enabled == true) {
|
||||
// ensure that if this address exists in the masternode that it displays the new alias
|
||||
module.exports.get_masternodes(function(masternodes) {
|
||||
var updated = false;
|
||||
@@ -415,33 +353,60 @@ module.exports = {
|
||||
},
|
||||
|
||||
// 'list' variable can be either 'received' or 'balance'
|
||||
update_richlist: function(list, cb){
|
||||
// Create the burn address array so that we omit burned coins from the rich list
|
||||
var oBurnAddresses = [];
|
||||
for (var x = 0; x < settings.burned_coins.length; x++) {
|
||||
oBurnAddresses.push(settings.burned_coins[x].address);
|
||||
}
|
||||
update_richlist: function(list, cb) {
|
||||
// number of addresses to lookup
|
||||
var total_addresses = 100;
|
||||
// create the burn address array so that we omit burned coins from the rich list
|
||||
var burn_addresses = settings.richlist_page.burned_coins.addresses;
|
||||
// always omit the private address from the richlist
|
||||
oBurnAddresses.push("private_tx");
|
||||
burn_addresses.push("private_tx");
|
||||
|
||||
if (list == 'received') {
|
||||
// Update 'received' richlist data
|
||||
Address.find({a_id: { $nin: oBurnAddresses }}, 'a_id name balance received').sort({received: 'desc'}).limit(100).exec(function(err, addresses) {
|
||||
Richlist.updateOne({coin: settings.coin}, {
|
||||
// update 'received' richlist data
|
||||
Address.find({a_id: { $nin: burn_addresses }}, 'a_id name balance received').sort({received: 'desc'}).limit(total_addresses).exec(function(err, addresses) {
|
||||
Richlist.updateOne({coin: settings.coin.name}, {
|
||||
received: addresses
|
||||
}, function() {
|
||||
return cb();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Update 'balance' richlist data
|
||||
Address.find({a_id: { $nin: oBurnAddresses }}, 'a_id name balance received').sort({balance: 'desc'}).limit(100).exec(function(err, addresses) {
|
||||
Richlist.updateOne({coin: settings.coin}, {
|
||||
balance: addresses
|
||||
}, function() {
|
||||
return cb();
|
||||
// update 'balance' richlist data
|
||||
// check if burned addresses are in use and if it is necessary to track burned balances
|
||||
if (settings.richlist_page.burned_coins.addresses == null || settings.richlist_page.burned_coins.addresses.length == 0 || !settings.richlist_page.burned_coins.include_burned_coins_in_distribution) {
|
||||
// update 'balance' richlist data by filtering burned coin addresses immidiately
|
||||
Address.find({a_id: { $nin: burn_addresses }}, 'a_id name balance received').sort({balance: 'desc'}).limit(total_addresses).exec(function(err, addresses) {
|
||||
Richlist.updateOne({coin: settings.coin.name}, {
|
||||
balance: addresses
|
||||
}, function() {
|
||||
return cb();
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// do not omit burned addresses from database query. instead, increase the limit of returned addresses and manually remove each burned address that made it into the rich list after recording the burned balance
|
||||
Address.find({}, 'a_id name balance received').sort({balance: 'desc'}).limit(total_addresses + burn_addresses.length).exec(function(err, addresses) {
|
||||
var return_addresses = [];
|
||||
var burned_balance = 0.0;
|
||||
// loop through all richlist addresses
|
||||
addresses.forEach(function (address) {
|
||||
// check if this is a burned coin address
|
||||
if (burn_addresses.findIndex(p => p.toLowerCase() == address.a_id.toLowerCase()) > -1) {
|
||||
// this is a burned coin address so save the balance, not the address
|
||||
burned_balance += address.balance;
|
||||
} else if (return_addresses.length < total_addresses) {
|
||||
// this is not a burned address so add it to the return list
|
||||
return_addresses.push(address);
|
||||
}
|
||||
});
|
||||
// update the rich list collection
|
||||
Richlist.updateOne({coin: settings.coin.name}, {
|
||||
balance: return_addresses,
|
||||
burned: burned_balance
|
||||
}, function() {
|
||||
return cb();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -468,29 +433,6 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
create_txs: function(block, cb) {
|
||||
is_locked("db_index", function (exists) {
|
||||
if (exists) {
|
||||
console.log("db_index lock file exists...");
|
||||
return cb();
|
||||
} else {
|
||||
lib.syncLoop(block.tx.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
save_tx(block.tx[i], block.height, function(err, tx_has_vout) {
|
||||
if (err) {
|
||||
loop.next();
|
||||
} else {
|
||||
//console.log('tx stored: %s', block.tx[i]);
|
||||
loop.next();
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
return cb();
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
get_last_txs: function(start, length, min, internal, cb) {
|
||||
this.get_last_txs_ajax(start, length, min, function(txs, count) {
|
||||
var data = [];
|
||||
@@ -536,7 +478,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
// min is zero (shouldn't ever be negative) which means we must pull record count from the coinstats collection (pulling from txes could potentially take a long time because it would include coinbase txes)
|
||||
Stats.findOne({coin:settings.coin}, function(err, stats) {
|
||||
Stats.findOne({coin: settings.coin.name}, function(err, stats) {
|
||||
// Get last transactions where there is at least 1 vout
|
||||
Tx.find({'total': {$gte: min}, 'vout': { $gte: { $size: 1 }}}).sort({blockindex: -1}).skip(Number(start)).limit(Number(length)).exec(function(err, txs) {
|
||||
if (err) {
|
||||
@@ -613,11 +555,11 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
create_market: function(coin, exchange, market, cb) {
|
||||
create_market: function(coin_symbol, pair_symbol, market, cb) {
|
||||
var newMarkets = new Markets({
|
||||
market: market,
|
||||
coin: coin,
|
||||
exchange: exchange,
|
||||
coin_symbol: coin_symbol,
|
||||
pair_symbol: pair_symbol,
|
||||
});
|
||||
|
||||
newMarkets.save(function(err) {
|
||||
@@ -625,32 +567,26 @@ module.exports = {
|
||||
console.log(err);
|
||||
return cb();
|
||||
} else {
|
||||
console.log("initial markets entry created for %s", market);
|
||||
//console.log(newMarkets);
|
||||
console.log("initial market entry created for %s: %s", market, coin_symbol +'/' + pair_symbol);
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// checks market data exists for given market
|
||||
check_market: function(market, cb) {
|
||||
Markets.findOne({market: market}, function(err, exists) {
|
||||
if(exists) {
|
||||
return cb(market, true);
|
||||
} else {
|
||||
return cb(market, false);
|
||||
}
|
||||
// check if market data exists for a given market and trading pair
|
||||
check_market: function(market, coin_symbol, pair_symbol, cb) {
|
||||
Markets.findOne({market: market, coin_symbol: coin_symbol, pair_symbol: pair_symbol}, function(err, exists) {
|
||||
return cb(market, exists);
|
||||
});
|
||||
},
|
||||
|
||||
// gets market data for given market
|
||||
get_market: function(market, cb) {
|
||||
Markets.findOne({market: market}, function(err, data) {
|
||||
if(data) {
|
||||
// gets market data for given market and trading pair
|
||||
get_market: function(market, coin_symbol, pair_symbol, cb) {
|
||||
Markets.findOne({market: market, coin_symbol: coin_symbol, pair_symbol: pair_symbol}, function(err, data) {
|
||||
if (data)
|
||||
return cb(data);
|
||||
} else {
|
||||
else
|
||||
return cb(null);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -701,8 +637,7 @@ module.exports = {
|
||||
console.log(err);
|
||||
return cb();
|
||||
} else {
|
||||
console.log("initial heavy entry created for %s", coin);
|
||||
console.log(newHeavy);
|
||||
console.log("initial heavycoin entry created for %s", coin);
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
@@ -727,7 +662,8 @@ module.exports = {
|
||||
}
|
||||
});
|
||||
},
|
||||
get_distribution: function(richlist, stats, cb){
|
||||
|
||||
get_distribution: function(richlist, stats, cb) {
|
||||
var distribution = {
|
||||
supply: stats.supply,
|
||||
t_1_25: {percent: 0, total: 0 },
|
||||
@@ -736,30 +672,36 @@ module.exports = {
|
||||
t_76_100: {percent: 0, total: 0 },
|
||||
t_101plus: {percent: 0, total: 0 }
|
||||
};
|
||||
|
||||
lib.syncLoop(richlist.balance.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
var count = i + 1;
|
||||
var percentage = ((richlist.balance[i].balance / 100000000) / stats.supply) * 100;
|
||||
|
||||
if (count <= 25 ) {
|
||||
distribution.t_1_25.percent = distribution.t_1_25.percent + percentage;
|
||||
distribution.t_1_25.total = distribution.t_1_25.total + (richlist.balance[i].balance / 100000000);
|
||||
}
|
||||
|
||||
if (count <= 50 && count > 25) {
|
||||
distribution.t_26_50.percent = distribution.t_26_50.percent + percentage;
|
||||
distribution.t_26_50.total = distribution.t_26_50.total + (richlist.balance[i].balance / 100000000);
|
||||
}
|
||||
|
||||
if (count <= 75 && count > 50) {
|
||||
distribution.t_51_75.percent = distribution.t_51_75.percent + percentage;
|
||||
distribution.t_51_75.total = distribution.t_51_75.total + (richlist.balance[i].balance / 100000000);
|
||||
}
|
||||
|
||||
if (count <= 100 && count > 75) {
|
||||
distribution.t_76_100.percent = distribution.t_76_100.percent + percentage;
|
||||
distribution.t_76_100.total = distribution.t_76_100.total + (richlist.balance[i].balance / 100000000);
|
||||
}
|
||||
|
||||
loop.next();
|
||||
}, function(){
|
||||
distribution.t_101plus.percent = parseFloat(100 - distribution.t_76_100.percent - distribution.t_51_75.percent - distribution.t_26_50.percent - distribution.t_1_25.percent).toFixed(2);
|
||||
distribution.t_101plus.total = parseFloat(distribution.supply - distribution.t_76_100.total - distribution.t_51_75.total - distribution.t_26_50.total - distribution.t_1_25.total).toFixed(8);
|
||||
}, function() {
|
||||
distribution.t_101plus.percent = parseFloat(100 - distribution.t_76_100.percent - distribution.t_51_75.percent - distribution.t_26_50.percent - distribution.t_1_25.percent - (settings.richlist_page.burned_coins.include_burned_coins_in_distribution == true && richlist.burned > 0 ? ((richlist.burned / 100000000) / stats.supply) * 100 : 0)).toFixed(2);
|
||||
distribution.t_101plus.total = parseFloat(distribution.supply - distribution.t_76_100.total - distribution.t_51_75.total - distribution.t_26_50.total - distribution.t_1_25.total - (settings.richlist_page.burned_coins.include_burned_coins_in_distribution == true && richlist.burned > 0 ? (richlist.burned / 100000000) : 0)).toFixed(8);
|
||||
distribution.t_1_25.percent = parseFloat(distribution.t_1_25.percent).toFixed(2);
|
||||
distribution.t_1_25.total = parseFloat(distribution.t_1_25.total).toFixed(8);
|
||||
distribution.t_26_50.percent = parseFloat(distribution.t_26_50.percent).toFixed(2);
|
||||
@@ -772,7 +714,7 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
// updates heavy stats for coin
|
||||
// updates heavycoin stats
|
||||
// height: current block height, count: amount of votes to store
|
||||
update_heavy: function(coin, height, count, cb) {
|
||||
var newVotes = [];
|
||||
@@ -782,7 +724,7 @@ module.exports = {
|
||||
lib.get_vote( function (vote) {
|
||||
lib.get_phase( function (phase) {
|
||||
lib.get_reward( function (reward) {
|
||||
lib.get_supply( function (supply) {
|
||||
module.exports.get_stats(settings.coin.name, function (stats) {
|
||||
lib.get_estnext( function (estnext) {
|
||||
lib.get_nextin( function (nextin) {
|
||||
lib.syncLoop(count, function (loop) {
|
||||
@@ -797,7 +739,7 @@ module.exports = {
|
||||
Heavy.updateOne({coin: coin}, {
|
||||
lvote: (vote ? vote : 0),
|
||||
reward: (reward ? reward : 0),
|
||||
supply: (supply ? supply : 0),
|
||||
supply: (stats && stats.supply ? stats.supply : 0),
|
||||
cap: (maxmoney ? maxmoney : 0),
|
||||
estnext: (estnext ? estnext : 0),
|
||||
phase: (phase ? phase : 'N/A'),
|
||||
@@ -806,8 +748,8 @@ module.exports = {
|
||||
votes: newVotes
|
||||
}, function() {
|
||||
// update reward_last_updated value
|
||||
module.exports.update_last_updated_stats(settings.coin, { reward_last_updated: Math.floor(new Date() / 1000) }, function (new_cb) {
|
||||
console.log('heavy update complete');
|
||||
module.exports.update_last_updated_stats(settings.coin.name, { reward_last_updated: Math.floor(new Date() / 1000) }, function (new_cb) {
|
||||
console.log('heavycoin update complete');
|
||||
return cb();
|
||||
});
|
||||
});
|
||||
@@ -823,29 +765,36 @@ module.exports = {
|
||||
},
|
||||
|
||||
// updates market data for given market; called by sync.js
|
||||
update_markets_db: function(market, cb) {
|
||||
update_markets_db: function(market, coin_symbol, pair_symbol, cb) {
|
||||
// check if market exists
|
||||
if (fs.existsSync('./lib/markets/' + market + '.js')) {
|
||||
get_market_data(market, function (err, obj) {
|
||||
get_market_data(market, coin_symbol, pair_symbol, function (err, obj) {
|
||||
// check if there was an error with getting market data
|
||||
if (err == null) {
|
||||
Markets.updateOne({market:market}, {
|
||||
// update the market collection for the current market and trading pair combination
|
||||
Markets.updateOne({market: market, coin_symbol: coin_symbol, pair_symbol: pair_symbol}, {
|
||||
chartdata: JSON.stringify(obj.chartdata),
|
||||
buys: obj.buys,
|
||||
sells: obj.sells,
|
||||
history: obj.trades,
|
||||
summary: obj.stats
|
||||
}, function() {
|
||||
if ( market == settings.markets.default ) {
|
||||
Stats.updateOne({coin:settings.coin}, {
|
||||
// check if this is the default market
|
||||
if (market == settings.markets_page.default_exchange.exchange_name) {
|
||||
// this is the default market so update the last price stats
|
||||
Stats.updateOne({coin: settings.coin.name}, {
|
||||
last_price: obj.stats.last,
|
||||
}, function(){
|
||||
}, function() {
|
||||
// finished updating market data
|
||||
return cb(null);
|
||||
});
|
||||
} else {
|
||||
// this is not the default market so we are finished updating market data
|
||||
return cb(null);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// an error occurred with getting market data so return the error msg
|
||||
return cb(err);
|
||||
}
|
||||
});
|
||||
@@ -854,25 +803,26 @@ module.exports = {
|
||||
return cb('market is not installed');
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
get_last_usd_price: function(cb) {
|
||||
// Check if the market price is being recorded in BTC
|
||||
if (settings.markets.enabled.length > 0 && settings.markets.exchange.toLowerCase() == "btc") {
|
||||
// Convert btc to usd via coindesk api
|
||||
coindesk.get_data(function (err, last_usd) {
|
||||
// Get current stats
|
||||
Stats.findOne({coin:settings.coin}, function(err, stats) {
|
||||
// Update the last usd price
|
||||
Stats.updateOne({coin:settings.coin}, {
|
||||
last_usd_price: (last_usd * stats.last_price),
|
||||
}, function(){
|
||||
return cb(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return cb(null);
|
||||
}
|
||||
// check if the default market price is enabled and being recorded in BTC
|
||||
if (settings.markets_page.exchanges[settings.markets_page.default_exchange.exchange_name].enabled == true && settings.markets_page.exchanges[settings.markets_page.default_exchange.exchange_name].trading_pairs.findIndex(p => p.toLowerCase().indexOf('/btc') > -1) > -1) {
|
||||
// convert btc to usd via coindesk api
|
||||
coindesk.get_data(function (err, last_usd) {
|
||||
// get current stats
|
||||
Stats.findOne({coin: settings.coin.name}, function(err, stats) {
|
||||
// update the last usd price
|
||||
Stats.updateOne({coin: settings.coin.name}, {
|
||||
last_usd_price: (last_usd * stats.last_price),
|
||||
}, function() {
|
||||
return cb(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// only btc conversion supported so just exit without updating last price for now
|
||||
return cb(null);
|
||||
}
|
||||
},
|
||||
|
||||
// updates stats data for given coin; called by sync.js
|
||||
@@ -882,7 +832,7 @@ module.exports = {
|
||||
console.log('Unable to connect to explorer API');
|
||||
return cb(false);
|
||||
}
|
||||
lib.get_supply( function (supply) {
|
||||
lib.get_supply(function (supply) {
|
||||
lib.get_connectioncount(function (connections) {
|
||||
Stats.findOne({coin: coin}, function(err, stats) {
|
||||
if (stats) {
|
||||
@@ -916,91 +866,75 @@ module.exports = {
|
||||
|
||||
// updates tx, address & richlist db's; called by sync.js
|
||||
update_tx_db: function(coin, start, end, txes, timeout, cb) {
|
||||
is_locked("db_index", function (exists) {
|
||||
if (exists) {
|
||||
console.log("db_index lock file exists...");
|
||||
return cb();
|
||||
} else {
|
||||
create_lock("db_index", function (){
|
||||
var complete = false;
|
||||
var blocks_to_scan = [];
|
||||
var task_limit_blocks = settings.block_parallel_tasks;
|
||||
if (typeof start === 'undefined' || start < 1) start = 1; // fix for invalid block height (skip genesis block as it should not have valid txs)
|
||||
if (task_limit_blocks < 1) { task_limit_blocks = 1; }
|
||||
var task_limit_txs = 1;
|
||||
for (i=start; i<(end+1); i++) {
|
||||
blocks_to_scan.push(i);
|
||||
}
|
||||
async.eachLimit(blocks_to_scan, task_limit_blocks, function(block_height, next_block) {
|
||||
if (block_height % settings.save_stats_after_sync_blocks === 0) {
|
||||
Stats.updateOne({coin: coin}, {
|
||||
last: block_height - 1,
|
||||
txes: txes,
|
||||
last_txs: '' //not used anymore left to clear out existing objects
|
||||
}, function() {});
|
||||
}
|
||||
lib.get_blockhash(block_height, function(blockhash){
|
||||
if (blockhash) {
|
||||
lib.get_block(blockhash, function(block) {
|
||||
if (block) {
|
||||
async.eachLimit(block.tx, task_limit_txs, function(txid, next_tx) {
|
||||
Tx.findOne({txid: txid}, function(err, tx) {
|
||||
if(tx) {
|
||||
setTimeout( function(){
|
||||
tx = null;
|
||||
next_tx();
|
||||
}, timeout);
|
||||
} else {
|
||||
save_tx(txid, block_height, function(err, tx_has_vout) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
console.log('%s: %s', block_height, txid);
|
||||
}
|
||||
if (tx_has_vout)
|
||||
txes++;
|
||||
setTimeout( function(){
|
||||
tx = null;
|
||||
next_tx();
|
||||
}, timeout);
|
||||
});
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
setTimeout( function(){
|
||||
blockhash = null;
|
||||
block = null;
|
||||
next_block();
|
||||
var complete = false;
|
||||
var blocks_to_scan = [];
|
||||
var task_limit_blocks = settings.sync.block_parallel_tasks;
|
||||
if (typeof start === 'undefined' || start < 1) start = 1; // fix for invalid block height (skip genesis block as it should not have valid txs)
|
||||
if (task_limit_blocks < 1) { task_limit_blocks = 1; }
|
||||
var task_limit_txs = 1;
|
||||
for (i=start; i<(end+1); i++)
|
||||
blocks_to_scan.push(i);
|
||||
async.eachLimit(blocks_to_scan, task_limit_blocks, function(block_height, next_block) {
|
||||
if (block_height % settings.sync.save_stats_after_sync_blocks === 0) {
|
||||
Stats.updateOne({coin: coin}, {
|
||||
last: block_height - 1,
|
||||
txes: txes
|
||||
}, function() {});
|
||||
}
|
||||
lib.get_blockhash(block_height, function(blockhash) {
|
||||
if (blockhash) {
|
||||
lib.get_block(blockhash, function(block) {
|
||||
if (block) {
|
||||
async.eachLimit(block.tx, task_limit_txs, function(txid, next_tx) {
|
||||
Tx.findOne({txid: txid}, function(err, tx) {
|
||||
if(tx) {
|
||||
setTimeout( function() {
|
||||
tx = null;
|
||||
next_tx();
|
||||
}, timeout);
|
||||
} else {
|
||||
save_tx(txid, block_height, function(err, tx_has_vout) {
|
||||
if (err)
|
||||
console.log(err);
|
||||
else
|
||||
console.log('%s: %s', block_height, txid);
|
||||
|
||||
if (tx_has_vout)
|
||||
txes++;
|
||||
setTimeout( function() {
|
||||
tx = null;
|
||||
next_tx();
|
||||
}, timeout);
|
||||
});
|
||||
} else {
|
||||
console.log('block not found: %s', blockhash);
|
||||
setTimeout( function(){
|
||||
next_block();
|
||||
}, timeout);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
setTimeout( function(){
|
||||
}, function() {
|
||||
setTimeout( function() {
|
||||
blockhash = null;
|
||||
block = null;
|
||||
next_block();
|
||||
}, timeout);
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
Tx.find({}).sort({timestamp: 'desc'}).limit(settings.index.last_txs).exec(function(err, txs){
|
||||
Stats.updateOne({coin: coin}, {
|
||||
last: end,
|
||||
txes: txes,
|
||||
last_txs: '' //not used anymore left to clear out existing objects
|
||||
}, function() {
|
||||
remove_lock("db_index", function(){
|
||||
return cb();
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log('block not found: %s', blockhash);
|
||||
setTimeout( function() {
|
||||
next_block();
|
||||
}, timeout);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
setTimeout( function() {
|
||||
next_block();
|
||||
}, timeout);
|
||||
}
|
||||
});
|
||||
}, function() {
|
||||
Stats.updateOne({coin: coin}, {
|
||||
last: end,
|
||||
txes: txes
|
||||
}, function() {
|
||||
return cb();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1067,7 +1001,7 @@ module.exports = {
|
||||
// lookup masternode in local collection
|
||||
module.exports.find_masternode(raw_masternode.txhash, raw_masternode.outidx, function (masternode) {
|
||||
// determine if the claim address feature is enabled
|
||||
if (settings.display.claim_address) {
|
||||
if (settings.claim_address_page.enabled == true) {
|
||||
// claim address is enabled so lookup the address claim name
|
||||
find_address(raw_masternode.addr, false, function(address) {
|
||||
if (address) {
|
||||
|
||||
Reference in New Issue
Block a user