mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
loopd: fix nil ptr derefence for monitor
Reason for the crash was an unpopulated HtlcAddress field.
This commit is contained in:
parent
e8005d095a
commit
7f9ab312fb
3 changed files with 61 additions and 34 deletions
61
client.go
61
client.go
|
|
@ -113,14 +113,61 @@ func NewClient(dbDir string, serverAddress string, insecure bool,
|
|||
return client, cleanup, nil
|
||||
}
|
||||
|
||||
// FetchLoopOutSwaps returns a list of all swaps currently in the database.
|
||||
func (s *Client) FetchLoopOutSwaps() ([]*loopdb.LoopOut, error) {
|
||||
return s.Store.FetchLoopOutSwaps()
|
||||
}
|
||||
// FetchSwaps returns all loop in and out swaps currently in the database.
|
||||
func (s *Client) FetchSwaps() ([]*SwapInfo, error) {
|
||||
loopOutSwaps, err := s.Store.FetchLoopOutSwaps()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// FetchLoopInSwaps returns a list of all swaps currently in the database.
|
||||
func (s *Client) FetchLoopInSwaps() ([]*loopdb.LoopIn, error) {
|
||||
return s.Store.FetchLoopInSwaps()
|
||||
loopInSwaps, err := s.Store.FetchLoopInSwaps()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
swaps := make([]*SwapInfo, 0, len(loopInSwaps)+len(loopOutSwaps))
|
||||
|
||||
for _, swp := range loopOutSwaps {
|
||||
htlc, err := swap.NewHtlc(
|
||||
swp.Contract.CltvExpiry, swp.Contract.SenderKey,
|
||||
swp.Contract.ReceiverKey, swp.Hash, swap.HtlcP2WSH,
|
||||
s.lndServices.ChainParams,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
swaps = append(swaps, &SwapInfo{
|
||||
SwapType: TypeOut,
|
||||
SwapContract: swp.Contract.SwapContract,
|
||||
State: swp.State(),
|
||||
SwapHash: swp.Hash,
|
||||
LastUpdate: swp.LastUpdateTime(),
|
||||
HtlcAddress: htlc.Address,
|
||||
})
|
||||
}
|
||||
|
||||
for _, swp := range loopInSwaps {
|
||||
htlc, err := swap.NewHtlc(
|
||||
swp.Contract.CltvExpiry, swp.Contract.SenderKey,
|
||||
swp.Contract.ReceiverKey, swp.Hash, swap.HtlcNP2WSH,
|
||||
s.lndServices.ChainParams,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
swaps = append(swaps, &SwapInfo{
|
||||
SwapType: TypeIn,
|
||||
SwapContract: swp.Contract.SwapContract,
|
||||
State: swp.State(),
|
||||
SwapHash: swp.Hash,
|
||||
LastUpdate: swp.LastUpdateTime(),
|
||||
HtlcAddress: htlc.Address,
|
||||
})
|
||||
}
|
||||
|
||||
return swaps, nil
|
||||
}
|
||||
|
||||
// Run is a blocking call that executes all swaps. Any pending swaps are
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ func daemon(config *config) error {
|
|||
config.SwapServer = testnetServer
|
||||
}
|
||||
|
||||
// Create an instance of the loop client library.
|
||||
swapClient, cleanup, err := getClient(
|
||||
config.Network, config.SwapServer, config.Insecure, &lnd.LndServices,
|
||||
)
|
||||
|
|
@ -40,35 +41,14 @@ func daemon(config *config) error {
|
|||
}
|
||||
defer cleanup()
|
||||
|
||||
// Before starting the client, build an in-memory view of all swaps.
|
||||
// This view is used to update newly connected clients with the most
|
||||
// recent swaps.
|
||||
loopOutSwaps, err := swapClient.FetchLoopOutSwaps()
|
||||
// Retrieve all currently existing swaps from the database.
|
||||
swapsList, err := swapClient.FetchSwaps()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, swap := range loopOutSwaps {
|
||||
swaps[swap.Hash] = loop.SwapInfo{
|
||||
SwapType: loop.TypeOut,
|
||||
SwapContract: swap.Contract.SwapContract,
|
||||
State: swap.State(),
|
||||
SwapHash: swap.Hash,
|
||||
LastUpdate: swap.LastUpdateTime(),
|
||||
}
|
||||
}
|
||||
|
||||
loopInSwaps, err := swapClient.FetchLoopInSwaps()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, swap := range loopInSwaps {
|
||||
swaps[swap.Hash] = loop.SwapInfo{
|
||||
SwapType: loop.TypeIn,
|
||||
SwapContract: swap.Contract.SwapContract,
|
||||
State: swap.State(),
|
||||
SwapHash: swap.Hash,
|
||||
LastUpdate: swap.LastUpdateTime(),
|
||||
}
|
||||
for _, s := range swapsList {
|
||||
swaps[s.SwapHash] = *s
|
||||
}
|
||||
|
||||
// Instantiate the loopd gRPC server.
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ func view(config *config) error {
|
|||
}
|
||||
|
||||
func viewOut(swapClient *loop.Client, chainParams *chaincfg.Params) error {
|
||||
swaps, err := swapClient.FetchLoopOutSwaps()
|
||||
swaps, err := swapClient.Store.FetchLoopOutSwaps()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -88,7 +88,7 @@ func viewOut(swapClient *loop.Client, chainParams *chaincfg.Params) error {
|
|||
}
|
||||
|
||||
func viewIn(swapClient *loop.Client, chainParams *chaincfg.Params) error {
|
||||
swaps, err := swapClient.FetchLoopInSwaps()
|
||||
swaps, err := swapClient.Store.FetchLoopInSwaps()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue