add .hash() function for a block
This is the plain old hash, which is a double sha256. The id of a block is the reverse of this.
This commit is contained in:
parent
aff3992ffb
commit
cc3196085f
@ -94,8 +94,12 @@ Block.prototype.toBufferWriter = function(bw) {
|
|||||||
return bw;
|
return bw;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Block.prototype.hash = function() {
|
||||||
|
return Hash.sha256sha256(this.blockheader.toBuffer());
|
||||||
|
};
|
||||||
|
|
||||||
Block.prototype.id = function() {
|
Block.prototype.id = function() {
|
||||||
return BufferReader(Hash.sha256sha256(this.blockheader.toBuffer())).reverse().read();
|
return BufferReader(this.hash()).reverse().read();
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Block;
|
module.exports = Block;
|
||||||
|
|||||||
@ -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() {
|
describe('#id', function() {
|
||||||
|
|
||||||
it('should return the correct id of the genesis block', function() {
|
it('should return the correct id of the genesis block', function() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user