Added height into tx index.

This commit is contained in:
Chris Kleeschulte 2017-01-18 19:11:47 -05:00
parent 43dfeffd5e
commit f1277c8ad3
2 changed files with 17 additions and 8 deletions

View File

@ -529,17 +529,21 @@ AddressService.prototype.blockHandler = function(block, connectBlock, callback)
var address = input.script.toAddress(); 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); 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) { if(err) {
return next(err); return next(err);
} }
var tx = result.transaction;
var height = result.height;
var output = tx.outputs[input.outputIndex]; var output = tx.outputs[input.outputIndex];
var outputKey = encoding.encodeAddressIndexKey(address, true, 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, tx.__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 outputValue = encoding.encodeAdressIndexValue(output.satoshis, output._scriptBuffer);
var inputValue = encoding.encodeAddressIndexValue(output.satoshis, input._scriptBuffer); var inputValue = encoding.encodeAddressIndexValue(output.satoshis, input._scriptBuffer);
operations = operations.concat([{ operations = operations.concat([{
type: action, type: action,
key: inputKey, key: inputKey,

View File

@ -64,12 +64,17 @@ TransactionService.prototype._decodeTransactionKey = function(buffer) {
return buffer.slice(1).toString('hex'); return buffer.slice(1).toString('hex');
}; };
TransactionService.prototype._encodeTransactionValue = function(transaction) { TransactionService.prototype._encodeTransactionValue = function(transaction, height) {
return transaction.uncheckedSerialize(); var heightBuffer = new Buffer(4);
heightBuffer.writeUInt32BE(height);
return new Buffer.concat([heightBuffer, transaction.uncheckedSerialize()]);
}; };
TransactionService.prototype._decodeTransactionValue = function(buffer) { TransactionService.prototype._decodeTransactionValue = function(buffer) {
return new bitcore.Transaction(buffer); return {
height: Buffer.readUInt32BE(height),
transaction: new bitcore.Transaction(buffer)
};
}; };
module.exports = TransactionService; module.exports = TransactionService;