|
|
@ -39,7 +39,6 @@ function Transaction(serialized) { |
|
|
|
this.inputs = []; |
|
|
|
this.outputs = []; |
|
|
|
this.witness = []; |
|
|
|
this._hasWitness = false; |
|
|
|
this._inputAmount = undefined; |
|
|
|
this._outputAmount = undefined; |
|
|
|
|
|
|
@ -59,7 +58,6 @@ function Transaction(serialized) { |
|
|
|
this._newTransaction(); |
|
|
|
} |
|
|
|
} |
|
|
|
var SERIALIZE_TRANSACTION_WITNESS = 0x40000000; |
|
|
|
var CURRENT_VERSION = 1; |
|
|
|
var DEFAULT_NLOCKTIME = 0; |
|
|
|
var MAX_BLOCK_SIZE = 1000000; |
|
|
@ -293,15 +291,18 @@ Transaction.prototype.inspect = function() { |
|
|
|
return '<Transaction: ' + this.uncheckedSerialize() + '>'; |
|
|
|
}; |
|
|
|
|
|
|
|
Transaction.prototype.toBuffer = function(nonWitness) { |
|
|
|
Transaction.prototype.toBuffer = function(noWitness) { |
|
|
|
var writer = new BufferWriter(); |
|
|
|
return this.toBufferWriter(writer, nonWitness).toBuffer(); |
|
|
|
return this.toBufferWriter(writer, noWitness).toBuffer(); |
|
|
|
}; |
|
|
|
|
|
|
|
Transaction.prototype.toBufferWriter = function(writer, nonWitness) { |
|
|
|
writer.writeInt32LE(this.version); |
|
|
|
writer.writeUInt32LE(this.version); |
|
|
|
if (this._hasWitness && !nonWitness) { |
|
|
|
Transaction.prototype.hasWitness = function() { |
|
|
|
return this.witness && this.witness.length > 0; |
|
|
|
}; |
|
|
|
|
|
|
|
Transaction.prototype.toBufferWriter = function(writer, noWitness) { |
|
|
|
writer.writeInt32LE(this.version); |
|
|
|
if (this.hasWitness() && !noWitness) { |
|
|
|
writer.write(new Buffer('0001', 'hex')); |
|
|
|
} |
|
|
|
writer.writeVarintNum(this.inputs.length); |
|
|
@ -312,7 +313,7 @@ Transaction.prototype.toBufferWriter = function(writer, nonWitness) { |
|
|
|
_.each(this.outputs, function(output) { |
|
|
|
output.toBufferWriter(writer); |
|
|
|
}); |
|
|
|
if (this._hasWitness && !nonWitness) { |
|
|
|
if (this.hasWitness() && !noWitness) { |
|
|
|
this._toBufferWriterWitness(writer); |
|
|
|
} |
|
|
|
writer.writeUInt32LE(this.nLockTime); |
|
|
@ -339,10 +340,10 @@ Transaction.prototype.fromBufferReader = function(reader) { |
|
|
|
var sizeTxIns = reader.readVarintNum(); |
|
|
|
|
|
|
|
// check for segwit
|
|
|
|
this._hasWitness = false; |
|
|
|
var hasWitness = false; |
|
|
|
if (sizeTxIns === 0 && reader.buf[reader.pos] !== 0) { |
|
|
|
reader.pos += 1; |
|
|
|
this._hasWitness = true; |
|
|
|
hasWitness = true; |
|
|
|
sizeTxIns = reader.readVarintNum(); |
|
|
|
} |
|
|
|
|
|
|
@ -356,7 +357,7 @@ Transaction.prototype.fromBufferReader = function(reader) { |
|
|
|
this.outputs.push(Output.fromBufferReader(reader)); |
|
|
|
} |
|
|
|
|
|
|
|
if (this._hasWitness) { |
|
|
|
if (hasWitness) { |
|
|
|
this._fromBufferReaderScriptWitnesses(reader); |
|
|
|
} |
|
|
|
|
|
|
@ -366,6 +367,7 @@ Transaction.prototype.fromBufferReader = function(reader) { |
|
|
|
|
|
|
|
Transaction.prototype._fromBufferReaderScriptWitnesses = function(reader) { |
|
|
|
var itemCount = reader.readVarintNum(); |
|
|
|
this.witness = []; |
|
|
|
for (var i = 0; i < itemCount; i++) { |
|
|
|
var size = reader.readVarintNum(); |
|
|
|
var item = reader.read(size); |
|
|
|