Serialize & Deserialize Tx Data properly

This commit is contained in:
Sky Young 2018-05-09 14:33:46 -07:00
parent 9746bf81b5
commit 8e72b51c43

View File

@ -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;
};