From 8e72b51c43c539a71a723cb5944425b8465bab7f Mon Sep 17 00:00:00 2001 From: Sky Young Date: Wed, 9 May 2018 14:33:46 -0700 Subject: [PATCH] Serialize & Deserialize Tx Data properly --- lib/primitives/tx.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/primitives/tx.js b/lib/primitives/tx.js index 7e466ec0..3ba07b69 100644 --- a/lib/primitives/tx.js +++ b/lib/primitives/tx.js @@ -51,6 +51,8 @@ function TX(options) { this.outputs = []; this.locktime = 0; + this.strFloData = ""; + this.mutable = false; this._hash = null; @@ -140,6 +142,8 @@ TX.prototype.inject = function inject(tx) { for (const output of tx.outputs) this.outputs.push(output.clone()); + this.strFloData = tx.strFloData; + this.locktime = tx.locktime; return this; @@ -2290,6 +2294,11 @@ TX.prototype.fromReader = function fromReader(br) { this.locktime = br.readU32(); + if (this.version >= 2){ + var floDataBuffer = br.readVarBytes(); + this.floDataStr = Buffer.from(floDataBuffer).toString(); + } + if (!this.mutable) { this._raw = br.endData(); this._size = this._raw.length; @@ -2357,6 +2366,12 @@ TX.prototype.fromWitnessReader = function fromWitnessReader(br) { this.locktime = br.readU32(); + if (this.version >= 2){ + var floDataLength = br.readVarint(); + var floDataBuffer = br.readBytes(floDataLength); + this.floDataStr = Buffer.from(floDataBuffer).toString(); + } + if (!this.mutable && hasWitness) { this._raw = br.endData(); this._size = this._raw.length; @@ -2422,6 +2437,11 @@ TX.prototype.writeNormal = function writeNormal(bw) { bw.writeU32(this.locktime); + if (this.version >= 2){ + bw.writeVarint(this.strFloData); + bw.writeVarBytes(Buffer.from(this.strFloData)); + } + return bw; };