From cc1f423e3f742bbd97acbc6c5d55d65267a57e29 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 6 Mar 2016 12:02:16 -0800 Subject: [PATCH] cleanup address handling in blockdb. --- lib/bcoin/blockdb.js | 63 ++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 46 deletions(-) diff --git a/lib/bcoin/blockdb.js b/lib/bcoin/blockdb.js index 26f68406..82ce3ec6 100644 --- a/lib/bcoin/blockdb.js +++ b/lib/bcoin/blockdb.js @@ -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);