diff --git a/lib/primitives/txmeta.js b/lib/primitives/txmeta.js index 53258c6e..8d2da6fa 100644 --- a/lib/primitives/txmeta.js +++ b/lib/primitives/txmeta.js @@ -15,6 +15,7 @@ var BufferReader = require('../utils/reader'); /** * An extended transaction object. * @constructor + * @param {Object} options */ function TXMeta(options) { @@ -193,8 +194,8 @@ TXMeta.fromJSON = function fromJSON(json) { }; /** - * Serialize a transaction to BCoin "extended format". - * This is the serialization format BCoin uses internally + * 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. diff --git a/lib/wallet/records.js b/lib/wallet/records.js index ca18753e..a75395da 100644 --- a/lib/wallet/records.js +++ b/lib/wallet/records.js @@ -474,6 +474,8 @@ PathMapRecord.fromRaw = function fromRaw(hash, data) { /** * TXRecord * @constructor + * @param {TX} tx + * @param {BlockMeta?} block */ function TXRecord(tx, block) { @@ -492,6 +494,14 @@ function TXRecord(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) { this.tx = tx; this.hash = tx.hash('hex'); @@ -502,22 +512,43 @@ TXRecord.prototype.fromTX = function fromTX(tx, block) { return this; }; +/** + * Instantiate tx record from tx and block. + * @param {TX} tx + * @param {Block?} block + * @returns {TXRecord} + */ + TXRecord.fromTX = function fromTX(tx, block) { return new TXRecord().fromTX(tx, block); }; +/** + * Set block data (confirm). + * @param {BlockMeta} block + */ + TXRecord.prototype.setBlock = function setBlock(block) { this.height = block.height; this.block = block.hash; this.ts = block.ts; }; +/** + * Unset block (unconfirm). + */ + TXRecord.prototype.unsetBlock = function unsetBlock() { this.height = -1; this.block = null; this.ts = 0; }; +/** + * Convert tx record to a block meta. + * @returns {BlockMeta} + */ + TXRecord.prototype.getBlock = function getBlock() { if (this.height === -1) return; @@ -526,8 +557,7 @@ TXRecord.prototype.getBlock = function getBlock() { /** * Calculate current number of transaction confirmations. - * @param {Number?} height - Current chain height. If not - * present, network chain height will be used. + * @param {Number} height - Current chain height. * @returns {Number} confirmations */ @@ -544,11 +574,7 @@ TXRecord.prototype.getDepth = function getDepth(height) { }; /** - * Serialize a transaction to BCoin "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. + * Serialize a transaction to "extended format". * @returns {Buffer} */ @@ -577,7 +603,7 @@ TXRecord.prototype.toRaw = function toRaw() { }; /** - * Inject properties from "extended" serialization format. + * Inject properties from "extended" format. * @private * @param {Buffer} data */ @@ -587,8 +613,8 @@ TXRecord.prototype.fromRaw = function fromRaw(data) { this.tx = new TX(); this.tx.fromReader(br); - this.hash = this.tx.hash('hex'); + this.hash = this.tx.hash('hex'); this.ps = br.readU32(); 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. * @param {Buffer} data - * @param {String?} enc - One of `"hex"` or `null`. * @returns {TX} */