lnwallet: use funcs in script_utils.go
This commit is contained in:
parent
30523d7db3
commit
c7d604fd0b
@ -154,15 +154,6 @@ func (lc *LightningChannel) VerifyCommitmentUpdate() error {
|
|||||||
return nil
|
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...
|
// createCommitTx...
|
||||||
func createCommitTx(fundingOutput *wire.TxIn, ourKey, theirKey *btcec.PublicKey,
|
func createCommitTx(fundingOutput *wire.TxIn, ourKey, theirKey *btcec.PublicKey,
|
||||||
revokeHash [32]byte, csvTimeout int64, amtToUs,
|
revokeHash [32]byte, csvTimeout int64, amtToUs,
|
||||||
@ -190,7 +181,7 @@ func createCommitTx(fundingOutput *wire.TxIn, ourKey, theirKey *btcec.PublicKey,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
payToUsScriptHash, err := P2SHify(ourRedeemScript)
|
payToUsScriptHash, err := scriptHashPkScript(ourRedeemScript)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -208,7 +199,7 @@ func createCommitTx(fundingOutput *wire.TxIn, ourKey, theirKey *btcec.PublicKey,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
payToThemScriptHash, err := P2SHify(theirRedeemScript)
|
payToThemScriptHash, err := scriptHashPkScript(theirRedeemScript)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -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
|
// Finally, add the 2-of-2 multi-sig output which will set up the lightning
|
||||||
// channel.
|
// channel.
|
||||||
// TODO(roasbeef): Cannonical sorting of keys here?
|
// TODO(roasbeef): track multi-sig and change outputs indexes
|
||||||
// * also, also this is currently bare-multi sig, keep this for network
|
|
||||||
// transparency or switch to P2SH?
|
|
||||||
keys := make([]*btcutil.AddressPubKey, 2)
|
|
||||||
ourKey := pendingReservation.partialState.multiSigKey.PubKey().SerializeCompressed()
|
ourKey := pendingReservation.partialState.multiSigKey.PubKey().SerializeCompressed()
|
||||||
keys[0], _ = btcutil.NewAddressPubKey(ourKey, ActiveNetParams)
|
|
||||||
pendingReservation.theirMultiSigKey = req.theirKey
|
pendingReservation.theirMultiSigKey = req.theirKey
|
||||||
keys[1], _ = btcutil.NewAddressPubKey(pendingReservation.theirMultiSigKey.SerializeCompressed(), ActiveNetParams)
|
theirKey := pendingReservation.theirMultiSigKey.SerializeCompressed()
|
||||||
multiSigScript, err := txscript.MultiSigScript(keys, 2)
|
|
||||||
|
channelCapacity := int64(pendingReservation.partialState.capacity)
|
||||||
|
redeemScript, multiSigOut, err := fundMultiSigOut(ourKey, theirKey,
|
||||||
|
channelCapacity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
req.err <- err
|
req.err <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
multiSigOut := wire.NewTxOut(int64(pendingReservation.partialState.capacity),
|
pendingReservation.partialState.fundingRedeemScript = redeemScript
|
||||||
multiSigScript)
|
|
||||||
pendingReservation.partialState.fundingTx.AddTxOut(multiSigOut)
|
pendingReservation.partialState.fundingTx.AddTxOut(multiSigOut)
|
||||||
|
|
||||||
// Sort the transaction. Since both side agree to a cannonical
|
// Sort the transaction. Since both side agree to a cannonical
|
||||||
|
Loading…
Reference in New Issue
Block a user