From 2e3d58c07a7f03d45bebc2b77132e218a879c548 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Mon, 12 Oct 2015 18:31:45 -0400 Subject: [PATCH] Fix bug where the outputIndex would be removed. The address history `combineTransactionInfo` method removes the outputIndex when creating the outputIndexes property. When these are from the mempool the original reference is also modified. We can easily solve this by returning new instances in `getOutputs` and `getInputs` instead of a reference to the actual mempool instance. This will also have the additional benefit that height and other properties that will be the same for every mempool entry will not be stored in memory longer than what is necessary to fulfill a request. --- lib/services/address/index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/services/address/index.js b/lib/services/address/index.js index 873e272c..9b15e569 100644 --- a/lib/services/address/index.js +++ b/lib/services/address/index.js @@ -870,8 +870,7 @@ AddressService.prototype.getInputs = function(addressStr, options, callback) { var mempoolInputs = self.mempoolInputIndex[addressStr]; if (mempoolInputs) { for(var i = 0; i < mempoolInputs.length; i++) { - // TODO copy - var newInput = mempoolInputs[i]; + var newInput = _.clone(mempoolInputs[i]); newInput.address = addressStr; newInput.height = -1; newInput.confirmations = 0; @@ -984,8 +983,7 @@ AddressService.prototype.getOutputs = function(addressStr, options, callback) { var mempoolOutputs = self.mempoolOutputIndex[addressStr]; if (mempoolOutputs) { for(var i = 0; i < mempoolOutputs.length; i++) { - // TODO copy - var newOutput = mempoolOutputs[i]; + var newOutput = _.clone(mempoolOutputs[i]); newOutput.address = addressStr; newOutput.height = -1; newOutput.confirmations = 0;