Skip to content

Commit

Permalink
rfqmsg: add SCID method to ID type
Browse files Browse the repository at this point in the history
The short channel ID (SCID) is derived from the message ID. We add a
method to the message ID type in an effort to remove duplication of the
SCID derivation code.
  • Loading branch information
ffranr committed Mar 21, 2024
1 parent d9da309 commit 13dddf3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
9 changes: 1 addition & 8 deletions rfqmsg/buy_accept.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rfqmsg

import (
"bytes"
"encoding/binary"
"fmt"
"io"

Expand Down Expand Up @@ -198,13 +197,7 @@ func NewBuyAcceptFromWireMsg(wireMsg WireMessage) (*BuyAccept, error) {

// ShortChannelId returns the short channel ID of the quote accept.
func (q *BuyAccept) ShortChannelId() SerialisedScid {
// Given valid RFQ message id, we then define a RFQ short chain id
// (SCID) by taking the last 8 bytes of the RFQ message id and
// interpreting them as a 64-bit integer.
scidBytes := q.ID[24:]

scidInteger := binary.BigEndian.Uint64(scidBytes)
return SerialisedScid(scidInteger)
return q.ID.Scid()
}

// ToWire returns a wire message with a serialized data field.
Expand Down
16 changes: 14 additions & 2 deletions rfqmsg/messages.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rfqmsg

import (
"encoding/binary"
"encoding/hex"
"errors"
"math"
Expand All @@ -9,6 +10,9 @@ import (
"github.com/lightningnetwork/lnd/routing/route"
)

// SerialisedScid is a serialised short channel id (SCID).
type SerialisedScid uint64

// ID is the identifier for a RFQ message.
type ID [32]byte

Expand All @@ -17,8 +21,16 @@ func (id ID) String() string {
return hex.EncodeToString(id[:])
}

// SerialisedScid is a serialised short channel id (SCID).
type SerialisedScid uint64
// Scid returns the short channel id (SCID) of the RFQ message.
func (id ID) Scid() SerialisedScid {
// Given valid RFQ message id, we then define a RFQ short channel id
// (SCID) by taking the last 8 bytes of the RFQ message id and
// interpreting them as a 64-bit integer.
scidBytes := id[24:]

scidInteger := binary.BigEndian.Uint64(scidBytes)
return SerialisedScid(scidInteger)
}

// MaxMessageType is the maximum supported message type value.
const MaxMessageType = lnwire.MessageType(math.MaxUint16)
Expand Down

0 comments on commit 13dddf3

Please sign in to comment.