do not store unspendable coins.
This commit is contained in:
parent
2faf8513c4
commit
079d82e80c
@ -844,6 +844,10 @@ ChainDB.prototype.connectBlock = function connectBlock(block, batch, callback) {
|
|||||||
for (j = 0; j < tx.outputs.length; j++) {
|
for (j = 0; j < tx.outputs.length; j++) {
|
||||||
output = tx.outputs[j];
|
output = tx.outputs[j];
|
||||||
key = hash + '/' + j;
|
key = hash + '/' + j;
|
||||||
|
|
||||||
|
if (output.script.isUnspendable())
|
||||||
|
continue;
|
||||||
|
|
||||||
coin = bcoin.coin(tx, j);
|
coin = bcoin.coin(tx, j);
|
||||||
|
|
||||||
if (self.options.indexAddress) {
|
if (self.options.indexAddress) {
|
||||||
@ -931,6 +935,9 @@ ChainDB.prototype.disconnectBlock = function disconnectBlock(block, batch, callb
|
|||||||
output = tx.outputs[j];
|
output = tx.outputs[j];
|
||||||
key = hash + '/' + j;
|
key = hash + '/' + j;
|
||||||
|
|
||||||
|
if (output.script.isUnspendable())
|
||||||
|
continue;
|
||||||
|
|
||||||
if (self.options.indexAddress) {
|
if (self.options.indexAddress) {
|
||||||
address = output.getAddress();
|
address = output.getAddress();
|
||||||
if (address)
|
if (address)
|
||||||
|
|||||||
@ -1374,10 +1374,11 @@ Mempool.prototype._addUnchecked = function addUnchecked(tx, callback, force) {
|
|||||||
batch.put('t/' + hash, tx.toExtended());
|
batch.put('t/' + hash, tx.toExtended());
|
||||||
batch.put('m/' + pad32(tx.ps) + '/' + hash, DUMMY);
|
batch.put('m/' + pad32(tx.ps) + '/' + hash, DUMMY);
|
||||||
|
|
||||||
addresses = tx.getAddresses();
|
if (this.options.indexAddress) {
|
||||||
|
addresses = tx.getAddresses();
|
||||||
for (i = 0; i < addresses.length; i++)
|
for (i = 0; i < addresses.length; i++)
|
||||||
batch.put('T/' + addresses[i] + '/' + hash, DUMMY);
|
batch.put('T/' + addresses[i] + '/' + hash, DUMMY);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < tx.inputs.length; i++) {
|
for (i = 0; i < tx.inputs.length; i++) {
|
||||||
input = tx.inputs[i];
|
input = tx.inputs[i];
|
||||||
@ -1388,25 +1389,32 @@ Mempool.prototype._addUnchecked = function addUnchecked(tx, callback, force) {
|
|||||||
|
|
||||||
assert(input.coin);
|
assert(input.coin);
|
||||||
|
|
||||||
address = input.getAddress();
|
|
||||||
|
|
||||||
batch.del('c/' + key);
|
batch.del('c/' + key);
|
||||||
batch.put('s/' + key, tx.hash());
|
batch.put('s/' + key, tx.hash());
|
||||||
|
|
||||||
if (address)
|
if (this.options.indexAddress) {
|
||||||
batch.del('C/' + address + '/' + key);
|
address = input.getAddress();
|
||||||
|
if (address)
|
||||||
|
batch.del('C/' + address + '/' + key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < tx.outputs.length; i++) {
|
for (i = 0; i < tx.outputs.length; i++) {
|
||||||
output = tx.outputs[i];
|
output = tx.outputs[i];
|
||||||
key = hash + '/' + i;
|
key = hash + '/' + i;
|
||||||
address = output.getAddress();
|
|
||||||
|
if (output.script.isUnspendable())
|
||||||
|
continue;
|
||||||
|
|
||||||
coin = bcoin.coin(tx, i).toRaw();
|
coin = bcoin.coin(tx, i).toRaw();
|
||||||
|
|
||||||
batch.put('c/' + key, coin);
|
batch.put('c/' + key, coin);
|
||||||
|
|
||||||
if (address)
|
if (this.options.indexAddress) {
|
||||||
batch.put('C/' + address + '/' + key, DUMMY);
|
address = output.getAddress();
|
||||||
|
if (address)
|
||||||
|
batch.put('C/' + address + '/' + key, DUMMY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return batch.write(callback);
|
return batch.write(callback);
|
||||||
@ -1445,10 +1453,11 @@ Mempool.prototype._removeUnchecked = function removeUnchecked(hash, callback, fo
|
|||||||
batch.del('t/' + hash);
|
batch.del('t/' + hash);
|
||||||
batch.del('m/' + pad32(tx.ps) + '/' + hash);
|
batch.del('m/' + pad32(tx.ps) + '/' + hash);
|
||||||
|
|
||||||
addresses = tx.getAddresses();
|
if (self.options.indexAddress) {
|
||||||
|
addresses = tx.getAddresses();
|
||||||
for (i = 0; i < addresses.length; i++)
|
for (i = 0; i < addresses.length; i++)
|
||||||
batch.del('T/' + addresses[i] + '/' + hash);
|
batch.del('T/' + addresses[i] + '/' + hash);
|
||||||
|
}
|
||||||
|
|
||||||
utils.forEachSerial(tx.inputs, function(input, next) {
|
utils.forEachSerial(tx.inputs, function(input, next) {
|
||||||
var key = input.prevout.hash + '/' + input.prevout.index;
|
var key = input.prevout.hash + '/' + input.prevout.index;
|
||||||
@ -1460,8 +1469,6 @@ Mempool.prototype._removeUnchecked = function removeUnchecked(hash, callback, fo
|
|||||||
if (!input.coin)
|
if (!input.coin)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
address = input.getAddress();
|
|
||||||
|
|
||||||
batch.del('s/' + key);
|
batch.del('s/' + key);
|
||||||
|
|
||||||
self.hasTX(input.prevout.hash, function(err, result) {
|
self.hasTX(input.prevout.hash, function(err, result) {
|
||||||
@ -1470,12 +1477,18 @@ Mempool.prototype._removeUnchecked = function removeUnchecked(hash, callback, fo
|
|||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
batch.put('c/' + key, input.coin.toRaw());
|
batch.put('c/' + key, input.coin.toRaw());
|
||||||
if (address)
|
if (self.options.indexAddress) {
|
||||||
batch.put('C/' + address + '/' + key, DUMMY);
|
address = input.getAddress();
|
||||||
|
if (address)
|
||||||
|
batch.put('C/' + address + '/' + key, DUMMY);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
batch.del('c/' + key);
|
batch.del('c/' + key);
|
||||||
if (address)
|
if (self.options.indexAddress) {
|
||||||
batch.del('C/' + address + '/' + key);
|
address = input.getAddress();
|
||||||
|
if (address)
|
||||||
|
batch.del('C/' + address + '/' + key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
@ -1487,12 +1500,17 @@ Mempool.prototype._removeUnchecked = function removeUnchecked(hash, callback, fo
|
|||||||
for (i = 0; i < tx.outputs.length; i++) {
|
for (i = 0; i < tx.outputs.length; i++) {
|
||||||
output = tx.outputs[i];
|
output = tx.outputs[i];
|
||||||
key = hash + '/' + i;
|
key = hash + '/' + i;
|
||||||
address = output.getAddress();
|
|
||||||
|
if (output.script.isUnspendable())
|
||||||
|
continue;
|
||||||
|
|
||||||
batch.del('c/' + key);
|
batch.del('c/' + key);
|
||||||
|
|
||||||
if (address)
|
if (self.options.indexAddress) {
|
||||||
batch.del('C/' + address + '/' + key);
|
address = output.getAddress();
|
||||||
|
if (address)
|
||||||
|
batch.del('C/' + address + '/' + key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return batch.write(callback);
|
return batch.write(callback);
|
||||||
|
|||||||
@ -469,6 +469,10 @@ TXDB.prototype._add = function add(tx, map, callback, force) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
key = hash + '/' + i;
|
key = hash + '/' + i;
|
||||||
|
|
||||||
|
if (output.script.isUnspendable())
|
||||||
|
return next();
|
||||||
|
|
||||||
coin = bcoin.coin(tx, i);
|
coin = bcoin.coin(tx, i);
|
||||||
|
|
||||||
self._getOrphans(key, function(err, orphans) {
|
self._getOrphans(key, function(err, orphans) {
|
||||||
@ -914,6 +918,9 @@ TXDB.prototype._remove = function remove(tx, map, callback, force) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (output.script.isUnspendable())
|
||||||
|
return;
|
||||||
|
|
||||||
if (self.options.indexAddress && address) {
|
if (self.options.indexAddress && address) {
|
||||||
map.table[address].forEach(function(id) {
|
map.table[address].forEach(function(id) {
|
||||||
batch.del('C/' + id + '/' + key);
|
batch.del('C/' + id + '/' + key);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user