diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 007dfb6a..c0e58960 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -154,15 +154,6 @@ func (lc *LightningChannel) VerifyCommitmentUpdate() error { return nil } -// P2SHify... -func P2SHify(scriptBytes []byte) ([]byte, error) { - bldr := txscript.NewScriptBuilder() - bldr.AddOp(txscript.OP_HASH160) - bldr.AddData(btcutil.Hash160(scriptBytes)) - bldr.AddOp(txscript.OP_EQUAL) - return bldr.Script() -} - // createCommitTx... func createCommitTx(fundingOutput *wire.TxIn, ourKey, theirKey *btcec.PublicKey, revokeHash [32]byte, csvTimeout int64, amtToUs, @@ -190,7 +181,7 @@ func createCommitTx(fundingOutput *wire.TxIn, ourKey, theirKey *btcec.PublicKey, if err != nil { return nil, err } - payToUsScriptHash, err := P2SHify(ourRedeemScript) + payToUsScriptHash, err := scriptHashPkScript(ourRedeemScript) if err != nil { return nil, err } @@ -208,7 +199,7 @@ func createCommitTx(fundingOutput *wire.TxIn, ourKey, theirKey *btcec.PublicKey, if err != nil { return nil, err } - payToThemScriptHash, err := P2SHify(theirRedeemScript) + payToThemScriptHash, err := scriptHashPkScript(theirRedeemScript) if err != nil { return nil, err } diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 5a0818eb..198fefb6 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -496,21 +496,19 @@ func (l *LightningWallet) handleFundingCounterPartyFunds(req *addCounterPartyFun // Finally, add the 2-of-2 multi-sig output which will set up the lightning // channel. - // TODO(roasbeef): Cannonical sorting of keys here? - // * also, also this is currently bare-multi sig, keep this for network - // transparency or switch to P2SH? - keys := make([]*btcutil.AddressPubKey, 2) + // TODO(roasbeef): track multi-sig and change outputs indexes ourKey := pendingReservation.partialState.multiSigKey.PubKey().SerializeCompressed() - keys[0], _ = btcutil.NewAddressPubKey(ourKey, ActiveNetParams) pendingReservation.theirMultiSigKey = req.theirKey - keys[1], _ = btcutil.NewAddressPubKey(pendingReservation.theirMultiSigKey.SerializeCompressed(), ActiveNetParams) - multiSigScript, err := txscript.MultiSigScript(keys, 2) + theirKey := pendingReservation.theirMultiSigKey.SerializeCompressed() + + channelCapacity := int64(pendingReservation.partialState.capacity) + redeemScript, multiSigOut, err := fundMultiSigOut(ourKey, theirKey, + channelCapacity) if err != nil { req.err <- err return } - multiSigOut := wire.NewTxOut(int64(pendingReservation.partialState.capacity), - multiSigScript) + pendingReservation.partialState.fundingRedeemScript = redeemScript pendingReservation.partialState.fundingTx.AddTxOut(multiSigOut) // Sort the transaction. Since both side agree to a cannonical