block: use Transaction.fromBuffer

This commit is contained in:
Daniel Cousens 2015-02-19 18:59:56 +11:00
parent 23bae5748e
commit 50dab3b6bf

View file

@ -39,46 +39,17 @@ Block.fromBuffer = function(buffer) {
if (buffer.length === 80) return block
function readUInt64() {
var i = bufferutils.readUInt64LE(buffer, offset)
offset += 8
return i
}
function readVarInt() {
var vi = bufferutils.readVarInt(buffer, offset)
offset += vi.size
return vi.number
}
function readScript() {
return Script.fromBuffer(readSlice(readVarInt()))
}
// FIXME: poor performance
function readTransaction() {
var tx = new Transaction()
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()
var tx = Transaction.fromBuffer(buffer.slice(offset), true)
offset += tx.toBuffer().length
return tx
}