lnwallet: publicly export constructor for LightningChannel

This commit is contained in:
Olaoluwa Osuntokun 2016-06-20 22:07:03 -07:00
parent 507520cda9
commit 27e6839060
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -99,7 +99,7 @@ type LightningChannel struct {
} }
// newLightningChannel... // newLightningChannel...
func newLightningChannel(wallet *LightningWallet, events chainntnfs.ChainNotifier, func NewLightningChannel(wallet *LightningWallet, events chainntnfs.ChainNotifier,
chanDB *channeldb.DB, state *channeldb.OpenChannel) (*LightningChannel, error) { chanDB *channeldb.DB, state *channeldb.OpenChannel) (*LightningChannel, error) {
lc := &LightningChannel{ lc := &LightningChannel{
@ -118,13 +118,11 @@ func newLightningChannel(wallet *LightningWallet, events chainntnfs.ChainNotifie
// Populate the totem. // Populate the totem.
lc.updateTotem <- struct{}{} lc.updateTotem <- struct{}{}
fundingTxId := state.FundingTx.TxSha()
fundingPkScript, err := witnessScriptHash(state.FundingRedeemScript) fundingPkScript, err := witnessScriptHash(state.FundingRedeemScript)
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, multiSigIndex := findScriptOutputIndex(state.FundingTx, fundingPkScript) lc.fundingTxIn = wire.NewTxIn(state.FundingOutpoint, nil, nil)
lc.fundingTxIn = wire.NewTxIn(wire.NewOutPoint(&fundingTxId, multiSigIndex), nil, nil)
lc.fundingP2SH = fundingPkScript lc.fundingP2SH = fundingPkScript
return lc, nil return lc, nil
@ -186,9 +184,11 @@ func (c *ChannelUpdate) SignCounterPartyCommitment() ([]byte, error) {
} }
// Sign their version of the commitment transaction. // 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.FundingRedeemScript, txscript.SigHashAll,
c.lnChannel.channelState.MultiSigKey) c.lnChannel.channelState.OurMultiSigKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -221,6 +221,9 @@ func (c *ChannelUpdate) VerifyNewCommitmentSigs(ourSig, theirSig []byte) error {
channelState := c.lnChannel.channelState 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 // When initially generating the redeemScript, we sorted the serialized
// public keys in descending order. So we do a quick comparison in order // public keys in descending order. So we do a quick comparison in order
// ensure the signatures appear on the Script Virual Machine stack in // ensure the signatures appear on the Script Virual Machine stack in
@ -290,6 +293,13 @@ func (c *ChannelUpdate) Commit(pastRevokePreimage []byte) error {
return nil 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... // AddHTLC...
// 1. request R_Hash from receiver (only if single hop, would be out of band) // 1. request R_Hash from receiver (only if single hop, would be out of band)
// 2. propose HTLC // 2. propose HTLC