From 966b8988e1e74342eec47be2313332ba35915f3a Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 18 Feb 2014 15:10:58 -0300 Subject: [PATCH] fix reverse buffertools use --- Block.js | 4 ++-- ScriptInterpreter.js | 10 +++++----- Transaction.js | 4 ++-- util/util.js | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Block.js b/Block.js index c7c255c..c1ce8fb 100644 --- a/Block.js +++ b/Block.js @@ -94,14 +94,14 @@ function spec(b) { // TODO: Create a compare method in node-buffertools that uses the correct // endian so we don't have to reverse both buffers before comparing. - this.hash.reverse(); + buffertools.reverse(this.hash); if (buffertools.compare(this.hash, target) > 0) { throw new VerificationError('Difficulty target not met'); } // Return the hash to its normal order - this.hash.reverse(); + buffertools.reverse(this.hash); return true; }; diff --git a/ScriptInterpreter.js b/ScriptInterpreter.js index 83253e9..dbe4bb5 100644 --- a/ScriptInterpreter.js +++ b/ScriptInterpreter.js @@ -836,7 +836,7 @@ function spec(b) { var w = new Buffer(v.length); v.copy(w); - w.reverse(); + w = buffertools.reverse(w); if (w[0] & 0x80) { w[0] &= 0x7f; return bignum.fromBuffer(w).neg(); @@ -859,9 +859,9 @@ function spec(b) { c = new Buffer(b.length + 1); b.copy(c, 1); c[0] = 0; - return c.reverse(); + return buffertools.reverse(c); } else { - return b.reverse(); + return buffertools.reverse(b); } } else if (cmp == 0) { return new Buffer([]); @@ -871,10 +871,10 @@ function spec(b) { c = new Buffer(b.length + 1); b.copy(c, 1); c[0] = 0x80; - return c.reverse(); + return buffertools.reverse(c); } else { b[0] |= 0x80; - return b.reverse(); + return buffertools.reverse(b); } } }; diff --git a/Transaction.js b/Transaction.js index 9fc5052..546ede2 100644 --- a/Transaction.js +++ b/Transaction.js @@ -557,7 +557,7 @@ function spec(b) { var ins = this.ins.map(function (txin) { var txinObj = { prev_out: { - hash: new Buffer(txin.getOutpointHash()).reverse().toString('hex'), + hash: buffertools.reverse(new Buffer(txin.getOutpointHash())).toString('hex'), n: txin.getOutpointIndex() } }; @@ -607,7 +607,7 @@ function spec(b) { txin.q = 0xffffffff; var hash = new Buffer(inputobj.txid, 'hex'); - hash.reverse(); + hash = buffertools.reverse(hash); var vout = parseInt(inputobj.vout); var voutBuf = new Buffer(4); voutBuf.writeUInt32LE(vout, 0); diff --git a/util/util.js b/util/util.js index dec16ff..e33a676 100644 --- a/util/util.js +++ b/util/util.js @@ -32,7 +32,7 @@ var formatHash = exports.formatHash = function (hash) { // Make a copy, because reverse() and toHex() are destructive. var hashEnd = new Buffer(10); hash.copy(hashEnd, 0, 22, 32); - return hashEnd.reverse().toString('hex'); + return buffertools.reverse(hashEnd).toString('hex'); }; /** @@ -42,7 +42,7 @@ var formatHashFull = exports.formatHashFull = function (hash) { // Make a copy, because reverse() and toHex() are destructive. var copy = new Buffer(hash.length); hash.copy(copy); - var hex = copy.reverse().toHex(); + var hex = buffertools.reverse(copy).toHex(); return hex; };