diff --git a/lib/services/address/encoding.js b/lib/services/address/encoding.js index 81421a18..ad4b55eb 100644 --- a/lib/services/address/encoding.js +++ b/lib/services/address/encoding.js @@ -19,6 +19,15 @@ exports.encodeSpentIndexSyncKey = function(txidBuffer, outputIndex) { return key.toString('binary'); }; +exports.encodeMempoolAddressIndexKey = function(hashBuffer, hashTypeBuffer) { + var key = Buffer.concat([ + hashBuffer, + hashTypeBuffer, + ]); + return key; +}; + + exports.encodeOutputKey = function(hashBuffer, hashTypeBuffer, height, txidBuffer, outputIndex) { var heightBuffer = new Buffer(4); heightBuffer.writeUInt32BE(height); diff --git a/lib/services/address/index.js b/lib/services/address/index.js index da903766..b5a98e18 100644 --- a/lib/services/address/index.js +++ b/lib/services/address/index.js @@ -307,12 +307,12 @@ AddressService.prototype.updateMempoolIndex = function(tx, add, callback) { continue; } - var hashBufferHex = addressInfo.hashBuffer.toString('hex'); + var addressIndexKey = encoding.encodeMempoolAddressIndexKey(addressInfo.hashBuffer, addressInfo.hashTypeBuffer); if(add) { - this.mempoolAddressIndex[hashBufferHex] = true; + this.mempoolAddressIndex[addressIndexKey] = true; } else { - delete this.mempoolAddressIndex[hashBufferHex]; + delete this.mempoolAddressIndex[addressIndexKey]; } // Update output index @@ -407,11 +407,12 @@ AddressService.prototype.updateMempoolIndex = function(tx, add, callback) { value: inputValue }); - var inputHashBufferHex = inputHashBuffer.toString('hex'); + var addressIndexKey = encoding.encodeMempoolAddressIndexKey(inputHashBuffer, inputHashType); + if(add) { - this.mempoolAddressIndex[inputHashBufferHex] = true; + this.mempoolAddressIndex[addressIndexKey] = true; } else { - delete this.mempoolAddressIndex[inputHashBufferHex]; + delete this.mempoolAddressIndex[addressIndexKey]; } } @@ -1523,9 +1524,9 @@ AddressService.prototype._getAddressMempoolSummary = function(address, options, var addressStr = address.toString(); var hashBuffer = address.hashBuffer; var hashTypeBuffer = constants.HASH_TYPES_MAP[address.type]; - var hashBufferHex = hashBuffer.toString('hex'); + var addressIndexKey = encoding.encodeMempoolAddressIndexKey(hashBuffer, hashTypeBuffer); - if(!this.mempoolAddressIndex[hashBufferHex]) { + if(!this.mempoolAddressIndex[addressIndexKey]) { return callback(null, result); } diff --git a/test/services/address/history.unit.js b/test/services/address/history.unit.js index ab3ee5c8..4c6306dd 100644 --- a/test/services/address/history.unit.js +++ b/test/services/address/history.unit.js @@ -122,7 +122,7 @@ describe('Address Service History', function() { history.get(function() { history.node.services.address.getAddressSummary.callCount.should.equal(1); history.node.services.address.getAddressSummary.args[0][0].should.equal(address); - history.node.services.address.getAddressSummary.args[0][1].should.equal({ + history.node.services.address.getAddressSummary.args[0][1].should.deep.equal({ noBalance: true, }); history._paginateWithDetails.callCount.should.equal(1); @@ -157,6 +157,7 @@ describe('Address Service History', function() { history.node.services.address.getAddressSummary.args[0][0].should.equal(address); history.node.services.address.getAddressSummary.args[0][1].should.deep.equal({ fullTxList: true, + noBalance: true, }); history._paginateWithDetails.callCount.should.equal(1); history._paginateWithDetails.args[0][0].should.equal(txids); diff --git a/test/services/address/index.unit.js b/test/services/address/index.unit.js index 4d4061e1..62745395 100644 --- a/test/services/address/index.unit.js +++ b/test/services/address/index.unit.js @@ -2521,8 +2521,9 @@ describe('Address Service', function() { ); as.mempoolSpentIndex[spentIndexSyncKey] = true; - var hashBufferHex = address.hashBuffer.toString('hex'); - as.mempoolAddressIndex[hashBufferHex] = true; + var hashTypeBuffer = constants.HASH_TYPES_MAP[address.type]; + var addressIndex = encoding.encodeMempoolAddressIndexKey(address.hashBuffer, hashTypeBuffer); + as.mempoolAddressIndex[addressIndex] = true; as._getInputsMempool = sinon.stub().callsArgWith(3, null, mempoolInputs); as._getOutputsMempool = sinon.stub().callsArgWith(3, null, mempoolOutputs);