mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 06:07:16 +01:00
watchtower/multi: switch over to wtpolicy
migrate to using wtpolicy.Policy in wtwire messages and wtserver
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/watchtower/blob"
|
||||
)
|
||||
|
||||
// CreateSession is sent from a client to tower when to negotiate a session, which
|
||||
@@ -11,9 +12,9 @@ import (
|
||||
// An update is consumed by uploading an encrypted blob that contains
|
||||
// information required to sweep a revoked commitment transaction.
|
||||
type CreateSession struct {
|
||||
// BlobVersion specifies the blob format that must be used by all
|
||||
// updates sent under the session key used to negotiate this session.
|
||||
BlobVersion uint16
|
||||
// BlobType specifies the blob format that must be used by all updates sent
|
||||
// under the session key used to negotiate this session.
|
||||
BlobType blob.Type
|
||||
|
||||
// MaxUpdates is the maximum number of updates the watchtower will honor
|
||||
// for this session.
|
||||
@@ -41,7 +42,7 @@ var _ Message = (*CreateSession)(nil)
|
||||
// This is part of the wtwire.Message interface.
|
||||
func (m *CreateSession) Decode(r io.Reader, pver uint32) error {
|
||||
return ReadElements(r,
|
||||
&m.BlobVersion,
|
||||
&m.BlobType,
|
||||
&m.MaxUpdates,
|
||||
&m.RewardRate,
|
||||
&m.SweepFeeRate,
|
||||
@@ -54,7 +55,7 @@ func (m *CreateSession) Decode(r io.Reader, pver uint32) error {
|
||||
// This is part of the wtwire.Message interface.
|
||||
func (m *CreateSession) Encode(w io.Writer, pver uint32) error {
|
||||
return WriteElements(w,
|
||||
m.BlobVersion,
|
||||
m.BlobType,
|
||||
m.MaxUpdates,
|
||||
m.RewardRate,
|
||||
m.SweepFeeRate,
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/watchtower/blob"
|
||||
)
|
||||
|
||||
// WriteElement is a one-stop shop to write the big endian representation of
|
||||
@@ -30,6 +31,13 @@ func WriteElement(w io.Writer, element interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
case blob.Type:
|
||||
var b [2]byte
|
||||
binary.BigEndian.PutUint16(b[:], uint16(e))
|
||||
if _, err := w.Write(b[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case uint32:
|
||||
var b [4]byte
|
||||
binary.BigEndian.PutUint32(b[:], e)
|
||||
@@ -127,6 +135,13 @@ func ReadElement(r io.Reader, element interface{}) error {
|
||||
}
|
||||
*e = binary.BigEndian.Uint16(b[:])
|
||||
|
||||
case *blob.Type:
|
||||
var b [2]byte
|
||||
if _, err := io.ReadFull(r, b[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
*e = blob.Type(binary.BigEndian.Uint16(b[:]))
|
||||
|
||||
case *uint32:
|
||||
var b [4]byte
|
||||
if _, err := io.ReadFull(r, b[:]); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user