@@ -19,9 +19,12 @@ import (
1919 "github.com/lightninglabs/taproot-assets/fn"
2020 "github.com/lightninglabs/taproot-assets/rfqmath"
2121 "github.com/lightninglabs/taproot-assets/rfqmsg"
22+ "github.com/lightninglabs/taproot-assets/taprpc/rfqrpc"
23+ "github.com/lightningnetwork/lnd/lnrpc"
2224 "github.com/lightningnetwork/lnd/lnutils"
2325 "github.com/lightningnetwork/lnd/lnwire"
2426 "github.com/lightningnetwork/lnd/routing/route"
27+ "github.com/lightningnetwork/lnd/zpay32"
2528)
2629
2730const (
@@ -1219,6 +1222,62 @@ func (m *Manager) RfqChannel(ctx context.Context, specifier asset.Specifier,
12191222 return balancesMap , nil
12201223}
12211224
1225+ // InboundPolicyFetcher is a helper that fetches the inbound policy of a channel
1226+ // based on its chanID.
1227+ type InboundPolicyFetcher func (ctx context.Context , chanID uint64 ,
1228+ remotePubStr string ) (* lnrpc.RoutingPolicy , error )
1229+
1230+ // RfqToHopHint creates the hop hint representation which encapsulates certain
1231+ // quote information along with some other data required by the payment to
1232+ // succeed.
1233+ // Depending on whether the hold flag is set, we either return the lnrpc version
1234+ // of a hop hint or the zpay32 version. This is because we use the lndclient
1235+ // wrapper for hold invoices while we use the raw lnrpc endpoint for simple
1236+ // invoices.
1237+ func (m * Manager ) RfqToHopHint (ctx context.Context ,
1238+ policyFetcher InboundPolicyFetcher , channelID uint64 ,
1239+ peerPubKey route.Vertex , quote * rfqrpc.PeerAcceptedBuyQuote ,
1240+ hold bool ) (* zpay32.HopHint , error ) {
1241+
1242+ inboundPolicy , err := policyFetcher (ctx , channelID , peerPubKey .String ())
1243+ if err != nil {
1244+ return nil , fmt .Errorf ("unable to get inbound channel " +
1245+ "policy for channel with ID %d: %w" , channelID , err )
1246+ }
1247+
1248+ peerPub , err := btcec .ParsePubKey (peerPubKey [:])
1249+ if err != nil {
1250+ return nil , fmt .Errorf ("error parsing peer " +
1251+ "pubkey: %w" , err )
1252+ }
1253+ hopHint := & zpay32.HopHint {
1254+ NodeID : peerPub ,
1255+ ChannelID : quote .Scid ,
1256+ FeeBaseMSat : uint32 (inboundPolicy .FeeBaseMsat ),
1257+ FeeProportionalMillionths : uint32 (
1258+ inboundPolicy .FeeRateMilliMsat ,
1259+ ),
1260+ CLTVExpiryDelta : uint16 (
1261+ inboundPolicy .TimeLockDelta ,
1262+ ),
1263+ }
1264+
1265+ return hopHint , nil
1266+ }
1267+
1268+ // Zpay32HopHintToLnrpc converts a zpay32 hop hint to the lnrpc representation.
1269+ func Zpay32HopHintToLnrpc (h * zpay32.HopHint ) * lnrpc.HopHint {
1270+ return & lnrpc.HopHint {
1271+ NodeId : fmt .Sprintf (
1272+ "%x" , h .NodeID .SerializeCompressed (),
1273+ ),
1274+ ChanId : h .ChannelID ,
1275+ FeeBaseMsat : h .FeeBaseMSat ,
1276+ FeeProportionalMillionths : h .FeeProportionalMillionths ,
1277+ CltvExpiryDelta : uint32 (h .CLTVExpiryDelta ),
1278+ }
1279+ }
1280+
12221281// publishSubscriberEvent publishes an event to all subscribers.
12231282func (m * Manager ) publishSubscriberEvent (event fn.Event ) {
12241283 // Iterate over the subscribers and deliver the event to each one.
0 commit comments