upgrade script
This commit is contained in:
parent
c595d49a4e
commit
ef7ec2328d
|
@ -380,9 +380,45 @@ BlockDb.prototype.fillConfirmations = function(txouts, cb) {
|
|||
});
|
||||
};
|
||||
|
||||
// This is for DB upgrades mainly
|
||||
/* this is only for migration scripts */
|
||||
BlockDb.prototype._runScript = function(script, cb) {
|
||||
db.batch(script,cb);
|
||||
};
|
||||
|
||||
BlockDb.prototype.migrateV02 = function(cb) {
|
||||
var k = 'txb-';
|
||||
this.txDb._db.createReadStream({
|
||||
start: k,
|
||||
end: k + '~'
|
||||
}).pipe(db.createWriteStream()).on('close', cb);
|
||||
};
|
||||
|
||||
BlockDb.prototype.migrateV02cleanup = function(cb) {
|
||||
|
||||
var self = this;
|
||||
console.log('## deleting txb- from txs db'); //todo
|
||||
|
||||
var k = 'txb-';
|
||||
var d = this.txDb._db;
|
||||
d.createReadStream({
|
||||
start: k,
|
||||
end: k + '~'
|
||||
})
|
||||
.pipe(d.createWriteStream({type:'del'}))
|
||||
.on('close', function(err){
|
||||
if (err) return cb(err);
|
||||
console.log('## deleting tx- from txs db'); //todo
|
||||
|
||||
var k = 'tx-';
|
||||
var d = self.txDb._db;
|
||||
d.createReadStream({
|
||||
start: k,
|
||||
end: k + '~'
|
||||
})
|
||||
.pipe(d.createWriteStream({type:'del'}))
|
||||
.on('close',cb);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
module.exports = require('soop')(BlockDb);
|
||||
|
|
|
@ -59,6 +59,8 @@ var TransactionDb = function() {
|
|||
this.network = config.network === 'testnet' ? networks.testnet : networks.livenet;
|
||||
this.poolMatch = new PoolMatch();
|
||||
this.safeConfirmations = config.safeConfirmations || DEFAULT_SAFE_CONFIRMATIONS;
|
||||
|
||||
this._db = db; // this is only exposed for migration script
|
||||
};
|
||||
|
||||
TransactionDb.prototype.close = function(cb) {
|
||||
|
|
|
@ -5,17 +5,6 @@
|
|||
var HistoricSync = require('../lib/HistoricSync');
|
||||
var async = require('async');
|
||||
|
||||
//
|
||||
// 1)
|
||||
// var MAIN_PREFIX = 'bma-'; // bma-<hash> => <height> (0 is unconnected)
|
||||
// var TIP = 'bti-'; // bti = <hash>:<height> last block on the chain
|
||||
//
|
||||
// var IN_BLK_PREFIX = 'btx-'; //btx-<txid> = <block>
|
||||
// v
|
||||
// 2) DELETE txs/tx-
|
||||
// 3) DELETE txs/txb
|
||||
//
|
||||
|
||||
|
||||
var historicSync = new HistoricSync({ shouldBroadcastSync: false });
|
||||
var txDb=historicSync.sync.txDb;
|
||||
|
@ -45,9 +34,9 @@ async.series([
|
|||
if (err) return w_cb(err);
|
||||
tipHash = hash;
|
||||
hash = val;
|
||||
height++;
|
||||
if (hash) height++;
|
||||
if (!(height%1000) || !hash) {
|
||||
console.log('\t%d blocks processed (set height 1/2)', height);
|
||||
console.log('*update 1/2\t%d blocks processed', height);
|
||||
bDb._runScript(script, function(err) {
|
||||
script=[];
|
||||
return w_cb(err);
|
||||
|
@ -58,7 +47,14 @@ async.series([
|
|||
}, c);
|
||||
},
|
||||
function(c){
|
||||
bDb.setTip(tipHash, height-1, c);
|
||||
console.log('Migrating txs... (this will take some minutes...)'); //TODO
|
||||
bDb.migrateV02(c);
|
||||
},
|
||||
function(c){
|
||||
bDb.setTip(tipHash, height, c);
|
||||
},
|
||||
function(c){
|
||||
bDb.migrateV02cleanup(c);
|
||||
},
|
||||
],function(err){
|
||||
if (err)
|
||||
|
|
Loading…
Reference in New Issue