github.com/decred/dcrlnd@v0.7.6/watchtower/wtdb/session_state_update.go (about)

     1  package wtdb
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/decred/dcrlnd/watchtower/blob"
     7  )
     8  
     9  // SessionStateUpdate holds a state update sent by a client along with its
    10  // SessionID.
    11  type SessionStateUpdate struct {
    12  	// ID the session id of the client who sent the state update.
    13  	ID SessionID
    14  
    15  	// SeqNum the sequence number of the update within the session.
    16  	SeqNum uint16
    17  
    18  	// LastApplied the highest index that client has acknowledged is
    19  	// committed
    20  	LastApplied uint16
    21  
    22  	// Hint is the 16-byte prefix of the revoked commitment transaction.
    23  	Hint blob.BreachHint
    24  
    25  	// EncryptedBlob is a ciphertext containing the sweep information for
    26  	// exacting justice if the commitment transaction matching the breach
    27  	// hint is broadcast.
    28  	EncryptedBlob []byte
    29  }
    30  
    31  // Encode serializes the state update into the provided io.Writer.
    32  func (u *SessionStateUpdate) Encode(w io.Writer) error {
    33  	return WriteElements(w,
    34  		u.ID,
    35  		u.SeqNum,
    36  		u.LastApplied,
    37  		u.Hint,
    38  		u.EncryptedBlob,
    39  	)
    40  }
    41  
    42  // Decode deserializes the target state update from the provided io.Reader.
    43  func (u *SessionStateUpdate) Decode(r io.Reader) error {
    44  	return ReadElements(r,
    45  		&u.ID,
    46  		&u.SeqNum,
    47  		&u.LastApplied,
    48  		&u.Hint,
    49  		&u.EncryptedBlob,
    50  	)
    51  }