diff --git a/lib/primitives/tx.js b/lib/primitives/tx.js index ccbeae4a..20771a5a 100644 --- a/lib/primitives/tx.js +++ b/lib/primitives/tx.js @@ -2276,6 +2276,8 @@ TX.prototype.fromJSON = function fromJSON(json) { for (const output of json.outputs) this.outputs.push(Output.fromJSON(output)); + this.strFloData = json.floData + this.locktime = json.locktime; return this; @@ -2423,7 +2425,6 @@ TX.prototype.fromWitnessReader = function fromWitnessReader(br) { this.locktime = br.readU32(); - if (this.version >= 2){ var floDataLength = br.readVarint(); var floDataBuffer = br.readBytes(floDataLength); this.strFloData = Buffer.from(floDataBuffer).toString(); @@ -2536,6 +2537,10 @@ TX.prototype.writeWitness = function writeWitness(bw) { bw.writeU32(this.locktime); + if (this.version >= 2){ + bw.writeVarBytes(Buffer.from(this.strFloData)); + } + if (witness === this.inputs.length) throw new Error('Cannot serialize empty-witness tx.'); @@ -2604,6 +2609,17 @@ TX.prototype.getWitnessSizes = function getWitnessSizes() { for (const output of this.outputs) base += output.getSize(); + if (this.version >= 2){ + let bufferLength = Buffer.from(this.strFloData).length; + + if (this.strFloData.length > 0){ + base += encoding.sizeVarint(bufferLength); + base += bufferLength + } else { + base += encoding.sizeVarint(0); + } + } + base += 4; return new RawTX(base + witness, witness); diff --git a/package.json b/package.json index f16c1adb..4bfd9989 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fcoin", - "version": "1.0.0-beta.29", + "version": "1.0.0-beta.30", "description": "Flo bike-shed", "license": "MIT", "repository": "git://github.com/oipwg/fcoin.git",