tx parsing.
This commit is contained in:
parent
3e13badc7a
commit
0a9ce90b84
@ -2127,7 +2127,7 @@ TX.fromRaw = function fromRaw(data, enc) {
|
||||
*/
|
||||
|
||||
TX.prototype.fromRaw = function fromRaw(data) {
|
||||
var p, i, inCount, outCount, input;
|
||||
var p, i, inCount, outCount;
|
||||
|
||||
if (TX.isWitness(data))
|
||||
return this.fromWitness(data);
|
||||
@ -2139,11 +2139,8 @@ TX.prototype.fromRaw = function fromRaw(data) {
|
||||
|
||||
inCount = p.readVarint();
|
||||
|
||||
for (i = 0; i < inCount; i++) {
|
||||
input = bcoin.input.fromRaw(p);
|
||||
input.witness = new bcoin.witness();
|
||||
this.inputs.push(input);
|
||||
}
|
||||
for (i = 0; i < inCount; i++)
|
||||
this.inputs.push(bcoin.input.fromRaw(p));
|
||||
|
||||
outCount = p.readVarint();
|
||||
|
||||
@ -2170,11 +2167,12 @@ TX.prototype.fromRaw = function fromRaw(data) {
|
||||
|
||||
TX.prototype.fromWitness = function fromWitness(data) {
|
||||
var p = bcoin.reader(data);
|
||||
var i, marker, inCount, outCount, witness, hasWitness, witnessSize;
|
||||
var i, marker, inCount, outCount, input, hasWitness, witnessSize;
|
||||
|
||||
p.start();
|
||||
|
||||
this.version = p.readU32(); // Technically signed
|
||||
|
||||
marker = p.readU8();
|
||||
this.flag = p.readU8();
|
||||
|
||||
@ -2197,9 +2195,9 @@ TX.prototype.fromWitness = function fromWitness(data) {
|
||||
p.start();
|
||||
|
||||
for (i = 0; i < inCount; i++) {
|
||||
witness = bcoin.witness.fromRaw(p);
|
||||
this.inputs[i].witness = witness;
|
||||
if (witness.items.length > 0)
|
||||
input = this.inputs[i];
|
||||
input.witness.fromRaw(p);
|
||||
if (input.witness.items.length > 0)
|
||||
hasWitness = true;
|
||||
}
|
||||
|
||||
@ -2251,6 +2249,9 @@ TX.prototype.frameNormal = function frameNormal(writer) {
|
||||
var p = bcoin.writer(writer);
|
||||
var i;
|
||||
|
||||
if (this.inputs.length === 0 && this.outputs.length === 1)
|
||||
throw new Error('Cannot serialize zero-input tx.');
|
||||
|
||||
p.write32(this.version);
|
||||
|
||||
p.writeVarint(this.inputs.length);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user