mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-12 14:12:27 +02:00
btcdnotify: use chain.NewRPCClientWithConfig
to init RPC client
So we can use the methods implemented on the chain RPC client.
This commit is contained in:
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/rpcclient"
|
"github.com/btcsuite/btcd/rpcclient"
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
|
"github.com/btcsuite/btcwallet/chain"
|
||||||
"github.com/lightningnetwork/lnd/blockcache"
|
"github.com/lightningnetwork/lnd/blockcache"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/queue"
|
"github.com/lightningnetwork/lnd/queue"
|
||||||
@ -58,7 +59,7 @@ type BtcdNotifier struct {
|
|||||||
active int32 // To be used atomically.
|
active int32 // To be used atomically.
|
||||||
stopped int32 // To be used atomically.
|
stopped int32 // To be used atomically.
|
||||||
|
|
||||||
chainConn *rpcclient.Client
|
chainConn *chain.RPCClient
|
||||||
chainParams *chaincfg.Params
|
chainParams *chaincfg.Params
|
||||||
|
|
||||||
notificationCancels chan interface{}
|
notificationCancels chan interface{}
|
||||||
@ -127,21 +128,30 @@ func New(config *rpcclient.ConnConfig, chainParams *chaincfg.Params,
|
|||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Disable connecting to btcd within the rpcclient.New method. We
|
||||||
|
// defer establishing the connection to our .Start() method.
|
||||||
|
config.DisableConnectOnNew = true
|
||||||
|
config.DisableAutoReconnect = false
|
||||||
|
|
||||||
ntfnCallbacks := &rpcclient.NotificationHandlers{
|
ntfnCallbacks := &rpcclient.NotificationHandlers{
|
||||||
OnBlockConnected: notifier.onBlockConnected,
|
OnBlockConnected: notifier.onBlockConnected,
|
||||||
OnBlockDisconnected: notifier.onBlockDisconnected,
|
OnBlockDisconnected: notifier.onBlockDisconnected,
|
||||||
OnRedeemingTx: notifier.onRedeemingTx,
|
OnRedeemingTx: notifier.onRedeemingTx,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable connecting to btcd within the rpcclient.New method. We
|
rpcCfg := &chain.RPCClientConfig{
|
||||||
// defer establishing the connection to our .Start() method.
|
ReconnectAttempts: 20,
|
||||||
config.DisableConnectOnNew = true
|
Conn: config,
|
||||||
config.DisableAutoReconnect = false
|
Chain: chainParams,
|
||||||
chainConn, err := rpcclient.New(config, ntfnCallbacks)
|
NotificationHandlers: ntfnCallbacks,
|
||||||
|
}
|
||||||
|
|
||||||
|
chainRPC, err := chain.NewRPCClientWithConfig(rpcCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
notifier.chainConn = chainConn
|
|
||||||
|
notifier.chainConn = chainRPC
|
||||||
|
|
||||||
return notifier, nil
|
return notifier, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user