Gabe Gattis
8 years ago
No known key found for this signature in database
GPG Key ID: 441430987182732C
5 changed files with
26 additions and
4 deletions
-
lib/block/blockheader.js
-
lib/encoding/bufferreader.js
-
lib/transaction/transaction.js
-
test/block/blockheader.js
-
test/transaction/transaction.js
|
|
@ -136,7 +136,7 @@ BlockHeader.fromString = function fromString(str) { |
|
|
|
*/ |
|
|
|
BlockHeader._fromBufferReader = function _fromBufferReader(br) { |
|
|
|
var info = {}; |
|
|
|
info.version = br.readUInt32LE(); |
|
|
|
info.version = br.readInt32LE(); |
|
|
|
info.prevHash = br.read(32); |
|
|
|
info.merkleRoot = br.read(32); |
|
|
|
info.time = br.readUInt32LE(); |
|
|
@ -191,7 +191,7 @@ BlockHeader.prototype.toBufferWriter = function toBufferWriter(bw) { |
|
|
|
if (!bw) { |
|
|
|
bw = new BufferWriter(); |
|
|
|
} |
|
|
|
bw.writeUInt32LE(this.version); |
|
|
|
bw.writeInt32LE(this.version); |
|
|
|
bw.write(this.prevHash); |
|
|
|
bw.write(this.merkleRoot); |
|
|
|
bw.writeUInt32LE(this.time); |
|
|
|
|
|
@ -83,6 +83,12 @@ BufferReader.prototype.readUInt32LE = function() { |
|
|
|
return val; |
|
|
|
}; |
|
|
|
|
|
|
|
BufferReader.prototype.readInt32LE = function() { |
|
|
|
var val = this.buf.readInt32LE(this.pos); |
|
|
|
this.pos = this.pos + 4; |
|
|
|
return val; |
|
|
|
}; |
|
|
|
|
|
|
|
BufferReader.prototype.readUInt64BEBN = function() { |
|
|
|
var buf = this.buf.slice(this.pos, this.pos + 8); |
|
|
|
var bn = BN.fromBuffer(buf); |
|
|
|
|
|
@ -279,7 +279,7 @@ Transaction.prototype.toBuffer = function() { |
|
|
|
}; |
|
|
|
|
|
|
|
Transaction.prototype.toBufferWriter = function(writer) { |
|
|
|
writer.writeUInt32LE(this.version); |
|
|
|
writer.writeInt32LE(this.version); |
|
|
|
writer.writeVarintNum(this.inputs.length); |
|
|
|
_.each(this.inputs, function(input) { |
|
|
|
input.toBufferWriter(writer); |
|
|
@ -301,7 +301,7 @@ Transaction.prototype.fromBufferReader = function(reader) { |
|
|
|
$.checkArgument(!reader.finished(), 'No transaction data received'); |
|
|
|
var i, sizeTxIns, sizeTxOuts; |
|
|
|
|
|
|
|
this.version = reader.readUInt32LE(); |
|
|
|
this.version = reader.readInt32LE(); |
|
|
|
sizeTxIns = reader.readVarintNum(); |
|
|
|
for (i = 0; i < sizeTxIns; i++) { |
|
|
|
var input = Input.fromBufferReader(reader); |
|
|
|
|
|
@ -79,6 +79,16 @@ describe('BlockHeader', function() { |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
describe('version', function() { |
|
|
|
it('is interpreted as an int32le', function() { |
|
|
|
var hex = 'ffffffff00000000000000000000000000000000000000000000000000000000000000004141414141414141414141414141414141414141414141414141414141414141010000000200000003000000'; |
|
|
|
var header = BlockHeader.fromBuffer(new Buffer(hex, 'hex')); |
|
|
|
header.version.should.equal(-1); |
|
|
|
header.timestamp.should.equal(1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('#fromObject', function() { |
|
|
|
|
|
|
|
it('should set all the variables', function() { |
|
|
|
|
|
@ -28,6 +28,12 @@ describe('Transaction', function() { |
|
|
|
transaction.uncheckedSerialize().should.equal(tx_1_hex); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should parse the version as a signed integer', function () { |
|
|
|
var transaction = Transaction('ffffffff0000ffffffff') |
|
|
|
transaction.version.should.equal(-1); |
|
|
|
transaction.nLockTime.should.equal(0xffffffff); |
|
|
|
}); |
|
|
|
|
|
|
|
it('fails if an invalid parameter is passed to constructor', function() { |
|
|
|
expect(function() { |
|
|
|
return new Transaction(1); |
|
|
|