Skip to content

Commit

Permalink
tapchannel: add assetIDFromQuote helper
Browse files Browse the repository at this point in the history
We add a simple assetIDFromQuote function that fetches the asset ID
associated with a certain accepted quote identified by its rfq ID. We
will later use this in the handleInvoice function to compare the asset
ID of the quote with that of the HTLCs.
  • Loading branch information
GeorgeTsagk committed Jan 16, 2025
1 parent e631a03 commit e177bd2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tapchannel/aux_invoice_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/lightninglabs/lndclient"
"github.com/lightninglabs/taproot-assets/address"
"github.com/lightninglabs/taproot-assets/asset"
"github.com/lightninglabs/taproot-assets/fn"
"github.com/lightninglabs/taproot-assets/rfq"
"github.com/lightninglabs/taproot-assets/rfqmath"
Expand Down Expand Up @@ -247,6 +248,34 @@ func (s *AuxInvoiceManager) handleInvoiceAccept(_ context.Context,
return resp, nil
}

// assetIDFromQuote retrieves the quote by looking up the rfq manager's maps of
// accepted quotes based on the passed rfq ID. If there's a match, the asset
// ID is returned.
func (s *AuxInvoiceManager) assetIDFromQuote(
rfqID rfqmsg.ID) (*asset.ID, error) {

acceptedBuyQuotes := s.cfg.RfqManager.PeerAcceptedBuyQuotes()
acceptedSellQuotes := s.cfg.RfqManager.LocalAcceptedSellQuotes()

buyQuote, isBuy := acceptedBuyQuotes[rfqID.Scid()]
sellQuote, isSell := acceptedSellQuotes[rfqID.Scid()]

switch {
case isBuy:
if buyQuote.Request.AssetSpecifier.HasId() {
return buyQuote.Request.AssetSpecifier.UnwrapIdToPtr(), nil
}

case isSell:
if sellQuote.Request.AssetSpecifier.HasId() {
return sellQuote.Request.AssetSpecifier.UnwrapIdToPtr(), nil
}
}

return nil, fmt.Errorf("rfqID does not match any accepted buy or " +
"sell quote")
}

// priceFromQuote retrieves the price from the accepted quote for the given RFQ
// ID. We allow the quote to either be a buy or a sell quote, since we don't
// know if this is a direct peer payment or a payment that is routed through the
Expand Down

0 comments on commit e177bd2

Please sign in to comment.