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); 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 * Set a block as the current tip of the blockchain
* *
@ -250,11 +268,9 @@ BlockService.prototype._confirmBlock = function(block) {
}).then(function() { }).then(function() {
return self.database.batchAsync(ops) return self.database.batchAsync(ops);
}).then(function() { }).then(this.unlock.bind(this));
return self.unlock();
});
}; };
BlockService.prototype._setNextBlock = function(ops, prevBlockHash, block) { BlockService.prototype._setNextBlock = function(ops, prevBlockHash, block) {

View File

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