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