watchtower/wtdb: add encode/decode to session info + updates
This commit is contained in:
parent
dccef4c8bf
commit
7ba197c6a7
@ -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.
|
||||
|
@ -1,5 +1,7 @@
|
||||
package wtdb
|
||||
|
||||
import "io"
|
||||
|
||||
// SessionStateUpdate holds a state update sent by a client along with its
|
||||
// SessionID.
|
||||
type SessionStateUpdate struct {
|
||||
@ -21,3 +23,25 @@ type SessionStateUpdate struct {
|
||||
// hint is braodcast.
|
||||
EncryptedBlob []byte
|
||||
}
|
||||
|
||||
// Encode serializes the state update into the provided io.Writer.
|
||||
func (u *SessionStateUpdate) Encode(w io.Writer) error {
|
||||
return WriteElements(w,
|
||||
u.ID,
|
||||
u.SeqNum,
|
||||
u.LastApplied,
|
||||
u.Hint,
|
||||
u.EncryptedBlob,
|
||||
)
|
||||
}
|
||||
|
||||
// Decode deserializes the target state update from the provided io.Reader.
|
||||
func (u *SessionStateUpdate) Decode(r io.Reader) error {
|
||||
return ReadElements(r,
|
||||
&u.ID,
|
||||
&u.SeqNum,
|
||||
&u.LastApplied,
|
||||
&u.Hint,
|
||||
&u.EncryptedBlob,
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user