From fef6643742a132b924affa279b8801df67341b5e Mon Sep 17 00:00:00 2001 From: Sky Young Date: Mon, 9 Sep 2019 15:24:18 -0600 Subject: [PATCH 1/2] Handle floData as a Buffer everywhere --- lib/primitives/tx.js | 49 +++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/lib/primitives/tx.js b/lib/primitives/tx.js index 5882f79e..b6606736 100644 --- a/lib/primitives/tx.js +++ b/lib/primitives/tx.js @@ -50,7 +50,7 @@ class TX { this.outputs = []; this.locktime = 0; - this.strFloData = ""; + this.floData = Buffer.alloc(0); this.mutable = false; @@ -145,7 +145,7 @@ class TX { for (const output of tx.outputs) this.outputs.push(output.clone()); - this.strFloData = tx.strFloData; + this.floData = tx.floData; this.locktime = tx.locktime; @@ -577,7 +577,7 @@ class TX { bw.writeU32(this.locktime); if (this.version >= 2 && includeFloData) { - bw.writeVarBytes(Buffer.from(this.strFloData)); + bw.writeVarBytes(this.floData); } // Append the hash type. @@ -629,8 +629,8 @@ class TX { break; } - if (includeFloData){ - let bufferLength = Buffer.from(this.strFloData).length; + if (this.version >= 2 && includeFloData){ + let bufferLength = this.floData.length; size += encoding.sizeVarint(bufferLength); size += bufferLength @@ -735,7 +735,7 @@ class TX { // Add the FloData to the transaction if (this.version >= 2 && includeFloData) { - bw.writeVarBytes(Buffer.from(this.strFloData)); + bw.writeVarBytes(this.floData); } bw.writeU32(type); @@ -2157,7 +2157,7 @@ class TX { }), outputs: this.outputs, locktime: this.locktime, - floData: this.strFloData + floData: this.floData.toString() }; } @@ -2225,7 +2225,7 @@ class TX { }), locktime: this.locktime, hex: this.toRaw().toString('hex'), - floData: this.strFloData + floData: this.floData }; } @@ -2251,7 +2251,7 @@ class TX { for (const output of json.outputs) this.outputs.push(Output.fromJSON(output)); - this.strFloData = json.floData + this.floData = json.floData this.locktime = json.locktime; @@ -2336,8 +2336,7 @@ class TX { } if (this.version >= 2){ - let floDataBuffer = br.readVarBytes(); - this.strFloData = Buffer.from(floDataBuffer).toString(); + this.floData = br.readVarBytes(); } if (!this.mutable) { @@ -2408,9 +2407,7 @@ class TX { this.locktime = br.readU32(); if (this.version >= 2){ - var floDataLength = br.readVarint(); - var floDataBuffer = br.readBytes(floDataLength); - this.strFloData = Buffer.from(floDataBuffer).toString(); + this.floData = br.readVarBytes(); } if (block) { @@ -2484,7 +2481,7 @@ class TX { bw.writeU32(this.locktime); if (this.version >= 2){ - bw.writeVarBytes(Buffer.from(this.strFloData)); + bw.writeVarBytes(this.floData); } return bw; @@ -2526,7 +2523,7 @@ class TX { bw.writeU32(this.locktime); if (this.version >= 2){ - bw.writeVarBytes(Buffer.from(this.strFloData)); + bw.writeVarBytes(this.floData); } if (witness === this.inputs.length) @@ -2557,14 +2554,8 @@ class TX { 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 += encoding.sizeVarint(this.floData.length); + base += this.floData.length } base += 4; @@ -2598,14 +2589,8 @@ class TX { 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 += encoding.sizeVarint(this.floData.length); + base += this.floData.length } base += 4; From c9410e950963012d8bf4d731d540b002a8fd786a Mon Sep 17 00:00:00 2001 From: Sky Young Date: Mon, 9 Sep 2019 15:30:58 -0600 Subject: [PATCH 2/2] Update to v1.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 08fb225e..f1cb99e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fcoin", - "version": "1.1.0", + "version": "1.1.1", "description": "FLO bike-shed", "license": "MIT", "repository": "git://github.com/oipwg/fcoin.git",