sync first attempt

This commit is contained in:
Manuel Araoz 2015-03-19 13:18:31 -03:00
parent fc8f53372a
commit f2fccdd14f
2 changed files with 23 additions and 6 deletions

View File

@ -206,9 +206,27 @@ BlockService.prototype.getLatest = function() {
return self.getBlock(blockHash);
}).catch(blockNotFound);
}).catch(function(err) {
if (err instanceof LevelUp.errors.NotFoundError) {
return null;
}
throw err;
});
};
/**
* Save a new block
*
* @param {bitcore.Block} block
* @return {Promise<Block>} a promise of the same block, for chaining
*/
BlockService.prototype.save = function(block) {
// TODO: unconfirm previous tip, confirm new tip.
return this._confirmBlock(block);
};
/**
* Set a block as the current tip of the blockchain
*
@ -250,11 +268,9 @@ BlockService.prototype._confirmBlock = function(block) {
}).then(function() {
return self.database.batchAsync(ops)
return self.database.batchAsync(ops);
}).then(function() {
return self.unlock();
});
}).then(this.unlock.bind(this));
};
BlockService.prototype._setNextBlock = function(ops, prevBlockHash, block) {

View File

@ -60,7 +60,8 @@
"glob": "*",
"js-yaml": "^3.2.7",
"level-lock": "^1.0.1",
"levelup": "~0.19.0",
"leveldown": "^1.0.0",
"levelup": "^0.19.0",
"moment": "~2.5.0",
"morgan": "^1.5.1",
"request": "^2.48.0",