block: add Block.prototype.verifyPow
This commit is contained in:
parent
15227d39bf
commit
26ccb43047
2 changed files with 25 additions and 0 deletions
src
11
src/block.js
11
src/block.js
|
@ -1,3 +1,4 @@
|
|||
var BigInteger = require('bigi')
|
||||
var bufferutils = require('./bufferutils')
|
||||
var bcrypto = require('./crypto')
|
||||
|
||||
|
@ -115,4 +116,14 @@ Block.prototype.toHex = function (headersOnly) {
|
|||
return this.toBuffer(headersOnly).toString('hex')
|
||||
}
|
||||
|
||||
Block.prototype.verifyPow = function () {
|
||||
var hash = BigInteger.fromBuffer([].reverse.call(this.getHash()))
|
||||
var mov = ((this.bits >>> 24) - 3) << 3
|
||||
var target = new BigInteger()
|
||||
target.fromInt(this.bits & 0x000ffffff)
|
||||
target = target.shiftLeft(mov)
|
||||
|
||||
return hash.compareTo(target) <= 0
|
||||
}
|
||||
|
||||
module.exports = Block
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue