Transaction: simplify fromBuffer verbosity
This commit is contained in:
parent
062540e3d9
commit
2234e496d1
1 changed files with 16 additions and 16 deletions
|
@ -113,14 +113,17 @@ Transaction.prototype.toBuffer = function () {
|
||||||
slice.copy(buffer, offset)
|
slice.copy(buffer, offset)
|
||||||
offset += slice.length
|
offset += slice.length
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeUInt32(i) {
|
function writeUInt32(i) {
|
||||||
buffer.writeUInt32LE(i, offset)
|
buffer.writeUInt32LE(i, offset)
|
||||||
offset += 4
|
offset += 4
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeUInt64(i) {
|
function writeUInt64(i) {
|
||||||
bufferutils.writeUInt64LE(buffer, i, offset)
|
bufferutils.writeUInt64LE(buffer, i, offset)
|
||||||
offset += 8
|
offset += 8
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeVarInt(i) {
|
function writeVarInt(i) {
|
||||||
var n = bufferutils.writeVarInt(buffer, i, offset)
|
var n = bufferutils.writeVarInt(buffer, i, offset)
|
||||||
offset += n
|
offset += n
|
||||||
|
@ -247,50 +250,47 @@ Transaction.fromBuffer = function(buffer) {
|
||||||
offset += n
|
offset += n
|
||||||
return buffer.slice(offset - n, offset)
|
return buffer.slice(offset - n, offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
function readUInt32() {
|
function readUInt32() {
|
||||||
var i = buffer.readUInt32LE(offset)
|
var i = buffer.readUInt32LE(offset)
|
||||||
offset += 4
|
offset += 4
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
function readUInt64() {
|
function readUInt64() {
|
||||||
var i = bufferutils.readUInt64LE(buffer, offset)
|
var i = bufferutils.readUInt64LE(buffer, offset)
|
||||||
offset += 8
|
offset += 8
|
||||||
return i
|
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() {
|
||||||
|
return Script.fromBuffer(readSlice(readVarInt()))
|
||||||
|
}
|
||||||
|
|
||||||
var tx = new Transaction()
|
var tx = new Transaction()
|
||||||
tx.version = readUInt32()
|
tx.version = readUInt32()
|
||||||
|
|
||||||
var vinLen = readVarInt()
|
var vinLen = readVarInt()
|
||||||
for (var i = 0; i < vinLen; ++i) {
|
for (var i = 0; i < vinLen; ++i) {
|
||||||
var hash = readSlice(32)
|
|
||||||
var vout = readUInt32()
|
|
||||||
var scriptLen = readVarInt()
|
|
||||||
var script = readSlice(scriptLen)
|
|
||||||
var sequence = readUInt32()
|
|
||||||
|
|
||||||
tx.ins.push({
|
tx.ins.push({
|
||||||
hash: hash,
|
hash: readSlice(32),
|
||||||
index: vout,
|
index: readUInt32(),
|
||||||
script: Script.fromBuffer(script),
|
script: readScript(),
|
||||||
sequence: sequence
|
sequence: readUInt32()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var voutLen = readVarInt()
|
var voutLen = readVarInt()
|
||||||
for (i = 0; i < voutLen; ++i) {
|
for (i = 0; i < voutLen; ++i) {
|
||||||
var value = readUInt64()
|
|
||||||
var scriptLen = readVarInt()
|
|
||||||
var script = readSlice(scriptLen)
|
|
||||||
|
|
||||||
tx.outs.push({
|
tx.outs.push({
|
||||||
value: value,
|
value: readUInt64(),
|
||||||
script: Script.fromBuffer(script)
|
script: readScript(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue