watchtower: make better use of getChanSummary

Small refactor just to make the upcoming commit easier to parse. In
this commit, we make better use of the getChanSummary helper function.
This commit is contained in:
Elle Mouton
2022-10-18 09:49:44 +02:00
parent b1d6991b27
commit 4ab8c57eae

View File

@ -893,13 +893,12 @@ func (c *ClientDB) FetchChanSummaries() (ChannelSummaries, error) {
var chanID lnwire.ChannelID var chanID lnwire.ChannelID
copy(chanID[:], k) copy(chanID[:], k)
var summary ClientChanSummary summary, err := getChanSummary(chanSummaries, chanID)
err := summary.Decode(bytes.NewReader(v))
if err != nil { if err != nil {
return err return err
} }
summaries[chanID] = summary summaries[chanID] = *summary
return nil return nil
}) })
@ -927,19 +926,10 @@ func (c *ClientDB) RegisterChannel(chanID lnwire.ChannelID,
return ErrUninitializedDB return ErrUninitializedDB
} }
_, err := getChanSummary(chanSummaries, chanID) chanSummaryBytes := chanSummaries.Get(chanID[:])
switch { if chanSummaryBytes != nil {
// Channel is already registered.
// Summary already exists.
case err == nil:
return ErrChannelAlreadyRegistered return ErrChannelAlreadyRegistered
// Channel is not registered, proceed with registration.
case err == ErrChannelNotRegistered:
// Unexpected error.
default:
return err
} }
summary := ClientChanSummary{ summary := ClientChanSummary{