|
|
@ -4,15 +4,15 @@ var BufferWriter = require('./bufferwriter'); |
|
|
|
var BufferReader = require('./bufferreader'); |
|
|
|
var Varint = require('./varint'); |
|
|
|
|
|
|
|
var Transaction = function Transaction(version, txinsvarint, txins, txoutsvarint, txouts, nlocktime) { |
|
|
|
var Transaction = function Transaction(version, txinsvi, txins, txoutsvi, txouts, nlocktime) { |
|
|
|
if (!(this instanceof Transaction)) |
|
|
|
return new Transaction(version, txinsvarint, txins, txoutsvarint, txouts, nlocktime); |
|
|
|
return new Transaction(version, txinsvi, txins, txoutsvi, txouts, nlocktime); |
|
|
|
if (typeof version === 'number') { |
|
|
|
this.set({ |
|
|
|
version: version, |
|
|
|
txinsvarint: txinsvarint, |
|
|
|
txinsvi: txinsvi, |
|
|
|
txins: txins, |
|
|
|
txoutsvarint: txoutsvarint, |
|
|
|
txoutsvi: txoutsvi, |
|
|
|
txouts: txouts, |
|
|
|
nlocktime: nlocktime |
|
|
|
}); |
|
|
@ -24,9 +24,9 @@ var Transaction = function Transaction(version, txinsvarint, txins, txoutsvarint |
|
|
|
|
|
|
|
Transaction.prototype.set = function(obj) { |
|
|
|
this.version = typeof obj.version !== 'undefined' ? obj.version : this.version; |
|
|
|
this.txinsvarint = obj.txinsvarint || this.txinsvarint; |
|
|
|
this.txinsvi = obj.txinsvi || this.txinsvi; |
|
|
|
this.txins = obj.txins || this.txins; |
|
|
|
this.txoutsvarint = obj.txoutsvarint || this.txoutsvarint; |
|
|
|
this.txoutsvi = obj.txoutsvi || this.txoutsvi; |
|
|
|
this.txouts = obj.txouts || this.txouts; |
|
|
|
this.nlocktime = typeof obj.nlocktime !== 'undefined' ? obj.nlocktime : this.nlocktime; |
|
|
|
return this; |
|
|
@ -38,14 +38,14 @@ Transaction.prototype.fromBuffer = function(buf) { |
|
|
|
|
|
|
|
Transaction.prototype.fromBufferReader = function(br) { |
|
|
|
this.version = br.readUInt32LE(); |
|
|
|
this.txinsvarint = Varint(br.readVarintBuf()); |
|
|
|
var txinsnum = this.txinsvarint.toNumber(); |
|
|
|
this.txinsvi = Varint(br.readVarintBuf()); |
|
|
|
var txinsnum = this.txinsvi.toNumber(); |
|
|
|
this.txins = []; |
|
|
|
for (var i = 0; i < txinsnum; i++) { |
|
|
|
this.txins.push(Txin().fromBufferReader(br)); |
|
|
|
} |
|
|
|
this.txoutsvarint = Varint(br.readVarintBuf()); |
|
|
|
var txoutsnum = this.txoutsvarint.toNumber(); |
|
|
|
this.txoutsvi = Varint(br.readVarintBuf()); |
|
|
|
var txoutsnum = this.txoutsvi.toNumber(); |
|
|
|
this.txouts = []; |
|
|
|
for (var i = 0; i < txoutsnum; i++) { |
|
|
|
this.txouts.push(Txout().fromBufferReader(br)); |
|
|
@ -62,11 +62,11 @@ Transaction.prototype.toBufferWriter = function(bw) { |
|
|
|
if (!bw) |
|
|
|
bw = new BufferWriter(); |
|
|
|
bw.writeUInt32LE(this.version); |
|
|
|
bw.write(this.txinsvarint.buf); |
|
|
|
bw.write(this.txinsvi.buf); |
|
|
|
for (var i = 0; i < this.txins.length; i++) { |
|
|
|
this.txins[i].toBufferWriter(bw); |
|
|
|
} |
|
|
|
bw.write(this.txoutsvarint.buf) |
|
|
|
bw.write(this.txoutsvi.buf) |
|
|
|
for (var i = 0; i < this.txouts.length; i++) { |
|
|
|
this.txouts[i].toBufferWriter(bw); |
|
|
|
} |
|
|
|