cleanup address handling in blockdb.

This commit is contained in:
Christopher Jeffrey 2016-03-06 12:02:16 -08:00
parent b5f8f7291a
commit cc1f423e3f

View File

@ -200,26 +200,20 @@ BlockDB.prototype.connectBlock = function connectBlock(block, callback, batch) {
tx.inputs.forEach(function(input) {
var type = input.getType();
var address = input.getAddress();
var uaddr;
if (input.isCoinbase())
return;
assert(input.output);
if (type === 'pubkey' || type === 'multisig')
address = null;
uaddr = address;
if (uaddr) {
if (!uniq[uaddr])
uniq[uaddr] = true;
else
uaddr = null;
if (address && !uniq[address]) {
uniq[address] = true;
batch.put('t/a/' + address + '/' + hash, DUMMY);
}
if (uaddr)
batch.put('t/a/' + uaddr + '/' + hash, DUMMY);
if (address) {
batch.del(
'u/a/' + address
@ -236,23 +230,15 @@ BlockDB.prototype.connectBlock = function connectBlock(block, callback, batch) {
tx.outputs.forEach(function(output, i) {
var type = output.getType();
var address = output.getAddress();
var uaddr;
if (type === 'pubkey' || type === 'multisig')
address = null;
uaddr = address;
if (uaddr) {
if (!uniq[uaddr])
uniq[uaddr] = true;
else
uaddr = null;
if (address && !uniq[address]) {
uniq[address] = true;
batch.put('t/a/' + address + '/' + hash, DUMMY);
}
if (uaddr)
batch.put('t/a/' + uaddr + '/' + hash, DUMMY);
if (address)
batch.put('u/a/' + address + '/' + hash + '/' + i, DUMMY);
@ -301,28 +287,21 @@ BlockDB.prototype.disconnectBlock = function disconnectBlock(hash, callback, bat
tx.inputs.forEach(function(input) {
var type = input.getType();
var address = input.getAddress();
var uaddr, coin;
var coin;
if (input.isCoinbase())
return;
assert(input.output);
if (type === 'pubkey' || type === 'multisig')
address = null;
uaddr = address;
if (uaddr) {
if (!uniq[uaddr])
uniq[uaddr] = true;
else
uaddr = null;
if (address && !uniq[address]) {
uniq[address] = true;
batch.del('t/a/' + address + '/' + hash);
}
assert(input.output);
if (uaddr)
batch.del('t/a/' + uaddr + '/' + hash);
if (address) {
batch.put('u/a/' + address
+ '/' + input.prevout.hash
@ -339,23 +318,15 @@ BlockDB.prototype.disconnectBlock = function disconnectBlock(hash, callback, bat
tx.outputs.forEach(function(output, i) {
var type = output.getType();
var address = output.getAddress();
var uaddr;
if (type === 'pubkey' || type === 'multisig')
address = null;
uaddr = address;
if (uaddr) {
if (!uniq[uaddr])
uniq[uaddr] = true;
else
uaddr = null;
if (address && !uniq[address]) {
uniq[address] = true;
batch.del('t/a/' + address + '/' + hash);
}
if (uaddr)
batch.del('t/a/' + uaddr + '/' + hash);
if (address)
batch.del('u/a/' + address + '/' + hash + '/' + i);