loopd: fix nil ptr derefence for monitor

Reason for the crash was an unpopulated HtlcAddress field.
This commit is contained in:
Joost Jager 2019-04-11 09:06:59 +02:00
parent e8005d095a
commit 7f9ab312fb
No known key found for this signature in database
GPG key ID: A61B9D4C393C59C7
3 changed files with 61 additions and 34 deletions

View file

@ -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.

View file

@ -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
}