2014-05-26 14:49:03 -07:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var HistoricSync = require('../lib/HistoricSync');
|
|
|
|
var async = require('async');
|
|
|
|
|
|
|
|
|
|
|
|
var historicSync = new HistoricSync({ shouldBroadcastSync: false });
|
|
|
|
var txDb=historicSync.sync.txDb;
|
|
|
|
var bDb=historicSync.sync.bDb;
|
|
|
|
|
|
|
|
var height = 0;
|
|
|
|
var hash = historicSync.genesis;
|
|
|
|
var tipHash;
|
|
|
|
|
|
|
|
async.series([
|
|
|
|
function(c){
|
|
|
|
txDb.checkVersion02(function(isV2){
|
|
|
|
var err;
|
|
|
|
if(isV2) err='Already in v0.2!';
|
|
|
|
return c(err);
|
|
|
|
});
|
|
|
|
},
|
2014-05-28 09:17:08 -07:00
|
|
|
function(c){
|
2014-05-29 06:47:10 -07:00
|
|
|
console.log('[1/3] Migrating txs ... (this will take some minutes...)'); //TODO
|
2014-05-28 09:17:08 -07:00
|
|
|
txDb.migrateV02(c);
|
|
|
|
},
|
2014-05-26 14:49:03 -07:00
|
|
|
function(c){
|
|
|
|
var script=[];
|
|
|
|
async.whilst(
|
|
|
|
function() {
|
|
|
|
return hash;
|
|
|
|
},
|
|
|
|
function (w_cb) {
|
|
|
|
script=script.concat(bDb._setHeightScript(hash,height));
|
|
|
|
bDb.getNext(hash,function(err,val){
|
|
|
|
if (err) return w_cb(err);
|
|
|
|
tipHash = hash;
|
|
|
|
hash = val;
|
2014-05-27 12:14:44 -07:00
|
|
|
if (hash) height++;
|
2014-05-26 14:49:03 -07:00
|
|
|
if (!(height%1000) || !hash) {
|
2014-05-29 06:47:10 -07:00
|
|
|
console.log('[2/3] migrating blocks \t%d blocks processed', height);
|
2014-05-26 14:49:03 -07:00
|
|
|
bDb._runScript(script, function(err) {
|
|
|
|
script=[];
|
|
|
|
return w_cb(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else return w_cb();
|
|
|
|
});
|
|
|
|
}, c);
|
|
|
|
},
|
|
|
|
function(c){
|
2014-05-29 06:47:10 -07:00
|
|
|
console.log('[3/3] Migrating txs... (this will take some minutes...)'); //TODO
|
2014-05-27 12:14:44 -07:00
|
|
|
bDb.migrateV02(c);
|
|
|
|
},
|
|
|
|
function(c){
|
|
|
|
bDb.setTip(tipHash, height, c);
|
|
|
|
},
|
|
|
|
function(c){
|
|
|
|
bDb.migrateV02cleanup(c);
|
2014-05-26 14:49:03 -07:00
|
|
|
},
|
|
|
|
],function(err){
|
|
|
|
if (err)
|
|
|
|
console.log('## '+err);
|
|
|
|
else
|
|
|
|
console.log('Finished OK.');
|
|
|
|
});
|