chain: cleanup some functions.
This commit is contained in:
parent
0f1a62b0de
commit
a443b88f92
@ -220,7 +220,7 @@ Chain.prototype._close = function close() {
|
||||
/**
|
||||
* Perform all necessary contextual verification on a block.
|
||||
* @private
|
||||
* @param {Block|MerkleBlock} block
|
||||
* @param {Block} block
|
||||
* @param {ChainEntry} prev
|
||||
* @returns {Promise} - Returns {@link ContextResult}.
|
||||
*/
|
||||
@ -509,7 +509,7 @@ Chain.prototype.setDeploymentState = function setDeploymentState(state) {
|
||||
* can skip this.
|
||||
* @private
|
||||
* @see https://github.com/bitcoin/bips/blob/master/bip-0030.mediawiki
|
||||
* @param {Block|MerkleBlock} block
|
||||
* @param {Block} block
|
||||
* @param {ChainEntry} prev
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -709,7 +709,7 @@ Chain.prototype.findFork = co(function* findFork(fork, longer) {
|
||||
* is received.
|
||||
* @private
|
||||
* @param {ChainEntry} competitor - The competing chain's tip.
|
||||
* @param {Block|MerkleBlock} block - The being being added.
|
||||
* @param {Block} block - The being being added.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -760,7 +760,7 @@ Chain.prototype.reorganize = co(function* reorganize(competitor, block) {
|
||||
* will reset the chain to the fork block.
|
||||
* @private
|
||||
* @param {ChainEntry} competitor - The competing chain's tip.
|
||||
* @param {Block|MerkleBlock} block - The being being added.
|
||||
* @param {Block} block - The being being added.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -877,7 +877,7 @@ Chain.prototype.reconnect = co(function* reconnect(entry) {
|
||||
* reorganize the chain (a higher fork).
|
||||
* @private
|
||||
* @param {ChainEntry} entry
|
||||
* @param {Block|MerkleBlock} block
|
||||
* @param {Block} block
|
||||
* @param {ChainEntry} prev
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -937,7 +937,7 @@ Chain.prototype.setBestChain = co(function* setBestChain(entry, block, prev) {
|
||||
* Save block on an alternate chain.
|
||||
* @private
|
||||
* @param {ChainEntry} entry
|
||||
* @param {Block|MerkleBlock} block
|
||||
* @param {Block} block
|
||||
* @param {ChainEntry} prev
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -1575,22 +1575,13 @@ Chain.prototype.has = co(function* has(hash) {
|
||||
});
|
||||
|
||||
/**
|
||||
* Test the chain to see if it has recently seen a block.
|
||||
* @param {Hash} hash
|
||||
* @returns {Boolean}
|
||||
* Find the corresponding block entry by hash or height.
|
||||
* @param {Hash|Number} hash/height
|
||||
* @returns {Promise} - Returns {@link ChainEntry}.
|
||||
*/
|
||||
|
||||
Chain.prototype.seen = function seen(hash) {
|
||||
if (this.hasOrphan(hash))
|
||||
return true;
|
||||
|
||||
if (this.locker.has(hash))
|
||||
return true;
|
||||
|
||||
if (this.invalid.has(hash))
|
||||
return true;
|
||||
|
||||
return this.db.hasCache(hash);
|
||||
Chain.prototype.getEntry = function getEntry(hash) {
|
||||
return this.db.getEntry(hash);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1603,6 +1594,16 @@ Chain.prototype.hasEntry = function hasEntry(hash) {
|
||||
return this.db.hasEntry(hash);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an orphan block.
|
||||
* @param {Hash} hash
|
||||
* @returns {Block}
|
||||
*/
|
||||
|
||||
Chain.prototype.getOrphan = function getOrphan(hash) {
|
||||
return this.orphanMap[hash] || null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test the chain to see if it contains an orphan.
|
||||
* @param {Hash} hash
|
||||
@ -1610,7 +1611,7 @@ Chain.prototype.hasEntry = function hasEntry(hash) {
|
||||
*/
|
||||
|
||||
Chain.prototype.hasOrphan = function hasOrphan(hash) {
|
||||
return !!this.getOrphan(hash);
|
||||
return this.orphanMap[hash] != null;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1623,26 +1624,6 @@ Chain.prototype.hasPending = function hasPending(hash) {
|
||||
return this.locker.hasPending(hash);
|
||||
};
|
||||
|
||||
/**
|
||||
* Find the corresponding block entry by hash or height.
|
||||
* @param {Hash|Number} hash/height
|
||||
* @returns {Promise} - Returns {@link ChainEntry}.
|
||||
*/
|
||||
|
||||
Chain.prototype.getEntry = function getEntry(hash) {
|
||||
return this.db.getEntry(hash);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an orphan block.
|
||||
* @param {Hash} hash
|
||||
* @returns {Block|MerkleBlock|MemBlock}
|
||||
*/
|
||||
|
||||
Chain.prototype.getOrphan = function getOrphan(hash) {
|
||||
return this.orphanMap[hash] || null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get coin viewpoint.
|
||||
* @param {TX} tx
|
||||
@ -1719,7 +1700,7 @@ Chain.prototype.getProgress = function getProgress() {
|
||||
|
||||
/**
|
||||
* Calculate chain locator (an array of hashes).
|
||||
* @param {(Number|Hash)?} start - Height or hash to treat as the tip.
|
||||
* @param {Hash} start - Height or hash to treat as the tip.
|
||||
* The current tip will be used if not present. Note that this can be a
|
||||
* non-existent hash, which is useful for headers-first locators.
|
||||
* @returns {Promise} - Returns {@link Hash}[].
|
||||
@ -1737,7 +1718,7 @@ Chain.prototype.getLocator = co(function* getLocator(start) {
|
||||
/**
|
||||
* Calculate chain locator without a lock.
|
||||
* @private
|
||||
* @param {(Number|Hash)?} start
|
||||
* @param {Hash} start
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -1749,16 +1730,12 @@ Chain.prototype._getLocator = co(function* getLocator(start) {
|
||||
if (start == null)
|
||||
start = this.tip.hash;
|
||||
|
||||
assert(typeof start === 'string');
|
||||
|
||||
entry = yield this.db.getEntry(start);
|
||||
|
||||
if (!entry) {
|
||||
// We could simply return `start` here,
|
||||
// but there is no required "spacing"
|
||||
// for locator hashes. Pretend this hash
|
||||
// is our tip. This is useful for
|
||||
// getheaders.
|
||||
if (typeof start === 'string')
|
||||
hashes.push(start);
|
||||
hashes.push(start);
|
||||
entry = this.tip;
|
||||
}
|
||||
|
||||
@ -1860,7 +1837,7 @@ Chain.prototype.getCurrentTarget = co(function* getCurrentTarget() {
|
||||
/**
|
||||
* Calculate the target based on the passed-in chain entry.
|
||||
* @param {ChainEntry} prev - Previous entry.
|
||||
* @param {Block|MerkleBlock|null} - Current block.
|
||||
* @param {Block} - Current block.
|
||||
* @returns {Promise} - returns Number
|
||||
* (target is in compact/mantissa form).
|
||||
*/
|
||||
@ -1882,8 +1859,9 @@ Chain.prototype.getTargetAsync = co(function* getTargetAsync(block, prev) {
|
||||
/**
|
||||
* Calculate the target synchronously. _Must_
|
||||
* have ancestors pre-allocated.
|
||||
* @param {Block|MerkleBlock|null} - Current block.
|
||||
* @param {Block} - Current block.
|
||||
* @param {ChainEntry} prev - Previous entry.
|
||||
* @param {ChainEntry[]} ancestors
|
||||
* @returns {Promise} - returns Number
|
||||
* (target is in compact/mantissa form).
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user