Add in floData to other Witness serizliation/deserialization functions

This commit is contained in:
Sky Young 2018-10-20 13:03:53 -06:00
parent ecde63c8d8
commit 92184992ea
2 changed files with 18 additions and 2 deletions

View File

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

View File

@ -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",