chain/mempool/node: expose getSpentView.
This commit is contained in:
parent
8cb2c4a1a0
commit
bffc225179
@ -1704,16 +1704,16 @@ Chain.prototype.hasPending = function hasPending(hash) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get coin viewpoint.
|
* Get coin viewpoint (spent).
|
||||||
* @method
|
* @method
|
||||||
* @param {TX} tx
|
* @param {TX} tx
|
||||||
* @returns {Promise} - Returns {@link CoinView}.
|
* @returns {Promise} - Returns {@link CoinView}.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Chain.prototype.getCoinView = co(function* getCoinView(tx) {
|
Chain.prototype.getSpentView = co(function* getSpentView(tx) {
|
||||||
var unlock = yield this.locker.lock();
|
var unlock = yield this.locker.lock();
|
||||||
try {
|
try {
|
||||||
return yield this.db.getCoinView(tx);
|
return yield this.db.getSpentView(tx);
|
||||||
} finally {
|
} finally {
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,8 @@ var layout = require('./layout');
|
|||||||
var LDB = require('../db/ldb');
|
var LDB = require('../db/ldb');
|
||||||
var Fees = require('./fees');
|
var Fees = require('./fees');
|
||||||
var Map = require('../utils/map');
|
var Map = require('../utils/map');
|
||||||
|
var CoinView = require('../coins/coinview');
|
||||||
|
var Coins = require('../coins/coins');
|
||||||
var VerifyError = errors.VerifyError;
|
var VerifyError = errors.VerifyError;
|
||||||
var VerifyResult = errors.VerifyResult;
|
var VerifyResult = errors.VerifyResult;
|
||||||
|
|
||||||
@ -1603,7 +1605,22 @@ Mempool.prototype.isDoubleSpend = function isDoubleSpend(tx) {
|
|||||||
* Get coin viewpoint (lock).
|
* Get coin viewpoint (lock).
|
||||||
* @method
|
* @method
|
||||||
* @param {TX} tx
|
* @param {TX} tx
|
||||||
* @param {CoinView} view
|
* @returns {Promise} - Returns {@link CoinView}.
|
||||||
|
*/
|
||||||
|
|
||||||
|
Mempool.prototype.getSpentView = co(function* getSpentView(tx) {
|
||||||
|
var unlock = yield this.locker.lock();
|
||||||
|
try {
|
||||||
|
return yield this.getCoinView(tx);
|
||||||
|
} finally {
|
||||||
|
unlock();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get coin viewpoint (no lock).
|
||||||
|
* @method
|
||||||
|
* @param {TX} tx
|
||||||
* @returns {Promise} - Returns {@link CoinView}.
|
* @returns {Promise} - Returns {@link CoinView}.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -1629,6 +1646,42 @@ Mempool.prototype.getCoinView = co(function* getCoinView(tx) {
|
|||||||
return view;
|
return view;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get coin viewpoint (no lock).
|
||||||
|
* @method
|
||||||
|
* @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, hash, entry, 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;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find missing outpoints.
|
* Find missing outpoints.
|
||||||
* @param {TX} tx
|
* @param {TX} tx
|
||||||
|
|||||||
@ -465,6 +465,18 @@ FullNode.prototype.getMeta = co(function* getMeta(hash) {
|
|||||||
return yield this.chain.db.getMeta(hash);
|
return yield this.chain.db.getMeta(hash);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a spent coin viewpoint from mempool or chain database.
|
||||||
|
* @param {TXMeta} meta
|
||||||
|
* @returns {Promise} - Returns {@link CoinView}.
|
||||||
|
*/
|
||||||
|
|
||||||
|
FullNode.prototype.getMetaView = co(function* getMetaView(meta) {
|
||||||
|
if (meta.height === -1)
|
||||||
|
return this.mempool.getSpentView(meta.tx);
|
||||||
|
return this.chain.getSpentView(meta.tx);
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve transactions pertaining to an
|
* Retrieve transactions pertaining to an
|
||||||
* address from the mempool or chain database.
|
* address from the mempool or chain database.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user