chainntfs: introduce ChainConnection interface to avoid import cycle and for future tests
* Looks rather hack atm. Put in place so progress can be had with lnwallet before notes is finished.
This commit is contained in:
parent
cf65aaa2c9
commit
5f705be63b
@ -7,17 +7,15 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
|
||||||
"github.com/btcsuite/btcwallet/chain"
|
"github.com/btcsuite/btcwallet/chain"
|
||||||
"github.com/btcsuite/btcwallet/wtxmgr"
|
"github.com/btcsuite/btcwallet/wtxmgr"
|
||||||
"li.lan/labs/plasma/chainntfs"
|
"li.lan/labs/plasma/chainntfs"
|
||||||
"li.lan/labs/plasma/lnwallet"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// BtcdNotifier...
|
// BtcdNotifier...
|
||||||
type BtcdNotifier struct {
|
type BtcdNotifier struct {
|
||||||
// TODO(roasbeef): refactor to use the new NotificationServer
|
// TODO(roasbeef): refactor to use the new NotificationServer
|
||||||
wallet *lnwallet.LightningWallet
|
conn ChainConnection
|
||||||
|
|
||||||
notificationRegistry chan interface{}
|
notificationRegistry chan interface{}
|
||||||
|
|
||||||
@ -28,9 +26,6 @@ type BtcdNotifier struct {
|
|||||||
connectedBlocks <-chan wtxmgr.BlockMeta
|
connectedBlocks <-chan wtxmgr.BlockMeta
|
||||||
disconnectedBlocks <-chan wtxmgr.BlockMeta
|
disconnectedBlocks <-chan wtxmgr.BlockMeta
|
||||||
relevantTxs <-chan chain.RelevantTx
|
relevantTxs <-chan chain.RelevantTx
|
||||||
managerLocked <-chan bool
|
|
||||||
confirmedBalance <-chan btcutil.Amount
|
|
||||||
unconfirmedBalance <-chan btcutil.Amount
|
|
||||||
|
|
||||||
rpcConnected chan struct{}
|
rpcConnected chan struct{}
|
||||||
|
|
||||||
@ -43,8 +38,9 @@ type BtcdNotifier struct {
|
|||||||
var _ chainntnfs.ChainNotifier = (*BtcdNotifier)(nil)
|
var _ chainntnfs.ChainNotifier = (*BtcdNotifier)(nil)
|
||||||
|
|
||||||
// NewBtcdNotifier...
|
// NewBtcdNotifier...
|
||||||
func NewBtcdNotifier() (*BtcdNotifier, error) {
|
func NewBtcdNotifier(c ChainConnection) (*BtcdNotifier, error) {
|
||||||
return &BtcdNotifier{
|
return &BtcdNotifier{
|
||||||
|
conn: c,
|
||||||
notificationRegistry: make(chan interface{}),
|
notificationRegistry: make(chan interface{}),
|
||||||
|
|
||||||
spendNotifications: make(map[wire.OutPoint]*spendNotification),
|
spendNotifications: make(map[wire.OutPoint]*spendNotification),
|
||||||
@ -54,9 +50,6 @@ func NewBtcdNotifier() (*BtcdNotifier, error) {
|
|||||||
connectedBlocks: make(chan wtxmgr.BlockMeta),
|
connectedBlocks: make(chan wtxmgr.BlockMeta),
|
||||||
disconnectedBlocks: make(chan wtxmgr.BlockMeta),
|
disconnectedBlocks: make(chan wtxmgr.BlockMeta),
|
||||||
relevantTxs: make(chan chain.RelevantTx),
|
relevantTxs: make(chan chain.RelevantTx),
|
||||||
managerLocked: make(chan bool),
|
|
||||||
confirmedBalance: make(chan btcutil.Amount),
|
|
||||||
unconfirmedBalance: make(chan btcutil.Amount),
|
|
||||||
|
|
||||||
rpcConnected: make(chan struct{}, 1),
|
rpcConnected: make(chan struct{}, 1),
|
||||||
|
|
||||||
@ -186,27 +179,15 @@ out:
|
|||||||
func (b *BtcdNotifier) initAllNotifications() error {
|
func (b *BtcdNotifier) initAllNotifications() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
b.connectedBlocks, err = b.wallet.ListenConnectedBlocks()
|
b.connectedBlocks, err = b.conn.ListenConnectedBlocks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b.disconnectedBlocks, err = b.wallet.ListenDisconnectedBlocks()
|
b.disconnectedBlocks, err = b.conn.ListenDisconnectedBlocks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b.relevantTxs, err = b.wallet.ListenRelevantTxs()
|
b.relevantTxs, err = b.conn.ListenRelevantTxs()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
b.managerLocked, err = b.wallet.ListenLockStatus()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
b.confirmedBalance, err = b.wallet.ListenConfirmedBalance()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
b.unconfirmedBalance, err = b.wallet.ListenUnconfirmedBalance()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
14
chainntfs/btcdnotify/source.go
Normal file
14
chainntfs/btcdnotify/source.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package btcdnotify
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/btcsuite/btcwallet/chain"
|
||||||
|
"github.com/btcsuite/btcwallet/wtxmgr"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ChainConnection...
|
||||||
|
// Required in order to avoid an import cycle, and do aide in testing.
|
||||||
|
type ChainConnection interface {
|
||||||
|
ListenConnectedBlocks() (<-chan wtxmgr.BlockMeta, error)
|
||||||
|
ListenDisconnectedBlocks() (<-chan wtxmgr.BlockMeta, error)
|
||||||
|
ListenRelevantTxs() (<-chan chain.RelevantTx, error)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user