2019-05-27 10:33:22 -07:00
var mongoose = require ( 'mongoose' )
2020-12-04 10:59:58 -07:00
, lib = require ( '../lib/explorer' )
2020-11-20 16:28:28 -07:00
, db = require ( '../lib/database' )
, Tx = require ( '../models/tx' )
, Address = require ( '../models/address' )
, AddressTx = require ( '../models/addresstx' )
, Richlist = require ( '../models/richlist' )
, Stats = require ( '../models/stats' )
2020-12-21 16:19:14 -07:00
, settings = require ( '../lib/settings' ) ;
2019-05-27 10:33:22 -07:00
var mode = 'update' ;
var database = 'index' ;
// displays usage and exits
function usage ( ) {
2020-12-04 10:59:58 -07:00
console . log ( 'Usage: scripts/sync.sh /path/to/nodejs [mode]' ) ;
2019-05-27 10:33:22 -07:00
console . log ( '' ) ;
2020-12-04 10:59:58 -07:00
console . log ( 'Mode: (required)' ) ;
2020-12-03 14:16:34 -07:00
console . log ( 'update Updates index from last sync to current block' ) ;
console . log ( 'check Checks index for (and adds) any missing transactions/addresses' ) ;
console . log ( 'reindex Clears index then resyncs from genesis to current block' ) ;
2020-12-04 10:59:58 -07:00
console . log ( 'reindex-rich Clears and recreates the richlist data' ) ;
2020-12-03 14:16:34 -07:00
console . log ( 'reindex-txcount Rescan and flatten the tx count value for faster access' ) ;
2021-01-24 15:26:17 -07:00
console . log ( 'reindex-last Rescan and flatten the last blockindex value for faster access' ) ;
2020-12-04 10:59:58 -07:00
console . log ( 'market Updates market summaries, orderbooks, trade history + charts' ) ;
console . log ( 'peers Updates peer info based on local wallet connections' ) ;
2020-12-30 18:22:02 -07:00
console . log ( 'masternodes Updates the list of active masternodes on the network' ) ;
2019-05-27 10:33:22 -07:00
console . log ( '' ) ;
2020-12-04 10:59:58 -07:00
console . log ( 'Notes:' ) ;
console . log ( '- \'current block\' is the latest created block when script is executed.' ) ;
console . log ( '- The market + peers databases only support (& defaults to) reindex mode.' ) ;
console . log ( '- If check mode finds missing data (ignoring new data since last sync),' ) ;
2019-05-27 10:33:22 -07:00
console . log ( ' index_timeout in settings.json is set too low.' )
console . log ( '' ) ;
process . exit ( 0 ) ;
}
// check options
if ( process . argv [ 2 ] == 'index' ) {
if ( process . argv . length < 3 ) {
usage ( ) ;
} else {
switch ( process . argv [ 3 ] )
{
2020-11-19 21:37:42 -07:00
case 'update' :
mode = 'update' ;
break ;
case 'check' :
mode = 'check' ;
break ;
case 'reindex' :
mode = 'reindex' ;
break ;
2020-11-20 14:06:53 -07:00
case 'reindex-rich' :
mode = 'reindex-rich' ;
2020-12-04 10:59:58 -07:00
break ;
2020-12-03 14:16:34 -07:00
case 'reindex-txcount' :
mode = 'reindex-txcount' ;
2020-11-20 14:06:53 -07:00
break ;
2021-01-24 15:26:17 -07:00
case 'reindex-last' :
mode = 'reindex-last' ;
break ;
2020-11-19 21:37:42 -07:00
default :
usage ( ) ;
2019-05-27 10:33:22 -07:00
}
}
2020-12-04 10:59:58 -07:00
} else if ( process . argv [ 2 ] == 'market' ) {
2019-05-27 10:33:22 -07:00
database = 'market' ;
2020-12-04 10:59:58 -07:00
} else if ( process . argv [ 2 ] == 'peers' ) {
database = 'peers' ;
2020-12-30 18:22:02 -07:00
} else if ( process . argv [ 2 ] == 'masternodes' ) {
database = 'masternodes' ;
2019-05-27 10:33:22 -07:00
} else {
usage ( ) ;
}
function create _lock ( cb ) {
if ( database == 'index' ) {
var fname = './tmp/' + database + '.pid' ;
2020-12-08 22:52:15 -07:00
db . fs . appendFile ( fname , process . pid . toString ( ) , function ( err ) {
2019-05-27 10:33:22 -07:00
if ( err ) {
console . log ( "Error: unable to create %s" , fname ) ;
process . exit ( 1 ) ;
} else {
return cb ( ) ;
}
} ) ;
} else {
return cb ( ) ;
}
}
function remove _lock ( cb ) {
if ( database == 'index' ) {
var fname = './tmp/' + database + '.pid' ;
2020-12-08 22:52:15 -07:00
db . fs . unlink ( fname , function ( err ) {
2019-05-27 10:33:22 -07:00
if ( err ) {
console . log ( "unable to remove lock: %s" , fname ) ;
process . exit ( 1 ) ;
} else {
return cb ( ) ;
}
} ) ;
} else {
return cb ( ) ;
2020-11-19 21:37:42 -07:00
}
2019-05-27 10:33:22 -07:00
}
function is _locked ( cb ) {
if ( database == 'index' ) {
var fname = './tmp/' + database + '.pid' ;
2020-12-08 22:52:15 -07:00
db . fs . exists ( fname , function ( exists ) {
2019-05-27 10:33:22 -07:00
if ( exists ) {
return cb ( true ) ;
} else {
return cb ( false ) ;
}
} ) ;
} else {
return cb ( ) ;
2020-11-19 21:37:42 -07:00
}
2019-05-27 10:33:22 -07:00
}
function exit ( ) {
remove _lock ( function ( ) {
mongoose . disconnect ( ) ;
process . exit ( 0 ) ;
} ) ;
}
var dbString = 'mongodb://' + settings . dbsettings . user ;
dbString = dbString + ':' + settings . dbsettings . password ;
dbString = dbString + '@' + settings . dbsettings . address ;
dbString = dbString + ':' + settings . dbsettings . port ;
dbString = dbString + '/' + settings . dbsettings . database ;
2020-12-04 10:59:58 -07:00
if ( database == 'peers' ) {
2021-01-22 15:04:32 -07:00
var rateLimitLib = require ( '../lib/ratelimit' ) ;
2020-12-04 10:59:58 -07:00
console . log ( 'syncing peers.. please wait..' ) ;
// syncing peers does not require a lock
mongoose . connect ( dbString , { useNewUrlParser : true , useCreateIndex : true , useUnifiedTopology : true , useFindAndModify : false } , function ( err ) {
if ( err ) {
console . log ( 'Unable to connect to database: %s' , dbString ) ;
console . log ( 'Aborting' ) ;
exit ( ) ;
} else {
2020-12-21 16:19:14 -07:00
lib . get _peerinfo ( function ( body ) {
if ( body != null ) {
lib . syncLoop ( body . length , function ( loop ) {
var i = loop . iteration ( ) ;
var address = body [ i ] . addr . substring ( 0 , body [ i ] . addr . lastIndexOf ( ":" ) ) . replace ( "[" , "" ) . replace ( "]" , "" ) ;
var port = body [ i ] . addr . substring ( body [ i ] . addr . lastIndexOf ( ":" ) + 1 ) ;
2021-01-22 15:04:32 -07:00
var rateLimit = new rateLimitLib . RateLimit ( 1 , 2000 , false ) ;
2020-12-21 16:19:14 -07:00
db . find _peer ( address , function ( peer ) {
if ( peer ) {
if ( isNaN ( peer [ 'port' ] ) || peer [ 'port' ] . length < 2 || peer [ 'country' ] . length < 1 || peer [ 'country_code' ] . length < 1 ) {
db . drop _peers ( function ( ) {
console . log ( 'Saved peers missing ports or country, dropping peers. Re-run this script afterwards.' ) ;
exit ( ) ;
} ) ;
}
2021-01-22 15:04:32 -07:00
console . log ( 'Updated peer %s [%s/%s]' , address , ( i + 1 ) . toString ( ) , body . length . toString ( ) ) ;
2020-12-21 16:19:14 -07:00
// peer already exists
loop . next ( ) ;
} else {
rateLimit . schedule ( function ( ) {
lib . get _geo _location ( address , function ( error , geo ) {
// check if an error was returned
if ( error ) {
console . log ( error ) ;
exit ( ) ;
} else {
// add peer to collection
db . create _peer ( {
address : address ,
port : port ,
protocol : body [ i ] . version ,
version : body [ i ] . subver . replace ( '/' , '' ) . replace ( '/' , '' ) ,
country : geo . country _name ,
country _code : geo . country _code
} , function ( ) {
2021-01-22 15:04:32 -07:00
console . log ( 'Added new peer %s [%s/%s]' , address , ( i + 1 ) . toString ( ) , body . length . toString ( ) ) ;
2020-12-21 16:19:14 -07:00
loop . next ( ) ;
} ) ;
}
2020-12-04 10:59:58 -07:00
} ) ;
} ) ;
2020-12-21 16:19:14 -07:00
}
} ) ;
} , function ( ) {
2020-12-31 15:19:48 -07:00
// update network_last_updated value
2021-01-22 15:04:32 -07:00
db . update _last _updated _stats ( settings . coin . name , { network _last _updated : Math . floor ( new Date ( ) / 1000 ) } , function ( cb ) {
2020-12-31 15:19:48 -07:00
console . log ( 'peer sync complete' ) ;
exit ( ) ;
} ) ;
2020-12-04 10:59:58 -07:00
} ) ;
2020-12-21 16:19:14 -07:00
} else {
console . log ( 'no peers found' ) ;
2020-12-04 10:59:58 -07:00
exit ( ) ;
2020-12-21 16:19:14 -07:00
}
2020-12-04 10:59:58 -07:00
} ) ;
}
} ) ;
2020-12-30 18:22:02 -07:00
} else if ( database == 'masternodes' ) {
console . log ( 'syncing masternodes.. please wait..' ) ;
// syncing masternodes does not require a lock
mongoose . connect ( dbString , { useNewUrlParser : true , useCreateIndex : true , useUnifiedTopology : true , useFindAndModify : false } , function ( err ) {
if ( err ) {
console . log ( 'Unable to connect to database: %s' , dbString ) ;
console . log ( 'Aborting' ) ;
exit ( ) ;
} else {
lib . get _masternodelist ( function ( body ) {
if ( body != null ) {
lib . syncLoop ( body . length , function ( loop ) {
var i = loop . iteration ( ) ;
db . save _masternode ( body [ i ] , function ( success ) {
if ( success )
loop . next ( ) ;
else {
console . log ( 'error: cannot save masternode %s.' , ( body [ i ] . addr ? body [ i ] . addr : 'UNKNOWN' ) ) ;
exit ( ) ;
}
} ) ;
} , function ( ) {
db . remove _old _masternodes ( function ( cb ) {
2021-01-22 15:04:32 -07:00
db . update _last _updated _stats ( settings . coin . name , { masternodes _last _updated : Math . floor ( new Date ( ) / 1000 ) } , function ( cb ) {
2020-12-30 18:22:02 -07:00
console . log ( 'masternode sync complete' ) ;
exit ( ) ;
} ) ;
} ) ;
} ) ;
} else {
console . log ( 'no masternodes found' ) ;
exit ( ) ;
}
} ) ;
}
} ) ;
2020-12-04 10:59:58 -07:00
} else {
// index and market sync requires locking
is _locked ( function ( exists ) {
if ( exists ) {
console . log ( "Script already running.." ) ;
process . exit ( 0 ) ;
} else {
create _lock ( function ( ) {
console . log ( "script launched with pid: " + process . pid ) ;
mongoose . connect ( dbString , { useNewUrlParser : true , useCreateIndex : true , useUnifiedTopology : true , useFindAndModify : false } , function ( err ) {
if ( err ) {
console . log ( 'Unable to connect to database: %s' , dbString ) ;
console . log ( 'Aborting' ) ;
exit ( ) ;
} else if ( database == 'index' ) {
2021-01-22 15:04:32 -07:00
db . check _stats ( settings . coin . name , function ( exists ) {
2020-12-04 10:59:58 -07:00
if ( exists == false ) {
console . log ( 'Run \'npm start\' to create database structures before running this script.' ) ;
exit ( ) ;
} else {
2021-02-03 20:54:15 -07:00
db . update _db ( settings . coin . name , function ( stats ) {
// check if stats returned properly
if ( stats !== false ) {
if ( settings . blockchain _specific . heavycoin . enabled == true )
db . update _heavy ( settings . coin . name , stats . count , 20 , function ( ) { } ) ;
if ( mode == 'reindex' ) {
Tx . deleteMany ( { } , function ( err ) {
console . log ( 'TXs cleared.' ) ;
Address . deleteMany ( { } , function ( err2 ) {
console . log ( 'Addresses cleared.' ) ;
AddressTx . deleteMany ( { } , function ( err3 ) {
console . log ( 'Address TXs cleared.' ) ;
Richlist . updateOne ( { coin : settings . coin . name } , {
received : [ ] ,
balance : [ ] ,
} , function ( err3 ) {
Stats . updateOne ( { coin : settings . coin . name } , {
last : 0 ,
count : 0 ,
supply : 0
} , function ( ) {
console . log ( 'index cleared (reindex)' ) ;
} ) ;
2020-12-05 12:39:36 -07:00
2021-02-03 20:54:15 -07:00
// Check if the sync msg should be shown
check _show _sync _message ( stats . count ) ;
2020-12-05 12:39:36 -07:00
2021-02-03 20:54:15 -07:00
db . update _tx _db ( settings . coin . name , 1 , stats . count , stats . txes , settings . sync . update _timeout , function ( ) {
db . update _richlist ( 'received' , function ( ) {
db . update _richlist ( 'balance' , function ( ) {
db . get _stats ( settings . coin . name , function ( nstats ) {
// always check for and remove the sync msg if exists
remove _sync _message ( ) ;
// update richlist_last_updated value
db . update _last _updated _stats ( settings . coin . name , { richlist _last _updated : Math . floor ( new Date ( ) / 1000 ) } , function ( cb ) {
// update blockchain_last_updated value
db . update _last _updated _stats ( settings . coin . name , { blockchain _last _updated : Math . floor ( new Date ( ) / 1000 ) } , function ( cb ) {
console . log ( 'reindex complete (block: %s)' , nstats . last ) ;
exit ( ) ;
} ) ;
2020-12-31 15:19:48 -07:00
} ) ;
} ) ;
2020-12-04 10:59:58 -07:00
} ) ;
2019-05-27 10:33:22 -07:00
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
2021-02-03 20:54:15 -07:00
} else if ( mode == 'check' ) {
console . log ( 'starting check.. please wait..' ) ;
db . update _tx _db ( settings . coin . name , 1 , stats . count , stats . txes , settings . sync . check _timeout , function ( ) {
db . get _stats ( settings . coin . name , function ( nstats ) {
console . log ( 'check complete (block: %s)' , nstats . last ) ;
exit ( ) ;
} ) ;
2020-12-04 10:59:58 -07:00
} ) ;
2021-02-03 20:54:15 -07:00
} else if ( mode == 'update' ) {
// Get the last synced block index value
var last = ( stats . last ? stats . last : 0 ) ;
// Get the total number of blocks
var count = ( stats . count ? stats . count : 0 ) ;
// Check if the sync msg should be shown
check _show _sync _message ( count - last ) ;
2019-10-01 21:25:47 -06:00
2021-02-03 20:54:15 -07:00
db . update _tx _db ( settings . coin . name , last , count , stats . txes , settings . sync . update _timeout , function ( ) {
db . update _richlist ( 'received' , function ( ) {
db . update _richlist ( 'balance' , function ( ) {
db . get _stats ( settings . coin . name , function ( nstats ) {
// always check for and remove the sync msg if exists
remove _sync _message ( ) ;
// update richlist_last_updated value
db . update _last _updated _stats ( settings . coin . name , { richlist _last _updated : Math . floor ( new Date ( ) / 1000 ) } , function ( cb ) {
// update blockchain_last_updated value
db . update _last _updated _stats ( settings . coin . name , { blockchain _last _updated : Math . floor ( new Date ( ) / 1000 ) } , function ( cb ) {
console . log ( 'update complete (block: %s)' , nstats . last ) ;
exit ( ) ;
} ) ;
2020-12-31 15:19:48 -07:00
} ) ;
} ) ;
2019-05-27 10:33:22 -07:00
} ) ;
} ) ;
} ) ;
2021-02-03 20:54:15 -07:00
} else if ( mode == 'reindex-rich' ) {
console . log ( 'check richlist' ) ;
db . check _richlist ( settings . coin . name , function ( exists ) {
if ( exists ) console . log ( 'richlist entry found, deleting now..' ) ;
db . delete _richlist ( settings . coin . name , function ( deleted ) {
if ( deleted ) console . log ( 'richlist entry deleted' ) ;
db . create _richlist ( settings . coin . name , function ( ) {
console . log ( 'richlist created.' ) ;
db . update _richlist ( 'received' , function ( ) {
console . log ( 'richlist updated received.' ) ;
db . update _richlist ( 'balance' , function ( ) {
// update richlist_last_updated value
db . update _last _updated _stats ( settings . coin . name , { richlist _last _updated : Math . floor ( new Date ( ) / 1000 ) } , function ( cb ) {
console . log ( 'richlist update complete' ) ;
exit ( ) ;
} ) ;
2020-12-31 15:19:48 -07:00
} ) ;
2020-11-20 14:06:53 -07:00
} ) ;
} ) ;
} ) ;
2020-11-22 17:00:44 -07:00
} ) ;
2021-02-03 20:54:15 -07:00
} else if ( mode == 'reindex-txcount' ) {
console . log ( 'calculating tx count.. please wait..' ) ;
// Resetting the transaction counter requires a single lookup on the txes collection to find all txes that have a positive or zero total and 1 or more vout
Tx . find ( { 'total' : { $gte : 0 } , 'vout' : { $gte : { $size : 1 } } } ) . countDocuments ( function ( err , count ) {
console . log ( 'found tx count: ' + count . toString ( ) ) ;
2021-01-24 15:26:17 -07:00
Stats . updateOne ( { coin : settings . coin . name } , {
2021-02-03 20:54:15 -07:00
txes : count
2021-01-24 15:26:17 -07:00
} , function ( ) {
2021-02-03 20:54:15 -07:00
console . log ( 'tx count update complete' ) ;
2021-01-24 15:26:17 -07:00
exit ( ) ;
} ) ;
2021-02-03 20:54:15 -07:00
} ) ;
} else if ( mode == 'reindex-last' ) {
console . log ( 'finding last blockindex.. please wait..' ) ;
// Resetting the last blockindex counter requires a single lookup on the txes collection to find the last indexed blockindex
Tx . find ( { } , { blockindex : 1 , _id : 0 } ) . sort ( { blockindex : - 1 } ) . limit ( 1 ) . exec ( function ( err , tx ) {
// check if any blocks exists
if ( err != null || tx == null || tx . length == 0 ) {
console . log ( 'no blocks found. setting last blockindex to 0.' ) ;
Stats . updateOne ( { coin : settings . coin . name } , {
last : 0
} , function ( ) {
console . log ( 'last blockindex update complete' ) ;
exit ( ) ;
} ) ;
} else {
console . log ( 'found last blockindex: ' + tx [ 0 ] . blockindex . toString ( ) ) ;
Stats . updateOne ( { coin : settings . coin . name } , {
last : tx [ 0 ] . blockindex
} , function ( ) {
console . log ( 'last blockindex update complete' ) ;
exit ( ) ;
} ) ;
}
} ) ;
}
} else {
// update_db threw an error so exit
exit ( ) ;
2019-05-27 10:33:22 -07:00
}
} ) ;
}
} ) ;
2020-12-04 10:59:58 -07:00
} else {
2021-01-22 15:04:32 -07:00
// check if market feature is enabled
if ( settings . markets _page . enabled == true ) {
var complete = 0 ;
var total _pairs = 0 ;
var exchanges = Object . keys ( settings . markets _page . exchanges ) ;
// loop through all exchanges to determine how many trading pairs must be updated
exchanges . forEach ( function ( key , index , map ) {
// check if market is enabled via settings
if ( settings . markets _page . exchanges [ key ] . enabled == true ) {
// check if market is installed/supported
if ( db . fs . existsSync ( './lib/markets/' + key + '.js' ) ) {
// add trading pairs to total
total _pairs += settings . markets _page . exchanges [ key ] . trading _pairs . length ;
// loop through all trading pairs for this market
for ( var i = 0 ; i < settings . markets _page . exchanges [ key ] . trading _pairs . length ; i ++ ) {
// ensure trading pair setting is always uppercase
settings . markets _page . exchanges [ key ] . trading _pairs [ i ] = settings . markets _page . exchanges [ key ] . trading _pairs [ i ] . toUpperCase ( ) ;
}
}
}
} ) ;
// check if there are any trading pairs to update
if ( total _pairs > 0 ) {
// initialize the rate limiter to wait 2 seconds between requests to prevent abusing external apis
var rateLimitLib = require ( '../lib/ratelimit' ) ;
var rateLimit = new rateLimitLib . RateLimit ( 1 , 2000 , false ) ;
// loop through and test all exchanges defined in the settings.json file
exchanges . forEach ( function ( key , index , map ) {
// check if market is enabled via settings
if ( settings . markets _page . exchanges [ key ] . enabled == true ) {
// check if market is installed/supported
if ( db . fs . existsSync ( './lib/markets/' + key + '.js' ) ) {
// loop through all trading pairs
settings . markets _page . exchanges [ key ] . trading _pairs . forEach ( function ( pair _key , pair _index , pair _map ) {
// split the pair data
var split _pair = pair _key . split ( '/' ) ;
// check if this is a valid trading pair
if ( split _pair . length == 2 ) {
// lookup the exchange in the market collection
db . check _market ( key , split _pair [ 0 ] , split _pair [ 1 ] , function ( mkt , exists ) {
// check if exchange trading pair exists in the market collection
if ( exists ) {
// automatically pause for 2 seconds in between requests
rateLimit . schedule ( function ( ) {
// update market data
db . update _markets _db ( key , split _pair [ 0 ] , split _pair [ 1 ] , function ( err ) {
if ( ! err ) {
2021-03-07 14:47:34 -07:00
console . log ( '%s[%s]: market data updated successfully.' , key , pair _key ) ;
2021-01-22 15:04:32 -07:00
complete ++ ;
if ( complete == total _pairs )
get _last _usd _price ( ) ;
} else {
2021-03-07 14:47:34 -07:00
console . log ( '%s[%s] error: %s' , key , pair _key , err ) ;
2021-01-22 15:04:32 -07:00
complete ++ ;
if ( complete == total _pairs )
get _last _usd _price ( ) ;
}
} ) ;
} ) ;
} else {
console . log ( 'error: entry for %s does not exist in markets database.' , key ) ;
complete ++ ;
if ( complete == total _pairs )
get _last _usd _price ( ) ;
}
} ) ;
}
} ) ;
} else {
// market not installed
console . log ( '%s market not installed' , key ) ;
complete ++ ;
if ( complete == total _pairs )
get _last _usd _price ( ) ;
}
2020-12-08 22:52:15 -07:00
}
} ) ;
} else {
2021-01-22 15:04:32 -07:00
// no market trading pairs are enabled
console . log ( 'error: no market trading pairs are enabled in settings' ) ;
exit ( ) ;
2020-12-08 22:52:15 -07:00
}
2021-01-22 15:04:32 -07:00
} else {
// market page is not enabled
console . log ( 'error: market feature is disabled in settings' ) ;
exit ( ) ;
2020-12-04 10:59:58 -07:00
}
2019-05-27 10:33:22 -07:00
}
2020-12-04 10:59:58 -07:00
} ) ;
2019-05-27 10:33:22 -07:00
} ) ;
2020-12-04 10:59:58 -07:00
}
} ) ;
}
2019-06-07 20:05:28 -06:00
2020-12-05 12:39:36 -07:00
function check _show _sync _message ( blocks _to _sync ) {
var retVal = false ;
2020-12-05 18:21:21 -07:00
var filePath = './tmp/show_sync_message.tmp' ;
2021-01-22 15:04:32 -07:00
// Check if the sync msg should be shown
if ( blocks _to _sync > settings . sync . show _sync _msg _when _syncing _more _than _blocks ) {
2020-12-05 12:39:36 -07:00
// Check if the show sync stub file already exists
2020-12-08 22:52:15 -07:00
if ( ! db . fs . existsSync ( filePath ) ) {
2020-12-05 12:39:36 -07:00
// File doesn't exist, so create it now
2020-12-08 22:52:15 -07:00
db . fs . writeFileSync ( filePath , '' ) ;
2020-12-05 12:39:36 -07:00
}
retVal = true ;
}
return retVal ;
}
function remove _sync _message ( ) {
2020-12-05 18:21:21 -07:00
var filePath = './tmp/show_sync_message.tmp' ;
2020-12-05 12:39:36 -07:00
// Check if the show sync stub file exists
2020-12-08 22:52:15 -07:00
if ( db . fs . existsSync ( filePath ) ) {
2020-12-05 12:39:36 -07:00
// File exists, so delete it now
try {
2020-12-08 22:52:15 -07:00
db . fs . unlinkSync ( filePath ) ;
2020-12-05 12:39:36 -07:00
} catch ( err ) {
console . log ( err ) ;
}
}
}
2019-06-07 20:05:28 -06:00
function get _last _usd _price ( ) {
// Get the last usd price for coinstats
2020-12-31 15:19:48 -07:00
db . get _last _usd _price ( function ( retVal ) {
// update markets_last_updated value
2021-01-22 15:04:32 -07:00
db . update _last _updated _stats ( settings . coin . name , { markets _last _updated : Math . floor ( new Date ( ) / 1000 ) } , function ( cb ) {
2020-12-31 15:19:48 -07:00
console . log ( 'market sync complete' ) ;
exit ( ) ;
} ) ;
} ) ;
2019-06-07 20:05:28 -06:00
}