mempool: optimize coin view.
This commit is contained in:
parent
b2065cc84d
commit
c86311029c
@ -854,7 +854,7 @@ ChainDB.prototype.hasCoins = function hasCoins(hash) {
|
||||
* @returns {Promise} - Returns {@link CoinView}.
|
||||
*/
|
||||
|
||||
ChainDB.prototype.getCoinView = co(function* getCoinView(tx, callback) {
|
||||
ChainDB.prototype.getCoinView = co(function* getCoinView(tx) {
|
||||
var view = new CoinView();
|
||||
var prevout = tx.getPrevout();
|
||||
var i, hash, coins;
|
||||
|
||||
@ -24,6 +24,8 @@ var Outpoint = require('../primitives/outpoint');
|
||||
var TX = require('../primitives/tx');
|
||||
var Coin = require('../primitives/coin');
|
||||
var MempoolEntry = require('./mempoolentry');
|
||||
var CoinView = require('../blockchain/coinview');
|
||||
var Coins = require('../blockchain/coins');
|
||||
|
||||
/**
|
||||
* Represents a mempool.
|
||||
@ -1656,7 +1658,7 @@ Mempool.prototype.fillAllCoins = co(function* fillAllCoins(tx) {
|
||||
* @returns {Promise} - Returns {@link CoinView}.
|
||||
*/
|
||||
|
||||
Mempool.prototype.getCoinView = co(function* getCoinView(tx) {
|
||||
Mempool.prototype.getCoinViewSlow = co(function* getCoinViewSlow(tx) {
|
||||
var view = yield this.chain.db.getCoinView(tx);
|
||||
var entries = view.toArray();
|
||||
var i, coins, entry;
|
||||
@ -1678,6 +1680,41 @@ Mempool.prototype.getCoinView = co(function* getCoinView(tx) {
|
||||
return view;
|
||||
});
|
||||
|
||||
/**
|
||||
* Get coin viewpoint.
|
||||
* @param {TX} tx
|
||||
* @returns {Promise} - Returns {@link CoinView}.
|
||||
*/
|
||||
|
||||
Mempool.prototype.getCoinView = co(function* getCoinView(tx) {
|
||||
var view = new CoinView();
|
||||
var prevout = tx.getPrevout();
|
||||
var i, entry, hash, coins;
|
||||
|
||||
for (i = 0; i < prevout.length; i++) {
|
||||
hash = prevout[i];
|
||||
entry = this.getEntry(hash);
|
||||
|
||||
if (entry) {
|
||||
view.addTX(entry.tx, -1);
|
||||
continue;
|
||||
}
|
||||
|
||||
coins = yield this.chain.db.getCoins(hash);
|
||||
|
||||
if (!coins) {
|
||||
coins = new Coins();
|
||||
coins.hash = hash;
|
||||
view.add(coins);
|
||||
continue;
|
||||
}
|
||||
|
||||
view.add(coins);
|
||||
}
|
||||
|
||||
return view;
|
||||
});
|
||||
|
||||
/**
|
||||
* Get a snapshot of all transaction hashes in the mempool. Used
|
||||
* for generating INV packets in response to MEMPOOL packets.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user