2019-05-27 10:33:22 -07:00
var express = require ( 'express' )
, path = require ( 'path' )
, nodeapi = require ( './lib/nodeapi' )
, favicon = require ( 'serve-favicon' )
, logger = require ( 'morgan' )
, cookieParser = require ( 'cookie-parser' )
, bodyParser = require ( 'body-parser' )
, settings = require ( './lib/settings' )
, routes = require ( './routes/index' )
, lib = require ( './lib/explorer' )
, db = require ( './lib/database' )
2020-11-22 20:29:56 -07:00
, package _metadata = require ( './package.json' )
2019-05-27 10:33:22 -07:00
, locale = require ( './lib/locale' )
2020-12-08 22:52:15 -07:00
, request = require ( 'postman-request' ) ;
2019-05-27 10:33:22 -07:00
var app = express ( ) ;
2020-12-21 19:28:55 -07:00
var apiAccessList = [ ] ;
2019-05-27 10:33:22 -07:00
2020-12-21 19:28:55 -07:00
// pass wallet rpc connection info to nodeapi
2019-05-27 10:33:22 -07:00
nodeapi . setWalletDetails ( settings . wallet ) ;
2020-12-21 19:28:55 -07:00
// dynamically build the nodeapi cmd access list by adding all non-heavy api cmds that have a value
Object . keys ( settings . api _cmds ) . forEach ( function ( key , index , map ) {
if ( key != 'heavies' && settings . api _cmds [ key ] != null && settings . api _cmds [ key ] != '' )
apiAccessList . push ( key ) ;
} ) ;
if ( settings . heavy ) {
// add all heavy api cmds that have a value
Object . keys ( settings . api _cmds . heavies ) . forEach ( function ( key , index , map ) {
if ( settings . api _cmds . heavies [ key ] != null && settings . api _cmds . heavies [ key ] != '' )
apiAccessList . push ( key ) ;
} ) ;
2019-05-27 10:33:22 -07:00
}
2020-12-21 19:28:55 -07:00
// whitelist the cmds in the nodeapi access list
nodeapi . setAccess ( 'only' , apiAccessList ) ;
2019-05-27 10:33:22 -07:00
// determine if cors should be enabled
if ( settings . usecors == true ) {
app . use ( function ( req , res , next ) {
res . header ( "Access-Control-Allow-Origin" , settings . corsorigin ) ;
res . header ( 'Access-Control-Allow-Methods' , 'DELETE, PUT, GET, POST' ) ;
res . header ( "Access-Control-Allow-Headers" , "Origin, X-Requested-With, Content-Type, Accept" ) ;
next ( ) ;
} ) ;
}
// view engine setup
app . set ( 'views' , path . join ( _ _dirname , 'views' ) ) ;
app . set ( 'view engine' , 'pug' ) ;
app . use ( favicon ( path . join ( _ _dirname , settings . favicon ) ) ) ;
app . use ( logger ( 'dev' ) ) ;
app . use ( bodyParser . json ( ) ) ;
app . use ( bodyParser . urlencoded ( { extended : true } ) ) ;
app . use ( cookieParser ( ) ) ;
app . use ( express . static ( path . join ( _ _dirname , 'public' ) ) ) ;
// routes
app . use ( '/api' , nodeapi . app ) ;
app . use ( '/' , routes ) ;
2020-12-28 15:12:56 -07:00
app . use ( '/ext/getmoneysupply' , function ( req , res ) {
// check if the getmoneysupply api is enabled
if ( settings . public _api . ext [ 'getmoneysupply' ] ) {
lib . get _supply ( function ( supply ) {
res . setHeader ( 'content-type' , 'text/plain' ) ;
res . end ( ( supply ? supply . toString ( ) : '0' ) ) ;
} ) ;
} else
res . end ( 'This method is disabled' ) ;
2019-05-27 10:33:22 -07:00
} ) ;
2020-12-28 15:12:56 -07:00
app . use ( '/ext/getaddress/:hash' , function ( req , res ) {
// check if the getaddress api is enabled
if ( settings . public _api . ext [ 'getaddress' ] ) {
db . get _address ( req . params . hash , false , function ( address ) {
db . get _address _txs _ajax ( req . params . hash , 0 , settings . txcount , function ( txs , count ) {
if ( address ) {
var last _txs = [ ] ;
for ( i = 0 ; i < txs . length ; i ++ ) {
if ( typeof txs [ i ] . txid !== "undefined" ) {
var out = 0 ,
vin = 0 ,
tx _type = 'vout' ,
row = { } ;
txs [ i ] . vout . forEach ( function ( r ) {
if ( r . addresses == req . params . hash )
out += r . amount ;
} ) ;
txs [ i ] . vin . forEach ( function ( s ) {
if ( s . addresses == req . params . hash )
vin += s . amount ;
} ) ;
if ( vin > out )
tx _type = 'vin' ;
row [ 'addresses' ] = txs [ i ] . txid ;
row [ 'type' ] = tx _type ;
last _txs . push ( row ) ;
2020-11-23 20:58:34 -07:00
}
}
2020-12-28 15:12:56 -07:00
var a _ext = {
address : address . a _id ,
sent : ( address . sent / 100000000 ) ,
received : ( address . received / 100000000 ) ,
balance : ( address . balance / 100000000 ) . toString ( ) . replace ( /(^-+)/mg , '' ) ,
last _txs : last _txs
} ;
res . send ( a _ext ) ;
} else
res . send ( { error : 'address not found.' , hash : req . params . hash } ) ;
} ) ;
2020-11-23 20:58:34 -07:00
} ) ;
2020-12-28 15:12:56 -07:00
} else
res . end ( 'This method is disabled' ) ;
2019-05-27 10:33:22 -07:00
} ) ;
2020-11-20 14:32:27 -07:00
app . use ( '/ext/gettx/:txid' , function ( req , res ) {
2020-12-28 15:12:56 -07:00
// check if the gettx api is enabled
if ( settings . public _api . ext [ 'gettx' ] ) {
var txid = req . params . txid ;
db . get _tx ( txid , function ( tx ) {
if ( tx ) {
lib . get _blockcount ( function ( blockcount ) {
res . send ( { active : 'tx' , tx : tx , confirmations : settings . confirmations , blockcount : ( blockcount ? blockcount : 0 ) } ) ;
} ) ;
}
else {
lib . get _rawtransaction ( txid , function ( rtx ) {
if ( rtx && rtx . txid ) {
lib . prepare _vin ( rtx , function ( vin ) {
lib . prepare _vout ( rtx . vout , rtx . txid , vin , ( ( typeof rtx . vjoinsplit === 'undefined' || rtx . vjoinsplit == null ) ? [ ] : rtx . vjoinsplit ) , function ( rvout , rvin ) {
lib . calculate _total ( rvout , function ( total ) {
if ( ! rtx . confirmations > 0 ) {
var utx = {
txid : rtx . txid ,
vin : rvin ,
vout : rvout ,
total : total . toFixed ( 8 ) ,
timestamp : rtx . time ,
blockhash : '-' ,
blockindex : - 1 ,
} ;
res . send ( { active : 'tx' , tx : utx , confirmations : settings . confirmations , blockcount : - 1 } ) ;
} else {
var utx = {
txid : rtx . txid ,
vin : rvin ,
vout : rvout ,
total : total . toFixed ( 8 ) ,
timestamp : rtx . time ,
blockhash : rtx . blockhash ,
blockindex : rtx . blockheight ,
} ;
lib . get _blockcount ( function ( blockcount ) {
res . send ( { active : 'tx' , tx : utx , confirmations : settings . confirmations , blockcount : ( blockcount ? blockcount : 0 ) } ) ;
} ) ;
}
} ) ;
2020-11-20 14:32:27 -07:00
} ) ;
} ) ;
2020-12-28 15:12:56 -07:00
} else {
res . send ( { error : 'tx not found.' , hash : txid } ) ;
}
} ) ;
}
} ) ;
} else
res . end ( 'This method is disabled' ) ;
2020-11-20 14:32:27 -07:00
} ) ;
2020-12-28 15:12:56 -07:00
app . use ( '/ext/getbalance/:hash' , function ( req , res ) {
// check if the getbalance api is enabled
if ( settings . public _api . ext [ 'getbalance' ] ) {
db . get _address ( req . params . hash , false , function ( address ) {
if ( address ) {
res . setHeader ( 'content-type' , 'text/plain' ) ;
res . end ( ( address . balance / 100000000 ) . toString ( ) . replace ( /(^-+)/mg , '' ) ) ;
} else
res . send ( { error : 'address not found.' , hash : req . params . hash } ) ;
} ) ;
} else
res . end ( 'This method is disabled' ) ;
2019-05-27 10:33:22 -07:00
} ) ;
2020-12-28 15:12:56 -07:00
app . use ( '/ext/getdistribution' , function ( req , res ) {
// check if the getdistribution api is enabled
if ( settings . public _api . ext [ 'getdistribution' ] ) {
db . get _richlist ( settings . coin , function ( richlist ) {
db . get _stats ( settings . coin , function ( stats ) {
db . get _distribution ( richlist , stats , function ( dist ) {
res . send ( dist ) ;
} ) ;
2019-05-27 10:33:22 -07:00
} ) ;
} ) ;
2020-12-28 15:12:56 -07:00
} else
res . end ( 'This method is disabled' ) ;
2019-05-27 10:33:22 -07:00
} ) ;
2020-12-28 15:12:56 -07:00
app . use ( '/ext/getcurrentprice' , function ( req , res ) {
// check if the getcurrentprice api is enabled
if ( settings . public _api . ext [ 'getcurrentprice' ] ) {
db . get _stats ( settings . coin , function ( stats ) {
eval ( 'var p_ext = { "last_price_' + settings . markets . exchange . toLowerCase ( ) + '": stats.last_price, "last_price_usd": stats.last_usd_price, }' ) ;
res . send ( p _ext ) ;
} ) ;
} else
res . end ( 'This method is disabled' ) ;
2019-05-27 10:33:22 -07:00
} ) ;
2020-12-28 15:12:56 -07:00
app . use ( '/ext/getbasicstats' , function ( req , res ) {
// check if the getbasicstats api is enabled
if ( settings . public _api . ext [ 'getbasicstats' ] ) {
2020-12-30 18:51:39 -07:00
// lookup stats
db . get _stats ( settings . coin , function ( stats ) {
// lookup coin supply
2020-12-28 15:12:56 -07:00
lib . get _supply ( function ( supply ) {
2020-12-30 18:51:39 -07:00
// lookup block count
lib . get _blockcount ( function ( blockcount ) {
// check if the masternode count api is enabled
if ( settings . public _api . rpc [ 'getmasternodecount' ] == true && settings . api _cmds [ 'getmasternodecount' ] != null && settings . api _cmds [ 'getmasternodecount' ] != '' ) {
// masternode count api is available
lib . get _masternodecount ( function ( masternodestotal ) {
eval ( 'var p_ext = { "block_count": (blockcount ? blockcount : 0), "money_supply": (supply ? supply : 0), "last_price_' + settings . markets . exchange . toLowerCase ( ) + '": stats.last_price, "last_price_usd": stats.last_usd_price, "masternode_count": masternodestotal.total }' ) ;
res . send ( p _ext ) ;
} ) ;
} else {
// masternode count api is not available
eval ( 'var p_ext = { "block_count": (blockcount ? blockcount : 0), "money_supply": (supply ? supply : 0), "last_price_' + settings . markets . exchange . toLowerCase ( ) + '": stats.last_price, "last_price_usd": stats.last_usd_price }' ) ;
2020-12-28 15:12:56 -07:00
res . send ( p _ext ) ;
2020-12-30 18:51:39 -07:00
}
2019-06-07 20:05:28 -06:00
} ) ;
2020-12-07 21:32:43 -07:00
} ) ;
2019-06-07 20:05:28 -06:00
} ) ;
2020-12-28 15:12:56 -07:00
} else
res . end ( 'This method is disabled' ) ;
2019-06-07 20:05:28 -06:00
} ) ;
2020-11-28 20:40:37 -07:00
app . use ( '/ext/getlasttxs/:min' , function ( req , res ) {
2020-12-28 15:12:56 -07:00
// check if the getlasttxs api is enabled or else check the headers to see if it matches an internal ajax request from the explorer itself (TODO: come up with a more secure method of whitelisting ajax calls from the explorer)
if ( settings . public _api . ext [ 'getlasttxs' ] || ( req . headers [ 'x-requested-with' ] != null && req . headers [ 'x-requested-with' ] . toLowerCase ( ) == 'xmlhttprequest' && req . headers . referer != null && req . headers . accept . indexOf ( 'text/javascript' ) > - 1 && req . headers . accept . indexOf ( 'application/json' ) > - 1 ) ) {
var min = req . params . min , start , length ;
// split url suffix by forward slash and remove blank entries
var split = req . url . split ( '/' ) . filter ( function ( v ) { return v ; } ) ;
// determine how many parameters were passed
switch ( split . length ) {
case 2 :
2020-12-18 14:55:30 -07:00
// capture start and length
start = split [ 0 ] ;
length = split [ 1 ] ;
2020-12-28 15:12:56 -07:00
break ;
default :
if ( split . length == 1 ) {
// capture start
start = split [ 0 ] ;
} else if ( split . length > 2 ) {
// capture start and length
start = split [ 0 ] ;
length = split [ 1 ] ;
}
break ;
}
2020-12-18 14:55:30 -07:00
2020-12-28 15:12:56 -07:00
// fix parameters
if ( typeof length === 'undefined' || isNaN ( length ) || length > settings . index . last _txs )
length = settings . index . last _txs ;
if ( typeof start === 'undefined' || isNaN ( start ) || start < 0 )
start = 0 ;
if ( typeof min === 'undefined' || isNaN ( min ) || min < 0 )
min = 0 ;
else
min = ( min * 100000000 ) ;
2020-12-18 14:55:30 -07:00
2020-12-28 15:12:56 -07:00
db . get _last _txs ( start , length , min , function ( data , count ) {
res . json ( { "data" : data , "recordsTotal" : count , "recordsFiltered" : count } ) ;
} ) ;
} else
res . end ( 'This method is disabled' ) ;
2020-11-28 20:40:37 -07:00
} ) ;
2020-12-18 15:17:52 -07:00
app . use ( '/ext/getaddresstxs/:address/:start/:length' , function ( req , res ) {
// fix parameters
if ( typeof req . params . length === 'undefined' || isNaN ( req . params . length ) || req . params . length > settings . txcount )
req . params . length = settings . txcount ;
if ( typeof req . params . start === 'undefined' || isNaN ( req . params . start ) || req . params . start < 0 )
req . params . start = 0 ;
if ( typeof req . params . min === 'undefined' || isNaN ( req . params . min ) || req . params . min < 0 )
req . params . min = 0 ;
else
req . params . min = ( req . params . min * 100000000 ) ;
2020-11-19 21:37:42 -07:00
2020-12-18 15:17:52 -07:00
db . get _address _txs _ajax ( req . params . address , req . params . start , req . params . length , function ( txs , count ) {
var data = [ ] ;
for ( i = 0 ; i < txs . length ; i ++ ) {
if ( typeof txs [ i ] . txid !== "undefined" ) {
var out = 0 ;
var vin = 0 ;
2020-11-19 21:37:42 -07:00
2020-12-18 15:17:52 -07:00
txs [ i ] . vout . forEach ( function ( r ) {
if ( r . addresses == req . params . address ) {
out += r . amount ;
}
} ) ;
2020-11-19 21:37:42 -07:00
2020-12-18 15:17:52 -07:00
txs [ i ] . vin . forEach ( function ( s ) {
if ( s . addresses == req . params . address ) {
vin += s . amount ;
}
} ) ;
2020-11-19 21:37:42 -07:00
2020-12-18 15:17:52 -07:00
var row = [ ] ;
row . push ( new Date ( ( txs [ i ] . timestamp ) * 1000 ) . toUTCString ( ) ) ;
row . push ( txs [ i ] . txid ) ;
row . push ( out ) ;
row . push ( vin ) ;
row . push ( txs [ i ] . balance ) ;
data . push ( row ) ;
}
}
res . json ( { "data" : data , "recordsTotal" : count , "recordsFiltered" : count } ) ;
} ) ;
2020-11-19 21:37:42 -07:00
} ) ;
2020-12-26 22:01:36 -07:00
app . post ( '/claim' , function ( req , res ) {
2020-12-22 18:06:40 -07:00
// initialize the bad-words filter
var bad _word _lib = require ( 'bad-words' ) ;
var bad _word _filter = new bad _word _lib ( ) ;
2020-12-23 18:40:10 -07:00
2020-12-22 18:06:40 -07:00
// clean the message (Display name) of bad words
2020-12-23 18:40:10 -07:00
var message = ( req . body . message == null || req . body . message == '' ? '' : bad _word _filter . clean ( req . body . message ) ) ;
2020-12-22 18:06:40 -07:00
// check if the message was filtered
if ( message == req . body . message ) {
// call the verifymessage api
lib . verify _message ( req . body . address , req . body . signature , req . body . message , function ( body ) {
if ( body == false ) {
res . json ( { 'status' : 'failed' , 'error' : true , 'message' : 'Invalid signature' } ) ;
} else if ( body == true ) {
2020-12-26 22:01:36 -07:00
db . update _label ( req . body . address , req . body . message , function ( val ) {
// check if the update was successful
if ( val == '' )
res . json ( { 'status' : 'success' } ) ;
else if ( val == 'no_address' )
res . json ( { 'status' : 'failed' , 'error' : true , 'message' : 'Wallet address ' + req . body . address + ' is not valid or does not have any transactions' } ) ;
else
res . json ( { 'status' : 'failed' , 'error' : true , 'message' : 'Wallet address or signature is invalid' } ) ;
2020-12-22 18:06:40 -07:00
} ) ;
} else
2020-12-26 22:01:36 -07:00
res . json ( { 'status' : 'failed' , 'error' : true , 'message' : 'Wallet address or signature is invalid' } ) ;
2020-12-22 18:06:40 -07:00
} ) ;
} else {
// message was filtered which would change the signature
res . json ( { 'status' : 'failed' , 'error' : true , 'message' : 'Display name contains bad words and cannot be saved: ' + message } ) ;
}
2020-12-21 18:12:40 -07:00
} ) ;
2020-11-22 14:39:10 -07:00
2019-05-27 10:33:22 -07:00
app . use ( '/ext/connections' , function ( req , res ) {
db . get _peers ( function ( peers ) {
res . send ( { data : peers } ) ;
} ) ;
} ) ;
2020-12-30 18:22:02 -07:00
// get the list of masternodes from local collection
app . use ( '/ext/getmasternodelist' , function ( req , res ) {
// check if the getmasternodelist api is enabled or else check the headers to see if it matches an internal ajax request from the explorer itself (TODO: come up with a more secure method of whitelisting ajax calls from the explorer)
if ( settings . public _api . ext [ 'getmasternodelist' ] || ( req . headers [ 'x-requested-with' ] != null && req . headers [ 'x-requested-with' ] . toLowerCase ( ) == 'xmlhttprequest' && req . headers . referer != null && req . headers . accept . indexOf ( 'text/javascript' ) > - 1 && req . headers . accept . indexOf ( 'application/json' ) > - 1 ) ) {
// get the masternode list from local collection
db . get _masternodes ( function ( masternodes ) {
// loop through masternode list and remove the mongo _id and __v keys
for ( i = 0 ; i < masternodes . length ; i ++ ) {
delete masternodes [ i ] [ '_doc' ] [ '_id' ] ;
delete masternodes [ i ] [ '_doc' ] [ '__v' ] ;
}
// return masternode list
res . send ( masternodes ) ;
} ) ;
} else
res . end ( 'This method is disabled' ) ;
} ) ;
2020-12-30 20:27:42 -07:00
// returns a list of masternode reward txs for a single masternode address from a specific block height
app . use ( '/ext/getmasternoderewards/:hash/:since' , function ( req , res ) {
// check if the getmasternoderewards api is enabled
if ( settings . public _api . ext [ 'getmasternoderewards' ] ) {
db . get _masternode _rewards ( req . params . hash , req . params . since , function ( rewards ) {
if ( rewards != null ) {
// loop through the tx list to fix vout values and remove unnecessary data such as the always empty vin array and the mongo _id and __v keys
for ( i = 0 ; i < rewards . length ; i ++ ) {
// remove unnecessary data keys
delete rewards [ i ] [ 'vin' ] ;
delete rewards [ i ] [ '_id' ] ;
delete rewards [ i ] [ '__v' ] ;
// convert amounts from satoshis
rewards [ i ] [ 'total' ] = rewards [ i ] [ 'total' ] / 100000000 ;
rewards [ i ] [ 'vout' ] [ 'amount' ] = rewards [ i ] [ 'vout' ] [ 'amount' ] / 100000000 ;
}
// return list of masternode rewards
res . json ( rewards ) ;
} else
res . send ( { error : "failed to retrieve masternode rewards" , hash : req . params . hash , since : req . params . since } ) ;
} ) ;
} else
res . end ( 'This method is disabled' ) ;
} ) ;
// returns the total masternode rewards received for a single masternode address from a specific block height
app . use ( '/ext/getmasternoderewardstotal/:hash/:since' , function ( req , res ) {
// check if the getmasternoderewardstotal api is enabled
if ( settings . public _api . ext [ 'getmasternoderewardstotal' ] ) {
db . get _masternode _rewards _totals ( req . params . hash , req . params . since , function ( total _rewards ) {
if ( total _rewards != null ) {
// return the total of masternode rewards
res . json ( total _rewards ) ;
} else
res . send ( { error : "failed to retrieve masternode rewards" , hash : req . params . hash , since : req . params . since } ) ;
} ) ;
} else
res . end ( 'This method is disabled' ) ;
} ) ;
2019-05-27 10:33:22 -07:00
// locals
app . set ( 'title' , settings . title ) ;
2020-11-22 20:29:56 -07:00
app . set ( 'explorer_version' , package _metadata . version ) ;
2019-05-27 10:33:22 -07:00
app . set ( 'symbol' , settings . symbol ) ;
app . set ( 'coin' , settings . coin ) ;
app . set ( 'locale' , locale ) ;
app . set ( 'display' , settings . display ) ;
app . set ( 'markets' , settings . markets ) ;
app . set ( 'twitter' , settings . twitter ) ;
app . set ( 'facebook' , settings . facebook ) ;
app . set ( 'googleplus' , settings . googleplus ) ;
app . set ( 'bitcointalk' , settings . bitcointalk ) ;
app . set ( 'github' , settings . github ) ;
app . set ( 'slack' , settings . slack ) ;
app . set ( 'discord' , settings . discord ) ;
app . set ( 'telegram' , settings . telegram ) ;
app . set ( 'reddit' , settings . reddit ) ;
app . set ( 'youtube' , settings . youtube ) ;
app . set ( 'website' , settings . website ) ;
app . set ( 'genesis_block' , settings . genesis _block ) ;
app . set ( 'index' , settings . index ) ;
2020-11-20 18:43:30 -07:00
app . set ( 'use_rpc' , settings . use _rpc ) ;
2019-05-27 10:33:22 -07:00
app . set ( 'heavy' , settings . heavy ) ;
2020-12-08 20:49:06 -07:00
app . set ( 'save_stats_after_sync_blocks' , settings . save _stats _after _sync _blocks ) ;
2020-11-20 16:28:28 -07:00
app . set ( 'lock_during_index' , settings . lock _during _index ) ;
2019-05-27 10:33:22 -07:00
app . set ( 'txcount' , settings . txcount ) ;
2020-11-20 18:18:36 -07:00
app . set ( 'txcount_per_page' , settings . txcount _per _page ) ;
2019-05-27 10:33:22 -07:00
app . set ( 'nethash' , settings . nethash ) ;
app . set ( 'nethash_units' , settings . nethash _units ) ;
app . set ( 'show_sent_received' , settings . show _sent _received ) ;
app . set ( 'logo' , settings . logo ) ;
2020-12-27 18:36:02 -07:00
// Check if header logo file exists
if ( db . fs . existsSync ( path . join ( './public' , settings . headerlogo ) ) )
app . set ( 'headerlogo' , settings . headerlogo ) ;
else
app . set ( 'headerlogo' , '' ) ;
2019-05-27 10:33:22 -07:00
app . set ( 'theme' , settings . theme ) ;
app . set ( 'labels' , settings . labels ) ;
app . set ( 'homelink' , settings . homelink ) ;
app . set ( 'logoheight' , settings . logoheight ) ;
2019-06-24 19:52:15 -06:00
app . set ( 'burned_coins' , settings . burned _coins ) ;
2020-12-07 21:32:43 -07:00
app . set ( 'api_cmds' , settings . api _cmds ) ;
2019-05-27 10:33:22 -07:00
2020-12-30 18:22:02 -07:00
// Always disable the rpc masternode list cmd from public apis
settings . public _api [ 'rpc' ] [ 'getmasternodelist' ] = false ;
app . set ( 'public_api' , settings . public _api ) ;
2020-12-09 19:36:39 -07:00
app . set ( 'sticky_header' , settings . sticky _header ) ;
app . set ( 'sticky_footer' , settings . sticky _footer ) ;
2020-12-05 20:10:17 -07:00
app . set ( 'footer_height_desktop' , settings . footer _height _desktop ) ;
app . set ( 'footer_height_tablet' , settings . footer _height _tablet ) ;
app . set ( 'footer_height_mobile' , settings . footer _height _mobile ) ;
app . set ( 'social_link_percent_height_desktop' , settings . social _link _percent _height _desktop ) ;
app . set ( 'social_link_percent_height_tablet' , settings . social _link _percent _height _tablet ) ;
app . set ( 'social_link_percent_height_mobile' , settings . social _link _percent _height _mobile ) ;
2019-05-27 10:33:22 -07:00
// determine panel offset based on which panels are enabled
2020-12-27 17:26:01 -07:00
var paneltotal = 5 ;
var panelcount = ( settings . display . networkpnl > 0 ? 1 : 0 ) +
( settings . display . difficultypnl > 0 ? 1 : 0 ) +
( settings . display . masternodespnl > 0 ? 1 : 0 ) +
( settings . display . coinsupplypnl > 0 ? 1 : 0 ) +
( settings . display . pricepnl > 0 ? 1 : 0 ) +
2020-12-27 17:58:09 -07:00
( settings . display . marketcappnl > 0 ? 1 : 0 ) +
( settings . display . logopnl > 0 ? 1 : 0 ) ;
2020-12-27 17:26:01 -07:00
app . set ( 'paneloffset' , paneltotal + 1 - panelcount ) ;
2019-05-27 10:33:22 -07:00
// determine panel order
var panelorder = new Array ( ) ;
2020-12-27 17:26:01 -07:00
2019-05-27 10:33:22 -07:00
if ( settings . display . networkpnl > 0 ) panelorder . push ( { name : 'networkpnl' , val : settings . display . networkpnl } ) ;
if ( settings . display . difficultypnl > 0 ) panelorder . push ( { name : 'difficultypnl' , val : settings . display . difficultypnl } ) ;
if ( settings . display . masternodespnl > 0 ) panelorder . push ( { name : 'masternodespnl' , val : settings . display . masternodespnl } ) ;
if ( settings . display . coinsupplypnl > 0 ) panelorder . push ( { name : 'coinsupplypnl' , val : settings . display . coinsupplypnl } ) ;
if ( settings . display . pricepnl > 0 ) panelorder . push ( { name : 'pricepnl' , val : settings . display . pricepnl } ) ;
2020-12-27 17:26:01 -07:00
if ( settings . display . marketcappnl > 0 ) panelorder . push ( { name : 'marketcappnl' , val : settings . display . marketcappnl } ) ;
2020-12-27 17:58:09 -07:00
if ( settings . display . logopnl > 0 ) panelorder . push ( { name : 'logopnl' , val : settings . display . logopnl } ) ;
2020-12-27 17:26:01 -07:00
2019-05-27 10:33:22 -07:00
panelorder . sort ( function ( a , b ) { return a . val - b . val ; } ) ;
2020-12-27 17:26:01 -07:00
for ( var i = 1 ; i < 6 ; i ++ )
2019-05-27 10:33:22 -07:00
app . set ( 'panel' + i . toString ( ) , ( ( panelorder . length >= i ) ? panelorder [ i - 1 ] . name : '' ) ) ;
2020-12-25 21:08:25 -07:00
// Dynamically populate market data
var market _data = [ ] ;
2020-12-05 17:39:14 -07:00
settings . markets . enabled . forEach ( function ( market ) {
// Check if market file exists
2020-12-08 22:52:15 -07:00
if ( db . fs . existsSync ( './lib/markets/' + market + '.js' ) ) {
2020-12-05 17:39:14 -07:00
// Load market file
var exMarket = require ( './lib/markets/' + market ) ;
2020-12-25 21:08:25 -07:00
// Save market_name and market_logo from market file to settings
eval ( 'market_data.push({id: "' + market + '", name: "' + ( exMarket . market _name == null ? '' : exMarket . market _name ) + '", logo: "' + ( exMarket . market _logo == null ? '' : exMarket . market _logo ) + '"});' ) ;
2020-12-05 17:39:14 -07:00
}
} ) ;
2020-12-25 21:08:25 -07:00
// Sort market data by name
market _data . sort ( function ( a , b ) {
var name1 = a . name . toLowerCase ( ) ;
var name2 = b . name . toLowerCase ( ) ;
if ( name1 < name2 )
return - 1 ;
else if ( name1 > name2 )
return 1 ;
else
return 0 ;
} ) ;
app . set ( 'market_data' , market _data ) ;
2020-12-05 17:39:14 -07:00
2019-05-27 10:33:22 -07:00
// catch 404 and forward to error handler
app . use ( function ( req , res , next ) {
var err = new Error ( 'Not Found' ) ;
err . status = 404 ;
next ( err ) ;
} ) ;
// development error handler
// will print stacktrace
if ( app . get ( 'env' ) === 'development' ) {
app . use ( function ( err , req , res , next ) {
res . status ( err . status || 500 ) ;
res . render ( 'error' , {
message : err . message ,
error : err
} ) ;
} ) ;
}
// production error handler
// no stacktraces leaked to user
app . use ( function ( err , req , res , next ) {
res . status ( err . status || 500 ) ;
res . render ( 'error' , {
message : err . message ,
error : { }
} ) ;
} ) ;
2020-11-20 16:28:28 -07:00
module . exports = app ;