block refactor.
This commit is contained in:
parent
a95ab18379
commit
78d32ce3a2
@ -17,30 +17,14 @@ var constants = bcoin.protocol.constants;
|
|||||||
* @exports Block
|
* @exports Block
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends AbstractBlock
|
* @extends AbstractBlock
|
||||||
* @param {NakedBlock} data
|
* @param {NakedBlock} options
|
||||||
* @property {String} type - "block" (inv type).
|
|
||||||
* @property {Number} version - Block version. Note
|
|
||||||
* that BCoin reads versions as unsigned despite
|
|
||||||
* them being signed on the protocol level. This
|
|
||||||
* number will never be negative.
|
|
||||||
* @property {Hash} prevBlock - Previous block hash.
|
|
||||||
* @property {Hash} merkleRoot - Merkle root hash.
|
|
||||||
* @property {Number} ts - Timestamp.
|
|
||||||
* @property {Number} bits
|
|
||||||
* @property {Number} nonce
|
|
||||||
* @property {Number} totalTX - Transaction count.
|
|
||||||
* @property {Number} height - Block height (-1 if not in the chain).
|
|
||||||
* @property {TX[]} txs - Transaction vector.
|
|
||||||
* @property {Hash?} commitmentHash - Commitment hash for segwit.
|
|
||||||
* @property {Buffer?} witnessNonce - Witness nonce for segwit.
|
|
||||||
* @property {ReversedHash} rhash - Reversed block hash (uint256le).
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Block(data) {
|
function Block(options) {
|
||||||
if (!(this instanceof Block))
|
if (!(this instanceof Block))
|
||||||
return new Block(data);
|
return new Block(options);
|
||||||
|
|
||||||
bcoin.abstractblock.call(this, data);
|
bcoin.abstractblock.call(this, options);
|
||||||
|
|
||||||
this.txs = [];
|
this.txs = [];
|
||||||
this._cbHeight = null;
|
this._cbHeight = null;
|
||||||
@ -50,30 +34,44 @@ function Block(data) {
|
|||||||
this._witnessSize = null;
|
this._witnessSize = null;
|
||||||
this._lastWitnessSize = 0;
|
this._lastWitnessSize = 0;
|
||||||
|
|
||||||
if (data)
|
if (options)
|
||||||
this.fromOptions(data);
|
this.fromOptions(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.inherits(Block, bcoin.abstractblock);
|
utils.inherits(Block, bcoin.abstractblock);
|
||||||
|
|
||||||
Block.prototype.fromOptions = function fromOptions(data) {
|
/**
|
||||||
|
* Inject properties from options object.
|
||||||
|
* @private
|
||||||
|
* @param {Object} options
|
||||||
|
*/
|
||||||
|
|
||||||
|
Block.prototype.fromOptions = function fromOptions(options) {
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
this._cbHeight = null;
|
this._cbHeight = null;
|
||||||
this._commitmentHash = null;
|
this._commitmentHash = null;
|
||||||
|
|
||||||
this._raw = data._raw || null;
|
this._raw = options._raw || null;
|
||||||
this._size = data._size || null;
|
this._size = options._size || null;
|
||||||
this._witnessSize = data._witnessSize != null ? data._witnessSize : null;
|
this._witnessSize = options._witnessSize != null
|
||||||
|
? options._witnessSize
|
||||||
|
: null;
|
||||||
|
|
||||||
if (data.txs) {
|
if (options.txs) {
|
||||||
for (i = 0; i < data.txs.length; i++)
|
for (i = 0; i < options.txs.length; i++)
|
||||||
this.addTX(data.txs[i]);
|
this.addTX(options.txs[i]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Block.fromOptions = function fromOptions(data) {
|
/**
|
||||||
return new Block().fromOptions(data);
|
* Instantiate block from options.
|
||||||
|
* @param {Object} options
|
||||||
|
* @returns {Block}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Block.fromOptions = function fromOptions(options) {
|
||||||
|
return new Block().fromOptions(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -15,26 +15,14 @@ var utils = require('./utils');
|
|||||||
* @exports Headers
|
* @exports Headers
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends AbstractBlock
|
* @extends AbstractBlock
|
||||||
* @param {NakedBlock} data
|
* @param {NakedBlock} options
|
||||||
* @property {Number} version - Block version. Note
|
|
||||||
* that BCoin reads versions as unsigned despite
|
|
||||||
* them being signed on the protocol level. This
|
|
||||||
* number will never be negative.
|
|
||||||
* @property {Hash} prevBlock - Previous block hash.
|
|
||||||
* @property {Hash} merkleRoot - Merkle root hash.
|
|
||||||
* @property {Number} ts - Timestamp.
|
|
||||||
* @property {Number} bits
|
|
||||||
* @property {Number} nonce
|
|
||||||
* @property {Number} totalTX - Transaction count.
|
|
||||||
* @property {Number} height - Block height (-1 if not present).
|
|
||||||
* @property {ReversedHash} rhash - Reversed block hash (uint256le).
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Headers(data) {
|
function Headers(options) {
|
||||||
if (!(this instanceof Headers))
|
if (!(this instanceof Headers))
|
||||||
return new Headers(data);
|
return new Headers(options);
|
||||||
|
|
||||||
bcoin.abstractblock.call(this, data);
|
bcoin.abstractblock.call(this, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.inherits(Headers, bcoin.abstractblock);
|
utils.inherits(Headers, bcoin.abstractblock);
|
||||||
|
|||||||
@ -18,24 +18,6 @@ var constants = bcoin.protocol.constants;
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @extends AbstractBlock
|
* @extends AbstractBlock
|
||||||
* @param {NakedBlock} options
|
* @param {NakedBlock} options
|
||||||
* @property {String} type - "merkleblock" (getdata type).
|
|
||||||
* @property {Number} version - Block version. Note
|
|
||||||
* that BCoin reads versions as unsigned despite
|
|
||||||
* them being signed on the protocol level. This
|
|
||||||
* number will never be negative.
|
|
||||||
* @property {Hash} prevBlock - Previous block hash.
|
|
||||||
* @property {Hash} merkleRoot - Merkle root hash.
|
|
||||||
* @property {Number} ts - Timestamp.
|
|
||||||
* @property {Number} bits
|
|
||||||
* @property {Number} nonce
|
|
||||||
* @property {Number} totalTX - Transaction count.
|
|
||||||
* @property {Number} height - Block height (-1 if not in the chain).
|
|
||||||
* @property {Buffer[]} hashes
|
|
||||||
* @property {Buffer} flags
|
|
||||||
* @property {TX[]} txs - Transaction vector.
|
|
||||||
* @property {Hash[]} matches - List of matched tx hashes.
|
|
||||||
* @property {Object} map - Map of matched tx hashes.
|
|
||||||
* @property {ReversedHash} rhash - Reversed block hash (uint256le).
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function MerkleBlock(options) {
|
function MerkleBlock(options) {
|
||||||
|
|||||||
@ -94,7 +94,8 @@ exports.inv = {
|
|||||||
FILTERED_BLOCK: 3,
|
FILTERED_BLOCK: 3,
|
||||||
WITNESS_TX: 1 | (1 << 30),
|
WITNESS_TX: 1 | (1 << 30),
|
||||||
WITNESS_BLOCK: 2 | (1 << 30),
|
WITNESS_BLOCK: 2 | (1 << 30),
|
||||||
WITNESS_FILTERED_BLOCK: 3 | (1 << 30)
|
WITNESS_FILTERED_BLOCK: 3 | (1 << 30),
|
||||||
|
CMPCT_BLOCK: 4
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user