2014-02-03 09:53:37 -08:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2014-01-10 11:02:33 -08:00
|
|
|
|
|
|
|
'use strict';
|
2014-01-06 18:50:29 -08:00
|
|
|
|
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
2014-01-07 09:12:44 -08:00
|
|
|
|
2014-01-10 11:02:33 -08:00
|
|
|
var SYNC_VERSION = '0.1';
|
|
|
|
var program = require('commander');
|
2014-01-16 11:11:20 -08:00
|
|
|
var HistoricSync = require('../lib/HistoricSync').class();
|
2014-01-10 11:02:33 -08:00
|
|
|
var async = require('async');
|
2014-01-06 18:50:29 -08:00
|
|
|
|
2014-01-10 14:14:13 -08:00
|
|
|
program
|
|
|
|
.version(SYNC_VERSION)
|
|
|
|
.option('-N --network [livenet]', 'Set bitcoin network [testnet]', 'testnet')
|
2014-01-17 05:44:14 -08:00
|
|
|
.option('-S --smart', 'genesis stored? uptoexisting = 1', 1)
|
2014-01-16 08:01:32 -08:00
|
|
|
.option('-D --destroy', 'Remove current DB (and start from there)', 0)
|
|
|
|
.option('-R --reverse', 'Sync backwards', 0)
|
2014-01-17 05:22:00 -08:00
|
|
|
.option('-U --uptoexisting', 'Sync only until an existing block is found', 0)
|
2014-01-30 18:16:43 -08:00
|
|
|
.option('-F --fromfiles', 'Sync using bitcoind .dat block files (faster)', 0)
|
2014-01-10 14:14:13 -08:00
|
|
|
.parse(process.argv);
|
2014-01-07 09:12:44 -08:00
|
|
|
|
2014-01-23 10:10:52 -08:00
|
|
|
var historicSync = new HistoricSync();
|
2014-01-06 18:50:29 -08:00
|
|
|
|
2014-01-17 11:36:34 -08:00
|
|
|
/* TODO: Sure?
|
2014-01-07 11:49:42 -08:00
|
|
|
if (program.remove) {
|
2014-01-17 11:36:34 -08:00
|
|
|
|
2014-01-06 18:50:29 -08:00
|
|
|
}
|
2014-01-17 11:36:34 -08:00
|
|
|
*/
|
2014-01-10 11:02:33 -08:00
|
|
|
async.series([
|
2014-01-16 11:11:20 -08:00
|
|
|
function(cb) {
|
|
|
|
historicSync.init(program, cb);
|
|
|
|
},
|
|
|
|
function(cb) {
|
2014-01-23 08:00:27 -08:00
|
|
|
|
2014-01-17 11:36:34 -08:00
|
|
|
if (program.smart) {
|
2014-01-30 18:16:43 -08:00
|
|
|
historicSync.smartImport({
|
|
|
|
destroy: program.destroy,
|
|
|
|
},cb);
|
2014-01-17 11:36:34 -08:00
|
|
|
}
|
|
|
|
else {
|
2014-01-21 14:13:21 -08:00
|
|
|
historicSync.importHistory({
|
2014-01-17 11:36:34 -08:00
|
|
|
destroy: program.destroy,
|
|
|
|
reverse: program.reverse,
|
2014-01-19 07:33:39 -08:00
|
|
|
upToExisting: program.uptoexisting,
|
2014-01-30 18:16:43 -08:00
|
|
|
fromFiles: program.fromfiles,
|
2014-01-17 11:36:34 -08:00
|
|
|
}, cb);
|
|
|
|
}
|
2014-01-16 11:11:20 -08:00
|
|
|
},
|
2014-01-17 11:36:34 -08:00
|
|
|
],
|
2014-01-18 13:28:24 -08:00
|
|
|
function(err) {
|
|
|
|
historicSync.close();
|
2014-01-17 11:36:34 -08:00
|
|
|
if (err) {
|
2014-01-23 08:00:27 -08:00
|
|
|
console.log('CRITICAL ERROR: ', historicSync.info());
|
2014-01-17 11:36:34 -08:00
|
|
|
}
|
|
|
|
else {
|
2014-01-21 14:13:21 -08:00
|
|
|
console.log('Finished.\n Status:\n', historicSync.info());
|
2014-01-17 11:36:34 -08:00
|
|
|
}
|
|
|
|
});
|
2014-01-06 19:19:12 -08:00
|
|
|
|