block: adds getUTCDate function
This commit is contained in:
parent
2214ccfdd8
commit
9897fa2876
2 changed files with 27 additions and 4 deletions
15
src/block.js
15
src/block.js
|
@ -132,12 +132,19 @@ Block.prototype.toHex = function(headersOnly) {
|
||||||
return this.toBuffer(headersOnly).toString('hex')
|
return this.toBuffer(headersOnly).toString('hex')
|
||||||
}
|
}
|
||||||
|
|
||||||
Block.prototype.getId = function() {
|
|
||||||
return bufferutils.reverse(this.getHash()).toString('hex')
|
|
||||||
}
|
|
||||||
|
|
||||||
Block.prototype.getHash = function() {
|
Block.prototype.getHash = function() {
|
||||||
return crypto.hash256(this.toBuffer(true))
|
return crypto.hash256(this.toBuffer(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Block.prototype.getId = function() {
|
||||||
|
return bufferutils.reverse(this.getHash()).toString('hex')
|
||||||
|
}
|
||||||
|
|
||||||
|
Block.prototype.getUTCDate = function() {
|
||||||
|
var date = new Date(0) // epoch
|
||||||
|
date.setUTCSeconds(this.timestamp)
|
||||||
|
|
||||||
|
return date
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Block
|
module.exports = Block
|
||||||
|
|
|
@ -69,4 +69,20 @@ describe('Block', function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('getUTCDate', function() {
|
||||||
|
fixtures.valid.forEach(function(f) {
|
||||||
|
var block
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
block = Block.fromHex(f.hex)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns UTC date of ' + f.id, function() {
|
||||||
|
var utcDate = block.getUTCDate().getTime()
|
||||||
|
|
||||||
|
assert.equal(utcDate, f.timestamp * 1e3)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue