wip
This commit is contained in:
parent
7afaa59862
commit
5de265e094
@ -60,29 +60,26 @@ AddressService.prototype.getAPIMethods = function() {
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Called by the Bus to get the available events for this service.
|
|
||||||
*/
|
|
||||||
AddressService.prototype.getPublishEvents = function() {
|
AddressService.prototype.getPublishEvents = function() {
|
||||||
return [];
|
return [];
|
||||||
};
|
};
|
||||||
|
|
||||||
AddressService.prototype._getAddress = function(opts, input) {
|
AddressService.prototype._getAddress = function(opts, item) {
|
||||||
|
|
||||||
if(opts.tx.isCoinbase()) {
|
if(opts.tx.isCoinbase()) {
|
||||||
log.debug('Coinbase Tx, no input available.');
|
log.debug('Coinbase Tx, no input/output available.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!input.script) {
|
if(!item.script) {
|
||||||
log.debug('Invalid script');
|
log.debug('Invalid script');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var address = this.getAddressString(input.script);
|
var address = this.getAddressString(item.script);
|
||||||
|
|
||||||
if(!address) {
|
if(!address) {
|
||||||
log.debug('Address not available from input script.');
|
log.debug('Address not available from input/output script.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,54 +104,55 @@ AddressService.prototype._getActions = function(connect) {
|
|||||||
|
|
||||||
AddressService.prototype._processInput = function(opts, input, cb) {
|
AddressService.prototype._processInput = function(opts, input, cb) {
|
||||||
|
|
||||||
// there are no valid inputs on coinbase tx's for the purposes of address indexing
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var address = this._getAddress(input.script);
|
var address = this._getAddress(opts, input);
|
||||||
|
|
||||||
if (!address) {
|
if (!address) {
|
||||||
return cb([]);
|
return setImemdiate(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var action = self._getAddress(opts.connect);
|
||||||
|
|
||||||
|
var operations = [];
|
||||||
|
|
||||||
|
// address index
|
||||||
var addressKey = self._encoding.encodeAddressIndexKey(address, opts.block.height, opts.tx.id);
|
var addressKey = self._encoding.encodeAddressIndexKey(address, opts.block.height, opts.tx.id);
|
||||||
|
|
||||||
if (connect) {
|
operations.push({
|
||||||
operations.push({
|
type: action.action,
|
||||||
type: 'del',
|
key: addressKey
|
||||||
key: addressKey
|
});
|
||||||
});
|
|
||||||
operations.push({
|
|
||||||
type: 'del',
|
|
||||||
key: utxoKey
|
|
||||||
});
|
|
||||||
return operations;
|
|
||||||
}
|
|
||||||
|
|
||||||
var prevTxId = input.prevTxId.toString('hex');
|
var prevTxId = input.prevTxId.toString('hex');
|
||||||
|
|
||||||
self._txService.getTransaction(prevTxId, {}, function(err, tx) {
|
self._txService.getTransaction(prevTxId, {}, function(err, tx) {
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
log.debug('Error saving tx inputs.');
|
||||||
|
return self._emit('error', err);
|
||||||
|
}
|
||||||
|
|
||||||
var utxo = tx.outputs[input.outputIndex];
|
var utxo = tx.outputs[input.outputIndex];
|
||||||
|
|
||||||
var inputValue = self._encoding.encodeUtxoIndexValue(tx.__height, utxo.satoshis, utxo._scriptBuffer);
|
// utxo index
|
||||||
|
|
||||||
|
|
||||||
|
// prev utxo
|
||||||
|
var oldUtxoKey = self._encoding.encodeUtxoIndexKey(address, tx.id, input.outputIndex);
|
||||||
|
|
||||||
|
// remove the old utxo
|
||||||
operations.push({
|
operations.push({
|
||||||
type: 'put',
|
type: action.reverseAction,
|
||||||
key: inputKey,
|
key: utxaKxey,
|
||||||
value: inputValue
|
value: inputValue
|
||||||
});
|
});
|
||||||
next();
|
|
||||||
|
return operations;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
return operations;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AddressService.prototype._processOutput = function(txid, output) {
|
AddressService.prototype._processOutput = function(txid, output) {
|
||||||
var script = output.script;
|
|
||||||
|
|
||||||
if(!script) {
|
|
||||||
log.debug('Invalid script');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var address = self.getAddressString(script);
|
var address = self.getAddressString(script);
|
||||||
|
|
||||||
@ -162,7 +160,6 @@ AddressService.prototype._processOutput = function(txid, output) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var addressKey = self._encoding.encodeAddressIndexKey(address, block.height, txid);
|
var addressKey = self._encoding.encodeAddressIndexKey(address, block.height, txid);
|
||||||
var utxoKey = self._encoding.encodeUtxoIndexKey(address, txid, outputIndex);
|
var utxoKey = self._encoding.encodeUtxoIndexKey(address, txid, outputIndex);
|
||||||
var utxoValue = self._encoding.encodeUtxoIndexValue(block.height, output.satoshis, output._scriptBuffer);
|
var utxoValue = self._encoding.encodeUtxoIndexValue(block.height, output.satoshis, output._scriptBuffer);
|
||||||
@ -171,6 +168,7 @@ AddressService.prototype._processOutput = function(txid, output) {
|
|||||||
type: action,
|
type: action,
|
||||||
key: addressKey
|
key: addressKey
|
||||||
});
|
});
|
||||||
|
|
||||||
operations.push({
|
operations.push({
|
||||||
type: action,
|
type: action,
|
||||||
key: utxoKey,
|
key: utxoKey,
|
||||||
@ -184,8 +182,7 @@ AddressService.prototype._processTransactions = function(opts, tx) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
var txid = tx.id;
|
var txid = tx.id;
|
||||||
|
|
||||||
|
var _opts = { opts.block, connect: connect ? true : false };
|
||||||
var _opts = { opts.block, connect: connect };
|
|
||||||
|
|
||||||
var outputOperations = tx.outputs.map(function(tx) {
|
var outputOperations = tx.outputs.map(function(tx) {
|
||||||
return self._processOutput(tx, opts);
|
return self._processOutput(tx, opts);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user