diff --git a/lib/block.js b/lib/block.js index ec0b994..7481c18 100644 --- a/lib/block.js +++ b/lib/block.js @@ -94,8 +94,12 @@ Block.prototype.toBufferWriter = function(bw) { return bw; }; +Block.prototype.hash = function() { + return Hash.sha256sha256(this.blockheader.toBuffer()); +}; + Block.prototype.id = function() { - return BufferReader(Hash.sha256sha256(this.blockheader.toBuffer())).reverse().read(); + return BufferReader(this.hash()).reverse().read(); }; module.exports = Block; diff --git a/test/block.js b/test/block.js index 5079cfa..2e2040e 100644 --- a/test/block.js +++ b/test/block.js @@ -127,6 +127,16 @@ describe('Block', function() { }); + describe('#hash', function() { + + it('should return the correct hash of the genesis block', function() { + var block = Block().fromBuffer(genesisbuf); + var blockhash = new Buffer(Array.apply([], new Buffer(genesisidhex, 'hex')).reverse()); + block.hash().toString('hex').should.equal(blockhash.toString('hex')); + }); + + }); + describe('#id', function() { it('should return the correct id of the genesis block', function() {