|
@ -38,6 +38,8 @@ function Transaction(serialized) { |
|
|
} |
|
|
} |
|
|
this.inputs = []; |
|
|
this.inputs = []; |
|
|
this.outputs = []; |
|
|
this.outputs = []; |
|
|
|
|
|
this.witness = []; |
|
|
|
|
|
this._hasWitness = false; |
|
|
this._inputAmount = undefined; |
|
|
this._inputAmount = undefined; |
|
|
this._outputAmount = undefined; |
|
|
this._outputAmount = undefined; |
|
|
|
|
|
|
|
@ -57,7 +59,7 @@ function Transaction(serialized) { |
|
|
this._newTransaction(); |
|
|
this._newTransaction(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
var SERIALIZE_TRANSACTION_WITNESS = 0x40000000; |
|
|
var CURRENT_VERSION = 1; |
|
|
var CURRENT_VERSION = 1; |
|
|
var DEFAULT_NLOCKTIME = 0; |
|
|
var DEFAULT_NLOCKTIME = 0; |
|
|
var MAX_BLOCK_SIZE = 1000000; |
|
|
var MAX_BLOCK_SIZE = 1000000; |
|
@ -299,22 +301,45 @@ Transaction.prototype.fromBuffer = function(buffer) { |
|
|
|
|
|
|
|
|
Transaction.prototype.fromBufferReader = function(reader) { |
|
|
Transaction.prototype.fromBufferReader = function(reader) { |
|
|
$.checkArgument(!reader.finished(), 'No transaction data received'); |
|
|
$.checkArgument(!reader.finished(), 'No transaction data received'); |
|
|
var i, sizeTxIns, sizeTxOuts; |
|
|
|
|
|
|
|
|
|
|
|
this.version = reader.readInt32LE(); |
|
|
this.version = reader.readInt32LE(); |
|
|
sizeTxIns = reader.readVarintNum(); |
|
|
var sizeTxIns = reader.readVarintNum(); |
|
|
for (i = 0; i < sizeTxIns; i++) { |
|
|
|
|
|
|
|
|
// check for segwit
|
|
|
|
|
|
this._hasWitness = false; |
|
|
|
|
|
if (sizeTxIns === 0 && reader.buf[reader.pos] !== 0) { |
|
|
|
|
|
reader.pos += 1; |
|
|
|
|
|
this._hasWitness = true; |
|
|
|
|
|
sizeTxIns = reader.readVarintNum(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < sizeTxIns; i++) { |
|
|
var input = Input.fromBufferReader(reader); |
|
|
var input = Input.fromBufferReader(reader); |
|
|
this.inputs.push(input); |
|
|
this.inputs.push(input); |
|
|
} |
|
|
} |
|
|
sizeTxOuts = reader.readVarintNum(); |
|
|
|
|
|
for (i = 0; i < sizeTxOuts; i++) { |
|
|
var sizeTxOuts = reader.readVarintNum(); |
|
|
|
|
|
for (var j = 0; j < sizeTxOuts; j++) { |
|
|
this.outputs.push(Output.fromBufferReader(reader)); |
|
|
this.outputs.push(Output.fromBufferReader(reader)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this._hasWitness) { |
|
|
|
|
|
this._fromBufferReaderScriptWitnesses(reader); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.nLockTime = reader.readUInt32LE(); |
|
|
this.nLockTime = reader.readUInt32LE(); |
|
|
return this; |
|
|
return this; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Transaction.prototype._fromBufferReaderScriptWitnesses = function(reader) { |
|
|
|
|
|
var itemCount = reader.readVarintNum(); |
|
|
|
|
|
for (var i = 0; i < itemCount; i++) { |
|
|
|
|
|
var size = reader.readVarintNum(); |
|
|
|
|
|
var item = reader.read(size); |
|
|
|
|
|
this.witness.push(item); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
Transaction.prototype.toObject = Transaction.prototype.toJSON = function toObject() { |
|
|
Transaction.prototype.toObject = Transaction.prototype.toJSON = function toObject() { |
|
|
var inputs = []; |
|
|
var inputs = []; |
|
|
this.inputs.forEach(function(input) { |
|
|
this.inputs.forEach(function(input) { |
|
|