rfqmsg

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2024 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// MsgTypeRequest is the message type identifier for a quote request
	// message.
	MsgTypeRequest = TapMessageTypeBaseOffset + 0

	// MsgTypeAccept is the message type identifier for a quote accept
	// message.
	MsgTypeAccept = TapMessageTypeBaseOffset + 1

	// MsgTypeReject is the message type identifier for a quote
	// reject message.
	MsgTypeReject = TapMessageTypeBaseOffset + 2
)
View Source
const (
	TypeRejectVersion tlv.Type = 0
	TypeRejectID      tlv.Type = 2
	TypeRejectErrCode tlv.Type = 3
	TypeRejectErrMsg  tlv.Type = 5
)
View Source
const MaxMessageType = lnwire.MessageType(math.MaxUint16)

MaxMessageType is the maximum supported message type value.

View Source
const (
	// MaxNumOutputs is the maximum number of asset outputs that are allowed
	// in a single record. This mainly affects the maximum number of asset
	// UTXOs that can reside within a single commitment. This number should
	// in practice be very small (probably close to 1), as all outputs must
	// be from the same asset group but from different tranches to be
	// encoded as an individual record.
	MaxNumOutputs = 2048
)
View Source
const TapMessageTypeBaseOffset = 20116 + lnwire.CustomTypeStart

TapMessageTypeBaseOffset is the taproot-assets specific message type identifier base offset. All tap messages will have a type identifier that is greater than this value.

This offset was chosen as the concatenation of the alphabetical index positions of the letters "t" (20), "a" (1), and "p" (16).

Variables

View Source
var (
	// ErrUnknownReject is the error code for when the quote is rejected
	// for an unspecified reason.
	ErrUnknownReject = RejectErr{
		Code: 0,
		Msg:  "unknown reject error",
	}

	// ErrPriceOracleUnavailable is the error code for when the price oracle
	// is unavailable.
	ErrPriceOracleUnavailable = RejectErr{
		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",
	}
)
View Source
var (
	// ErrListInvalid is the error that's returned when a list of encoded
	// entries is invalid.
	ErrListInvalid = errors.New("encoded list is invalid")
)
View Source
var (
	// ErrUnknownMessageType is an error that is returned when an unknown
	// message type is encountered.
	ErrUnknownMessageType = errors.New("unknown message type")
)

Functions

func AssetIdDecoder

func AssetIdDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error

func AssetIdEncoder

func AssetIdEncoder(w io.Writer, val any, buf *[8]byte) error

func IdDecoder

func IdDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error

func IdEncoder

func IdEncoder(w io.Writer, val any, buf *[8]byte) error

func SomeRfqIDRecord

func SomeRfqIDRecord(id ID) tlv.OptionalRecordT[HtlcRfqIDType, ID]

SomeRfqIDRecord creates an optional record that represents an RFQ ID.

func Sum

func Sum(balances []*AssetBalance) uint64

Sum returns the sum of the amounts of all the asset Balances in the list.

func TypeRecordRejectErrCode

func TypeRecordRejectErrCode(errCode *uint8) tlv.Record

func TypeRecordRejectErrMsg

func TypeRecordRejectErrMsg(errMsg *string) tlv.Record

func TypeRecordRejectID

func TypeRecordRejectID(id *ID) tlv.Record

func TypeRecordRejectVersion

func TypeRecordRejectVersion(version *WireMsgDataVersion) tlv.Record

func WireMsgDataVersionDecoder

func WireMsgDataVersionDecoder(r io.Reader, val any, buf *[8]byte,
	l uint64) error

WireMsgDataVersionDecoder is a function that can be used to decode a WireMsgDataVersion from a reader.

func WireMsgDataVersionEncoder

func WireMsgDataVersionEncoder(w io.Writer, val any, buf *[8]byte) error

WireMsgDataVersionEncoder is a function that can be used to encode a WireMsgDataVersion to a writer.

Types

type AssetBalance

type AssetBalance struct {
	// AssetID is the ID of the asset that this output is associated with.
	AssetID tlv.RecordT[tlv.TlvType0, asset.ID]

	// Amount is the amount of the asset that this output represents.
	Amount tlv.RecordT[tlv.TlvType1, uint64]
}

AssetBalance is a record that represents the amount of an asset that is being transferred or is available to be spent.

func DecodeAssetBalance

func DecodeAssetBalance(blob tlv.Blob) (*AssetBalance, error)

DecodeAssetBalance deserializes a AssetBalance from the given blob.

func NewAssetBalance

func NewAssetBalance(assetID asset.ID, amount uint64) *AssetBalance

NewAssetBalance creates a new AssetBalance record with the given asset ID and amount.

func (*AssetBalance) Bytes

func (a *AssetBalance) Bytes() []byte

Bytes returns the serialized AssetBalance record.

func (*AssetBalance) Decode

func (a *AssetBalance) Decode(r io.Reader) error

Decode deserializes the AssetBalance from the given io.Reader.

func (*AssetBalance) Encode

func (a *AssetBalance) Encode(w io.Writer) error

Encode serializes the AssetBalance to the given io.Writer.

type AssetBalanceListRecord

type AssetBalanceListRecord struct {
	Balances []*AssetBalance
}

AssetBalanceListRecord is a record that represents a list of asset Balances.

func (*AssetBalanceListRecord) Decode

func (l *AssetBalanceListRecord) Decode(r io.Reader) error

Decode deserializes the AssetBalanceListRecord from the given io.Reader.

func (*AssetBalanceListRecord) Encode

func (l *AssetBalanceListRecord) Encode(w io.Writer) error

Encode serializes the AssetBalanceListRecord to the given io.Writer.

func (*AssetBalanceListRecord) Record

func (l *AssetBalanceListRecord) Record() tlv.Record

Record creates a Record out of a AssetBalanceListRecord using the eAssetBalanceList and dAssetBalanceList functions.

NOTE: This is part of the tlv.RecordProducer interface.

func (*AssetBalanceListRecord) Sum

func (l *AssetBalanceListRecord) Sum() uint64

Sum returns the sum of the amounts of all the asset Balances in the list.

type BuyAccept

type BuyAccept struct {
	// Peer is the peer that sent the quote request.
	Peer route.Vertex

	// Request is the quote request message that this message responds to.
	// This field is not included in the wire message.
	Request BuyRequest

	// Version is the version of the message data.
	Version WireMsgDataVersion

	// ID represents the unique identifier of the quote request message that
	// this response is associated with.
	ID ID

	// AskPrice is the asking price of the quote in milli-satoshis per asset
	// unit.
	AskPrice lnwire.MilliSatoshi

	// Expiry is the asking price expiry lifetime unix timestamp.
	Expiry uint64
	// contains filtered or unexported fields
}

BuyAccept is a struct that represents a buy quote request accept message.

func NewBuyAcceptFromRequest

func NewBuyAcceptFromRequest(request BuyRequest, askPrice lnwire.MilliSatoshi,
	expiry uint64) *BuyAccept

NewBuyAcceptFromRequest creates a new instance of a quote accept message given a quote request message.

func (*BuyAccept) MsgID

func (q *BuyAccept) MsgID() ID

MsgID returns the quote request session ID.

func (*BuyAccept) MsgPeer

func (q *BuyAccept) MsgPeer() route.Vertex

MsgPeer returns the peer that sent the message.

func (*BuyAccept) ShortChannelId

func (q *BuyAccept) ShortChannelId() SerialisedScid

ShortChannelId returns the short channel ID of the quote accept.

func (*BuyAccept) String

func (q *BuyAccept) String() string

String returns a human-readable string representation of the message.

func (*BuyAccept) ToWire

func (q *BuyAccept) ToWire() (WireMessage, error)

ToWire returns a wire message with a serialized data field.

TODO(ffranr): This method should accept a signer so that we can generate a signature over the message data.

type BuyRequest

type BuyRequest struct {
	// Peer is the peer that sent the quote request.
	Peer route.Vertex

	// Version is the version of the message data.
	Version WireMsgDataVersion

	// ID is the unique identifier of the quote request.
	ID ID

	// AssetID represents the identifier of the asset for which the peer
	// is requesting a quote.
	AssetID *asset.ID

	// AssetGroupKey is the public group key of the asset for which the peer
	// is requesting a quote.
	AssetGroupKey *btcec.PublicKey

	// AssetAmount is the amount of the asset for which the peer is
	// requesting a quote.
	AssetAmount uint64

	// BidPrice is the peer's proposed bid price for the asset amount.
	BidPrice lnwire.MilliSatoshi
}

BuyRequest is a struct that represents an asset buy quote request.

func NewBuyRequest

func NewBuyRequest(peer route.Vertex, assetID *asset.ID,
	assetGroupKey *btcec.PublicKey, assetAmount uint64,
	bidPrice lnwire.MilliSatoshi) (*BuyRequest, error)

NewBuyRequest creates a new asset buy quote request.

func NewBuyRequestMsgFromWire

func NewBuyRequestMsgFromWire(wireMsg WireMessage,
	msgData requestWireMsgData) (*BuyRequest, error)

NewBuyRequestMsgFromWire instantiates a new instance from a wire message.

func (*BuyRequest) String

func (q *BuyRequest) String() string

String returns a human-readable string representation of the message.

func (*BuyRequest) ToWire

func (q *BuyRequest) ToWire() (WireMessage, error)

ToWire returns a wire message with a serialized data field.

func (*BuyRequest) Validate

func (q *BuyRequest) Validate() error

Validate ensures that the buy request is valid.

type Htlc

type Htlc struct {
	// Amounts is a list of asset balances that are changed by the HTLC.
	Amounts tlv.RecordT[HtlcAmountRecordType, AssetBalanceListRecord]

	// RfqID is the RFQ ID that corresponds to the HTLC.
	RfqID tlv.OptionalRecordT[HtlcRfqIDType, ID]
}

Htlc is a record that represents the capacity change related to an in-flight HTLC. This entails all the (asset_id, amount) tuples and other information that we may need to be able to update the TAP portion of a commitment balance.

func DecodeHtlc

func DecodeHtlc(blob tlv.Blob) (*Htlc, error)

DecodeHtlc deserializes a Htlc from the given blob.

func HtlcFromCustomRecords

func HtlcFromCustomRecords(records lnwire.CustomRecords) (*Htlc, error)

HtlcFromCustomRecords creates a new Htlc record from the given custom records.

func NewHtlc

func NewHtlc(amounts []*AssetBalance, rfqID fn.Option[ID]) *Htlc

NewHtlc creates a new Htlc record with the given funded assets.

func (*Htlc) Balances

func (h *Htlc) Balances() []*AssetBalance

Balances returns the list of asset Balances that are updated in the Htlc struct.

func (*Htlc) Bytes

func (h *Htlc) Bytes() []byte

Bytes returns the serialized Htlc record.

func (*Htlc) Decode

func (h *Htlc) Decode(r io.Reader) error

Decode deserializes the Htlc from the given io.Reader.

func (*Htlc) Encode

func (h *Htlc) Encode(w io.Writer) error

Encode serializes the Htlc to the given io.Writer.

func (*Htlc) Records

func (h *Htlc) Records() []tlv.Record

Records returns the records that make up the Htlc.

type HtlcAmountRecordType

type HtlcAmountRecordType = tlv.TlvType65536

HtlcAmountRecordType is a type alias for the TLV type that is used to encode an asset ID and amount list within the custom records of an HTLC record on the wire.

type HtlcRfqIDType

type HtlcRfqIDType = tlv.TlvType65538

HtlcRfqIDType is the type alias for the TLV type that is used to encode an RFQ id within the custom records of an HTLC record on the wire.

type ID

type ID [32]byte

ID is the identifier for a RFQ message.

func (*ID) Record

func (id *ID) Record() tlv.Record

Record returns a TLV record that can be used to encode/decode an ID to/from a TLV stream.

NOTE: This is part of the tlv.RecordProducer interface.

func (ID) Scid

func (id ID) Scid() SerialisedScid

Scid returns the short channel id (SCID) of the RFQ message.

func (ID) String

func (id ID) String() string

String returns the string representation of the ID.

type IncomingMsg

type IncomingMsg interface {
	// String returns a human-readable string representation of the message.
	String() string
}

IncomingMsg is an interface that represents an inbound wire message that has been received from a peer.

func NewIncomingAcceptFromWire

func NewIncomingAcceptFromWire(wireMsg WireMessage) (IncomingMsg, error)

NewIncomingAcceptFromWire creates a new quote accept message from an incoming wire message.

This is an incoming accept message. An incoming buy accept message indicates that our peer accepts our buy request, meaning they are willing to sell the asset to us. Conversely, an incoming sell accept message indicates that our peer accepts our sell request, meaning they are willing to buy the asset from us.

func NewIncomingMsgFromWire

func NewIncomingMsgFromWire(wireMsg WireMessage) (IncomingMsg, error)

NewIncomingMsgFromWire creates a new RFQ message from a wire message.

func NewIncomingRequestFromWire

func NewIncomingRequestFromWire(wireMsg WireMessage) (IncomingMsg, error)

NewIncomingRequestFromWire creates a new request message from an incoming wire message.

Note that this is an incoming request. Which means that a buy request is a request from our peer to buy the asset from us, and a sell request is a request from out peer to sell the asset to us.

type JsonAssetBalance

type JsonAssetBalance struct {
	AssetID       string `json:"asset_id"`
	Name          string `json:"name"`
	LocalBalance  uint64 `json:"local_balance"`
	RemoteBalance uint64 `json:"remote_balance"`
}

JsonAssetBalance is a struct that represents the balance of a single asset ID within a channel.

type JsonAssetChanInfo

type JsonAssetChanInfo struct {
	AssetInfo     JsonAssetUtxo `json:"asset_utxo"`
	Capacity      uint64        `json:"capacity"`
	LocalBalance  uint64        `json:"local_balance"`
	RemoteBalance uint64        `json:"remote_balance"`
}

JsonAssetChanInfo is a struct that represents the channel information of a single asset within a channel.

type JsonAssetChannel

type JsonAssetChannel struct {
	Assets []JsonAssetChanInfo `json:"assets"`
}

JsonAssetChannel is a struct that represents the channel information of all assets within a channel.

type JsonAssetChannelBalances

type JsonAssetChannelBalances struct {
	OpenChannels    map[string]*JsonAssetBalance `json:"open_channels"`
	PendingChannels map[string]*JsonAssetBalance `json:"pending_channels"`
}

JsonAssetChannelBalances is a struct that represents the balance information of all assets within open and pending channels.

type JsonAssetGenesis

type JsonAssetGenesis struct {
	GenesisPoint string `json:"genesis_point"`
	Name         string `json:"name"`
	MetaHash     string `json:"meta_hash"`
	AssetID      string `json:"asset_id"`
}

JsonAssetGenesis is a struct that represents the genesis information of an asset.

type JsonAssetUtxo

type JsonAssetUtxo struct {
	Version      int64            `json:"version"`
	AssetGenesis JsonAssetGenesis `json:"asset_genesis"`
	Amount       uint64           `json:"amount"`
	ScriptKey    string           `json:"script_key"`
}

JsonAssetUtxo is a struct that represents the UTXO information of an asset within a channel.

type JsonCloseOutput

type JsonCloseOutput struct {
	BtcInternalKey   string            `json:"btc_internal_key"`
	AssetInternalKey string            `json:"asset_internal_key"`
	ScriptKeys       map[string]string `json:"script_keys"`
}

JsonCloseOutput is a struct that represents the additional co-op close output information of asset channels.

type OutgoingMsg

type OutgoingMsg interface {
	// String returns a human-readable string representation of the message.
	String() string

	// ToWire returns a wire message with a serialized data field.
	ToWire() (WireMessage, error)
}

OutgoingMsg is an interface that represents an outbound wire message that can be sent to a peer.

type QuoteResponse

type QuoteResponse interface {
	// MsgPeer returns the peer that sent the message.
	MsgPeer() route.Vertex

	// MsgID returns the quote request session ID.
	MsgID() ID

	// String returns a human-readable string representation of the message.
	String() string
}

QuoteResponse defines an interface for handling incoming peer messages that serve as responses to quote requests.

type Reject

type Reject struct {
	// Peer is the peer that sent the quote request.
	Peer route.Vertex
	// contains filtered or unexported fields
}

Reject is a struct that represents a quote reject message.

func NewQuoteRejectFromWireMsg

func NewQuoteRejectFromWireMsg(wireMsg WireMessage) (*Reject, error)

NewQuoteRejectFromWireMsg instantiates a new instance from a wire message.

func NewReject

func NewReject(peer route.Vertex, requestId ID,
	rejectErr RejectErr) *Reject

NewReject creates a new instance of a quote reject message.

func (*Reject) Bytes

func (q *Reject) Bytes() ([]byte, error)

Bytes encodes the structure into a TLV stream and returns the bytes.

func (*Reject) Decode

func (q *Reject) Decode(r io.Reader) error

Decode decodes the structure from a TLV stream.

func (*Reject) Encode

func (q *Reject) Encode(writer io.Writer) error

Encode encodes the structure into a TLV stream.

func (*Reject) String

func (q *Reject) String() string

String returns a human-readable string representation of the message.

func (*Reject) ToWire

func (q *Reject) ToWire() (WireMessage, error)

ToWire returns a wire message with a serialized data field.

type RejectErr

type RejectErr struct {
	// Code is the error code that provides the reason for the rejection.
	Code uint8

	// Msg is the error message that provides the reason for the rejection.
	Msg string
}

RejectErr is a struct that represents the error code and message of a quote reject message.

type SellAccept

type SellAccept struct {
	// Peer is the peer that sent the quote request.
	Peer route.Vertex

	// Request is the quote request message that this message responds to.
	// This field is not included in the wire message.
	Request SellRequest

	// Version is the version of the message data.
	Version WireMsgDataVersion

	// ID represents the unique identifier of the asset sell quote request
	// message that this response is associated with.
	ID ID

	// BidPrice is the bid price that the message author is willing to pay
	// for the asset that is for sale.
	BidPrice lnwire.MilliSatoshi

	// Expiry is the bid price expiry lifetime unix timestamp.
	Expiry uint64
	// contains filtered or unexported fields
}

SellAccept is a struct that represents a sell quote request accept message.

func NewSellAcceptFromRequest

func NewSellAcceptFromRequest(request SellRequest, bidPrice lnwire.MilliSatoshi,
	expiry uint64) *SellAccept

NewSellAcceptFromRequest creates a new instance of an asset sell quote accept message given an asset sell quote request message.

func (*SellAccept) MsgID

func (q *SellAccept) MsgID() ID

MsgID returns the quote request session ID.

func (*SellAccept) MsgPeer

func (q *SellAccept) MsgPeer() route.Vertex

MsgPeer returns the peer that sent the message.

func (*SellAccept) ShortChannelId

func (q *SellAccept) ShortChannelId() SerialisedScid

ShortChannelId returns the short channel ID associated with the asset sale event.

func (*SellAccept) String

func (q *SellAccept) String() string

String returns a human-readable string representation of the message.

func (*SellAccept) ToWire

func (q *SellAccept) ToWire() (WireMessage, error)

ToWire returns a wire message with a serialized data field.

TODO(ffranr): This method should accept a signer so that we can generate a signature over the message data.

type SellRequest

type SellRequest struct {
	// Peer is the peer that sent the quote request.
	Peer route.Vertex

	// Version is the version of the message data.
	Version WireMsgDataVersion

	// ID is the unique identifier of the quote request.
	ID ID

	// AssetID represents the identifier of the asset for which the peer
	// is requesting a quote.
	AssetID *asset.ID

	// AssetGroupKey is the public group key of the asset for which the peer
	// is requesting a quote.
	AssetGroupKey *btcec.PublicKey

	// AssetAmount represents the quantity of the specific asset that the
	// peer intends to sell.
	AssetAmount uint64

	// AskPrice is the peer's proposed ask price for the asset amount. This
	// is not the final price, but a suggested price that the requesting
	// peer is willing to accept.
	AskPrice lnwire.MilliSatoshi
}

SellRequest is a struct that represents a asset sell quote request.

func NewSellRequest

func NewSellRequest(peer route.Vertex, assetID *asset.ID,
	assetGroupKey *btcec.PublicKey, assetAmount uint64,
	askPrice lnwire.MilliSatoshi) (*SellRequest, error)

NewSellRequest creates a new asset sell quote request.

func NewSellRequestMsgFromWire

func NewSellRequestMsgFromWire(wireMsg WireMessage,
	msgData requestWireMsgData) (*SellRequest, error)

NewSellRequestMsgFromWire instantiates a new instance from a wire message.

func (*SellRequest) String

func (q *SellRequest) String() string

String returns a human-readable string representation of the message.

func (*SellRequest) ToWire

func (q *SellRequest) ToWire() (WireMessage, error)

ToWire returns a wire message with a serialized data field.

func (*SellRequest) Validate

func (q *SellRequest) Validate() error

Validate ensures that the quote request is valid.

type SerialisedScid

type SerialisedScid uint64

SerialisedScid is a serialised short channel id (SCID).

type WireMessage

type WireMessage struct {
	// Peer is the origin/destination peer for this message.
	Peer route.Vertex

	// MsgType is the protocol message type number.
	MsgType lnwire.MessageType

	// Data is the data exchanged.
	Data []byte
}

WireMessage is a struct that represents a general wire message.

type WireMsgDataVersion

type WireMsgDataVersion uint8

WireMsgDataVersion specifies the version of the contents within a wire message data field.

const (
	// V0 represents version 0 of the contents in a wire message data field.
	V0 WireMsgDataVersion = 0
)

func (*WireMsgDataVersion) Record

func (v *WireMsgDataVersion) Record() tlv.Record

Record returns a TLV record that can be used to encode/decode a WireMsgDataVersion to/from a TLV stream.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL