chaindb: strict arg checking.
This commit is contained in:
parent
0208f9383c
commit
096957ccb9
@ -437,8 +437,7 @@ ChainDB.prototype.addCache = function addCache(entry) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ChainDB.prototype.hasCache = function hasCache(hash) {
|
ChainDB.prototype.hasCache = function hasCache(hash) {
|
||||||
if (hash == null || hash < 0)
|
checkHash(hash);
|
||||||
return false;
|
|
||||||
|
|
||||||
if (typeof hash === 'number')
|
if (typeof hash === 'number')
|
||||||
return this.cacheHeight.has(hash);
|
return this.cacheHeight.has(hash);
|
||||||
@ -454,8 +453,7 @@ ChainDB.prototype.hasCache = function hasCache(hash) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ChainDB.prototype.getCache = function getCache(hash) {
|
ChainDB.prototype.getCache = function getCache(hash) {
|
||||||
if (hash == null || hash < 0)
|
checkHash(hash);
|
||||||
return;
|
|
||||||
|
|
||||||
if (typeof hash === 'number')
|
if (typeof hash === 'number')
|
||||||
return this.cacheHeight.get(hash);
|
return this.cacheHeight.get(hash);
|
||||||
@ -472,10 +470,7 @@ ChainDB.prototype.getCache = function getCache(hash) {
|
|||||||
ChainDB.prototype.getHeight = function getHeight(hash, callback) {
|
ChainDB.prototype.getHeight = function getHeight(hash, callback) {
|
||||||
var entry;
|
var entry;
|
||||||
|
|
||||||
if (hash == null || hash < 0) {
|
checkHash(hash);
|
||||||
callback = utils.asyncify(callback);
|
|
||||||
return callback(null, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof hash === 'number') {
|
if (typeof hash === 'number') {
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.asyncify(callback);
|
||||||
@ -518,10 +513,7 @@ ChainDB.prototype.getHeight = function getHeight(hash, callback) {
|
|||||||
ChainDB.prototype.getHash = function getHash(height, callback) {
|
ChainDB.prototype.getHash = function getHash(height, callback) {
|
||||||
var entry;
|
var entry;
|
||||||
|
|
||||||
if (height == null || height < 0) {
|
checkHash(height);
|
||||||
callback = utils.asyncify(callback);
|
|
||||||
return callback(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof height === 'string') {
|
if (typeof height === 'string') {
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.asyncify(callback);
|
||||||
@ -567,8 +559,7 @@ ChainDB.prototype.getChainHeight = function getChainHeight(callback) {
|
|||||||
ChainDB.prototype.getBoth = function getBoth(block, callback) {
|
ChainDB.prototype.getBoth = function getBoth(block, callback) {
|
||||||
var hash, height;
|
var hash, height;
|
||||||
|
|
||||||
if (block == null || block < 0)
|
checkHash(block);
|
||||||
return utils.asyncify(callback)(null, null, -1);
|
|
||||||
|
|
||||||
if (typeof block === 'string')
|
if (typeof block === 'string')
|
||||||
hash = block;
|
hash = block;
|
||||||
@ -608,8 +599,7 @@ ChainDB.prototype.getEntry = function getEntry(hash, callback) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
var entry;
|
var entry;
|
||||||
|
|
||||||
if (hash == null || hash < 0)
|
checkHash(hash);
|
||||||
return utils.nextTick(callback);
|
|
||||||
|
|
||||||
this.getHash(hash, function(err, hash) {
|
this.getHash(hash, function(err, hash) {
|
||||||
if (err)
|
if (err)
|
||||||
@ -941,8 +931,7 @@ ChainDB.prototype.reset = function reset(block, callback) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ChainDB.prototype.has = function has(height, callback) {
|
ChainDB.prototype.has = function has(height, callback) {
|
||||||
if (height == null || height < 0)
|
checkHash(height);
|
||||||
return utils.asyncify(callback)(null, false);
|
|
||||||
|
|
||||||
this.getBoth(height, function(err, hash, height) {
|
this.getBoth(height, function(err, hash, height) {
|
||||||
if (err)
|
if (err)
|
||||||
@ -1880,6 +1869,11 @@ function getSize(value) {
|
|||||||
return 80 + value.length;
|
return 80 + value.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkHash(hash) {
|
||||||
|
assert(typeof hash === 'string' || typeof hash === 'number',
|
||||||
|
'Must pass in height or hash.');
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Expose
|
* Expose
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user