From 27e6839060f7607bdc05d0d6e114e1ce8936caa5 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 20 Jun 2016 22:07:03 -0700 Subject: [PATCH] lnwallet: publicly export constructor for LightningChannel --- lnwallet/channel.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 4a0c8396..865d0eef 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -99,7 +99,7 @@ type LightningChannel struct { } // newLightningChannel... -func newLightningChannel(wallet *LightningWallet, events chainntnfs.ChainNotifier, +func NewLightningChannel(wallet *LightningWallet, events chainntnfs.ChainNotifier, chanDB *channeldb.DB, state *channeldb.OpenChannel) (*LightningChannel, error) { lc := &LightningChannel{ @@ -118,13 +118,11 @@ func newLightningChannel(wallet *LightningWallet, events chainntnfs.ChainNotifie // Populate the totem. lc.updateTotem <- struct{}{} - fundingTxId := state.FundingTx.TxSha() fundingPkScript, err := witnessScriptHash(state.FundingRedeemScript) if err != nil { return nil, err } - _, multiSigIndex := findScriptOutputIndex(state.FundingTx, fundingPkScript) - lc.fundingTxIn = wire.NewTxIn(wire.NewOutPoint(&fundingTxId, multiSigIndex), nil, nil) + lc.fundingTxIn = wire.NewTxIn(state.FundingOutpoint, nil, nil) lc.fundingP2SH = fundingPkScript return lc, nil @@ -186,9 +184,11 @@ func (c *ChannelUpdate) SignCounterPartyCommitment() ([]byte, error) { } // Sign their version of the commitment transaction. - sig, err := txscript.RawTxInSignature(c.theirPendingCommitTx, 0, + hashCache := txscript.NewTxSigHashes(c.theirPendingCommitTx) + sig, err := txscript.RawTxInWitnessSignature(c.theirPendingCommitTx, + hashCache, 0, int64(c.lnChannel.channelState.Capacity), c.lnChannel.channelState.FundingRedeemScript, txscript.SigHashAll, - c.lnChannel.channelState.MultiSigKey) + c.lnChannel.channelState.OurMultiSigKey) if err != nil { return nil, err } @@ -221,6 +221,9 @@ func (c *ChannelUpdate) VerifyNewCommitmentSigs(ourSig, theirSig []byte) error { channelState := c.lnChannel.channelState + // TODO(roasbeef): replace with sighash calc and regular sig check + // after merge + // When initially generating the redeemScript, we sorted the serialized // public keys in descending order. So we do a quick comparison in order // ensure the signatures appear on the Script Virual Machine stack in @@ -290,6 +293,13 @@ func (c *ChannelUpdate) Commit(pastRevokePreimage []byte) error { return nil } +// ChannelPoint returns the outpoint of the original funding transaction which +// created this active channel. This outpoint is used throughout various +// sub-systems to uniquely identify an open channel. +func (lc *LightningChannel) ChannelPoint() wire.OutPoint { + return lc.fundingTxIn.PreviousOutPoint +} + // AddHTLC... // 1. request R_Hash from receiver (only if single hop, would be out of band) // 2. propose HTLC