|
@ -4,15 +4,15 @@ var BufferWriter = require('./bufferwriter'); |
|
|
var Blockheader = require('./blockheader'); |
|
|
var Blockheader = require('./blockheader'); |
|
|
var Varint = require('./varint'); |
|
|
var Varint = require('./varint'); |
|
|
|
|
|
|
|
|
var Block = function Block(magicnum, blocksize, blockheader, txsvarint, txs) { |
|
|
var Block = function Block(magicnum, blocksize, blockheader, txsvi, txs) { |
|
|
if (!(this instanceof Block)) |
|
|
if (!(this instanceof Block)) |
|
|
return new Block(magicnum, blocksize, blockheader, txsvarint, txs); |
|
|
return new Block(magicnum, blocksize, blockheader, txsvi, txs); |
|
|
if (typeof magicnum === 'number') { |
|
|
if (typeof magicnum === 'number') { |
|
|
this.set({ |
|
|
this.set({ |
|
|
magicnum: magicnum, |
|
|
magicnum: magicnum, |
|
|
blocksize: blocksize, |
|
|
blocksize: blocksize, |
|
|
blockheader: blockheader, |
|
|
blockheader: blockheader, |
|
|
txsvarint: txsvarint, |
|
|
txsvi: txsvi, |
|
|
txs: txs |
|
|
txs: txs |
|
|
}); |
|
|
}); |
|
|
} else if (magicnum) { |
|
|
} else if (magicnum) { |
|
@ -24,7 +24,7 @@ Block.prototype.set = function(obj) { |
|
|
this.magicnum = typeof obj.magicnum !== 'undefined' ? obj.magicnum : this.magicnum; |
|
|
this.magicnum = typeof obj.magicnum !== 'undefined' ? obj.magicnum : this.magicnum; |
|
|
this.blocksize = typeof obj.blocksize !== 'undefined' ? obj.blocksize : this.blocksize; |
|
|
this.blocksize = typeof obj.blocksize !== 'undefined' ? obj.blocksize : this.blocksize; |
|
|
this.blockheader = obj.blockheader || this.blockheader; |
|
|
this.blockheader = obj.blockheader || this.blockheader; |
|
|
this.txsvarint = obj.txsvarint || this.txsvarint; |
|
|
this.txsvi = obj.txsvi || this.txsvi; |
|
|
this.txs = obj.txs || this.txs; |
|
|
this.txs = obj.txs || this.txs; |
|
|
return this; |
|
|
return this; |
|
|
}; |
|
|
}; |
|
@ -37,8 +37,8 @@ Block.prototype.fromBufferReader = function(br) { |
|
|
this.magicnum = br.readUInt32LE(); |
|
|
this.magicnum = br.readUInt32LE(); |
|
|
this.blocksize = br.readUInt32LE(); |
|
|
this.blocksize = br.readUInt32LE(); |
|
|
this.blockheader = Blockheader().fromBufferReader(br); |
|
|
this.blockheader = Blockheader().fromBufferReader(br); |
|
|
this.txsvarint = Varint(br.readVarintBuf()); |
|
|
this.txsvi = Varint(br.readVarintBuf()); |
|
|
var txslen = this.txsvarint.toNumber(); |
|
|
var txslen = this.txsvi.toNumber(); |
|
|
this.txs = []; |
|
|
this.txs = []; |
|
|
for (var i = 0; i < txslen; i++) { |
|
|
for (var i = 0; i < txslen; i++) { |
|
|
this.txs.push(Transaction().fromBufferReader(br)); |
|
|
this.txs.push(Transaction().fromBufferReader(br)); |
|
@ -56,8 +56,8 @@ Block.prototype.toBufferWriter = function(bw) { |
|
|
bw.writeUInt32LE(this.magicnum); |
|
|
bw.writeUInt32LE(this.magicnum); |
|
|
bw.writeUInt32LE(this.blocksize); |
|
|
bw.writeUInt32LE(this.blocksize); |
|
|
bw.write(this.blockheader.toBuffer()); |
|
|
bw.write(this.blockheader.toBuffer()); |
|
|
bw.write(this.txsvarint.buf); |
|
|
bw.write(this.txsvi.buf); |
|
|
var txslen = this.txsvarint.toNumber(); |
|
|
var txslen = this.txsvi.toNumber(); |
|
|
for (var i = 0; i < txslen; i++) { |
|
|
for (var i = 0; i < txslen; i++) { |
|
|
this.txs[i].toBufferWriter(bw); |
|
|
this.txs[i].toBufferWriter(bw); |
|
|
} |
|
|
} |
|
|