diff --git a/lib/services/address/index.js b/lib/services/address/index.js index 139bb96f..f0592609 100644 --- a/lib/services/address/index.js +++ b/lib/services/address/index.js @@ -529,17 +529,21 @@ AddressService.prototype.blockHandler = function(block, connectBlock, callback) var address = input.script.toAddress(); - // To be able to query inputs by address and spent height var inputKey = encoding.encodeAddressIndexKey(address, true, height, txid, inputIndex, true); - self.node.services.transaction.getTransaction(input.prevTxId, function(err, tx) { + + self.node.services.transaction.getTransaction(input.prevTxId, function(err, result) { if(err) { return next(err); } + + var tx = result.transaction; + var height = result.height; var output = tx.outputs[input.outputIndex]; - var outputKey = encoding.encodeAddressIndexKey(address, true, tx.__height, tx.id, input.outputIndex, false); - var outputKeyToDelete = encoding.encodeAddressIndexKey(address, false, tx.__height, tx.id, input.outputIndex, false); + var outputKey = encoding.encodeAddressIndexKey(address, true, height, tx.id, input.outputIndex, false); + var outputKeyToDelete = encoding.encodeAddressIndexKey(address, false, height, tx.id, input.outputIndex, false); var outputValue = encoding.encodeAdressIndexValue(output.satoshis, output._scriptBuffer); var inputValue = encoding.encodeAddressIndexValue(output.satoshis, input._scriptBuffer); + operations = operations.concat([{ type: action, key: inputKey, diff --git a/lib/services/transaction.js b/lib/services/transaction.js index 2dc6ea44..dd17e053 100644 --- a/lib/services/transaction.js +++ b/lib/services/transaction.js @@ -64,12 +64,17 @@ TransactionService.prototype._decodeTransactionKey = function(buffer) { return buffer.slice(1).toString('hex'); }; -TransactionService.prototype._encodeTransactionValue = function(transaction) { - return transaction.uncheckedSerialize(); +TransactionService.prototype._encodeTransactionValue = function(transaction, height) { + var heightBuffer = new Buffer(4); + heightBuffer.writeUInt32BE(height); + return new Buffer.concat([heightBuffer, transaction.uncheckedSerialize()]); }; TransactionService.prototype._decodeTransactionValue = function(buffer) { - return new bitcore.Transaction(buffer); + return { + height: Buffer.readUInt32BE(height), + transaction: new bitcore.Transaction(buffer) + }; }; -module.exports = TransactionService; \ No newline at end of file +module.exports = TransactionService;