Skip to content

Commit

Permalink
Merge pull request #1124 from lightninglabs/rfq-simple-refactor
Browse files Browse the repository at this point in the history
RFQ cleanup
  • Loading branch information
guggero authored Sep 17, 2024
2 parents 552f838 + 9351be1 commit 15582a5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 55 deletions.
31 changes: 0 additions & 31 deletions rfqmsg/records.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rfqmsg

import (
"bytes"
"crypto/sha256"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -391,33 +390,3 @@ func IdDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error {

return tlv.NewTypeForDecodingErr(val, "MessageID", l, idBytesLen)
}

func AssetIdEncoder(w io.Writer, val any, buf *[8]byte) error {
if t, ok := val.(**asset.ID); ok {
id := [sha256.Size]byte(**t)
return tlv.EBytes32(w, &id, buf)
}

return tlv.NewTypeForEncodingErr(val, "assetId")
}

func AssetIdDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error {
const assetIDBytesLen = sha256.Size

if typ, ok := val.(**asset.ID); ok {
var idBytes [assetIDBytesLen]byte

err := tlv.DBytes32(r, &idBytes, buf, assetIDBytesLen)
if err != nil {
return err
}

id := asset.ID(idBytes)
assetId := &id

*typ = assetId
return nil
}

return tlv.NewTypeForDecodingErr(val, "assetId", l, sha256.Size)
}
14 changes: 0 additions & 14 deletions rfqmsg/reject.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,6 @@ var (
Code: 1,
Msg: "price oracle unavailable",
}

// ErrNoSuitableSellOffer is the error code for when there is no
// suitable sell offer available.
ErrNoSuitableSellOffer = RejectErr{
Code: 2,
Msg: "no suitable sell offer available",
}

// ErrNoSuitableBuyOffer is the error code for when there is no suitable
// buy offer available.
ErrNoSuitableBuyOffer = RejectErr{
Code: 3,
Msg: "no suitable buy offer available",
}
)

const (
Expand Down
10 changes: 8 additions & 2 deletions rfqmsg/reject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@ func TestRejectEncodeDecode(t *testing.T) {
peer: route.Vertex{1, 2, 3},
version: 0,
id: id,
err: ErrNoSuitableSellOffer,
},
{
testName: "all fields populated with basic values",
peer: route.Vertex{1, 2, 3},
version: 5,
id: id,
err: ErrNoSuitableBuyOffer,
},
{
testName: "all fields populated with basic values; " +
"error field populated",
peer: route.Vertex{1, 2, 3},
version: 5,
id: id,
err: ErrPriceOracleUnavailable,
},
}

Expand Down
9 changes: 1 addition & 8 deletions rfqmsg/sell_accept.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package rfqmsg

import (
"encoding/binary"
"fmt"

"github.com/lightningnetwork/lnd/lnwire"
Expand Down Expand Up @@ -94,13 +93,7 @@ func newSellAcceptFromWireMsg(wireMsg WireMessage,
// ShortChannelId returns the short channel ID associated with the asset sale
// event.
func (q *SellAccept) 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

0 comments on commit 15582a5

Please sign in to comment.