lnwallet: add more godoc to InputScript rename ScriptSig field to SigScript

This commit is contained in:
Olaoluwa Osuntokun 2018-11-17 20:46:51 -08:00
parent 73c9c2ee15
commit bd9ebbd5af
No known key found for this signature in database
GPG Key ID: CE58F7F8E20FD9A2
5 changed files with 29 additions and 20 deletions

@ -180,9 +180,10 @@ func (b *BtcWallet) SignOutputRaw(tx *wire.MsgTx,
// TODO(roasbeef): generate sighash midstate if not present? // TODO(roasbeef): generate sighash midstate if not present?
amt := signDesc.Output.Value amt := signDesc.Output.Value
sig, err := txscript.RawTxInWitnessSignature(tx, signDesc.SigHashes, sig, err := txscript.RawTxInWitnessSignature(
signDesc.InputIndex, amt, witnessScript, signDesc.HashType, tx, signDesc.SigHashes, signDesc.InputIndex, amt,
privKey) witnessScript, signDesc.HashType, privKey,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -227,8 +228,9 @@ func (b *BtcWallet) ComputeInputScript(tx *wire.MsgTx,
// spend the p2sh output. The sigScript will contain only a // spend the p2sh output. The sigScript will contain only a
// single push of the p2wkh witness program corresponding to // single push of the p2wkh witness program corresponding to
// the matching public key of this address. // the matching public key of this address.
p2wkhAddr, err := btcutil.NewAddressWitnessPubKeyHash(pubKeyHash, p2wkhAddr, err := btcutil.NewAddressWitnessPubKeyHash(
b.netParams) pubKeyHash, b.netParams,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -244,7 +246,7 @@ func (b *BtcWallet) ComputeInputScript(tx *wire.MsgTx,
return nil, err return nil, err
} }
inputScript.ScriptSig = sigScript inputScript.SigScript = sigScript
// Otherwise, this is a regular p2wkh output, so we include the // Otherwise, this is a regular p2wkh output, so we include the
// witness program itself as the subscript to generate the proper // witness program itself as the subscript to generate the proper
@ -267,7 +269,8 @@ func (b *BtcWallet) ComputeInputScript(tx *wire.MsgTx,
// TODO(roasbeef): adhere to passed HashType // TODO(roasbeef): adhere to passed HashType
witnessScript, err := txscript.WitnessSignature(tx, signDesc.SigHashes, witnessScript, err := txscript.WitnessSignature(tx, signDesc.SigHashes,
signDesc.InputIndex, signDesc.Output.Value, witnessProgram, signDesc.InputIndex, signDesc.Output.Value, witnessProgram,
signDesc.HashType, privKey, true) signDesc.HashType, privKey, true,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -127,7 +127,7 @@ type TransactionSubscription interface {
type WalletController interface { type WalletController interface {
// FetchInputInfo queries for the WalletController's knowledge of the // FetchInputInfo queries for the WalletController's knowledge of the
// passed outpoint. If the base wallet determines this output is under // passed outpoint. If the base wallet determines this output is under
// its control, then the original txout should be returned. Otherwise, // its control, then the original txout should be returned. Otherwise,
// a non-nil error value of ErrNotMine should be returned instead. // a non-nil error value of ErrNotMine should be returned instead.
FetchInputInfo(prevOut *wire.OutPoint) (*wire.TxOut, error) FetchInputInfo(prevOut *wire.OutPoint) (*wire.TxOut, error)

@ -50,11 +50,15 @@ func (c *ChannelContribution) toChanConfig() channeldb.ChannelConfig {
} }
// InputScript represents any script inputs required to redeem a previous // InputScript represents any script inputs required to redeem a previous
// output. This struct is used rather than just a witness, or scripSig in // output. This struct is used rather than just a witness, or scripSig in order
// order to accommodate nested p2sh which utilizes both types of input scripts. // to accommodate nested p2sh which utilizes both types of input scripts.
type InputScript struct { type InputScript struct {
Witness [][]byte // Witness is the full witness stack required to unlock this output.
ScriptSig []byte Witness wire.TxWitness
// SigScript will only be populated if this is an input script sweeping
// a nested p2sh output.
SigScript []byte
} }
// ChannelReservation represents an intent to open a lightning payment channel // ChannelReservation represents an intent to open a lightning payment channel

@ -438,13 +438,15 @@ func (m *mockSigner) ComputeInputScript(tx *wire.MsgTx, signDesc *SignDescriptor
"address %v", addresses[0]) "address %v", addresses[0])
} }
scriptSig, err := txscript.SignatureScript(tx, signDesc.InputIndex, sigScript, err := txscript.SignatureScript(
signDesc.Output.PkScript, txscript.SigHashAll, privKey, true) tx, signDesc.InputIndex, signDesc.Output.PkScript,
txscript.SigHashAll, privKey, true,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &InputScript{ScriptSig: scriptSig}, nil return &InputScript{SigScript: sigScript}, nil
case txscript.WitnessV0PubKeyHashTy: case txscript.WitnessV0PubKeyHashTy:
privKey := m.findKey(addresses[0].ScriptAddress(), signDesc.SingleTweak, privKey := m.findKey(addresses[0].ScriptAddress(), signDesc.SingleTweak,

@ -747,14 +747,15 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
signDesc.Output = info signDesc.Output = info
signDesc.InputIndex = i signDesc.InputIndex = i
inputScript, err := l.Cfg.Signer.ComputeInputScript(fundingTx, inputScript, err := l.Cfg.Signer.ComputeInputScript(
&signDesc) fundingTx, &signDesc,
)
if err != nil { if err != nil {
req.err <- err req.err <- err
return return
} }
txIn.SignatureScript = inputScript.ScriptSig txIn.SignatureScript = inputScript.SigScript
txIn.Witness = inputScript.Witness txIn.Witness = inputScript.Witness
pendingReservation.ourFundingInputScripts = append( pendingReservation.ourFundingInputScripts = append(
pendingReservation.ourFundingInputScripts, pendingReservation.ourFundingInputScripts,
@ -958,7 +959,7 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs
if len(inputScripts) != 0 && len(txin.Witness) == 0 { if len(inputScripts) != 0 && len(txin.Witness) == 0 {
// Attach the input scripts so we can verify it below. // Attach the input scripts so we can verify it below.
txin.Witness = inputScripts[sigIndex].Witness txin.Witness = inputScripts[sigIndex].Witness
txin.SignatureScript = inputScripts[sigIndex].ScriptSig txin.SignatureScript = inputScripts[sigIndex].SigScript
// Fetch the alleged previous output along with the // Fetch the alleged previous output along with the
// pkscript referenced by this input. // pkscript referenced by this input.
@ -1256,7 +1257,6 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
// selection is successful/possible, then the selected coins are available // selection is successful/possible, then the selected coins are available
// within the passed contribution's inputs. If necessary, a change address will // within the passed contribution's inputs. If necessary, a change address will
// also be generated. // also be generated.
// TODO(roasbeef): remove hardcoded fees.
func (l *LightningWallet) selectCoinsAndChange(feeRate SatPerKWeight, func (l *LightningWallet) selectCoinsAndChange(feeRate SatPerKWeight,
amt btcutil.Amount, minConfs int32, amt btcutil.Amount, minConfs int32,
contribution *ChannelContribution) error { contribution *ChannelContribution) error {