Skip to content

Commit da10dba

Browse files
committed
WIP
1 parent d1f928f commit da10dba

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

rfqmessages/quote_request.go

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package rfqmessages
22

33
import (
44
"crypto/sha256"
5+
"fmt"
56
"io"
67

78
"github.com/btcsuite/btcd/btcec/v2"
@@ -118,6 +119,20 @@ type QuoteRequest struct {
118119
SuggestedRateTick uint64
119120
}
120121

122+
// Validate ensures that the quote request is valid.
123+
func (q *QuoteRequest) Validate() error {
124+
if q.AssetID == nil && q.AssetGroupKey == nil {
125+
return fmt.Errorf("asset id and group key cannot both be nil")
126+
}
127+
128+
if q.AssetID != nil && q.AssetGroupKey != nil {
129+
return fmt.Errorf("asset id and group key cannot both be " +
130+
"non-nil")
131+
}
132+
133+
return nil
134+
}
135+
121136
// EncodeRecords determines the non-nil records to include when encoding an
122137
// asset witness at runtime.
123138
func (q *QuoteRequest) EncodeRecords() []tlv.Record {

rfqservice/stream.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ func NewStreamHandler(ctx context.Context,
7171
}, nil
7272
}
7373

74-
// handleRecvRawMessage handles an incoming raw peer message.
75-
func (h *StreamHandler) handleQuoteRequestMsg(
74+
// handleIncomingRawMessage handles an incoming raw peer message.
75+
func (h *StreamHandler) handleIncomingQuoteRequestMsg(
7676
rawMsg lndclient.CustomMessage) error {
7777

7878
// Attempt to decode the message as a request for quote (RFQ) message.
@@ -83,6 +83,12 @@ func (h *StreamHandler) handleQuoteRequestMsg(
8383
err)
8484
}
8585

86+
// Validate incoming quote request.
87+
if err = quoteRequest.Validate(); err != nil {
88+
return fmt.Errorf("unable to validate incoming RFQ message: %w",
89+
err)
90+
}
91+
8692
// TODO(ffranr): Determine whether to keep or discard the RFQ message
8793
// based on the peer's ID and the asset's ID.
8894

@@ -98,13 +104,13 @@ func (h *StreamHandler) handleQuoteRequestMsg(
98104
return nil
99105
}
100106

101-
// handleRecvRawMessage handles an incoming raw peer message.
102-
func (h *StreamHandler) handleRecvRawMessage(
107+
// handleIncomingRawMessage handles an incoming raw peer message.
108+
func (h *StreamHandler) handleIncomingRawMessage(
103109
rawMsg lndclient.CustomMessage) error {
104110

105111
switch rawMsg.MsgType {
106112
case msg.MsgTypeQuoteRequest:
107-
err := h.handleQuoteRequestMsg(rawMsg)
113+
err := h.handleIncomingQuoteRequestMsg(rawMsg)
108114
if err != nil {
109115
return fmt.Errorf("unable to handle incoming quote "+
110116
"request message: %w", err)
@@ -130,8 +136,9 @@ func (h *StreamHandler) Start() error {
130136
"channel closed unexpectedly")
131137
}
132138

133-
log.Infof("Received raw custom message: %v", rawMsg)
134-
err := h.handleRecvRawMessage(rawMsg)
139+
log.Infof("Handling incoming raw custom message: %v",
140+
rawMsg)
141+
err := h.handleIncomingRawMessage(rawMsg)
135142
if err != nil {
136143
log.Warnf("Error handling raw custom "+
137144
"message recieve event: %v", err)

0 commit comments

Comments
 (0)