bcoin-org / bledger

Bcoin ledger support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Impossible to use with legacy txs

tynes opened this issue · comments

On this line:

assert(!this.isWitness(), 'input script is program.');

If options.witness is false, then it asserts!this.isWitness()
which eventually tries to look at this.coin, which is still assigned a
null value in the constructor, and is not assigned anything until strictly
afterwards in the control flow,

this.coin = Coin.fromTX(this.tx, this.index, 0);

so this code path appears will always throw
an error as this.getCoin returns null and has no property script

  getPrev() {
    if (!this._prev)
      this._prev = this.getCoin().script;

    return this._prev;
  }

Maybe we can make this.tx and this.index required and then assign this.coin no matter what, then we can assert this.isWitness() if options.witness is true and !this.isWitness() if options.witness is false

Fixed 99460b0

options.witness does not necessarily mean it has witness program. It might be nested witness program, in that case that will cause problems. We could have this.witness = true if this.isWitness, but that won't catch all cases, so it might cause errors on the user side.

It's better to make sure, they choose witness themselves all the time.

@tynes is this still an issue ?