remove old save/remove block methods.
This commit is contained in:
parent
6b51badfa9
commit
49bb2d44e4
@ -158,245 +158,6 @@ BlockDB.prototype.parseOffset = function parseOffset(data) {
|
||||
};
|
||||
};
|
||||
|
||||
BlockDB.prototype.saveBlock = function saveBlock(block, callback) {
|
||||
var self = this;
|
||||
|
||||
this.data.saveAsync(block._raw, function(err, data) {
|
||||
var batch, blockOffset;
|
||||
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
batch = self.index.batch();
|
||||
|
||||
blockOffset = self.createOffset(data.size, data.offset, block.height);
|
||||
|
||||
batch.put('b/b/' + block.hash('hex'), blockOffset);
|
||||
batch.put('b/h/' + block.height, blockOffset);
|
||||
|
||||
block.txs.forEach(function(tx, i) {
|
||||
var hash = tx.hash('hex');
|
||||
var uniq = {};
|
||||
var txOffset;
|
||||
|
||||
txOffset = self.createOffset(
|
||||
tx._size,
|
||||
data.offset + tx._offset,
|
||||
block.height
|
||||
);
|
||||
|
||||
batch.put('t/t/' + hash, txOffset);
|
||||
|
||||
tx.inputs.forEach(function(input) {
|
||||
var type = input.getType();
|
||||
var address = input.getAddress();
|
||||
var uaddr;
|
||||
|
||||
if (input.isCoinbase())
|
||||
return;
|
||||
|
||||
if (type === 'pubkey' || type === 'multisig')
|
||||
address = null;
|
||||
|
||||
uaddr = address;
|
||||
|
||||
if (uaddr) {
|
||||
if (!uniq[uaddr])
|
||||
uniq[uaddr] = true;
|
||||
else
|
||||
uaddr = null;
|
||||
}
|
||||
|
||||
if (uaddr)
|
||||
batch.put('t/a/' + uaddr + '/' + hash, txOffset);
|
||||
|
||||
if (address) {
|
||||
batch.del(
|
||||
'u/a/' + address
|
||||
+ '/' + input.prevout.hash
|
||||
+ '/' + input.prevout.index);
|
||||
}
|
||||
|
||||
batch.del('u/t/' + input.prevout.hash + '/' + input.prevout.index);
|
||||
|
||||
if (self.options.cache)
|
||||
self.cache.unspent.remove(input.prevout.hash + '/' + input.prevout.index);
|
||||
});
|
||||
|
||||
tx.outputs.forEach(function(output, i) {
|
||||
var type = output.getType();
|
||||
var address = output.getAddress();
|
||||
var uaddr, coinOffset;
|
||||
|
||||
if (type === 'pubkey' || type === 'multisig')
|
||||
address = null;
|
||||
|
||||
uaddr = address;
|
||||
|
||||
if (uaddr) {
|
||||
if (!uniq[uaddr])
|
||||
uniq[uaddr] = true;
|
||||
else
|
||||
uaddr = null;
|
||||
}
|
||||
|
||||
coinOffset = self.createOffset(
|
||||
output._size,
|
||||
data.offset + tx._offset + output._offset,
|
||||
block.height
|
||||
);
|
||||
|
||||
if (uaddr)
|
||||
batch.put('t/a/' + uaddr + '/' + hash, txOffset);
|
||||
|
||||
if (address)
|
||||
batch.put('u/a/' + address + '/' + hash + '/' + i, coinOffset);
|
||||
|
||||
batch.put('u/t/' + hash + '/' + i, coinOffset);
|
||||
});
|
||||
});
|
||||
|
||||
batch.write(function(err) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
self.emit('save block', block);
|
||||
return callback(null, block);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
BlockDB.prototype.removeBlock = function removeBlock(hash, callback) {
|
||||
var self = this;
|
||||
|
||||
this.getBlock(hash, function(err, block) {
|
||||
var batch;
|
||||
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
if (!block)
|
||||
return callback();
|
||||
|
||||
batch = self.index.batch();
|
||||
|
||||
if (typeof hash === 'string')
|
||||
assert(block.hash('hex') === hash);
|
||||
|
||||
batch.del('b/b/' + block.hash('hex'));
|
||||
batch.del('b/h/' + block.height);
|
||||
|
||||
utils.forEach(block.txs, function(tx, next, i) {
|
||||
var hash = tx.hash('hex');
|
||||
var uniq = {};
|
||||
|
||||
if (self.options.cache)
|
||||
self.cache.tx.remove(hash);
|
||||
|
||||
batch.del('t/t/' + hash);
|
||||
|
||||
self.fillTX(tx, function(err) {
|
||||
if (err)
|
||||
return next(err);
|
||||
|
||||
tx.inputs.forEach(function(input) {
|
||||
var type = input.getType();
|
||||
var address = input.getAddress();
|
||||
var uaddr, coinOffset;
|
||||
|
||||
if (input.isCoinbase())
|
||||
return;
|
||||
|
||||
if (type === 'pubkey' || type === 'multisig')
|
||||
address = null;
|
||||
|
||||
uaddr = address;
|
||||
|
||||
if (uaddr) {
|
||||
if (!uniq[uaddr])
|
||||
uniq[uaddr] = true;
|
||||
else
|
||||
uaddr = null;
|
||||
}
|
||||
|
||||
assert(input.output._fileOffset >= 0);
|
||||
|
||||
coinOffset = self.createOffset(
|
||||
input.output._size,
|
||||
input.output._fileOffset,
|
||||
input.output.height
|
||||
);
|
||||
|
||||
if (uaddr)
|
||||
batch.del('t/a/' + uaddr + '/' + hash);
|
||||
|
||||
if (address) {
|
||||
batch.put('u/a/' + address
|
||||
+ '/' + input.prevout.hash
|
||||
+ '/' + input.prevout.index,
|
||||
coinOffset);
|
||||
}
|
||||
|
||||
batch.put('u/t/'
|
||||
+ input.prevout.hash
|
||||
+ '/' + input.prevout.index,
|
||||
coinOffset);
|
||||
});
|
||||
|
||||
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 (uaddr)
|
||||
batch.del('t/a/' + uaddr + '/' + hash);
|
||||
|
||||
if (address)
|
||||
batch.del('u/a/' + address + '/' + hash + '/' + i);
|
||||
|
||||
batch.del('u/t/' + hash + '/' + i);
|
||||
|
||||
if (self.options.cache)
|
||||
self.cache.unspent.remove(hash + '/' + i);
|
||||
});
|
||||
|
||||
next();
|
||||
});
|
||||
}, function(err) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
batch.write(function(err) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
// TODO: Add check to make sure we
|
||||
// can ONLY remove the last block.
|
||||
assert(block._fileOffset >= 0);
|
||||
assert(block._fileOffset < self.data.size);
|
||||
self.emit('remove block', block);
|
||||
return callback(null, block);
|
||||
// XXX This seems to be truncating too much right now
|
||||
self.data.truncateAsync(block._fileOffset, function(err) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
self.emit('remove block', block);
|
||||
return callback(null, block);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
BlockDB.prototype.saveBlock = function saveBlock(block, callback) {
|
||||
var self = this;
|
||||
|
||||
@ -1391,18 +1152,6 @@ BlockDB.prototype.reset = function reset(height, callback, emit) {
|
||||
});
|
||||
};
|
||||
|
||||
BlockDB.prototype.getTip = function getTip(callback) {
|
||||
var tip;
|
||||
|
||||
assert(this.node);
|
||||
assert(this.node.chain);
|
||||
assert(this.node.chain.tip);
|
||||
|
||||
tip = this.node.chain.tip.hash;
|
||||
|
||||
return callback(null, tip);
|
||||
};
|
||||
|
||||
BlockDB.prototype._getEntry = function _getEntry(height, callback) {
|
||||
if (!this.node)
|
||||
return callback();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user