replace .buffer with .read
This commit is contained in:
parent
8e049b7244
commit
0212e4bd4c
|
@ -35,8 +35,8 @@ Blockheader.prototype.fromBuffer = function(buf) {
|
||||||
|
|
||||||
Blockheader.prototype.fromBufferReader = function(br) {
|
Blockheader.prototype.fromBufferReader = function(br) {
|
||||||
this.version = br.readUInt32LE();
|
this.version = br.readUInt32LE();
|
||||||
this.prevblockidbuf = br.buffer(32);
|
this.prevblockidbuf = br.read(32);
|
||||||
this.merklerootbuf = br.buffer(32);
|
this.merklerootbuf = br.read(32);
|
||||||
this.time = br.readUInt32LE();
|
this.time = br.readUInt32LE();
|
||||||
this.bits = br.readUInt32LE();
|
this.bits = br.readUInt32LE();
|
||||||
this.nonce = br.readUInt32LE();
|
this.nonce = br.readUInt32LE();
|
||||||
|
|
|
@ -22,10 +22,6 @@ BufferReader.prototype.eof = function() {
|
||||||
return this.pos >= this.buf.length;
|
return this.pos >= this.buf.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
BufferReader.prototype.buffer = function(len) {
|
|
||||||
return this.read(len);
|
|
||||||
};
|
|
||||||
|
|
||||||
BufferReader.prototype.read = function(len) {
|
BufferReader.prototype.read = function(len) {
|
||||||
if (!len)
|
if (!len)
|
||||||
var len = this.buf.length;
|
var len = this.buf.length;
|
||||||
|
@ -102,13 +98,13 @@ BufferReader.prototype.readVarintBuf = function() {
|
||||||
var first = this.buf.readUInt8(this.pos);
|
var first = this.buf.readUInt8(this.pos);
|
||||||
switch (first) {
|
switch (first) {
|
||||||
case 0xFD:
|
case 0xFD:
|
||||||
return this.buffer(1 + 2);
|
return this.read(1 + 2);
|
||||||
case 0xFE:
|
case 0xFE:
|
||||||
return this.buffer(1 + 4);
|
return this.read(1 + 4);
|
||||||
case 0xFF:
|
case 0xFF:
|
||||||
return this.buffer(1 + 8);
|
return this.read(1 + 8);
|
||||||
default:
|
default:
|
||||||
return this.buffer(1);
|
return this.read(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -37,13 +37,13 @@ Script.prototype.fromBuffer = function(buf) {
|
||||||
if (opcodenum > 0 && opcodenum < Opcode.map.OP_PUSHDATA1) {
|
if (opcodenum > 0 && opcodenum < Opcode.map.OP_PUSHDATA1) {
|
||||||
len = opcodenum;
|
len = opcodenum;
|
||||||
this.chunks.push({
|
this.chunks.push({
|
||||||
buf: br.buffer(len),
|
buf: br.read(len),
|
||||||
len: len,
|
len: len,
|
||||||
opcodenum: opcodenum
|
opcodenum: opcodenum
|
||||||
});
|
});
|
||||||
} else if (opcodenum === Opcode.map.OP_PUSHDATA1) {
|
} else if (opcodenum === Opcode.map.OP_PUSHDATA1) {
|
||||||
len = br.readUInt8();
|
len = br.readUInt8();
|
||||||
var buf = br.buffer(len);
|
var buf = br.read(len);
|
||||||
this.chunks.push({
|
this.chunks.push({
|
||||||
buf: buf,
|
buf: buf,
|
||||||
len: len,
|
len: len,
|
||||||
|
@ -51,7 +51,7 @@ Script.prototype.fromBuffer = function(buf) {
|
||||||
});
|
});
|
||||||
} else if (opcodenum === Opcode.map.OP_PUSHDATA2) {
|
} else if (opcodenum === Opcode.map.OP_PUSHDATA2) {
|
||||||
len = br.readUInt16LE();
|
len = br.readUInt16LE();
|
||||||
buf = br.buffer(len);
|
buf = br.read(len);
|
||||||
this.chunks.push({
|
this.chunks.push({
|
||||||
buf: buf,
|
buf: buf,
|
||||||
len: len,
|
len: len,
|
||||||
|
@ -59,7 +59,7 @@ Script.prototype.fromBuffer = function(buf) {
|
||||||
});
|
});
|
||||||
} else if (opcodenum === Opcode.map.OP_PUSHDATA4) {
|
} else if (opcodenum === Opcode.map.OP_PUSHDATA4) {
|
||||||
len = br.readUInt32LE();
|
len = br.readUInt32LE();
|
||||||
buf = br.buffer(len);
|
buf = br.read(len);
|
||||||
this.chunks.push({
|
this.chunks.push({
|
||||||
buf: buf,
|
buf: buf,
|
||||||
len: len,
|
len: len,
|
||||||
|
|
|
@ -32,10 +32,10 @@ Txin.prototype.fromBuffer = function(buf) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Txin.prototype.fromBufferReader = function(br) {
|
Txin.prototype.fromBufferReader = function(br) {
|
||||||
this.txidbuf = br.buffer(32);
|
this.txidbuf = br.read(32);
|
||||||
this.txoutnum = br.readUInt32LE();
|
this.txoutnum = br.readUInt32LE();
|
||||||
this.varint = Varint(br.readVarintBuf());
|
this.varint = Varint(br.readVarintBuf());
|
||||||
this.script = Script().fromBuffer(br.buffer(this.varint.toNumber()));
|
this.script = Script().fromBuffer(br.read(this.varint.toNumber()));
|
||||||
this.seqnum = br.readUInt32LE();
|
this.seqnum = br.readUInt32LE();
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,7 +33,7 @@ Txout.prototype.fromBuffer = function(buf) {
|
||||||
Txout.prototype.fromBufferReader = function(br) {
|
Txout.prototype.fromBufferReader = function(br) {
|
||||||
this.valuebn = br.readUInt64LEBN();
|
this.valuebn = br.readUInt64LEBN();
|
||||||
this.varint = Varint(br.readVarintNum());
|
this.varint = Varint(br.readVarintNum());
|
||||||
this.script = Script().fromBuffer(br.buffer(this.varint.toNumber()));
|
this.script = Script().fromBuffer(br.read(this.varint.toNumber()));
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -36,20 +36,6 @@ describe('BufferReader', function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#buffer', function() {
|
|
||||||
|
|
||||||
it('should return a buffer of this length', function() {
|
|
||||||
var buf = new Buffer(10);
|
|
||||||
buf.fill(0);
|
|
||||||
var br = new BufferReader(buf);
|
|
||||||
var buf2 = br.buffer(2);
|
|
||||||
buf2.length.should.equal(2);
|
|
||||||
br.eof().should.equal(false);
|
|
||||||
br.pos.should.equal(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('read', function() {
|
describe('read', function() {
|
||||||
|
|
||||||
it('should return the same buffer', function() {
|
it('should return the same buffer', function() {
|
||||||
|
|
Loading…
Reference in New Issue