Use buffer-reverse instead [].reverse.call
This commit is contained in:
parent
f999ff6382
commit
bc9a95e0ae
3 changed files with 9 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
||||||
var bufferutils = require('./bufferutils')
|
var bufferutils = require('./bufferutils')
|
||||||
var bcrypto = require('./crypto')
|
var bcrypto = require('./crypto')
|
||||||
var compare = require('buffer-compare')
|
var bufferCompare = require('buffer-compare')
|
||||||
|
var bufferReverse = require('buffer-reverse')
|
||||||
|
|
||||||
var Transaction = require('./transaction')
|
var Transaction = require('./transaction')
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ Block.prototype.getHash = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
Block.prototype.getId = function () {
|
Block.prototype.getId = function () {
|
||||||
return [].reverse.call(this.getHash()).toString('hex')
|
return bufferReverse(this.getHash()).toString('hex')
|
||||||
}
|
}
|
||||||
|
|
||||||
Block.prototype.getUTCDate = function () {
|
Block.prototype.getUTCDate = function () {
|
||||||
|
@ -133,10 +134,10 @@ Block.calculateTarget = function (bits) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Block.prototype.checkProofOfWork = function () {
|
Block.prototype.checkProofOfWork = function () {
|
||||||
var hash = [].reverse.call(this.getHash())
|
var hash = bufferReverse(this.getHash())
|
||||||
var target = Block.calculateTarget(this.bits)
|
var target = Block.calculateTarget(this.bits)
|
||||||
|
|
||||||
return compare(hash, target) <= 0
|
return bufferCompare(hash, target) <= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Block
|
module.exports = Block
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
var bcrypto = require('./crypto')
|
var bcrypto = require('./crypto')
|
||||||
var bscript = require('./script')
|
var bscript = require('./script')
|
||||||
var bufferutils = require('./bufferutils')
|
var bufferutils = require('./bufferutils')
|
||||||
|
var bufferReverse = require('buffer-reverse')
|
||||||
var opcodes = require('./opcodes')
|
var opcodes = require('./opcodes')
|
||||||
var typeforce = require('typeforce')
|
var typeforce = require('typeforce')
|
||||||
var types = require('./types')
|
var types = require('./types')
|
||||||
|
@ -247,7 +248,7 @@ Transaction.prototype.getHash = function () {
|
||||||
|
|
||||||
Transaction.prototype.getId = function () {
|
Transaction.prototype.getId = function () {
|
||||||
// transaction hash's are displayed in reverse order
|
// transaction hash's are displayed in reverse order
|
||||||
return [].reverse.call(this.getHash()).toString('hex')
|
return bufferReverse(this.getHash()).toString('hex')
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.toBuffer = function () {
|
Transaction.prototype.toBuffer = function () {
|
||||||
|
|
|
@ -2,6 +2,7 @@ var baddress = require('./address')
|
||||||
var bcrypto = require('./crypto')
|
var bcrypto = require('./crypto')
|
||||||
var bscript = require('./script')
|
var bscript = require('./script')
|
||||||
var bufferEquals = require('buffer-equals')
|
var bufferEquals = require('buffer-equals')
|
||||||
|
var bufferReverse = require('buffer-reverse')
|
||||||
var networks = require('./networks')
|
var networks = require('./networks')
|
||||||
var ops = require('./opcodes')
|
var ops = require('./opcodes')
|
||||||
var typeforce = require('typeforce')
|
var typeforce = require('typeforce')
|
||||||
|
@ -198,7 +199,7 @@ TransactionBuilder.prototype.addInput = function (txHash, vout, sequence, prevOu
|
||||||
// is it a hex string?
|
// is it a hex string?
|
||||||
if (typeof txHash === 'string') {
|
if (typeof txHash === 'string') {
|
||||||
// transaction hashs's are displayed in reverse order, un-reverse it
|
// transaction hashs's are displayed in reverse order, un-reverse it
|
||||||
txHash = [].reverse.call(new Buffer(txHash, 'hex'))
|
txHash = bufferReverse(new Buffer(txHash, 'hex'))
|
||||||
|
|
||||||
// is it a Transaction object?
|
// is it a Transaction object?
|
||||||
} else if (txHash instanceof Transaction) {
|
} else if (txHash instanceof Transaction) {
|
||||||
|
|
Loading…
Reference in a new issue