From 6a45d693ee3642ed5a2dc4d5c708619298dc21c6 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 13 May 2016 15:33:25 -0700 Subject: [PATCH] rename chainblock for consistency. --- lib/bcoin/chain.js | 62 ++++++------- lib/bcoin/chaindb.js | 28 +++--- lib/bcoin/{chainblock.js => chainentry.js} | 102 ++++++++++----------- lib/bcoin/env.js | 4 +- lib/bcoin/lru.js | 2 +- lib/bcoin/miner.js | 2 +- lib/bcoin/protocol/framer.js | 2 +- lib/bcoin/protocol/network.js | 6 +- lib/bcoin/types.js | 4 +- lib/bcoin/workers.js | 4 +- 10 files changed, 108 insertions(+), 108 deletions(-) rename lib/bcoin/{chainblock.js => chainentry.js} (78%) diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index a308d71c..35955cc5 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -32,7 +32,7 @@ var VerifyError = bcoin.errors.VerifyError; * @property {Locker} locker * @property {Object} invalid * @property {Number} bestHeight - * @property {ChainBlock?} tip + * @property {ChainEntry?} tip * @property {Number} height * @property {Boolean} segwitActive * @property {Boolean} csvActive @@ -403,7 +403,7 @@ Chain.prototype._preload = function _preload(callback) { } // Create a chain entry. - entry = new bcoin.chainblock(self, data, lastEntry); + entry = new bcoin.chainentry(self, data, lastEntry); if (entry.height <= chainHeight) self.db.addCache(entry); @@ -430,7 +430,7 @@ Chain.prototype._preload = function _preload(callback) { * Perform all necessary contextual verification on a block. * @private * @param {Block|MerkleBlock} block - * @param {ChainBlock} entry + * @param {ChainEntry} entry * @param {Function} callback - Returns [{@link VerifyError}]. */ @@ -465,7 +465,7 @@ Chain.prototype.isGenesis = function isGenesis(block) { * coinbase height, finality checks. * @private * @param {Block|MerkleBlock} block - * @param {ChainBlock} entry + * @param {ChainEntry} entry * @param {Function} callback - Returns * [{@link VerifyError}, {@link VerifyFlags}]. */ @@ -607,8 +607,8 @@ Chain.prototype._verify = function _verify(block, prev, callback) { * Check all deployments on a chain, ranging from p2sh to segwit. * @private * @param {Block} block - * @param {ChainBlock} prev - * @param {ChainBlock[]} ancestors + * @param {ChainEntry} prev + * @param {ChainEntry[]} ancestors * @param {Function} callback - Returns * [{@link VerifyError}, {@link DeploymentState}]. */ @@ -724,7 +724,7 @@ Chain.prototype._checkDeployments = function _checkDeployments(block, prev, ance * @private * @see https://github.com/bitcoin/bips/blob/master/bip-0030.mediawiki * @param {Block|MerkleBlock} block - * @param {ChainBlock} prev + * @param {ChainEntry} prev * @param {Function} callback - Returns [{@link VerifyError}]. */ @@ -762,7 +762,7 @@ Chain.prototype._checkDuplicates = function _checkDuplicates(block, prev, callba * @private * @see https://github.com/bitcoin/bips/blob/master/bip-0030.mediawiki * @param {Block|MerkleBlock} block - * @param {ChainBlock} prev + * @param {ChainEntry} prev * @param {Function} callback - Returns [{@link VerifyError}]. */ @@ -807,7 +807,7 @@ Chain.prototype._findDuplicates = function _findDuplicates(block, prev, callback * @private * @see TX#checkInputs * @param {Block} block - * @param {ChainBlock} prev + * @param {ChainEntry} prev * @param {DeploymentState} state * @param {Function} callback - Returns [{@link VerifyError}]. */ @@ -932,9 +932,9 @@ Chain.prototype._getCachedHeight = function _getCachedHeight(hash) { /** * Find the block at which a fork ocurred. * @private - * @param {ChainBlock} fork - The current chain. - * @param {ChainBlock} longer - The competing chain. - * @param {Function} callback - Returns [{@link Error}, {@link ChainBlock}]. + * @param {ChainEntry} fork - The current chain. + * @param {ChainEntry} longer - The competing chain. + * @param {Function} callback - Returns [{@link Error}, {@link ChainEntry}]. */ Chain.prototype._findFork = function _findFork(fork, longer, callback) { @@ -983,7 +983,7 @@ Chain.prototype._findFork = function _findFork(fork, longer, callback) { * Called when a competing chain with a higher chainwork * is received. * @private - * @param {ChainBlock} entry - The competing chain's tip. + * @param {ChainEntry} entry - The competing chain's tip. * @param {Block|MerkleBlock} block - The being being added. * @param {Function} callback */ @@ -1078,7 +1078,7 @@ Chain.prototype._reorganize = function _reorganize(entry, block, callback) { /** * Disconnect an entry from the chain (updates the tip). - * @param {ChainBlock} entry + * @param {ChainEntry} entry * @param {Function} callback */ @@ -1113,7 +1113,7 @@ Chain.prototype.disconnect = function disconnect(entry, callback) { * This will do contextual-verification on the block * (necessary because we cannot validate the inputs * in alternate chains when they come in). - * @param {ChainBlock} entry + * @param {ChainEntry} entry * @param {Function} callback */ @@ -1171,9 +1171,9 @@ Chain.prototype.connect = function connect(entry, callback) { * save the block without connection (alternate chain), or * reorganize the chain (a higher fork). * @private - * @param {ChainBlock} entry + * @param {ChainEntry} entry * @param {Block|MerkleBlock} block - * @param {ChainBlock} prev + * @param {ChainEntry} prev * @param {Function} callback - Returns [{@link VerifyError}]. */ @@ -1536,7 +1536,7 @@ Chain.prototype.add = function add(block, callback, force) { block.setHeight(height); // Create a new chain entry. - entry = new bcoin.chainblock(self, { + entry = new bcoin.chainentry(self, { hash: hash, version: block.version, prevBlock: block.prevBlock, @@ -1716,7 +1716,7 @@ Chain.prototype.has = function has(hash, callback) { /** * Find a block entry by timestamp. * @param {Number} ts - Timestamp. - * @param {Function} callback - Returns [Error, {@link ChainBlock}]. + * @param {Function} callback - Returns [Error, {@link ChainEntry}]. */ Chain.prototype.byTime = function byTime(ts, callback) { @@ -1799,7 +1799,7 @@ Chain.prototype.hasPending = function hasPending(hash) { /** * Find the corresponding block entry by hash or height. * @param {Hash|Number} hash/height - * @param {Function} callback - Returns [Error, {@link ChainBlock}]. + * @param {Function} callback - Returns [Error, {@link ChainEntry}]. */ Chain.prototype.getEntry = function getEntry(hash, callback) { @@ -1985,7 +1985,7 @@ Chain.prototype.getCurrentTarget = function getCurrentTarget(callback) { /** * Calculate the target based on the passed-in chain entry. - * @param {ChainBlock} prev - Previous entry. + * @param {ChainEntry} prev - Previous entry. * @param {Block|MerkleBlock|null} - Current block. * @param {Function} callback - returns [Error, Number] * (target is in compact/mantissa form). @@ -2011,7 +2011,7 @@ Chain.prototype.getTargetAsync = function getTargetAsync(block, prev, callback) * Calculate the target synchronously. _Must_ * have ancestors pre-allocated. * @param {Block|MerkleBlock|null} - Current block. - * @param {ChainBlock} prev - Previous entry. + * @param {ChainEntry} prev - Previous entry. * @param {Function} callback - returns [Error, Number] * (target is in compact/mantissa form). */ @@ -2053,8 +2053,8 @@ Chain.prototype.getTarget = function getTarget(block, prev, ancestors) { /** * Retarget. This is called when the chain height * hits a retarget diff interval. - * @param {ChainBlock} prev - Previous entry. - * @param {ChainBlock} first - Chain entry from 2 weeks prior. + * @param {ChainEntry} prev - Previous entry. + * @param {ChainEntry} first - Chain entry from 2 weeks prior. * @returns {Number} target - Target in compact/mantissa form. */ @@ -2114,7 +2114,7 @@ Chain.prototype.findLocator = function findLocator(locator, callback) { * @example * chain.isActive(entry, 'witness', callback); * @see https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki - * @param {ChainBlock} prev - Previous chain entry. + * @param {ChainEntry} prev - Previous chain entry. * @param {String} id - Deployment id. * @param {Function} callback - Returns [Error, Number]. */ @@ -2137,7 +2137,7 @@ Chain.prototype.isActive = function isActive(prev, id, callback) { * @example * chain.getState(entry, 'witness', callback); * @see https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki - * @param {ChainBlock} prev - Previous chain entry. + * @param {ChainEntry} prev - Previous chain entry. * @param {String} id - Deployment id. * @param {Function} callback - Returns [Error, Number]. */ @@ -2289,7 +2289,7 @@ Chain.prototype.getState = function getState(prev, id, callback) { /** * Compute the version for a new block (BIP9: versionbits). * @see https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki - * @param {ChainBlock} prev - Previous chain entry (usually the tip). + * @param {ChainEntry} prev - Previous chain entry (usually the tip). * @param {Function} callback - Returns [Error, Number]. */ @@ -2371,7 +2371,7 @@ Chain.prototype._getInitialState = function _getInitialState(callback) { /** * Check transaction finality, taking into account MEDIAN_TIME_PAST * if it is present in the lock flags. - * @param {ChainBlock} prev - Previous chain entry. + * @param {ChainEntry} prev - Previous chain entry. * @param {TX} tx * @param {LockFlags} flags * @param {Function} callback - Returns [Error, Boolean]. @@ -2401,7 +2401,7 @@ Chain.prototype.checkFinal = function checkFinal(prev, tx, flags, callback) { * Get the necessary minimum time and height sequence locks for a transaction. * @param {TX} tx * @param {LockFlags} flags - * @param {ChainBlock} prev + * @param {ChainEntry} prev * @param {Function} callback - Returns * [Error, Number(minTime), Number(minHeight)]. */ @@ -2459,7 +2459,7 @@ Chain.prototype.getLocks = function getLocks(prev, tx, flags, callback) { /** * Evaluate sequence locks. - * @param {ChainBlock} prev + * @param {ChainEntry} prev * @param {Number} minHeight * @param {Number} minTime * @param {Function} callback - Returns [Error, Boolean]. @@ -2487,7 +2487,7 @@ Chain.prototype.evalLocks = function evalLocks(prev, minHeight, minTime, callbac * Verify sequence locks. * @param {TX} tx * @param {LockFlags} flags - * @param {ChainBlock} prev + * @param {ChainEntry} prev * @param {Function} callback - Returns [Error, Boolean]. */ diff --git a/lib/bcoin/chaindb.js b/lib/bcoin/chaindb.js index 74ef4228..4d925ec4 100644 --- a/lib/bcoin/chaindb.js +++ b/lib/bcoin/chaindb.js @@ -133,7 +133,7 @@ ChainDB.prototype._init = function _init() { if (exists) return finish(); - genesis = new bcoin.chainblock(self.chain, { + genesis = new bcoin.chainentry(self.chain, { hash: self.network.genesis.hash, version: self.network.genesis.version, prevBlock: self.network.genesis.prevBlock, @@ -222,7 +222,7 @@ ChainDB.prototype.dump = function dump(callback) { /** * Add an entry to the LRU cache. - * @param {ChainBlock} entry + * @param {ChainEntry} entry */ ChainDB.prototype.addCache = function addCache(entry) { @@ -382,7 +382,7 @@ ChainDB.prototype.getBoth = function getBoth(block, callback) { /** * Retrieve a chain entry but do _not_ add it to the LRU cache. * @param {Hash} hash - * @param {Function} callback - Returns [Error, {@link ChainBlock}]. + * @param {Function} callback - Returns [Error, {@link ChainEntry}]. */ ChainDB.prototype.getEntry = function getEntry(hash, callback) { @@ -402,7 +402,7 @@ ChainDB.prototype.getEntry = function getEntry(hash, callback) { return callback(null, self.cacheHash.get(hash)); return self.db.fetch('e/' + hash, function(data) { - return bcoin.chainblock.fromRaw(self.chain, data); + return bcoin.chainentry.fromRaw(self.chain, data); }, callback); }); }; @@ -410,7 +410,7 @@ ChainDB.prototype.getEntry = function getEntry(hash, callback) { /** * Retrieve a chain entry and add it to the LRU cache. * @param {Hash} hash - * @param {Function} callback - Returns [Error, {@link ChainBlock}]. + * @param {Function} callback - Returns [Error, {@link ChainEntry}]. */ ChainDB.prototype.get = function get(hash, callback) { @@ -437,7 +437,7 @@ ChainDB.prototype.get = function get(hash, callback) { * connect it as the tip. Note that this method * does _not_ perform any verification which is * instead performed in {@link Chain#add}. - * @param {ChainBlock} entry + * @param {ChainEntry} entry * @param {Block} block * @param {Boolean} connect - Whether to connect the * block's inputs and add it as a tip. @@ -489,7 +489,7 @@ ChainDB.prototype.save = function save(entry, block, connect, callback) { /** * Retrieve the tip entry from the tip record. - * @param {Function} callback - Returns [Error, {@link ChainBlock}]. + * @param {Function} callback - Returns [Error, {@link ChainEntry}]. */ ChainDB.prototype.getTip = function getTip(callback) { @@ -510,8 +510,8 @@ ChainDB.prototype.getTip = function getTip(callback) { /** * Connect the block to the chain. - * @param {ChainBlock|Hash|Height} block - entry, height, or hash. - * @param {Function} callback - Returns [Error, {@link ChainBlock}]. + * @param {ChainEntry|Hash|Height} block - entry, height, or hash. + * @param {Function} callback - Returns [Error, {@link ChainEntry}]. */ ChainDB.prototype.connect = function connect(entry, block, callback) { @@ -542,8 +542,8 @@ ChainDB.prototype.connect = function connect(entry, block, callback) { /** * Disconnect block from the chain. - * @param {ChainBlock|Hash|Height} block - Entry, height, or hash. - * @param {Function} callback - Returns [Error, {@link ChainBlock}]. + * @param {ChainEntry|Hash|Height} block - Entry, height, or hash. + * @param {Function} callback - Returns [Error, {@link ChainEntry}]. */ ChainDB.prototype.disconnect = function disconnect(block, callback) { @@ -581,7 +581,7 @@ ChainDB.prototype.disconnect = function disconnect(block, callback) { }; ChainDB.prototype._ensureEntry = function _ensureEntry(block, callback) { - if (block instanceof bcoin.chainblock) + if (block instanceof bcoin.chainentry) return callback(null, block); return this.get(block, callback); }; @@ -601,7 +601,7 @@ ChainDB.prototype.getNextHash = function getNextHash(hash, callback) { /** * Check to see if a block is on the main chain. - * @param {ChainBlock|Hash} hash + * @param {ChainEntry|Hash} hash * @param {Function} callback - Returns [Error, Boolean]. */ @@ -609,7 +609,7 @@ ChainDB.prototype.isMainChain = function isMainChain(hash, callback) { var self = this; var query; - if (hash instanceof bcoin.chainblock) { + if (hash instanceof bcoin.chainentry) { query = hash.height; hash = hash.hash; } else { diff --git a/lib/bcoin/chainblock.js b/lib/bcoin/chainentry.js similarity index 78% rename from lib/bcoin/chainblock.js rename to lib/bcoin/chainentry.js index 100fcadc..52805a61 100644 --- a/lib/bcoin/chainblock.js +++ b/lib/bcoin/chainentry.js @@ -1,5 +1,5 @@ /*! - * chainblock.js - chainblock object for bcoin + * chainentry.js - chainentry object for bcoin * Copyright (c) 2014-2015, Fedor Indutny (MIT License) * Copyright (c) 2014-2016, Christopher Jeffrey (MIT License). * https://github.com/indutny/bcoin @@ -19,11 +19,11 @@ var BufferReader = require('./reader'); * chainwork _with_ the entry in order to * avoid reading the entire chain index on * boot and recalculating the chainworks. - * @exports ChainBlock + * @exports ChainEntry * @constructor * @param {Chain} chain * @param {Object} data - * @param {ChainBlock} prev + * @param {ChainEntry} prev * @property {Hash} hash * @property {Number} version - Transaction version. Note that BCoin reads * versions as unsigned even though they are signed at the protocol level. @@ -38,9 +38,9 @@ var BufferReader = require('./reader'); * @property {ReversedHash} rhash - Reversed block hash (uint256le). */ -function ChainBlock(chain, data, prev) { - if (!(this instanceof ChainBlock)) - return new ChainBlock(chain, data); +function ChainEntry(chain, data, prev) { + if (!(this instanceof ChainEntry)) + return new ChainEntry(chain, data); this.chain = chain; this.network = this.chain.network; @@ -61,7 +61,7 @@ function ChainBlock(chain, data, prev) { * @returns {BN} proof */ -ChainBlock.prototype.getProof = function getProof() { +ChainEntry.prototype.getProof = function getProof() { var target = utils.fromCompact(this.bits); if (target.isNeg() || target.cmpn(0) === 0) return new bn(0); @@ -74,7 +74,7 @@ ChainBlock.prototype.getProof = function getProof() { * @returns {BN} chainwork */ -ChainBlock.prototype.getChainwork = function getChainwork(prev) { +ChainEntry.prototype.getChainwork = function getChainwork(prev) { return (prev ? prev.chainwork : new bn(0)).add(this.getProof()); }; @@ -83,7 +83,7 @@ ChainBlock.prototype.getChainwork = function getChainwork(prev) { * @returns {Boolean} */ -ChainBlock.prototype.isGenesis = function isGenesis() { +ChainEntry.prototype.isGenesis = function isGenesis() { return this.hash === this.network.genesis.hash; }; @@ -91,11 +91,11 @@ ChainBlock.prototype.isGenesis = function isGenesis() { * Allocate ancestors based on retarget interval and * majority window. These ancestors will be stored * in the `ancestors` array and enable use of synchronous - * ChainBlock methods. + * ChainEntry methods. * @param {Function} callback */ -ChainBlock.prototype.getRetargetAncestors = function getRetargetAncestors(callback) { +ChainEntry.prototype.getRetargetAncestors = function getRetargetAncestors(callback) { var majorityWindow = this.network.block.majorityWindow; var medianTimespan = constants.block.MEDIAN_TIMESPAN; var powDiffInterval = this.network.pow.retargetInterval; @@ -109,10 +109,10 @@ ChainBlock.prototype.getRetargetAncestors = function getRetargetAncestors(callba /** * Collect ancestors. * @param {Number} max - Number of ancestors. - * @param {Function} callback - Returns [Error, ChainBlock[]]. + * @param {Function} callback - Returns [Error, ChainEntry[]]. */ -ChainBlock.prototype.getAncestors = function getAncestors(max, callback) { +ChainEntry.prototype.getAncestors = function getAncestors(max, callback) { var entry = this; var ancestors = []; @@ -158,17 +158,17 @@ ChainBlock.prototype.getAncestors = function getAncestors(max, callback) { * @param {Function} callback - Return [Error, Boolean]. */ -ChainBlock.prototype.isMainChain = function isMainChain(callback) { +ChainEntry.prototype.isMainChain = function isMainChain(callback) { return this.chain.db.isMainChain(this, callback); }; /** * Collect ancestors up to `height`. * @param {Number} height - * @param {Function} callback - Returns [Error, ChainBlock[]]. + * @param {Function} callback - Returns [Error, ChainEntry[]]. */ -ChainBlock.prototype.getAncestorByHeight = function getAncestorByHeight(height, callback) { +ChainEntry.prototype.getAncestorByHeight = function getAncestorByHeight(height, callback) { var self = this; if (height < 0) @@ -203,10 +203,10 @@ ChainBlock.prototype.getAncestorByHeight = function getAncestorByHeight(height, * the same entry. This is done for sane porting of * bitcoind functions to BCoin. * @param {Number} index - * @returns {Function} callback - Returns [Error, ChainBlock]. + * @returns {Function} callback - Returns [Error, ChainEntry]. */ -ChainBlock.prototype.getAncestor = function getAncestor(index, callback) { +ChainEntry.prototype.getAncestor = function getAncestor(index, callback) { assert(index >= 0); return this.getAncestors(index + 1, function(err, ancestors) { if (err) @@ -221,19 +221,19 @@ ChainBlock.prototype.getAncestor = function getAncestor(index, callback) { /** * Get previous entry. - * @param {Function} callback - Returns [Error, ChainBlock]. + * @param {Function} callback - Returns [Error, ChainEntry]. */ -ChainBlock.prototype.getPrevious = function getPrevious(callback) { +ChainEntry.prototype.getPrevious = function getPrevious(callback) { return this.chain.db.get(this.prevBlock, callback); }; /** * Get next entry. - * @param {Function} callback - Returns [Error, ChainBlock]. + * @param {Function} callback - Returns [Error, ChainEntry]. */ -ChainBlock.prototype.getNext = function getNext(callback) { +ChainEntry.prototype.getNext = function getNext(callback) { var self = this; return this.chain.db.getNextHash(this.hash, function(err, hash) { if (err) @@ -249,11 +249,11 @@ ChainBlock.prototype.getNext = function getNext(callback) { /** * Get median time past. * @see GetMedianTimePast(). - * @param {ChainBlock[]} ancestors - Note that index 0 is the same entry. + * @param {ChainEntry[]} ancestors - Note that index 0 is the same entry. * @returns {Number} Median time past. */ -ChainBlock.prototype.getMedianTime = function getMedianTime(ancestors) { +ChainEntry.prototype.getMedianTime = function getMedianTime(ancestors) { var entry = this; var median = []; var timeSpan = constants.block.MEDIAN_TIMESPAN; @@ -268,11 +268,11 @@ ChainBlock.prototype.getMedianTime = function getMedianTime(ancestors) { }; /** - * Get median time past asynchronously (see {@link ChainBlock#getMedianTime}). + * Get median time past asynchronously (see {@link ChainEntry#getMedianTime}). * @param {Function} callback - Returns [Error, Number]. */ -ChainBlock.prototype.getMedianTimeAsync = function getMedianTimeAsync(callback) { +ChainEntry.prototype.getMedianTimeAsync = function getMedianTimeAsync(callback) { var self = this; return this.getAncestors(constants.block.MEDIAN_TIMESPAN, function(err, ancestors) { @@ -286,22 +286,22 @@ ChainBlock.prototype.getMedianTimeAsync = function getMedianTimeAsync(callback) /** * Check isSuperMajority against majorityRejectOutdated. * @param {Number} version - * @param {ChainBlock[]} ancestors + * @param {ChainEntry[]} ancestors * @returns {Boolean} */ -ChainBlock.prototype.isOutdated = function isOutdated(version, ancestors) { +ChainEntry.prototype.isOutdated = function isOutdated(version, ancestors) { return this.isSuperMajority(version, this.network.block.majorityRejectOutdated, ancestors); }; /** - * Check {@link ChainBlock#isUpgraded asynchronously}. + * Check {@link ChainEntry#isUpgraded asynchronously}. * @param {Number} version * @param {Function} callback - Returns [Error, Boolean]. * @returns {Boolean} */ -ChainBlock.prototype.isOutdatedAsync = function isOutdatedAsync(version, callback) { +ChainEntry.prototype.isOutdatedAsync = function isOutdatedAsync(version, callback) { return this.isSuperMajorityAsync( version, this.network.block.majorityRejectOutdated, @@ -311,22 +311,22 @@ ChainBlock.prototype.isOutdatedAsync = function isOutdatedAsync(version, callbac /** * Check isSuperMajority against majorityEnforceUpgrade. * @param {Number} version - * @param {ChainBlock[]} ancestors + * @param {ChainEntry[]} ancestors * @returns {Boolean} */ -ChainBlock.prototype.isUpgraded = function isUpgraded(version, ancestors) { +ChainEntry.prototype.isUpgraded = function isUpgraded(version, ancestors) { return this.isSuperMajority(version, this.network.block.majorityEnforceUpgrade, ancestors); }; /** - * Check {@link ChainBlock#isUpgraded} asynchronously. + * Check {@link ChainEntry#isUpgraded} asynchronously. * @param {Number} version * @param {Function} callback * @returns {Boolean} */ -ChainBlock.prototype.isUpgradedAsync = function isUpgradedAsync(version, callback) { +ChainEntry.prototype.isUpgradedAsync = function isUpgradedAsync(version, callback) { return this.isSuperMajorityAsync( version, this.network.block.majorityEnforceUpgrade, @@ -337,11 +337,11 @@ ChainBlock.prototype.isUpgradedAsync = function isUpgradedAsync(version, callbac * Calculate found number of block versions within the majority window. * @param {Number} version * @param {Number} required - * @param {ChainBlock[]} ancestors + * @param {ChainEntry[]} ancestors * @returns {Boolean} */ -ChainBlock.prototype.isSuperMajority = function isSuperMajority(version, required, ancestors) { +ChainEntry.prototype.isSuperMajority = function isSuperMajority(version, required, ancestors) { var entry = this; var found = 0; var majorityWindow = this.network.block.majorityWindow; @@ -357,14 +357,14 @@ ChainBlock.prototype.isSuperMajority = function isSuperMajority(version, require }; /** - * Calculate {@link ChainBlock#isSuperMajority asynchronously}. + * Calculate {@link ChainEntry#isSuperMajority asynchronously}. * @param {Number} version * @param {Number} required * @param {Function} callback - Returns [Error, Boolean]. * @returns {Boolean} */ -ChainBlock.prototype.isSuperMajorityAsync = function isSuperMajorityAsync(version, required, callback) { +ChainEntry.prototype.isSuperMajorityAsync = function isSuperMajorityAsync(version, required, callback) { var self = this; return this.getAncestors(this.network.block.majorityWindow, function(err, ancestors) { @@ -375,7 +375,7 @@ ChainBlock.prototype.isSuperMajorityAsync = function isSuperMajorityAsync(versio }); }; -ChainBlock.prototype.__defineGetter__('rhash', function() { +ChainEntry.prototype.__defineGetter__('rhash', function() { return utils.revHex(this.hash); }); @@ -384,7 +384,7 @@ ChainBlock.prototype.__defineGetter__('rhash', function() { * @returns {Buffer} */ -ChainBlock.prototype.toRaw = function toRaw(writer) { +ChainEntry.prototype.toRaw = function toRaw(writer) { var p = new BufferWriter(writer); p.write32(this.version); @@ -406,16 +406,16 @@ ChainBlock.prototype.toRaw = function toRaw(writer) { * Deserialize the entry. * @param {Chain} chain * @param {Buffer} buf - * @returns {ChainBlock} + * @returns {ChainEntry} */ -ChainBlock.fromRaw = function fromRaw(chain, buf) { +ChainEntry.fromRaw = function fromRaw(chain, buf) { var p = new BufferReader(buf, true); var hash = utils.dsha256(p.readBytes(80)); p.seek(-80); - return new ChainBlock(chain, { + return new ChainEntry(chain, { hash: hash.toString('hex'), version: p.readU32(), // Technically signed prevBlock: p.readHash('hex'), @@ -434,7 +434,7 @@ ChainBlock.fromRaw = function fromRaw(chain, buf) { * @returns {Object} */ -ChainBlock.prototype.toJSON = function toJSON() { +ChainEntry.prototype.toJSON = function toJSON() { return { version: this.version, hash: utils.revHex(this.hash), @@ -452,15 +452,15 @@ ChainBlock.prototype.toJSON = function toJSON() { * Instantiate block from jsonified object. * @param {Chain} chain * @param {Object} json - * @returns {ChainBlock} + * @returns {ChainEntry} */ -ChainBlock.fromJSON = function fromJSON(chain, json) { +ChainEntry.fromJSON = function fromJSON(chain, json) { json.hash = utils.revHex(json.hash); json.prevBlock = utils.revHex(json.prevBlock); json.merkleRoot = utils.revHex(json.merkleRoot); json.chainwork = new bn(json.chainwork, 10); - return new ChainBlock(chain, json); + return new ChainEntry(chain, json); }; /** @@ -468,20 +468,20 @@ ChainBlock.fromJSON = function fromJSON(chain, json) { * @returns {Object} */ -ChainBlock.prototype.inspect = function inspect() { +ChainEntry.prototype.inspect = function inspect() { return this.toJSON(); }; /** - * Test whether an object is a {@link ChainBlock}. + * Test whether an object is a {@link ChainEntry}. * @param {Object} obj * @returns {Boolean} */ -ChainBlock.isChainBlock = function isChainBlock(obj) { +ChainEntry.isChainEntry = function isChainEntry(obj) { return obj && bn.isBN(obj.chainwork) && typeof obj.getMedianTime === 'function'; }; -module.exports = ChainBlock; +module.exports = ChainEntry; diff --git a/lib/bcoin/env.js b/lib/bcoin/env.js index f4f52a02..db266623 100644 --- a/lib/bcoin/env.js +++ b/lib/bcoin/env.js @@ -82,7 +82,7 @@ try { * @property {Function} node - {@link Node} constructor. * @property {Function} spvnode - {@link SPVNode} constructor. * @property {Function} fullnode - {@link Fullnode} constructor. - * @property {Function} chainblock - {@link ChainBlock} constructor. + * @property {Function} chainentry - {@link ChainEntry} constructor. * @property {Function} chaindb - {@link ChainDB} constructor. * @property {Function} chain - {@link Chain} constructor. * @property {Function} mempool - {@link Mempool} constructor. @@ -163,7 +163,7 @@ function Environment(options) { this.node = require('./node'); this.spvnode = require('./spvnode'); this.fullnode = require('./fullnode'); - this.chainblock = require('./chainblock'); + this.chainentry = require('./chainentry'); this.chaindb = require('./chaindb'); this.chain = require('./chain'); this.mempool = require('./mempool'); diff --git a/lib/bcoin/lru.js b/lib/bcoin/lru.js index 8079f6b6..f7e5c20e 100644 --- a/lib/bcoin/lru.js +++ b/lib/bcoin/lru.js @@ -9,7 +9,7 @@ var utils = require('./utils'); var assert = utils.assert; /** - * An LRU cache, used for caching {@link ChainBlock}s. + * An LRU cache, used for caching {@link ChainEntry}s. * @exports LRU * @constructor * @param {Number} maxSize diff --git a/lib/bcoin/miner.js b/lib/bcoin/miner.js index cada7363..5536c88f 100644 --- a/lib/bcoin/miner.js +++ b/lib/bcoin/miner.js @@ -334,7 +334,7 @@ Miner.prototype.mineBlock = function mineBlock(version, callback) { * @exports MinerBlock * @constructor * @param {Object} options - * @param {ChainBlock} options.tip + * @param {ChainEntry} options.tip * @param {Number} options.height * @param {Number} options.target - Compact form. * @param {Function} options.dsha256 diff --git a/lib/bcoin/protocol/framer.js b/lib/bcoin/protocol/framer.js index 2b7c58f5..036094f8 100644 --- a/lib/bcoin/protocol/framer.js +++ b/lib/bcoin/protocol/framer.js @@ -1066,7 +1066,7 @@ Framer.headers = function _headers(headers, writer) { /** * Serialize a block header without any transaction count field. - * @param {NakedBlock|Block|MerkleBlock|Headers|ChainBlock} block + * @param {NakedBlock|Block|MerkleBlock|Headers|ChainEntry} block * @param {BufferWriter?} writer - A buffer writer to continue writing from. * @returns {Buffer} Returns a BufferWriter if `writer` was passed in. */ diff --git a/lib/bcoin/protocol/network.js b/lib/bcoin/protocol/network.js index 02085d9f..8a730483 100644 --- a/lib/bcoin/protocol/network.js +++ b/lib/bcoin/protocol/network.js @@ -223,21 +223,21 @@ main.pow.retargetInterval = main.pow.targetTimespan / main.pow.targetSpacing | 0 main.block = { /** - * Required versions to upgrade (see {@link ChainBlock#IsUpgraded}). + * Required versions to upgrade (see {@link ChainEntry#IsUpgraded}). */ majorityEnforceUpgrade: 750, /** * Required versions to consider block - * outdated (see {@link ChainBlock#IsOutdated}). + * outdated (see {@link ChainEntry#IsOutdated}). */ majorityRejectOutdated: 950, /** * Majority window to check for upgraded and outdated - * blocks (see {@link ChainBlock#IsSuperMajority}). + * blocks (see {@link ChainEntry#IsSuperMajority}). */ majorityWindow: 1000, diff --git a/lib/bcoin/types.js b/lib/bcoin/types.js index e617d831..2625dc18 100644 --- a/lib/bcoin/types.js +++ b/lib/bcoin/types.js @@ -429,14 +429,14 @@ /** * @callback EntryCallback * @param {Error?} err - * @param {ChainBlock} entry + * @param {ChainEntry} entry * @global */ /** * @callback EntriesCallback * @param {Error?} err - * @param {ChainBlock[]} entry + * @param {ChainEntry[]} entry * @global */ diff --git a/lib/bcoin/workers.js b/lib/bcoin/workers.js index d38e4997..60725661 100644 --- a/lib/bcoin/workers.js +++ b/lib/bcoin/workers.js @@ -697,7 +697,7 @@ Framer.item = function _item(item, p) { } else if (item instanceof bcoin.coin) { p.writeU8(42); bcoin.protocol.framer.coin(item, true, p); - } else if (item instanceof bcoin.chainblock) { + } else if (item instanceof bcoin.chainentry) { p.writeU8(43); item.toRaw(p); } else if (bn.isBN(item)) { @@ -857,7 +857,7 @@ Parser.parseItem = function parseItem(p) { case 42: return bcoin.coin.fromExtended(p); case 43: - return bcoin.chainblock.fromRaw(null, p); + return bcoin.chainentry.fromRaw(null, p); case 50: return new bn(p.readVarBytes()); default: