From 48c1c39dc9f7f1193715042ef20f98703ed0b1f5 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 16 Dec 2015 22:58:01 -0600 Subject: [PATCH] lnwallet: add skeleton for LightningChannel * pretty much same as strux/lchannel.go * Too beefy atm, added note to bring back old CompleteReservation struct --- lnwallet/channel.go | 104 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 96 insertions(+), 8 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 33b0a377..3c9f3ccb 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -9,11 +9,7 @@ import ( "github.com/btcsuite/btcwallet/walletdb" ) -type LightningChannel struct { - shachan *revocation.HyperShaChain - wallet *LightningWallet - channelEvents *chainntnfs.ChainNotifier // P2SHify... func P2SHify(scriptBytes []byte) ([]byte, error) { bldr := txscript.NewScriptBuilder() @@ -23,19 +19,111 @@ func P2SHify(scriptBytes []byte) ([]byte, error) { return bldr.Script() } - sync.RWMutex +type nodeId [32]byte + +type LightningChannel struct { + wallet *LightningWallet + channelEvents *chainntnfs.ChainNotifier + + // TODO(roasbeef): Stores all previous R values + timeouts for each + // commitment update, plus some other meta-data...Or just use OP_RETURN + // to help out? channelNamespace walletdb.Namespace - // TODO(roasbeef): create and embed 'Service' interface w/ below? - started int32 + Id [32]byte + capacity btcutil.Amount + ourTotalFunds btcutil.Amount + theirTotalFunds btcutil.Amount + + // TODO(roasbeef): another shachain for R values for HTLC's? + // solve above? + ourShaChain *revocation.HyperShaChain + theirShaChain *revocation.HyperShaChain + + ourFundingKey *btcec.PrivateKey + theirFundingKey *btcec.PublicKey + + ourCommitKey *btcec.PublicKey + theirCommitKey *btcec.PublicKey + + fundingTx *wire.MsgTx + commitmentTx *wire.MsgTx + + sync.RWMutex + + // TODO(roasbeef): create and embed 'Service' interface w/ below? + started int32 shutdown int32 quit chan struct{} wg sync.WaitGroup } -func newLightningChannel() *LightningChannel { +// newLightningChannel... +// TODO(roasbeef): bring back and embedd CompleteReservation struct? kinda large +// atm..... +func newLightningChannel(wallet *LightningWallet, events *chainntnfs.ChainNotifier, + dbNamespace walletdb.Namespace, theirNodeID nodeId, ourFunds, + theirFunds btcutil.Amount, ourChain, theirChain *revocation.HyperShaChain, + ourFundingKey *btcec.PrivateKey, theirFundingKey *btcec.PublicKey, + commitKey, theirCommitKey *btcec.PublicKey, fundingTx, + commitTx *wire.MsgTx) (*LightningChannel, error) { + + return &LightningChannel{ + wallet: wallet, + channelEvents: events, + channelNamespace: dbNamespace, + Id: theirNodeID, + capacity: ourFunds + theirFunds, + ourTotalFunds: ourFunds, + theirTotalFunds: theirFunds, + ourShaChain: ourChain, + theirShaChain: theirChain, + ourFundingKey: ourFundingKey, + theirFundingKey: theirFundingKey, + ourCommitKey: commitKey, + theirCommitKey: theirCommitKey, + fundingTx: fundingTx, + commitmentTx: commitTx, + }, nil +} + +// AddHTLC... +func (lc *LightningChannel) AddHTLC() { +} + +// SettleHTLC... +func (lc *LightningChannel) SettleHTLC() { +} + +// OurBalance... +func (lc *LightningChannel) OurBalance() btcutil.Amount { + return 0 +} + +// TheirBalance... +func (lc *LightningChannel) TheirBalance() btcutil.Amount { + return 0 +} + +// CurrentCommitTx... +func (lc *LightningChannel) CurrentCommitTx() *btcutil.Tx { + return nil +} + +// SignTheirCommitTx... +func (lc *LightningChannel) SignTheirCommitTx(commitTx *btcutil.Tx) error { + return nil +} + +// AddTheirSig... +func (lc *LightningChannel) AddTheirSig(sig []byte) error { + return nil +} + +// VerifyCommitmentUpdate... +func (lc *LightningChannel) VerifyCommitmentUpdate() error { return nil }