lnwallet+sweep: extend the WitnessGenerator type to return an InputScript
In this commit, we extend the WitnessGenerator type to now return an InputScript. This allows it to be more encompassing, as now callers can expect a sigScript to be populated if the input being swept requires a sigScript field. Along the way, we've also renamed input.BuildWitness to input.CraftInputScript. We also take a step towards allowing the sweeper to sweep transactions for n2pwkh outputs. We do so by modifying the BuiltWitness method to instead return an InputScript. Additionally, when populating inputs if a sigScript is present, it will now be populated.
This commit is contained in:
4 files changed
+132
-47
No files matched your search
+7
-6
@@ -807,13 +807,13 @@ func (bo *breachedOutput) SignDesc() *lnwallet.SignDescriptor {
|
||||
return &bo.signDesc
|
||||
}
|
||||
|
||||
// BuildWitness computes a valid witness that allows us to spend from the
|
||||
// CraftInputScript computes a valid witness that allows us to spend from the
|
||||
// breached output. It does so by first generating and memoizing the witness
|
||||
// generation function, which parameterized primarily by the witness type and
|
||||
// sign descriptor. The method then returns the witness computed by invoking
|
||||
// this function on the first and subsequent calls.
|
||||
func (bo *breachedOutput) BuildWitness(signer lnwallet.Signer, txn *wire.MsgTx,
|
||||
hashCache *txscript.TxSigHashes, txinIdx int) ([][]byte, error) {
|
||||
func (bo *breachedOutput) CraftInputScript(signer lnwallet.Signer, txn *wire.MsgTx,
|
||||
hashCache *txscript.TxSigHashes, txinIdx int) (*lnwallet.InputScript, error) {
|
||||
|
||||
// First, we ensure that the witness generation function has been
|
||||
// initialized for this breached output.
|
||||
@@ -1082,15 +1082,16 @@ func (b *breachArbiter) sweepSpendableOutputsTxn(txWeight int64,
|
||||
// First, we construct a valid witness for this outpoint and
|
||||
// transaction using the SpendableOutput's witness generation
|
||||
// function.
|
||||
witness, err := so.BuildWitness(b.cfg.Signer, txn, hashCache,
|
||||
idx)
|
||||
inputScript, err := so.CraftInputScript(
|
||||
b.cfg.Signer, txn, hashCache, idx,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Then, we add the witness to the transaction at the
|
||||
// appropriate txin index.
|
||||
txn.TxIn[idx].Witness = witness
|
||||
txn.TxIn[idx].Witness = inputScript.Witness
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user