This commit is contained in:
Chris Kleeschulte 2017-07-18 13:29:16 -04:00
parent 8365f358e7
commit a8eb0f8979
3 changed files with 51 additions and 44 deletions

View File

@ -421,15 +421,46 @@ AddressService.prototype._onReorg = function(oldBlockList, newBlockList, commonA
value: tipOps.value
}];
// remove all the old blocks that we reorg from
oldBlockList.forEach(function(block) {
removalOps.push([
{
type: 'del',
key: this.encoding.encodeTransactionKey(),
},
]);
});
// for every tx, remove the address index key for every input and output
for(var i = 0; i < oldBlockList.length; i++) {
var block = oldBlockList[i];
//txs
for(var j = 0; j < block.transactions.length; j++) {
var tx = block.transactions[j];
//inputs
var address;
for(var k = 0; k < tx.inputs.length; k++) {
var input = tx.inputs[k];
address = utils.getAddressString({ tx: tx, item: input, network: this._network });
if (!address) {
continue;
}
removalOps.push({
type: 'del',
key: this.encoding.encodeTransactionKey(address, block.height, tx.id, k, 1)
});
}
//outputs
for(k = 0; k < tx.outputs.length; k++) {
var output = tx.outputs[k];
address = utils.getAddressString({ tx: tx, item: output, network: this._network });
if (!address) {
continue;
}
removalOps.push({
type: 'del',
key: this.encoding.encodeTransactionKey(address, block.height, tx.id, k, 0)
});
}
}
}
this._db.batch(removalOps);

View File

@ -184,19 +184,16 @@ TransactionService.prototype._onReorg = function(oldBlockList, newBlockList, com
value: tipOps.value
}];
// remove all the old blocks that we reorg from
oldBlockList.forEach(function(block) {
removalOps.concat([
{
for(var i = 0; i < oldBlockList.length; i++) {
var block = oldBlockList[i];
for(var j = 0; j < block.transactions.length; j++) {
var tx = block.transactions[j];
removalOps.push({
type: 'del',
key: this.encoding.encodeAddressIndexKey(block.hash),
},
{
type: 'del',
key: this.encoding.encodeBlockTimestampKey(block.hash),
}
]);
});
key: this._encoding.encodeTransactionKey(tx.id)
});
}
}
this._db.batch(removalOps);

View File

@ -65,7 +65,8 @@ utils.getAddressString = function(opts) {
return;
}
if (opts.tx && opts.tx.isCoinbase()) {
// is coinbase and is input, no address
if (opts.tx && opts.tx.isCoinbase() && opts.item.prevTxId) {
return;
}
@ -153,28 +154,6 @@ utils.toIntIfNumberLike = function(a) {
return a;
};
utils.getAddressString = function(script, output) {
var address = script.toAddress(this.node.network.name);
if(address) {
return address.toString();
}
try {
var pubkey = script.getPublicKey();
if(pubkey) {
return pubkey.toString('hex');
}
} catch(e) {
}
//TODO add back in P2PK, but for this we need to look up the utxo for this script
if(output && output.script && output.script.isPublicKeyOut()) {
return output.script.getPublicKey().toString('hex');
}
return null;
};
utils.getBlockInfoString = function(tip, best) {
var diff = best - tip;