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