Serialize & Deserialize Tx Data properly
This commit is contained in:
parent
9746bf81b5
commit
8e72b51c43
@ -51,6 +51,8 @@ function TX(options) {
|
|||||||
this.outputs = [];
|
this.outputs = [];
|
||||||
this.locktime = 0;
|
this.locktime = 0;
|
||||||
|
|
||||||
|
this.strFloData = "";
|
||||||
|
|
||||||
this.mutable = false;
|
this.mutable = false;
|
||||||
|
|
||||||
this._hash = null;
|
this._hash = null;
|
||||||
@ -140,6 +142,8 @@ TX.prototype.inject = function inject(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.locktime = tx.locktime;
|
this.locktime = tx.locktime;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -2290,6 +2294,11 @@ TX.prototype.fromReader = function fromReader(br) {
|
|||||||
|
|
||||||
this.locktime = br.readU32();
|
this.locktime = br.readU32();
|
||||||
|
|
||||||
|
if (this.version >= 2){
|
||||||
|
var floDataBuffer = br.readVarBytes();
|
||||||
|
this.floDataStr = Buffer.from(floDataBuffer).toString();
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.mutable) {
|
if (!this.mutable) {
|
||||||
this._raw = br.endData();
|
this._raw = br.endData();
|
||||||
this._size = this._raw.length;
|
this._size = this._raw.length;
|
||||||
@ -2357,6 +2366,12 @@ TX.prototype.fromWitnessReader = function fromWitnessReader(br) {
|
|||||||
|
|
||||||
this.locktime = br.readU32();
|
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) {
|
if (!this.mutable && hasWitness) {
|
||||||
this._raw = br.endData();
|
this._raw = br.endData();
|
||||||
this._size = this._raw.length;
|
this._size = this._raw.length;
|
||||||
@ -2422,6 +2437,11 @@ TX.prototype.writeNormal = function writeNormal(bw) {
|
|||||||
|
|
||||||
bw.writeU32(this.locktime);
|
bw.writeU32(this.locktime);
|
||||||
|
|
||||||
|
if (this.version >= 2){
|
||||||
|
bw.writeVarint(this.strFloData);
|
||||||
|
bw.writeVarBytes(Buffer.from(this.strFloData));
|
||||||
|
}
|
||||||
|
|
||||||
return bw;
|
return bw;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user