2015-12-03 03:49:41 +03:00
|
|
|
package wallet
|
|
|
|
|
2015-12-16 23:40:11 +03:00
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"li.lan/labs/plasma/chainntfs"
|
|
|
|
"li.lan/labs/plasma/revocation"
|
|
|
|
|
|
|
|
"github.com/btcsuite/btcwallet/walletdb"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2015-12-17 07:55:52 +03:00
|
|
|
// 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()
|
|
|
|
}
|
2015-12-16 23:40:11 +03:00
|
|
|
|
|
|
|
|
2015-12-17 07:58:01 +03:00
|
|
|
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?
|
2015-12-16 23:40:11 +03:00
|
|
|
channelNamespace walletdb.Namespace
|
|
|
|
|
2015-12-17 07:58:01 +03:00
|
|
|
Id [32]byte
|
|
|
|
|
|
|
|
capacity btcutil.Amount
|
|
|
|
ourTotalFunds btcutil.Amount
|
|
|
|
theirTotalFunds btcutil.Amount
|
2015-12-16 23:40:11 +03:00
|
|
|
|
2015-12-17 07:58:01 +03:00
|
|
|
// 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
|
2015-12-16 23:40:11 +03:00
|
|
|
shutdown int32
|
|
|
|
|
|
|
|
quit chan struct{}
|
|
|
|
wg sync.WaitGroup
|
|
|
|
}
|
|
|
|
|
2015-12-17 07:58:01 +03:00
|
|
|
// 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 {
|
2015-12-16 23:40:11 +03:00
|
|
|
return nil
|
2015-12-03 03:49:41 +03:00
|
|
|
}
|