Skip to content

Commit a1d989d

Browse files
committed
rfqmsg: use transfer type for buy/sell request classification
Update the buy/sell classification logic for incoming requests to rely on the new transfer type field. When the requesting peer attempts to pay an invoice using a Tap asset, they are "selling" the Tap asset to the edge node. Conversely, when the requesting peer attempts to receive a Tap asset as payment to settle an invoice, they are "buying" the Tap asset from the edge node.
1 parent ee8aac2 commit a1d989d

File tree

1 file changed

+14
-38
lines changed

1 file changed

+14
-38
lines changed

rfqmsg/request.go

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -509,44 +509,20 @@ func NewIncomingRequestFromWire(wireMsg WireMessage) (IncomingMsg, error) {
509509
"request: %w", err)
510510
}
511511

512-
// We will now determine whether this is a buy or sell request. We
513-
// currently only support exchanging a taproot asset for BTC. Therefore,
514-
// we can distinguish between buy/sell requests by identifying the all
515-
// zero in/out asset ID which designates BTC.
516-
isBuyRequest := false
517-
518-
// Check the outgoing asset ID to determine if this is a buy request.
519-
msgData.OutAssetID.WhenSome(
520-
func(outAssetID tlv.RecordT[tlv.TlvType13, asset.ID]) {
521-
var zeroAssetID [32]byte
522-
523-
// If the outgoing asset ID is all zeros (signifying
524-
// BTC), then this is a buy request. In other words, the
525-
// incoming asset is the taproot asset, and the outgoing
526-
// asset is BTC.
527-
isBuyRequest = outAssetID.Val == zeroAssetID
528-
},
529-
)
530-
531-
// The outgoing asset ID may not be set, but the outgoing asset group
532-
// key may be set. If the outbound asset group key is not specified
533-
// (and the outbound asset ID is not set), then this is a buy request.
534-
// In other words, only the inbound asset is specified, and the outbound
535-
// asset is BTC.
536-
msgData.OutAssetGroupKey.WhenSome(
537-
func(gk tlv.RecordT[tlv.TlvType15, *btcec.PublicKey]) {
538-
// Here we carry through any ture value of isBuyRequest
539-
// from the previous check.
540-
isBuyRequest = isBuyRequest || (gk.Val != nil)
541-
},
542-
)
543-
544-
// If this is a buy request, then we will create a new buy request
545-
// message.
546-
if isBuyRequest {
512+
// Classify the incoming request as a buy or sell.
513+
//
514+
// When the requesting peer attempts to pay an invoice using a Tap
515+
// asset, they are "selling" the Tap asset to the edge node. Conversely,
516+
// when the requesting peer attempts to receive a Tap asset as payment
517+
// to settle an invoice, they are "buying" the Tap asset from the edge
518+
// node.
519+
switch msgData.TransferType.Val {
520+
case PayInvoiceTransferType:
521+
return NewSellRequestFromWire(wireMsg, msgData)
522+
case RecvPaymentTransferType:
547523
return NewBuyRequestFromWire(wireMsg, msgData)
524+
default:
525+
return nil, fmt.Errorf("unknown incoming request message "+
526+
"transfer type: %d", msgData.TransferType.Val)
548527
}
549-
550-
// Otherwise, this is a sell request.
551-
return NewSellRequestFromWire(wireMsg, msgData)
552528
}

0 commit comments

Comments
 (0)