Use buffer-reverse instead [].reverse.call

This commit is contained in:
Kirill Fomichev 2016-03-09 13:58:40 +03:00
parent f999ff6382
commit bc9a95e0ae
3 changed files with 9 additions and 6 deletions

View file

@ -1,6 +1,7 @@
var bufferutils = require('./bufferutils')
var bcrypto = require('./crypto')
var compare = require('buffer-compare')
var bufferCompare = require('buffer-compare')
var bufferReverse = require('buffer-reverse')
var Transaction = require('./transaction')
@ -71,7 +72,7 @@ Block.prototype.getHash = function () {
}
Block.prototype.getId = function () {
return [].reverse.call(this.getHash()).toString('hex')
return bufferReverse(this.getHash()).toString('hex')
}
Block.prototype.getUTCDate = function () {
@ -133,10 +134,10 @@ Block.calculateTarget = function (bits) {
}
Block.prototype.checkProofOfWork = function () {
var hash = [].reverse.call(this.getHash())
var hash = bufferReverse(this.getHash())
var target = Block.calculateTarget(this.bits)
return compare(hash, target) <= 0
return bufferCompare(hash, target) <= 0
}
module.exports = Block

View file

@ -1,6 +1,7 @@
var bcrypto = require('./crypto')
var bscript = require('./script')
var bufferutils = require('./bufferutils')
var bufferReverse = require('buffer-reverse')
var opcodes = require('./opcodes')
var typeforce = require('typeforce')
var types = require('./types')
@ -247,7 +248,7 @@ Transaction.prototype.getHash = function () {
Transaction.prototype.getId = function () {
// 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 () {

View file

@ -2,6 +2,7 @@ var baddress = require('./address')
var bcrypto = require('./crypto')
var bscript = require('./script')
var bufferEquals = require('buffer-equals')
var bufferReverse = require('buffer-reverse')
var networks = require('./networks')
var ops = require('./opcodes')
var typeforce = require('typeforce')
@ -198,7 +199,7 @@ TransactionBuilder.prototype.addInput = function (txHash, vout, sequence, prevOu
// is it a hex string?
if (typeof txHash === 'string') {
// 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?
} else if (txHash instanceof Transaction) {