minor: comments.

This commit is contained in:
Christopher Jeffrey 2016-12-11 08:32:46 -08:00
parent ed4fb0f92c
commit d4cb8d82a2
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 39 additions and 13 deletions

View File

@ -15,6 +15,7 @@ var BufferReader = require('../utils/reader');
/** /**
* An extended transaction object. * An extended transaction object.
* @constructor * @constructor
* @param {Object} options
*/ */
function TXMeta(options) { function TXMeta(options) {
@ -193,8 +194,8 @@ TXMeta.fromJSON = function fromJSON(json) {
}; };
/** /**
* Serialize a transaction to BCoin "extended format". * Serialize a transaction to "extended format".
* This is the serialization format BCoin uses internally * This is the serialization format bcoin uses internally
* to store transactions in the database. The extended * to store transactions in the database. The extended
* serialization includes the height, block hash, index, * serialization includes the height, block hash, index,
* timestamp, and pending-since time. * timestamp, and pending-since time.

View File

@ -474,6 +474,8 @@ PathMapRecord.fromRaw = function fromRaw(hash, data) {
/** /**
* TXRecord * TXRecord
* @constructor * @constructor
* @param {TX} tx
* @param {BlockMeta?} block
*/ */
function TXRecord(tx, block) { function TXRecord(tx, block) {
@ -492,6 +494,14 @@ function TXRecord(tx, block) {
this.fromTX(tx, block); this.fromTX(tx, block);
} }
/**
* Inject properties from tx and block.
* @private
* @param {TX} tx
* @param {Block?} block
* @returns {TXRecord}
*/
TXRecord.prototype.fromTX = function fromTX(tx, block) { TXRecord.prototype.fromTX = function fromTX(tx, block) {
this.tx = tx; this.tx = tx;
this.hash = tx.hash('hex'); this.hash = tx.hash('hex');
@ -502,22 +512,43 @@ TXRecord.prototype.fromTX = function fromTX(tx, block) {
return this; return this;
}; };
/**
* Instantiate tx record from tx and block.
* @param {TX} tx
* @param {Block?} block
* @returns {TXRecord}
*/
TXRecord.fromTX = function fromTX(tx, block) { TXRecord.fromTX = function fromTX(tx, block) {
return new TXRecord().fromTX(tx, block); return new TXRecord().fromTX(tx, block);
}; };
/**
* Set block data (confirm).
* @param {BlockMeta} block
*/
TXRecord.prototype.setBlock = function setBlock(block) { TXRecord.prototype.setBlock = function setBlock(block) {
this.height = block.height; this.height = block.height;
this.block = block.hash; this.block = block.hash;
this.ts = block.ts; this.ts = block.ts;
}; };
/**
* Unset block (unconfirm).
*/
TXRecord.prototype.unsetBlock = function unsetBlock() { TXRecord.prototype.unsetBlock = function unsetBlock() {
this.height = -1; this.height = -1;
this.block = null; this.block = null;
this.ts = 0; this.ts = 0;
}; };
/**
* Convert tx record to a block meta.
* @returns {BlockMeta}
*/
TXRecord.prototype.getBlock = function getBlock() { TXRecord.prototype.getBlock = function getBlock() {
if (this.height === -1) if (this.height === -1)
return; return;
@ -526,8 +557,7 @@ TXRecord.prototype.getBlock = function getBlock() {
/** /**
* Calculate current number of transaction confirmations. * Calculate current number of transaction confirmations.
* @param {Number?} height - Current chain height. If not * @param {Number} height - Current chain height.
* present, network chain height will be used.
* @returns {Number} confirmations * @returns {Number} confirmations
*/ */
@ -544,11 +574,7 @@ TXRecord.prototype.getDepth = function getDepth(height) {
}; };
/** /**
* Serialize a transaction to BCoin "extended format". * Serialize a transaction to "extended format".
* This is the serialization format BCoin uses internally
* to store transactions in the database. The extended
* serialization includes the height, block hash, index,
* timestamp, and pending-since time.
* @returns {Buffer} * @returns {Buffer}
*/ */
@ -577,7 +603,7 @@ TXRecord.prototype.toRaw = function toRaw() {
}; };
/** /**
* Inject properties from "extended" serialization format. * Inject properties from "extended" format.
* @private * @private
* @param {Buffer} data * @param {Buffer} data
*/ */
@ -587,8 +613,8 @@ TXRecord.prototype.fromRaw = function fromRaw(data) {
this.tx = new TX(); this.tx = new TX();
this.tx.fromReader(br); this.tx.fromReader(br);
this.hash = this.tx.hash('hex');
this.hash = this.tx.hash('hex');
this.ps = br.readU32(); this.ps = br.readU32();
if (br.readU8() === 1) { if (br.readU8() === 1) {
@ -604,10 +630,9 @@ TXRecord.prototype.fromRaw = function fromRaw(data) {
}; };
/** /**
* Instantiate a transaction from a Buffer * Instantiate a transaction from a buffer
* in "extended" serialization format. * in "extended" serialization format.
* @param {Buffer} data * @param {Buffer} data
* @param {String?} enc - One of `"hex"` or `null`.
* @returns {TX} * @returns {TX}
*/ */