lnwallet: use funcs in script_utils.go

This commit is contained in:
Olaoluwa Osuntokun 2015-12-20 17:11:21 -06:00
parent 30523d7db3
commit c7d604fd0b
2 changed files with 9 additions and 20 deletions

@ -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
}

@ -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