Revert "store undo coins in coinviews."
This reverts commit f2465c2caf.
This commit is contained in:
parent
f2465c2caf
commit
6081998516
@ -874,8 +874,7 @@ ChainDB.prototype.removeBlock = function removeBlock(hash, batch, callback) {
|
|||||||
|
|
||||||
ChainDB.prototype.connectBlock = function connectBlock(block, view, batch, callback) {
|
ChainDB.prototype.connectBlock = function connectBlock(block, view, batch, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var undo = new bcoin.coinview();
|
var undo = new BufferWriter();
|
||||||
var hasUndo = false;
|
|
||||||
var i, j, tx, input, output, key, addresses, address, hash, coins, raw;
|
var i, j, tx, input, output, key, addresses, address, hash, coins, raw;
|
||||||
|
|
||||||
if (this.options.spv) {
|
if (this.options.spv) {
|
||||||
@ -917,8 +916,7 @@ ChainDB.prototype.connectBlock = function connectBlock(block, view, batch, callb
|
|||||||
batch.del(layout.C(address, input.prevout.hash, input.prevout.index));
|
batch.del(layout.C(address, input.prevout.hash, input.prevout.index));
|
||||||
}
|
}
|
||||||
|
|
||||||
hasUndo = true;
|
Framer.coin(input.coin, false, undo);
|
||||||
undo.addCoin(input.coin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < tx.outputs.length; j++) {
|
for (j = 0; j < tx.outputs.length; j++) {
|
||||||
@ -949,8 +947,8 @@ ChainDB.prototype.connectBlock = function connectBlock(block, view, batch, callb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasUndo)
|
if (undo.written > 0)
|
||||||
batch.put(layout.u(block.hash()), undo.toRaw());
|
batch.put(layout.u(block.hash()), undo.render());
|
||||||
|
|
||||||
this.emit('add block', block);
|
this.emit('add block', block);
|
||||||
|
|
||||||
@ -1397,7 +1395,16 @@ ChainDB.prototype.getCoinView = function getCoinView(block, callback) {
|
|||||||
|
|
||||||
ChainDB.prototype.getUndoCoins = function getUndoCoins(hash, callback) {
|
ChainDB.prototype.getUndoCoins = function getUndoCoins(hash, callback) {
|
||||||
return this.db.fetch(layout.u(hash), function(data) {
|
return this.db.fetch(layout.u(hash), function(data) {
|
||||||
return bcoin.coinview.fromRaw(data);
|
var p = new BufferReader(data);
|
||||||
|
var coins = [];
|
||||||
|
var coin;
|
||||||
|
|
||||||
|
while (p.left()) {
|
||||||
|
coin = Parser.parseCoin(p, false);
|
||||||
|
coins.push(new bcoin.coin(coin));
|
||||||
|
}
|
||||||
|
|
||||||
|
return coins;
|
||||||
}, callback);
|
}, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1409,7 +1416,7 @@ ChainDB.prototype.getUndoCoins = function getUndoCoins(hash, callback) {
|
|||||||
|
|
||||||
ChainDB.prototype.getUndoView = function getUndoView(block, callback) {
|
ChainDB.prototype.getUndoView = function getUndoView(block, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var i, j, tx, input;
|
var i, j, k, tx, input, coin;
|
||||||
|
|
||||||
return this.getCoinView(block, function(err, view) {
|
return this.getCoinView(block, function(err, view) {
|
||||||
if (err)
|
if (err)
|
||||||
@ -1422,7 +1429,7 @@ ChainDB.prototype.getUndoView = function getUndoView(block, callback) {
|
|||||||
if (!coins)
|
if (!coins)
|
||||||
return callback(null, view);
|
return callback(null, view);
|
||||||
|
|
||||||
for (i = 0; i < block.txs.length; i++) {
|
for (i = 0, k = 0; i < block.txs.length; i++) {
|
||||||
tx = block.txs[i];
|
tx = block.txs[i];
|
||||||
|
|
||||||
if (tx.isCoinbase())
|
if (tx.isCoinbase())
|
||||||
@ -1430,8 +1437,11 @@ ChainDB.prototype.getUndoView = function getUndoView(block, callback) {
|
|||||||
|
|
||||||
for (j = 0; j < tx.inputs.length; j++) {
|
for (j = 0; j < tx.inputs.length; j++) {
|
||||||
input = tx.inputs[j];
|
input = tx.inputs[j];
|
||||||
input.coin = coins.spend(input.prevout.hash, input.prevout.index);
|
coin = coins[k++];
|
||||||
view.addCoin(input.coin);
|
coin.hash = input.prevout.hash;
|
||||||
|
coin.index = input.prevout.index;
|
||||||
|
input.coin = coin;
|
||||||
|
view.addCoin(coin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,8 +8,6 @@
|
|||||||
var bcoin = require('./env');
|
var bcoin = require('./env');
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var BufferReader = require('./reader');
|
|
||||||
var BufferWriter = require('./writer');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A collections of {@link Coins} objects.
|
* A collections of {@link Coins} objects.
|
||||||
@ -98,36 +96,6 @@ CoinView.prototype.spend = function spend(hash, index) {
|
|||||||
return this.coins[hash].spend(index);
|
return this.coins[hash].spend(index);
|
||||||
};
|
};
|
||||||
|
|
||||||
CoinView.prototype.toRaw = function toRaw() {
|
|
||||||
var keys = Object.keys(this.coins);
|
|
||||||
var p = new BufferWriter();
|
|
||||||
var out = [];
|
|
||||||
var i, hash;
|
|
||||||
|
|
||||||
for (i = 0; i < keys.length; i++) {
|
|
||||||
hash = keys[i];
|
|
||||||
p.writeHash(hash);
|
|
||||||
p.writeVarBytes(this.coins[hash].toRaw());
|
|
||||||
}
|
|
||||||
|
|
||||||
return p.render();
|
|
||||||
};
|
|
||||||
|
|
||||||
CoinView.fromRaw = function fromRaw(data) {
|
|
||||||
var p = new BufferReader(data, true);
|
|
||||||
var map = {};
|
|
||||||
var hash, coins;
|
|
||||||
|
|
||||||
while (p.left()) {
|
|
||||||
hash = p.readHash('hex');
|
|
||||||
coins = bcoin.coins.fromRaw(p.readVarBytes());
|
|
||||||
coins.hash = hash;
|
|
||||||
map[hash] = coins;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CoinView(map);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill transaction(s) with coins.
|
* Fill transaction(s) with coins.
|
||||||
* @param {TX} tx
|
* @param {TX} tx
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user