block: use Transaction.fromBuffer
This commit is contained in:
parent
23bae5748e
commit
50dab3b6bf
1 changed files with 3 additions and 32 deletions
35
src/block.js
35
src/block.js
|
@ -39,46 +39,17 @@ Block.fromBuffer = function(buffer) {
|
||||||
|
|
||||||
if (buffer.length === 80) return block
|
if (buffer.length === 80) return block
|
||||||
|
|
||||||
function readUInt64() {
|
|
||||||
var i = bufferutils.readUInt64LE(buffer, offset)
|
|
||||||
offset += 8
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
function readVarInt() {
|
function readVarInt() {
|
||||||
var vi = bufferutils.readVarInt(buffer, offset)
|
var vi = bufferutils.readVarInt(buffer, offset)
|
||||||
offset += vi.size
|
offset += vi.size
|
||||||
return vi.number
|
return vi.number
|
||||||
}
|
}
|
||||||
|
|
||||||
function readScript() {
|
// FIXME: poor performance
|
||||||
return Script.fromBuffer(readSlice(readVarInt()))
|
|
||||||
}
|
|
||||||
|
|
||||||
function readTransaction() {
|
function readTransaction() {
|
||||||
var tx = new Transaction()
|
var tx = Transaction.fromBuffer(buffer.slice(offset), true)
|
||||||
tx.version = readUInt32()
|
|
||||||
|
|
||||||
var vinLen = readVarInt()
|
|
||||||
for (var i = 0; i < vinLen; ++i) {
|
|
||||||
tx.ins.push({
|
|
||||||
hash: readSlice(32),
|
|
||||||
index: readUInt32(),
|
|
||||||
script: readScript(),
|
|
||||||
sequence: readUInt32()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
var voutLen = readVarInt()
|
|
||||||
for (i = 0; i < voutLen; ++i) {
|
|
||||||
tx.outs.push({
|
|
||||||
value: readUInt64(),
|
|
||||||
script: readScript(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
tx.locktime = readUInt32()
|
|
||||||
|
|
||||||
|
offset += tx.toBuffer().length
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue