watchtower: load persisted towers upon TowerClient creation

We do this as a convenience for WatchtowerClient users so that they do
not need to re-add towers upon restarts. We ensure not to re-add towers
that have been previously removed by determining whether it has any
lingering active sessions.
This commit is contained in:
Wilmer Paulino committed 2019-07-30 15:18:17 -07:00
1 parent 787986283c
commit 359b2049b6
2 files changed
+50 -32

No files matched your search

+11
View File
@@ -1,6 +1,8 @@
package wtdb
import (
"encoding/hex"
"fmt"
"io"
"net"
@@ -92,6 +94,15 @@ func (t *Tower) LNAddrs() []*lnwire.NetAddress {
return addrs
}
// String returns a user-friendly identifier of the tower.
func (t *Tower) String() string {
pubKey := hex.EncodeToString(t.IdentityKey.SerializeCompressed())
if len(t.Addresses) == 0 {
return pubKey
}
return fmt.Sprintf("%v@%v", pubKey, t.Addresses[0])
}
// Encode writes the Tower to the passed io.Writer. The TowerID is not
// serialized, since it acts as the key.
func (t *Tower) Encode(w io.Writer) error {