diff --git a/src/transaction.js b/src/transaction.js index 16fafda..137b175 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -282,6 +282,9 @@ Transaction.deserialize = function(buffer) { if (typeof buffer == "string") buffer = new Buffer(buffer, 'hex') else if (Array.isArray(buffer)) buffer = new Buffer(buffer) + // Copy because we mutate (reverse TxOutHashs) + buffer = new Buffer(buffer) + var offset = 0 function readSlice(n) { offset += n diff --git a/test/transaction.js b/test/transaction.js index ce831b2..a9e5ef7 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -38,6 +38,13 @@ describe('Transaction', function() { assert.equal(b2h(actual), expected) }) + it('does not mutate the input buffer', function() { + var buffer = new Buffer(serializedTx, 'hex') + Transaction.deserialize(buffer) + + assert.equal(buffer.toString('hex'), serializedTx) + }) + it('decodes version correctly', function(){ assert.equal(tx.version, 1) })