From c2baa09b1f5e93b69a6749edb1def8377ab9c626 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 6 Mar 2016 12:36:07 -0800 Subject: [PATCH] more serialization. --- lib/bcoin/tx.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 97fdffb4..e9046816 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -1075,18 +1075,26 @@ TX.prototype.toExtended = function toExtended(coins) { var buf = new Buffer(tx.length + 4 + 32 + 4 + 4 + 4); var block = this.block ? new Buffer(this.block, 'hex') : constants.zeroHash; var height = this.height; + var index = this.index; + var changeIndex = this.changeIndex != null ? this.changeIndex : -1; var off = 0; if (height === -1) height = 0x7fffffff; + if (index === -1) + index = 0x7fffffff; + + if (changeIndex === -1) + changeIndex = 0x7fffffff; + off += utils.copy(tx, buf, off); off += utils.writeU32(buf, height, off); off += utils.copy(block, buf, off); off += utils.writeU32(buf, this.index, off); off += utils.writeU32(buf, this.ts, off); off += utils.writeU32(buf, this.ps, off); - // off += utils.writeU32(buf, this.changeIndex || -1, off); + // off += utils.writeU32(buf, changeIndex, off); if (coins) { off += utils.writeIntv(buf, this.inputs.length, off); @@ -1131,6 +1139,8 @@ TX._fromExtended = function _fromExtended(buf, coins) { off += 4; tx.ps = utils.readU32(buf, off); off += 4; + // tx.changeIndex = utils.readU32(buf, off); + // off += 4; if (+tx.block === 0) tx.block = null; @@ -1138,6 +1148,12 @@ TX._fromExtended = function _fromExtended(buf, coins) { if (tx.height === 0x7fffffff) tx.height = -1; + if (tx.index === 0x7fffffff) + tx.index = -1; + + if (tx.changeIndex === 0x7fffffff) + tx.changeIndex = -1; + if (coins) { coinCount = utils.readIntv(buf, off); off = coinCount.off;