diff --git a/channeldb/codec.go b/channeldb/codec.go index 03d2b416..149be180 100644 --- a/channeldb/codec.go +++ b/channeldb/codec.go @@ -4,6 +4,7 @@ import ( "encoding/binary" "fmt" "io" + "net" "github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/lnwire" @@ -176,6 +177,22 @@ func WriteElement(w io.Writer, element interface{}) error { return err } + case net.Addr: + if err := serializeAddr(w, e); err != nil { + return err + } + + case []net.Addr: + if err := WriteElement(w, uint32(len(e))); err != nil { + return err + } + + for _, addr := range e { + if err := serializeAddr(w, addr); err != nil { + return err + } + } + default: return UnknownElementType{"WriteElement", e} } @@ -355,6 +372,28 @@ func ReadElement(r io.Reader, element interface{}) error { return err } + case *net.Addr: + addr, err := deserializeAddr(r) + if err != nil { + return err + } + *e = addr + + case *[]net.Addr: + var numAddrs uint32 + if err := ReadElement(r, &numAddrs); err != nil { + return err + } + + *e = make([]net.Addr, numAddrs) + for i := uint32(0); i < numAddrs; i++ { + addr, err := deserializeAddr(r) + if err != nil { + return err + } + (*e)[i] = addr + } + default: return UnknownElementType{"ReadElement", e} }