diff --git a/scripts/sync.js b/scripts/sync.js index ea52a98..3fcbc9e 100644 --- a/scripts/sync.js +++ b/scripts/sync.js @@ -296,42 +296,54 @@ if (database == 'peers') { if (settings.blockchain_specific.heavycoin.enabled == true) db.update_heavy(settings.coin.name, stats.count, 20, function() {}); if (mode == 'reindex') { + console.log('deleting transactions.. please wait..'); Tx.deleteMany({}, function(err) { - console.log('TXs cleared.'); + console.log('transactions deleted successfully'); + console.log('deleting addresses.. please wait..'); Address.deleteMany({}, function(err2) { - console.log('Addresses cleared.'); + console.log('addresses deleted successfully'); + console.log('deleting address transactions.. please wait..'); AddressTx.deleteMany({}, function(err3) { - console.log('Address TXs cleared.'); + console.log('address transactions deleted successfully'); + console.log('deleting top 100 data.. please wait..'); Richlist.updateOne({coin: settings.coin.name}, { received: [], balance: [] }, function(err3) { + console.log('top 100 data deleted successfully'); + + console.log('deleting block index.. please wait..'); Stats.updateOne({coin: settings.coin.name}, { last: 0, count: 0, - supply: 0 + supply: 0, + txes: 0, + blockchain_last_updated: 0, + richlist_last_updated: 0 }, function() { - console.log('index cleared (reindex)'); - }); + console.log('block index deleted successfully'); - // Check if the sync msg should be shown - check_show_sync_message(stats.count); + // Check if the sync msg should be shown + check_show_sync_message(stats.count); - db.update_tx_db(settings.coin.name, block_start, stats.count, stats.txes, settings.sync.update_timeout, false, 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(); + console.log('starting resync of blockchain data.. please wait..'); + db.update_tx_db(settings.coin.name, block_start, stats.count, stats.txes, settings.sync.update_timeout, false, function() { + // update blockchain_last_updated value + db.update_last_updated_stats(settings.coin.name, { blockchain_last_updated: Math.floor(new Date() / 1000) }, function (cb) { + db.update_richlist('received', function() { + 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) { + db.get_stats(settings.coin.name, function(nstats) { + // always check for and remove the sync msg if exists + remove_sync_message(); + + console.log('reindex complete (block: %s)', nstats.last); + exit(); + }); }); }); }); diff --git a/scripts/sync.sh b/scripts/sync.sh index 37081f9..988d59b 100755 --- a/scripts/sync.sh +++ b/scripts/sync.sh @@ -120,6 +120,19 @@ if [ -n "${MODE}" ]; then # Check if the desired mode requires a lock if [ "${MODE}" != "peers" ] && [ "${MODE}" != "masternodes" ]; then # A lock is required + # Check if this is a reindex + if [ "${MODE}" = "index reindex" ]; then + # Prompt for the reindex + echo "You are about to delete all blockchain data (transactions and addresses)" + echo "and resync from the genesis block." + echo "Are you sure you want to do this? [y/n]: "; + read -p "" REINDEX_ANSWER + # Determine if the reindex should proceed + case "$REINDEX_ANSWER" in + y|Y|yes|Yes|YES) ;; + *) echo "Process aborted. Nothing was deleted." && exit ;; + esac + fi # Check if the script is already running (tmp/index.pid file already exists) if [ -f "${EXPLORER_PATH}/tmp/index.pid" ]; then # The tmp/index.pid file exists. Check if the process is actually still running