mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-12 14:42:38 +02:00
watchtower: add GetTower to tower iterator
Add a GetTower method to the tower iterator.
This commit is contained in:
@@ -29,6 +29,10 @@ type TowerCandidateIterator interface {
|
||||
// candidates available as long as they remain in the set.
|
||||
Reset() error
|
||||
|
||||
// GetTower gets the tower with the given ID from the iterator. If no
|
||||
// such tower is found then ErrTowerNotInIterator is returned.
|
||||
GetTower(id wtdb.TowerID) (*Tower, error)
|
||||
|
||||
// Next returns the next candidate tower. The iterator is not required
|
||||
// to return results in any particular order. If no more candidates are
|
||||
// available, ErrTowerCandidatesExhausted is returned.
|
||||
@@ -76,6 +80,20 @@ func (t *towerListIterator) Reset() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTower gets the tower with the given ID from the iterator. If no such tower
|
||||
// is found then ErrTowerNotInIterator is returned.
|
||||
func (t *towerListIterator) GetTower(id wtdb.TowerID) (*Tower, error) {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
|
||||
tower, ok := t.candidates[id]
|
||||
if !ok {
|
||||
return nil, ErrTowerNotInIterator
|
||||
}
|
||||
|
||||
return tower, nil
|
||||
}
|
||||
|
||||
// Next returns the next candidate tower. This iterator will always return
|
||||
// candidates in the order given when the iterator was instantiated. If no more
|
||||
// candidates are available, ErrTowerCandidatesExhausted is returned.
|
||||
|
Reference in New Issue
Block a user