From bc9a95e0ae977df385b8c869c67334bc132506fc Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Wed, 9 Mar 2016 13:58:40 +0300 Subject: [PATCH] Use buffer-reverse instead [].reverse.call --- src/block.js | 9 +++++---- src/transaction.js | 3 ++- src/transaction_builder.js | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/block.js b/src/block.js index 4e10e84..75a7980 100644 --- a/src/block.js +++ b/src/block.js @@ -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 diff --git a/src/transaction.js b/src/transaction.js index 3a38c21..d4a4b90 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -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 () { diff --git a/src/transaction_builder.js b/src/transaction_builder.js index 0ca9b0c..c76b4a1 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -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) {