tx: serialization.
This commit is contained in:
parent
dc0cbc3637
commit
d73c80c21d
@ -2397,26 +2397,31 @@ TX.isWitness = function isWitness(data) {
|
||||
|
||||
TX.prototype.toExtended = function toExtended(saveCoins, writer) {
|
||||
var p = BufferWriter(writer);
|
||||
var height = this.height;
|
||||
var index = this.index;
|
||||
var i, input, field, bit, oct;
|
||||
|
||||
this.toRaw(p);
|
||||
|
||||
p.writeU32(this.ps);
|
||||
|
||||
if (this.height !== -1) {
|
||||
assert(this.block != null);
|
||||
assert(this.height !== -1);
|
||||
assert(this.index !== -1);
|
||||
assert(this.ts !== 0);
|
||||
if (this.block) {
|
||||
p.writeU8(1);
|
||||
p.writeHash(this.block);
|
||||
p.writeU32(this.height);
|
||||
p.writeU32(this.ts);
|
||||
p.writeU32(this.index);
|
||||
} else {
|
||||
p.writeU8(0);
|
||||
}
|
||||
|
||||
if (height === -1)
|
||||
height = 0x7fffffff;
|
||||
|
||||
if (index === -1)
|
||||
index = 0x7fffffff;
|
||||
|
||||
p.writeU32(height);
|
||||
p.writeU32(this.ts);
|
||||
p.writeU32(index);
|
||||
|
||||
if (saveCoins) {
|
||||
field = new Buffer(Math.ceil(this.inputs.length / 8));
|
||||
field.fill(0);
|
||||
@ -2458,12 +2463,18 @@ TX.prototype.fromExtended = function fromExtended(data, saveCoins) {
|
||||
|
||||
this.ps = p.readU32();
|
||||
|
||||
if (p.readU8() == 1) {
|
||||
if (p.readU8() == 1)
|
||||
this.block = p.readHash('hex');
|
||||
this.height = p.readU32();
|
||||
this.ts = p.readU32();
|
||||
this.index = p.readU32();
|
||||
}
|
||||
|
||||
this.height = p.readU32();
|
||||
this.ts = p.readU32();
|
||||
this.index = p.readU32();
|
||||
|
||||
if (this.height === 0x7fffffff)
|
||||
this.height = -1;
|
||||
|
||||
if (this.index === 0x7fffffff)
|
||||
this.index = -1;
|
||||
|
||||
if (saveCoins) {
|
||||
field = p.readBytes(Math.ceil(this.inputs.length / 8), true);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user