Handle floData as a Buffer everywhere

This commit is contained in:
Sky Young 2019-09-09 15:24:18 -06:00
parent 632b62986c
commit fef6643742

View File

@ -50,7 +50,7 @@ class TX {
this.outputs = []; this.outputs = [];
this.locktime = 0; this.locktime = 0;
this.strFloData = ""; this.floData = Buffer.alloc(0);
this.mutable = false; this.mutable = false;
@ -145,7 +145,7 @@ class TX {
for (const output of tx.outputs) for (const output of tx.outputs)
this.outputs.push(output.clone()); this.outputs.push(output.clone());
this.strFloData = tx.strFloData; this.floData = tx.floData;
this.locktime = tx.locktime; this.locktime = tx.locktime;
@ -577,7 +577,7 @@ class TX {
bw.writeU32(this.locktime); bw.writeU32(this.locktime);
if (this.version >= 2 && includeFloData) { if (this.version >= 2 && includeFloData) {
bw.writeVarBytes(Buffer.from(this.strFloData)); bw.writeVarBytes(this.floData);
} }
// Append the hash type. // Append the hash type.
@ -629,8 +629,8 @@ class TX {
break; break;
} }
if (includeFloData){ if (this.version >= 2 && includeFloData){
let bufferLength = Buffer.from(this.strFloData).length; let bufferLength = this.floData.length;
size += encoding.sizeVarint(bufferLength); size += encoding.sizeVarint(bufferLength);
size += bufferLength size += bufferLength
@ -735,7 +735,7 @@ class TX {
// Add the FloData to the transaction // Add the FloData to the transaction
if (this.version >= 2 && includeFloData) { if (this.version >= 2 && includeFloData) {
bw.writeVarBytes(Buffer.from(this.strFloData)); bw.writeVarBytes(this.floData);
} }
bw.writeU32(type); bw.writeU32(type);
@ -2157,7 +2157,7 @@ class TX {
}), }),
outputs: this.outputs, outputs: this.outputs,
locktime: this.locktime, locktime: this.locktime,
floData: this.strFloData floData: this.floData.toString()
}; };
} }
@ -2225,7 +2225,7 @@ class TX {
}), }),
locktime: this.locktime, locktime: this.locktime,
hex: this.toRaw().toString('hex'), hex: this.toRaw().toString('hex'),
floData: this.strFloData floData: this.floData
}; };
} }
@ -2251,7 +2251,7 @@ class TX {
for (const output of json.outputs) for (const output of json.outputs)
this.outputs.push(Output.fromJSON(output)); this.outputs.push(Output.fromJSON(output));
this.strFloData = json.floData this.floData = json.floData
this.locktime = json.locktime; this.locktime = json.locktime;
@ -2336,8 +2336,7 @@ class TX {
} }
if (this.version >= 2){ if (this.version >= 2){
let floDataBuffer = br.readVarBytes(); this.floData = br.readVarBytes();
this.strFloData = Buffer.from(floDataBuffer).toString();
} }
if (!this.mutable) { if (!this.mutable) {
@ -2408,9 +2407,7 @@ class TX {
this.locktime = br.readU32(); this.locktime = br.readU32();
if (this.version >= 2){ if (this.version >= 2){
var floDataLength = br.readVarint(); this.floData = br.readVarBytes();
var floDataBuffer = br.readBytes(floDataLength);
this.strFloData = Buffer.from(floDataBuffer).toString();
} }
if (block) { if (block) {
@ -2484,7 +2481,7 @@ class TX {
bw.writeU32(this.locktime); bw.writeU32(this.locktime);
if (this.version >= 2){ if (this.version >= 2){
bw.writeVarBytes(Buffer.from(this.strFloData)); bw.writeVarBytes(this.floData);
} }
return bw; return bw;
@ -2526,7 +2523,7 @@ class TX {
bw.writeU32(this.locktime); bw.writeU32(this.locktime);
if (this.version >= 2){ if (this.version >= 2){
bw.writeVarBytes(Buffer.from(this.strFloData)); bw.writeVarBytes(this.floData);
} }
if (witness === this.inputs.length) if (witness === this.inputs.length)
@ -2557,14 +2554,8 @@ class TX {
base += output.getSize(); base += output.getSize();
if (this.version >= 2){ if (this.version >= 2){
let bufferLength = Buffer.from(this.strFloData).length; base += encoding.sizeVarint(this.floData.length);
base += this.floData.length
if (this.strFloData.length > 0){
base += encoding.sizeVarint(bufferLength);
base += bufferLength
} else {
base += encoding.sizeVarint(0);
}
} }
base += 4; base += 4;
@ -2598,14 +2589,8 @@ class TX {
base += output.getSize(); base += output.getSize();
if (this.version >= 2){ if (this.version >= 2){
let bufferLength = Buffer.from(this.strFloData).length; base += encoding.sizeVarint(this.floData.length);
base += this.floData.length
if (this.strFloData.length > 0){
base += encoding.sizeVarint(bufferLength);
base += bufferLength
} else {
base += encoding.sizeVarint(0);
}
} }
base += 4; base += 4;