watchtower/wtdb: add encode/decode to session info + updates

This commit is contained in:
Conner Fromknecht
2019-04-26 17:20:52 -07:00
parent dccef4c8bf
commit 7ba197c6a7
2 changed files with 47 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package wtdb
import (
"errors"
"io"
"github.com/lightningnetwork/lnd/watchtower/wtpolicy"
)
@@ -59,6 +60,28 @@ type SessionInfo struct {
// TODO(conner): store client metrics, DOS score, etc
}
// Encode serializes the session info to the given io.Writer.
func (s *SessionInfo) Encode(w io.Writer) error {
return WriteElements(w,
s.ID,
s.Policy,
s.LastApplied,
s.ClientLastApplied,
s.RewardAddress,
)
}
// Decode deserializes the session infor from the given io.Reader.
func (s *SessionInfo) Decode(r io.Reader) error {
return ReadElements(r,
&s.ID,
&s.Policy,
&s.LastApplied,
&s.ClientLastApplied,
&s.RewardAddress,
)
}
// AcceptUpdateSequence validates that a state update's sequence number and last
// applied are valid given our past history with the client. These checks ensure
// that clients are properly in sync and following the update protocol properly.