@@ -419,6 +419,38 @@ func IsAssetInvoice(invoice *lnrpc.Invoice, rfqLookup RfqLookup) bool {
419419 return false
420420}
421421
422+ // GetBuyQuoteFromRouteHints is a helper method that extracts a buy quote from
423+ // the route hints of an invoice, given that the quote is accepted and has a
424+ // matching specifier. If no matching quote is found, it returns an error.
425+ func (s * AuxInvoiceManager ) GetBuyQuoteFromRouteHints (invoice * lnrpc.Invoice ,
426+ specifier asset.Specifier ) (* rfqmsg.BuyAccept , error ) {
427+
428+ buyQuotes := s .cfg .RfqManager .PeerAcceptedBuyQuotes ()
429+ for _ , hint := range invoice .RouteHints {
430+ for _ , h := range hint .HopHints {
431+ scid := rfqmsg .SerialisedScid (h .ChanId )
432+ buyQuote , ok := buyQuotes [scid ]
433+ if ! ok {
434+ continue
435+ }
436+
437+ quoteSpecifier := buyQuote .Request .AssetSpecifier
438+ areEqual , err := quoteSpecifier .Equal (& specifier , false )
439+ if err != nil {
440+ return nil , fmt .Errorf ("error comparing " +
441+ "specifiers: %w" , err )
442+ }
443+
444+ if areEqual {
445+ return & buyQuote , nil
446+ }
447+ }
448+ }
449+
450+ return nil , fmt .Errorf ("no buy quote found for specifier %s" ,
451+ specifier .String ())
452+ }
453+
422454// validateAssetHTLC runs a couple of checks on the provided asset HTLC.
423455func (s * AuxInvoiceManager ) validateAssetHTLC (ctx context.Context ,
424456 htlc * rfqmsg.Htlc , circuitKey invoices.CircuitKey ) error {
0 commit comments