bitcore-node-zcash/util/sync.js

50 lines
942 B
JavaScript
Raw Normal View History

#! /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-06 18:50:29 -08:00
require('buffertools').extend();
2014-01-10 11:02:33 -08:00
var SYNC_VERSION = '0.1';
var program = require('commander');
var Sync = require('../lib/Sync').class();
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-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-10 14:14:13 -08:00
.parse(process.argv);
2014-01-07 09:12:44 -08:00
2014-01-10 11:02:33 -08:00
var sync = new Sync({
networkName: program.network
2014-01-10 11:02:33 -08:00
});
2014-01-06 18:50:29 -08:00
2014-01-07 11:49:42 -08:00
if (program.remove) {
2014-01-06 18:50:29 -08:00
}
2014-01-10 11:02:33 -08:00
async.series([
function(cb) {
sync.init(program);
cb();
2014-01-10 11:02:33 -08:00
},
function(cb) {
2014-01-15 12:36:49 -08:00
sync.import_history(program, function(err, count) {
if (err) {
console.log('CRITICAL ERROR: ', err);
}
else {
2014-01-16 08:01:32 -08:00
console.log('Done! [%d blocks]', count, err);
}
cb();
});
2014-01-10 11:02:33 -08:00
},
function(cb) {
sync.close();
cb();
2014-01-10 11:02:33 -08:00
}]);
2014-01-06 19:19:12 -08:00