mempool: clean up comments. misc.

This commit is contained in:
Christopher Jeffrey 2016-08-15 19:38:51 -07:00
parent 31d2f36c42
commit 53f209dda5
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 28 additions and 32 deletions

View File

@ -81,8 +81,6 @@ function Fullnode(options) {
logger: this.logger,
chain: this.chain,
fees: this.fees,
db: 'memory',
location: this.location('mempool'),
limitFree: this.options.limitFree,
limitFreeRelay: this.options.limitFreeRelay,
requireStandard: this.options.requireStandard,
@ -504,23 +502,21 @@ Fullnode.prototype.getCoin = function getCoin(hash, index, callback) {
Fullnode.prototype.getCoinsByAddress = function getCoinsByAddress(addresses, callback) {
var self = this;
var coins = this.mempool.getCoinsByAddress(addresses);
var i, coin, spent;
this.chain.db.getCoinsByAddress(addresses, function(err, blockCoins) {
if (err)
return callback(err);
utils.forEach(blockCoins, function(coin, next) {
var spent = self.mempool.isSpent(coin.hash, coin.index);
for (i = 0; i < blockCoins.length; i++) {
coin = blockCoins[i];
spent = self.mempool.isSpent(coin.hash, coin.index);
if (!spent)
coins.push(coin);
}
return next();
}, function(err) {
if (err)
return callback(err);
return callback(null, coins);
});
return callback(null, coins);
});
};

View File

@ -248,7 +248,7 @@ Mempool.prototype.removeBlock = function removeBlock(block, callback, force) {
Mempool.prototype.limitMempoolSize = function limitMempoolSize(entryHash, callback) {
var self = this;
var trimmed = false;
var end, hashes, entry;
var hashes, end, entry;
if (this.getSize() <= this.maxSize)
return callback(null, trimmed);
@ -279,6 +279,8 @@ Mempool.prototype.limitMempoolSize = function limitMempoolSize(entryHash, callba
if (self.getSize() <= self.maxSize)
return callback(null, trimmed);
hashes = Object.keys(self.tx);
utils.forEachSerial(hashes, function(hash, next) {
if (self.getSize() <= self.maxSize)
return callback(null, trimmed);
@ -324,7 +326,7 @@ Mempool.prototype.limitOrphans = function limitOrphans() {
* Retrieve a transaction from the mempool.
* Note that this will not be filled with coins.
* @param {TX|Hash} hash
* @param {Function} callback - Returns [Error, {@link TX}].
* @returns {TX}
*/
Mempool.prototype.getTX = function getTX(hash) {
@ -338,7 +340,7 @@ Mempool.prototype.getTX = function getTX(hash) {
* Retrieve a transaction from the mempool.
* Note that this will not be filled with coins.
* @param {TX|Hash} hash
* @param {Function} callback - Returns [Error, {@link TX}].
* @returns {MempoolEntry}
*/
Mempool.prototype.getEntry = function getEntry(hash) {
@ -349,7 +351,7 @@ Mempool.prototype.getEntry = function getEntry(hash) {
* Retrieve a coin from the mempool (unspents only).
* @param {Hash} hash
* @param {Number} index
* @param {Function} callback - Returns [Error, {@link Coin}].
* @returns {Coin}
*/
Mempool.prototype.getCoin = function getCoin(hash, index) {
@ -374,7 +376,7 @@ Mempool.prototype.getCoin = function getCoin(hash, index) {
* for transaction outputs that never existed.
* @param {Hash} hash
* @param {Number} index
* @param {Function} callback - Returns [Error, Boolean].
* @returns {Boolean}
*/
Mempool.prototype.isSpent = function isSpent(hash, index) {
@ -383,8 +385,8 @@ Mempool.prototype.isSpent = function isSpent(hash, index) {
/**
* Find all coins pertaining to a certain address.
* @param {Base58Address|Base58Address[]} addresses
* @param {Function} callback - Returns [Error, {@link Coin}[]].
* @param {Address[]} addresses
* @returns {Coin[]}
*/
Mempool.prototype.getCoinsByAddress = function getCoinsByAddress(addresses) {
@ -399,7 +401,7 @@ Mempool.prototype.getCoinsByAddress = function getCoinsByAddress(addresses) {
if (!hash)
continue;
coin = this.coinIndex.searchCoin(hash);
coin = this.coinIndex.getCoins(hash);
for (j = 0; j < coin.length; j++)
coins.push(coin[j]);
@ -410,8 +412,8 @@ Mempool.prototype.getCoinsByAddress = function getCoinsByAddress(addresses) {
/**
* Find all transactions pertaining to a certain address.
* @param {Base58Address|Base58Address[]} addresses
* @param {Function} callback - Returns [Error, {@link TX}[]].
* @param {Address[]} addresses
* @returns {TX[]}
*/
Mempool.prototype.getTXByAddress = function getTXByAddress(addresses) {
@ -426,7 +428,7 @@ Mempool.prototype.getTXByAddress = function getTXByAddress(addresses) {
if (!hash)
continue;
tx = this.txIndex.searchTX(hash);
tx = this.txIndex.getTX(hash);
for (j = 0; j < tx.length; j++)
txs.push(tx[j]);
@ -441,7 +443,6 @@ Mempool.prototype.getTXByAddress = function getTXByAddress(addresses) {
* in that it will fill with all historical coins and not
* just unspent coins.
* @param {TX} tx
* @param {Function} callback - Returns [Error, {@link TX}].
*/
Mempool.prototype.fillHistory = function fillHistory(tx) {
@ -470,7 +471,6 @@ Mempool.prototype.fillHistory = function fillHistory(tx) {
* Fill a transaction with all available (unspent) coins
* in the mempool.
* @param {TX} tx
* @param {Function} callback - Returns [Error, {@link TX}].
*/
Mempool.prototype.fillCoins = function fillCoins(tx) {
@ -498,7 +498,7 @@ Mempool.prototype.fillCoins = function fillCoins(tx) {
/**
* Test the mempool to see if it contains a transaction.
* @param {Hash} hash
* @param {Function} callback - Returns [Error, Boolean].
* @returns {Boolean}
*/
Mempool.prototype.hasTX = function hasTX(hash) {
@ -508,7 +508,7 @@ Mempool.prototype.hasTX = function hasTX(hash) {
/**
* Test the mempool to see if it contains a transaction or an orphan.
* @param {Hash} hash
* @param {Function} callback - Returns [Error, Boolean].
* @returns {Boolean}
*/
Mempool.prototype.has = function has(hash) {
@ -963,7 +963,7 @@ Mempool.prototype.verify = function verify(entry, callback) {
* Count the highest number of
* ancestors a transaction may have.
* @param {TX} tx
* @param {Function} callback - Returns [Error, Number].
* @returns {Number}
*/
Mempool.prototype.countAncestors = function countAncestors(tx) {
@ -988,7 +988,7 @@ Mempool.prototype.countAncestors = function countAncestors(tx) {
* Count the highest number of
* descendants a transaction may have.
* @param {TX} tx
* @param {Function} callback - Returns [Error, Number].
* @returns {Number}
*/
Mempool.prototype.countDescendants = function countDescendants(tx) {
@ -1013,7 +1013,7 @@ Mempool.prototype.countDescendants = function countDescendants(tx) {
* Find a unconfirmed transactions that
* this transaction depends on.
* @param {TX} tx
* @param {Function} callback - Returns [Error, Number].
* @returns {Hash[]}
*/
Mempool.prototype.getDepends = function getDepends(tx) {
@ -1077,6 +1077,7 @@ Mempool.prototype.storeOrphan = function storeOrphan(tx) {
/**
* Return the full balance of all unspents in the mempool
* (not very useful in practice, only used for testing).
* @returns {Amount}
*/
Mempool.prototype.getBalance = function getBalance() {
@ -1100,7 +1101,7 @@ Mempool.prototype.getBalance = function getBalance() {
/**
* Retrieve _all_ transactions from the mempool.
* @param {Function} callback - Returns [Error, {@link TX}[]].
* @returns {TX[]}
*/
Mempool.prototype.getHistory = function getHistory() {
@ -1396,7 +1397,6 @@ Mempool.prototype.getConfidence = function getConfidence(hash, callback) {
* Add a transaction to the mempool database.
* @private
* @param {MempoolEntry} entry
* @param {Function} callback
*/
Mempool.prototype._addUnchecked = function _addUnchecked(entry) {
@ -1840,7 +1840,7 @@ function AddressIndex(mempool) {
this.map = {};
}
AddressIndex.prototype.searchCoin = function searchCoin(address) {
AddressIndex.prototype.getCoins = function getCoins(address) {
var items = this.map[address];
var out = [];
var i, item, outpoint, coin;
@ -1859,7 +1859,7 @@ AddressIndex.prototype.searchCoin = function searchCoin(address) {
return out;
};
AddressIndex.prototype.searchTX = function searchTX(address) {
AddressIndex.prototype.getTX = function getTX(address) {
var items = this.map[address];
var out = [];
var i, hash, tx;