rename compactblock to avoid confusion.

This commit is contained in:
Christopher Jeffrey 2016-06-07 11:32:52 -07:00
parent f2bc10726b
commit 5357fd8567
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
5 changed files with 25 additions and 25 deletions

View File

@ -1333,7 +1333,7 @@ Chain.prototype.isBusy = function isBusy() {
/** /**
* Add a block to the chain, perform all necessary verification. * Add a block to the chain, perform all necessary verification.
* @param {Block|MerkleBlock|CompactBlock} block * @param {Block|MerkleBlock|MemBlock} block
* @param {Function} callback - Returns [{@link VerifyError}]. * @param {Function} callback - Returns [{@link VerifyError}].
*/ */
@ -1531,7 +1531,7 @@ Chain.prototype.add = function add(block, callback, force) {
// fully validated here. They are deserialized, // fully validated here. They are deserialized,
// validated, and emitted. Hopefully the deserialized // validated, and emitted. Hopefully the deserialized
// blocks get cleaned up by the GC quickly. // blocks get cleaned up by the GC quickly.
if (block.compact) { if (block.memory) {
try { try {
block = block.toBlock(); block = block.toBlock();
} catch (e) { } catch (e) {
@ -1822,7 +1822,7 @@ Chain.prototype.getEntry = function getEntry(hash, callback) {
/** /**
* Get an orphan block. * Get an orphan block.
* @param {Hash} hash * @param {Hash} hash
* @returns {Block|MerkleBlock|CompactBlock} * @returns {Block|MerkleBlock|MemBlock}
*/ */
Chain.prototype.getOrphan = function getOrphan(hash) { Chain.prototype.getOrphan = function getOrphan(hash) {

View File

@ -79,7 +79,7 @@ if (!utils.isBrowser)
* @property {Function} mtx - {@link MTX} constructor. * @property {Function} mtx - {@link MTX} constructor.
* @property {Function} txdb - {@link TXDB} constructor. * @property {Function} txdb - {@link TXDB} constructor.
* @property {Function} abstractblock - {@link AbstractBlock} constructor. * @property {Function} abstractblock - {@link AbstractBlock} constructor.
* @property {Function} compactblock - {@link CompactBlock} constructor. * @property {Function} memblock - {@link MemBlock} constructor.
* @property {Function} block - {@link Block} constructor. * @property {Function} block - {@link Block} constructor.
* @property {Function} merkleblock - {@link MerkleBlock} constructor. * @property {Function} merkleblock - {@link MerkleBlock} constructor.
* @property {Function} headers - {@link Headers} constructor. * @property {Function} headers - {@link Headers} constructor.
@ -157,7 +157,7 @@ function Environment(options) {
this.mtx = require('./mtx'); this.mtx = require('./mtx');
this.txdb = require('./txdb'); this.txdb = require('./txdb');
this.abstractblock = require('./abstractblock'); this.abstractblock = require('./abstractblock');
this.compactblock = require('./compactblock'); this.memblock = require('./memblock');
this.block = require('./block'); this.block = require('./block');
this.merkleblock = require('./merkleblock'); this.merkleblock = require('./merkleblock');
this.headers = require('./headers'); this.headers = require('./headers');

View File

@ -1,5 +1,5 @@
/*! /*!
* compactblock.js - compact block object for bcoin * memblock.js - memblock block object for bcoin
* Copyright (c) 2014-2015, Fedor Indutny (MIT License) * Copyright (c) 2014-2015, Fedor Indutny (MIT License)
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License). * Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
* https://github.com/indutny/bcoin * https://github.com/indutny/bcoin
@ -14,7 +14,7 @@ var utils = require('./utils');
* collector's head will explode if there is too much * collector's head will explode if there is too much
* data on the javascript heap. Blocks can currently * data on the javascript heap. Blocks can currently
* be up to 1mb in size. In the future, they may be * be up to 1mb in size. In the future, they may be
* 2mb, 8mb, or maybe 20mb, who knows? A CompactBlock * 2mb, 8mb, or maybe 20mb, who knows? A MemBlock
* is an optimization in BCoin which defers parsing of * is an optimization in BCoin which defers parsing of
* the serialized transactions (the block Buffer) until * the serialized transactions (the block Buffer) until
* the block has passed through the chain queue and * the block has passed through the chain queue and
@ -24,7 +24,7 @@ var utils = require('./utils');
* lot of strain off of the garbage collector. Having * lot of strain off of the garbage collector. Having
* 500mb of blocks on the js heap would not be a good * 500mb of blocks on the js heap would not be a good
* thing. * thing.
* @exports CompactBlock * @exports MemBlock
* @constructor * @constructor
* @param {Object} data * @param {Object} data
* @property {Number} version - Block version. Note * @property {Number} version - Block version. Note
@ -38,7 +38,7 @@ var utils = require('./utils');
* @property {Number} nonce * @property {Number} nonce
* @property {Number} totalTX - Transaction count. * @property {Number} totalTX - Transaction count.
* @property {Number} height - Block height (-1 if not present). * @property {Number} height - Block height (-1 if not present).
* @property {Boolean} compact - Always true. * @property {Boolean} memory - Always true.
* @property {Number} coinbaseHeight - The coinbase height which * @property {Number} coinbaseHeight - The coinbase height which
* was extracted by the parser (the coinbase is the only * was extracted by the parser (the coinbase is the only
* transaction we parse ahead of time). * transaction we parse ahead of time).
@ -46,37 +46,37 @@ var utils = require('./utils');
* @property {ReversedHash} rhash - Reversed block hash (uint256le). * @property {ReversedHash} rhash - Reversed block hash (uint256le).
*/ */
function CompactBlock(data) { function MemBlock(data) {
if (!(this instanceof CompactBlock)) if (!(this instanceof MemBlock))
return new CompactBlock(data); return new MemBlock(data);
bcoin.abstractblock.call(this, data); bcoin.abstractblock.call(this, data);
this.compact = true; this.memory = true;
this.coinbaseHeight = data.coinbaseHeight; this.coinbaseHeight = data.coinbaseHeight;
this.raw = data.raw; this.raw = data.raw;
} }
utils.inherits(CompactBlock, bcoin.abstractblock); utils.inherits(MemBlock, bcoin.abstractblock);
/** /**
* Get the full block size. * Get the full block size.
* @returns {Number} * @returns {Number}
*/ */
CompactBlock.prototype.getSize = function getSize() { MemBlock.prototype.getSize = function getSize() {
return this.raw.length; return this.raw.length;
}; };
/** /**
* Verify the block headers. * Verify the block headers.
* @alias CompactBlock#verify * @alias MemBlock#verify
* @param {Object?} ret - Return object, may be * @param {Object?} ret - Return object, may be
* set with properties `reason` and `score`. * set with properties `reason` and `score`.
* @returns {Boolean} * @returns {Boolean}
*/ */
CompactBlock.prototype._verify = function _verify(ret) { MemBlock.prototype._verify = function _verify(ret) {
return this.verifyHeaders(ret); return this.verifyHeaders(ret);
}; };
@ -86,7 +86,7 @@ CompactBlock.prototype._verify = function _verify(ret) {
* @returns {Number} height (-1 if not present). * @returns {Number} height (-1 if not present).
*/ */
CompactBlock.prototype.getCoinbaseHeight = function getCoinbaseHeight() { MemBlock.prototype.getCoinbaseHeight = function getCoinbaseHeight() {
return this.coinbaseHeight; return this.coinbaseHeight;
}; };
@ -96,19 +96,19 @@ CompactBlock.prototype.getCoinbaseHeight = function getCoinbaseHeight() {
* @throws Parse error * @throws Parse error
*/ */
CompactBlock.prototype.toBlock = function toBlock() { MemBlock.prototype.toBlock = function toBlock() {
var data = bcoin.protocol.parser.parseBlock(this.raw); var data = bcoin.protocol.parser.parseBlock(this.raw);
delete this.raw; delete this.raw;
return new bcoin.block(data); return new bcoin.block(data);
}; };
/** /**
* Test whether an object is a CompactBlock. * Test whether an object is a MemBlock.
* @param {Object} obj * @param {Object} obj
* @returns {Boolean} * @returns {Boolean}
*/ */
CompactBlock.isCompactBlock = function isCompactBlock(obj) { MemBlock.isMemBlock = function isMemBlock(obj) {
return obj && typeof obj.toBlock === 'function'; return obj && typeof obj.toBlock === 'function';
}; };
@ -116,4 +116,4 @@ CompactBlock.isCompactBlock = function isCompactBlock(obj) {
* Expose * Expose
*/ */
module.exports = CompactBlock; module.exports = MemBlock;

View File

@ -685,7 +685,7 @@ Peer.prototype._onPacket = function onPacket(packet) {
case 'filterclear': case 'filterclear':
return this._handleFilterClear(payload); return this._handleFilterClear(payload);
case 'block': case 'block':
payload = new bcoin.compactblock(payload); payload = new bcoin.memblock(payload);
this.fire(cmd, payload); this.fire(cmd, payload);
break; break;
case 'merkleblock': case 'merkleblock':

View File

@ -342,7 +342,7 @@ Parser.prototype.parsePayload = function parsePayload(cmd, p) {
case 'headers': case 'headers':
return Parser.parseHeaders(p); return Parser.parseHeaders(p);
case 'block': case 'block':
return Parser.parseBlockCompact(p); return Parser.parseMemBlock(p);
case 'tx': case 'tx':
return Parser.parseTX(p); return Parser.parseTX(p);
case 'reject': case 'reject':
@ -829,7 +829,7 @@ Parser.parseBlock = function parseBlock(p) {
* @returns {NakedBlock} * @returns {NakedBlock}
*/ */
Parser.parseBlockCompact = function parseBlockCompact(p) { Parser.parseMemBlock = function parseMemBlock(p) {
var version, prevBlock, merkleRoot; var version, prevBlock, merkleRoot;
var ts, bits, nonce, totalTX, height; var ts, bits, nonce, totalTX, height;
var inCount, input; var inCount, input;